Status: accepted · Date: 2026-11-09 · Amends: ADR-0003
Enforcement: packages/api/src/platform/rpc/request-authority.test.ts, packages/api/src/platform/rpc/session-authority.test.ts, packages/auth/src/auth-round-trips.test.ts, packages/api/src/platform/rpc/session-revocation.test.ts.
Every signed-in request previously read the Session and User from Postgres. A mobile scoped call read it twice. The files gateway read it twice and then read membership. Issue #189 and PRs #192–#194 reduced the browser presentation read; the owner accepted a 60 second revocation window for ordinary data access to remove the remaining serial session read.
Decision
- SSR, oRPC and the files gateway read the request session from Better Auth's signed compact cookie snapshot, at most 60 seconds old, or from Postgres on a miss.
- Procedures that create, reveal or redirect credentials or standing channels, change account control, administer Users, touch billing or push, or approve a pending agent tool call that lets a run continue (
agentTools.resolve) read the database session. Resolving a stored proposal (proposals.resolve) is a one-shot data write, like the manual path, and uses the request session. The authority middlewares andsession-authority.test.tsclassify every procedure (until 2026-11-28 amarkAuthoritativemarker). Admin and sensitive Better Auth endpoints remain authoritative. - The membership reader checks
memberon every request. RLS checksapp.org_id()on every tenant statement. - The Better Auth handler strips the snapshot from every endpoint except the presentation
GET /get-session. - The cookie integration forwards
Set-Cookieon a miss. A hit does not re-issue the snapshot. - The mobile scope header is compared with the request session. Authoritative procedures compare it again with the database read.
Consequences
Session reads records the revocation behavior. A copied cookie can continue to access ordinary data for at most 60 seconds. An SSE request keeps the identity read at its start. Presigned download and upload URLs require a database session check before minting. A revoked session cannot mint a new URL; one minted before revocation remains usable until expiry, at most 15 minutes. Bump session.cookieCache.version when fields used by the server change. A mobile RPC response does not store the re-issued cookie, so subsequent requests can miss again. Local measurements are recorded in the measurement report.
Alternatives
- The status quo retains a serial database round trip on every request.
- KV
secondaryStorageis eventually consistent, has no atomic operations, and moves sessions out of Postgres. - Isolate-local memory has no cross-isolate invalidation.
- A shorter
maxAgereduces the window but increases misses.
Amendment (2026-11-28): one request authority
The six rules above were implemented in three places (the procedure middlewares, the files gateway, the tool authorization) and had drifted. packages/api/src/platform/rpc/request-authority.ts now owns them: a caller asks for the acting User or the Member's tenant at the request authority (rule 1) or the database authority (rule 2). What that settled:
- The database session must be the request session's User and Session, and for a tenant it must name the same Active Organization. The files gateway already refused otherwise and the tools refused a changed Active Organization;
uploads.prepare,uploads.resume,uploads.signPartanddocuments.prepareTextused the database's Active Organization silently and now refuse (FORBIDDEN, "The active organization changed.") like the others. - Rule 3 at the
databaseauthority:memberis read again, not taken from the request's memo, so a tool call inside a long assistant stream sees a membership revoked since the stream began. Arequest-level ask still reads it once per request. - Rule 6: the scope is compared once with the database read (it was compared twice).
- An OAuth access token is refused by the authority middlewares, as before; it may still act through the tool catalog, where the token's User is what the database vouches for.
- Only two middlewares read the database session,
requireDatabaseSessionandrequireDatabaseTenant; a feature can no longer mark its own.
Amendment (2026-11-29) — Scoped RPC refusals
At either authority, a captured tuple with no live Session returns UNAUTHORIZED (401), so a client can start reauthentication. A different live tuple or an anonymous scope against a live Session returns SCOPE_MISMATCH (409). A malformed header returns BAD_REQUEST (400).
A keyed collection write uses request authority for its first admitted attempt. Before returning a stored receipt, it asks database authority for the live Session and membership. Each replay asks independently, including inside a batch.