Repository navigation
Description
Context
Found while answering the independent review of #4168 (refs #4138). It is the same bug class as that review's second finding: an authorization check that compares a login's expiry against a time stamped before an asynchronous wait.
POST /api/auth/principals/:id/reference-grants stamps now: Date.now() when it builds the call (createGrant, packages/ui-server/src/middleware/principals.ts:244-252). It then awaits the write worker. Inside the worker's transaction, createReferenceGrant checks the target and the creating owner with isUsablePrincipal(…, input.now) (isUsablePrincipal(target, input.now), packages/ui-server/src/db/reference-grants.ts:138-139). Any time spent queued behind other writes therefore falls outside the expiry check. A target or creator login that expires while the request waits still passes. Revocation is unaffected, because it is read from the row inside the transaction. Grant revocation takes the same now: Date.now() stamp (principals.ts:281); whether its use of that time is an authority check needs reading.
Observed from the code only: no reproduction has been run. The analogous deletion case was reproduced and fixed in #4168, with a held-writer test in packages/ui-server/tests/chat-lifecycle.test.ts.
Scope
Check principal usability for reference-grant creation (and revocation, if it is an authority check there) against the clock at the check inside the writer transaction. Keep input.now for recorded timestamps and retention.
Out of scope
Other isUsablePrincipal callers (safety reviews already read the clock inside their transaction), grant semantics, limits and retention.
Acceptance criteria
- A creating owner or target login that is usable when the request is stamped but expires before the writer commits is refused (
ReferenceGrantPrincipalError). This is proven by a real-SQLite test that holds the writer and fails before the change. - The stamped time still records
createdAtand drives retention exactly as before.
Verification
Run the failing-first held-writer test. A mutation back to input.now must fail it.
Contract impact
None: no shape changes. A request that previously succeeded on an expired login is now refused.
Activity
schlessera commentedon Nov 17, 2026
Decision (maintainer, 2026-11-17):
priority: p2, in 0.45.0.schlessera commentedon Nov 17, 2026
Claimed for implementation. Claim token:
claim-cafb11c7. Branch:fix/4169-grant-expiry-clock.Path collision with draft #4002 (reference-grants.ts); closure-only with #3622, #4167, #4168 and others.
test(ui-server): record the pinned-clock reference fixture's grant as…
fix(ui-server): check reference-grant login expiry against the clock …
schlessera commentedon Nov 17, 2026
Merged in #4177 as
18da31bc6through the integration lease (orchestrator merge queue for 0.45.0). Candidate confirmation passed on the exact head; the squash's own main run carries the post-merge heavy categories.