Repository navigation
fix(ui-server): check login expiry against the clock inside the writer for profile, push, storage-notice and hygiene writes (#4176) - #4181
Merged
Conversation
…r for profile, push, storage-notice and hygiene writes (#4176) Session worker-profile save and bind, push subscription binding, storage notice dispatch and the hygiene review's worker procedures checked a login's expiry against a time the caller stamped before waiting for the write worker, so a login that expired while queued still passed. Each check now reads the clock inside the writer; the stamp still records updated_at, created_at and attempted_at, drives the draft cleanup and orders the storage notifier's time windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Collisions at head 3164ec2 ( |
Owner
Author
Independent reviewReviewed head 3164ec2 against base b77f5d6. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4181,
"head": "3164ec215c98b15904e6ccb2915bbdf0ae70a1de",
"base": "b77f5d6ece1bb2d82f9ed4daaea21d2a679db280",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
This was referenced Nov 17, 2026
schlessera
marked this pull request as ready for review
November 17, 2026 15:17
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 #4176
What changed
Five write-worker procedures checked a login's expiry against a time the caller stamped before it waited for the write worker. So a login that expired while the request was queued behind other writes still passed. Each check now reads the clock inside the writer:
saveProfileandbindDraftProfilecallauthorizeProfile(db, principalId, Date.now())inside their transaction. A login that expired while queued is refused withSessionProfileError401, and nothing is written. A bind leaves its draft in place.INSERT … SELECT … WHERE expires_at > ?bindsDate.now()for the expiry check. Such a login binds no device, andsubscribeanswersfalse.begindecides the recipient withowner(sub.principal_id, Date.now()). Such a login gets no attempt (null), and no receipt row is written.hygiene-writes.ts's workerauthority()checkedisUsablePrincipal(p, now()), andnow()is thetimethathygiene-review.tsstamps withnow()beforewrite(...). Every hygiene worker procedure that callsauthoritynow checks againstDate.now(), and refuses withHygieneAuthorityError.At every site, the stamp is still used wherever it records a time:
updated_at(profiles),created_at(push),attempted_at(storage receipts) and the hygiene card times. It still drives the draft-preference cleanup, and it still runs the storage notifier's reversed-clock guard, eligibility windows and quiet hours. Revocation is unchanged in every case, because it was already read from the row inside the transaction.Why this shape
This is the same pattern as #4177 (#4169) and the second review finding on #4168: authority is checked against the clock at the check, and the request's stamp is kept for recorded times. Replacing the stamp everywhere would also move recorded timestamps, retention and the storage notifier's time windows, which the issue keeps unchanged. Tests also inject a clock as the stamp, so the tests that drive quiet hours and retry windows with a fixed clock still do.
Audit for the same class. I read every write-worker module under
packages/ui-server/src(export const url = import.meta.url) that checksisUsablePrincipal,expires_ator principal ownership:principal-writes:createPrincipalreadsDate.now()for its creator check. The login stamp only drives pruning.maintenance-writes,shared-scan-writes,intake-writesandinteractive-share-writesreadDate.now()at the check.schedules/service-writesusessuppliedNow ?? Date.now(), and production suppliesundefined.The only further site was the hygiene review, which is fixed here.
Proportionate containment
false,null,HygieneAuthorityError).Proof
Held-writer tests run on real file-backed SQLite and the real write worker, held with
holdUntilReleased. A new shared helper,packages/ui-server/tests/helpers/held-writer.ts, spies onWorker.prototype.postMessageto see when the procedure is posted behind the hold. It then sets the login'sexpires_atto one millisecond past the latest possible stamp from a second connection, and waits for the clock to pass it.Failing-first, before the change:
The three stamp tests pass both before and after the change. After the change, the four touched test files (
app-writes-offloop,push,storage-offloop,inbox-writes-offloop) give 56 pass, 0 fail.Mutations on the fixed tree. Each was restored afterwards, and each failed only the named assertion:
src/ws/session-profile-writes.tsNO_PROFILE_RECORDED(7 pass 1 fail)src/ws/session-profile-writes.tsPROFILE_BIND_EXPIRY_CHECKED_AT_COMMIT(7 pass 1 fail)src/activity/push-writes.tsPUSH_SUBSCRIBE_EXPIRY_CHECKED_AT_COMMIT(7 pass 1 fail)src/storage/notify-writes.tsSTORAGE_NOTICE_OWNER_EXPIRY_CHECKED_AT_COMMIT(7 pass 1 fail)src/inbox/hygiene-writes.tsHYGIENE_AUTHORITY_EXPIRY_CHECKED_AT_COMMIT(7 pass 1 fail)src/ws/session-profile-writes.tsPROFILE_SAVE_UPDATED_AT_IS_THE_STAMP(7 pass 1 fail)src/ws/session-profile-writes.tsPROFILE_DRAFT_CLEANUP_USES_THE_STAMP(7 pass 1 fail)src/ws/session-profile-writes.tsPROFILE_BIND_UPDATED_AT_IS_THE_STAMP(7 pass 1 fail)src/activity/push-writes.tsPUSH_SUBSCRIBE_CREATED_AT_IS_THE_STAMP(7 pass 1 fail)src/storage/notify-writes.tsSTORAGE_NOTICE_ATTEMPTED_AT_IS_THE_STAMP(7 pass 1 fail)Also:
bun run typecheckis clean. No exports changed.hygiene-review.test.tsandgovernance-policy.test.tsfail the same set of test names withorigin/main's source as with this change. Those failures come from the sandbox: the agent worker boundary is unavailable becauseunshareis not permitted.{"version":1,"kind":"brain-check-pr-receipt","head":"3164ec215c98b15904e6ccb2915bbdf0ae70a1de","base":"origin/main","mode":"focused","startedAt":"2026-11-17T11:36:12.338Z","finishedAt":"2026-11-17T11:37:03.159Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":16356.592958999998},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":134.7701920000036},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":117.87566099999822},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":21.399405000003753},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":34171.427644999996}]}Checklist
packages/ui-server/carries a recorded independent review of its head. The orchestrator requests it..changeset/4176-writer-clock-expiry.md).Anything left open
reference-grants.test.ts. Whichever lands second can switch it totests/helpers/held-writer.ts. This is optional and is not part of the acceptance criteria.🤖 Generated with Claude Code