Skip to content

Admin page: clear the result cache and change federation settings live - #83

Merged
alisman merged 2 commits into
masterfrom
session/cache2
Oct 27, 2026
Merged

alisman merged 2 commits into
masterfrom
session/cache2

Conversation

@alisman

@alisman alisman commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Supersedes #82 — this branch contains its commit (ced27b5, clearing the result cache) plus the federation settings on top.

What

A signed-in user whose email is in ADMIN_EMAILS gets Admin in the account menu, opening /admin:

  • Result cache — clear it for the whole deployment, and see when it was last cleared and by whom.
  • Federation settings — every federation setting (databases, MCP peers, patient-level federation, access), with its environment value (secrets only as set / not set) and any override in force. An administrator can set or reset one for the whole deployment; recent changes are listed.

How

  • lib/settings.ts: an app_setting row overrides the environment variable of the same name for every server process within seconds. Federation code reads settings through setting(name), never process.env. Database addresses and credentials are never editable.
  • app_setting_log records every change, who made it, and the value before and after (append-only for the app role).
  • cacheVersion() (lib/next-cache.ts) — the data version plus the settings' fingerprint, which includes the last clear — is now every cached entry's key argument, so nothing computed under old settings is served under new ones. A clear also still expires RESULT_TAG. Cohort locks keep dataVersion() alone.
  • requireAdmin (lib/auth.ts) refuses with 404 where the deployment has no sign-in and 403 for anyone signed out or not listed.

Deploy

Requires migration db/migrations/0010_app_settings.sql — run npm run db:migrate (with MIGRATION_DATABASE_URL) against production before deploying. Already applied to the dev Supabase database.

Testing

  • test/settings.db-test.ts (new), test/auth.test.ts, test/result-cache-tag.test.ts
  • Unit tests: 1674 pass; typecheck clean. Full gate left to CI.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q3ezTXZQm7eQwpY7oWgS4D

alisman and others added 2 commits October 27, 2026 13:22
A signed-in user whose email is in ADMIN_EMAILS gets "Admin" in the account menu, opening /admin,
whose one action is clearing the result cache for the whole deployment.

Every 'use cache: remote' body now starts with resultEntry() (lib/next-cache.ts), which sets the
day's lifetime as before and tags the entry RESULT_TAG; POST /api/admin {action: "clearCache"}
expires that tag with revalidateTag(tag, {expire: 0}). On Vercel that is the Runtime Cache shared
by every function instance; elsewhere it is the answering process's own memory. No database
change: nothing records the clear.

requireAdmin (lib/auth.ts) refuses with 404 where the deployment has no sign-in and 403 for anyone
signed out or not listed. With the development sign-in anyone can claim an address, so there it is
a convenience, not a guard; that sign-in is already refused on Vercel production.

Verified on an isolated next dev (in-process Postgres, dev sign-in): Explore 55 ms cached ->
707 ms recomputed after a clear -> 36 ms cached again, the study list likewise; a signed-out and
a non-admin request are refused; a non-admin has no menu item; the page and its confirm flow
driven in Chromium with no console errors. test/auth.test.ts covers who is an admin;
test/result-cache-tag.test.ts fails on a cached body without resultEntry() (checked by planting
one). Gate: lint, build, unit (1674) and postgres (66) passed; stopped before e2e.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTZPdCcLJ4FcYtykedj
…ache

/admin also lists every federation setting (databases, MCP peers, patient-level federation,
access) with its environment value and any override, and lets an administrator set or reset one
for the whole deployment. lib/settings.ts: an app_setting row (migration 0010) overrides the
environment variable of the same name for every process within seconds; federation code reads
settings through setting(name), never process.env. cacheVersion() — the data version plus the
settings' fingerprint, which includes the last clear — keys every cached entry, so nothing computed
under old settings is served under new ones; a clear also still expires RESULT_TAG. Database
addresses and credentials are never editable.

Cherry-picked from the WIP commit 17cc230 (session/admin-federation) onto the cache-clearing
commit; where they overlapped, the WIP version already contained the cache clearing. Requires
db/migrations/0010_app_settings.sql. Unit tests (1674) pass; the gate has not been run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q3ezTXZQm7eQwpY7oWgS4D
@vercel

vercel Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cbiolab-genie Ready Ready Preview Oct 27, 2026 7:50pm UTC
cohort-lab Ready Ready Preview Oct 27, 2026 7:50pm UTC

Request Review

@alisman
alisman merged commit 0401b16 into master Oct 27, 2026
10 checks passed
@alisman
alisman deleted the session/cache2 branch October 27, 2026 20:18

This branch was successfully deployed

1 active deployment
Preview – cohort-lab — 18a4883b Deployed Oct 27, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant