Skip to content

fix(graphql-server): a flush makes rebuilt hosts read their settings again - #2018

Open
yyyyaaa wants to merge 1 commit into
mainfrom
fix/flush-invalidates-settings-loaders
Open

yyyyaaa wants to merge 1 commit into
mainfrom
fix/flush-invalidates-settings-loaders

Conversation

@yyyyaaa

@yyyyaaa yyyyaaa commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Fixes the constructive half of constructive-io/constructive-planning#2539: a change to a database's CORS list (or its other API settings) can stay invisible on some of its hosts after a flush.

Why a flush wasn't enough

  • A host's API structure holds the settings the loaders resolved (resolveModuleSettings): CORS origins, auth, RLS, database, pubkey and WebAuthn settings. The structure is cached per host in svcCache.
  • Each loader also keeps its own cache: 5 minutes for corsOrigins, 1 minute for the others.
  • flushService evicted the hosts but left the loader caches. A host rebuilt in that window got the loaders' old copy, and kept it as long as the host stayed cached.
sequenceDiagram
  participant D as Desktop build
  participant S as GraphQL server
  D->>S: write cors_settings [preview]
  D->>S: sign in on auth-<db>, create site on api-<db>
  Note over S: auth/api hosts cached, corsLoader caches [preview] (5 min)
  D->>S: write cors_settings [preview, site], then touch a route
  S->>S: schema:update → flushService evicts the hosts
  D->>S: next request on auth-<db>
  Note over S: before: rebuilt from corsLoader → [preview], site refused<br/>after: loaders cleared → reads [preview, site]
Loading

On devnet this blocked sign-up on every new Desktop app's deployed site: auth- and api-<db> refused the site's origin while admin-<db> allowed it.

Change

  • invalidateApiSettings(databaseId?) in middleware/api.ts clears the loader registry the host builds read.
  • flushService (schema:update), flushAllServices (listener reconnect) and the authenticated /flush call it before they evict hosts.

The other half of #2539, sending schema:update from the settings tables themselves, belongs in constructive-db. Until it lands, Desktop keeps writing a route back to trigger the flush.

🤖 Generated with Claude Code

https://claude.ai/code/session_017WbsG8xSPVNk24sN2QThLw

…again

A host's API structure carries settings the loaders resolved: CORS origins,
auth, RLS, database, pubkey and WebAuthn settings. Each loader keeps its own
cache (5 minutes for CORS, 1 minute for the others), and flushService only
evicted the host. A host rebuilt within that time took the loaders' old copy
and kept it for as long as the host stays cached.

So a database whose CORS list gained an origin kept refusing it on every host
read in the 5 minutes before the write, even after a schema:update: a new
app's deployed site could not sign up through its auth host
(constructive-planning#2539).

flushService, flushAllServices and the authenticated /flush now clear the
settings loaders for the database (or for all) before they evict its hosts.
@luxor-code-review

luxor-code-review Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This change introduces a flush middleware (flush.ts) that invalidates cached settings/loader state in response to cache-invalidation signals, wires it into the middleware stack in api.ts, and adds flush.test.ts covering the flush behavior. Candidate concerns around stale CORS origins after flush, unauthenticated flush triggering, and invalidation ordering were checked against the loader registry and create-loader.ts implementations and did not hold up; the diff is clean.

Reviewed commit: 368666d

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