Repository navigation
fix(ui-server): check reference-grant login expiry against the clock inside the writer transaction (#4169) - #4177
Merged
Merged
Conversation
…inside the writer transaction (#4169) Grant creation compared the target and creating owner's expiry with the time the route stamped before it waited for the write worker, so a login that expired while queued still passed. Read the clock at the check; the stamp still records created_at and drives retention. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
9 of 10 tasks
Owner
Author
Independent reviewReviewed head bb8e83f against base c26fb22. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4177,
"head": "bb8e83fc10ec87423fe6a74f3299c664423d92f9",
"base": "c26fb229fa1ef920ce219e77256e859e9982c263",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
This was referenced Nov 17, 2026
schlessera
marked this pull request as ready for review
November 17, 2026 12:52
… data (#4169) The reference worker fixture runs on the pinned 2026-07-12 clock, and its owner login expires a day later. Creating its grant through createReferenceGrant now checks that login against the real clock, which refuses it. The fixture needs a recorded grant, not a request, so insert the row at AT, as it already does for the principal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Independent reviewReviewed head b939714 against base 94f5580. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4177,
"head": "b939714e9d6945758b9db9b0c95658c64d1cbf7c",
"base": "94f55806c3fe2686c5e026d368fbe0683fac265a",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
This was referenced Nov 17, 2026
5 of 6 tasks
schlessera
marked this pull request as draft
November 17, 2026 18:44
schlessera
marked this pull request as ready for review
November 17, 2026 18:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4169
What changed
POST /api/auth/principals/:id/reference-grantsstampsnow: Date.now()and then waits for the write worker. Inside the worker's transaction,createReferenceGrantchecked the target and the creating owner withisUsablePrincipal(…, input.now), so a login that expired while the request was queued behind other writes still got a grant. The check now reads the clock inside the writer transaction, and such a login is refused withReferenceGrantPrincipalError, which the route answers asUnknown principal(404).input.nowstill recordscreated_at, drives retention of revoked grants and feeds the live-grant capacity count, exactly as before.Why this shape
This follows the fix in #4168 (second review finding): check authority against the clock at the check, and keep the request's stamp for recorded times. Replacing the stamp everywhere would also have moved
created_atand the retention cutoff, which the issue keeps unchanged.Revocation.
revokeReferenceGrantusesinput.nowonly as therevoked_atvalue it writes (revokeReferenceGrant,packages/ui-server/src/db/reference-grants.ts:162-165). It makes no principal or expiry check. The caller's owner authority is checked by the route guard before the await, the same as for every route. So the stamp there is a recorded time, not an authority check, and it is unchanged.Audit of ui-server for the same class. I grepped every
isUsablePrincipal(andexpires_at > ?site inpackages/ui-server/src. Most readDate.now()or anow()clock at the check, or run synchronously with no await between stamp and check (inbox escalation, inbox notify, route guards,authGuard). Safety reviews already read the clock inside their transaction. Chat deletion is #4168. Three sites reuse a pre-wait stamp inside a writer procedure: session worker-profile save and bind, push subscription binding, and storage-notice dispatch. Issue scope excludes other callers, so they are filed as #4176 with held-writer acceptance criteria.Proportionate containment
coveringReferenceGrant,isLiveReferenceGrant) cover that and are unchanged.reference-grants.test.tsstill create grants for other, usable principals.Proof
Failing-first, before the change (new describe block "reference grant creation behind a held writer" in
packages/ui-server/tests/reference-grants.test.ts, real file-backed SQLite, real write worker held withholdUntilReleased, expiry set tostamp + 1from a second connection aftercreateGrantwas posted):After the change:
18 pass, 0 fail.Mutations on the fixed tree (each restored after):
input.nowREFERENCE_GRANT_TARGET_EXPIRY_CHECKED_AT_COMMIT(17 pass, 1 fail)input.nowREFERENCE_GRANT_CREATOR_EXPIRY_CHECKED_AT_COMMIT(17 pass, 1 fail)REFERENCE_GRANT_RETENTION_USES_THE_STAMP(17 pass, 1 fail)createdAtfrom the in-transaction clockREFERENCE_GRANT_CREATED_AT_IS_THE_STAMP(17 pass, 1 fail)Also:
bun run testonreference-grants,principal-routes,principalsandgithub-reference-accesstests gave 64 pass, 0 fail. Rootbun run typecheckis clean. No exports changed.Pinned-clock fixture (second commit)
Candidate confirmation on
04762013bfailed in unit (4): eight tests inpackages/ui-server/tests/reference-writes-offloop.test.tsthrewReferenceGrantPrincipalErrorwhile building their fixture. That fixture runs on the pinned2026-07-12clock and gives its owner loginexpires_at = AT + 1 day, so in real time the login expired months ago. The old check passed only because it trusted the caller'snow: AT. One of its tests also advances the fake clock two days to end that authority, so the expiry cannot simply move into the real future.The fixture was wrong, not the check. The only production caller is the write-worker procedure behind the route, which runs on the real clock, so an injectable clock would be a seam that only tests use. The fixture needs a recorded grant, not a request, so it now inserts the grant row at
AT, as it already inserts the principal. Production code is unchanged in this commit.REFERENCE_OPERATION_REACHED_POOL_BOUNDARYin "revocation sees a first private publication…" (7 pass, 1 fail). Restored afterwards.Date.now(), so none has this problem. These are 9 test files,experiments/git-read-qualification.test.tsandscripts/native-proof/reference-efficiency.ts, whose clock starts atDate.now().check:prdoes not select them.reference-grants18/0,reference-writes-offloop8/0,reference-source30/0,reference-worktrees25/0,reference-tools35/0,reference-worktree-hygiene36/0,github-reference-access19/0,account-writes-offloop24/0.github-reference-git(offline git child),reference-transportandhttp-supported-mounts(bubblewrap/user namespaces unavailable) fail identically with main'sreference-grants.ts. None of their failures involve the grant refusal.NODE_OPTIONS=--max-old-space-size=8192 bun run typecheckis clean.{"version":1,"kind":"brain-check-pr-receipt","head":"abe191496ff08d18db649ecb0c1804b3c0ac3a10","base":"origin/main","mode":"focused","startedAt":"2026-11-17T18:19:21.767Z","finishedAt":"2026-11-17T18:20:16.940Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":16598.572792},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":170.4759050000066},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":155.73637700000108},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":27.89847000000009},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":38199.580267}]}Checklist
packages/ui-server/carries a recorded independent review of its head. The orchestrator requests it..changeset/4169-reference-grant-expiry-clock.md).Anything left open
🤖 Generated with Claude Code