Repository navigation
CONTRACT: fix(ui-server): bind a chat's safety history to the account, not the login (#3952) - #3965
Merged
Merged
Conversation
…, not the login (#3952) Every owner sign-in mints its own principal, but a chat's safety record was bound to the exact principal that started it, so continuing a chat from another device was refused as a safety principal mismatch. Under the maintainer's ruling (option A), the history belongs to the account. `sameAccount` (account-partition.ts) treats two principals as one account only when `accountScope` puts them in the same partition in every auth mode: today the same principal, or two owner logins. An unresolvable principal is unknown and shares with nobody. It replaces the exact comparisons in collection begin (session, dialogue owner, fork source), collection binding (binding and retained owner), safety reads and review target/eligibility. Migration 087 applies the same rule in the safety_decision_identity trigger. Read snapshots, cursors, review handles, receipts and the verdict's principal stay bound to the exact login, and no stored row is rewritten. Two existing tests treated a second password login as a foreign owner; they now assert the new rule and keep a real other-account refusal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
schlessera
force-pushed
the
fix/3952-safety-account-partition
branch
from
November 11, 2026 03:02
a34d071 to
0838eea
Compare
schlessera
marked this pull request as ready for review
November 11, 2026 03:04
schlessera
marked this pull request as draft
November 11, 2026 03:37
schlessera
marked this pull request as ready for review
November 11, 2026 03:37
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 #3952
What changed
Every owner sign-in mints its own principal, but a chat's safety record was bound to the exact principal that started it. So when the owner continued a chat from another device (or after their login renewed), every turn was refused as
Safety principal mismatch(orSafety history ownership mismatchonce the chat had a dialogue owner). That is a refusal of the turn since #3812; before #3812 it latched the whole brain on a hosted instance. Following the maintainer's ruling on #3952 (option A), a chat's safety history now belongs to its account. Any owner login continues the chat, and its turns join the same safety history and taint. It can also read that history and review its occurrences. An agent, a proxy user, a system principal, or a principal whose row no longer exists is still refused, exactly as before. Stored rows keep the principal that wrote them; nothing is rewritten.sameAccount(db, bound, principal)(packages/ui-server/src/middleware/account-partition.ts) decides it from the existing partition notion. Two principals are one account only whenaccountScopeputs them in the same partition in every auth mode. A record keeps who made it, not the auth mode it was made under. Today that means the same principal, or two owner logins. An ambient principal shares the owner's partition only in some modes, and agent and system principals hold none, so each stays bound to itself. An unresolvable principal is unknown, never the same account.Safety principal mismatchbeginSafetyCollectionSafety history ownership mismatch(dialogue owner)beginSafetyCollectionSafety fork history ownership mismatchbeginSafetyCollection(handoff source)Safety binding owner mismatchbindSafetyCollection(runs inside begin for a resumed chat)Safety retained owner mismatchbindSafetyCollectionSafetyHistory.authorizesafetyReviewTarget,eligiblesafety_decision_identitytrigger (session, collection, dialogue owner)087_safety_account_partition.sqlConflicting safety collection), catalog creation, read snapshots/cursors, review handles and receipts, per-principal limits, the verdict'sprincipalIdWithout the bind and retained-owner changes the turn still fails: begin calls
bindSafetyCollectionfor a resumed chat, which compared the turn's principal to the chat's exactly. The mutation table shows it.Why this shape
Reviews get the same treatment. A verdict already needs a live password-mode owner epoch: owner kind, password or passkey, rechecked in the acquired transaction (
authorized,safety-reviews.ts). Every owner login is that same human, so letting one review a chat another login started grants no authority the reviewer lacks. Leaving reviews exact would break option A in practice. The device continuing the chat could not clear occurrences its own turns raised, because the review target compares against the chat's starting principal. And once that login expires, nobody could review the chat at all. What belongs to one login stays exact: the prepared handle (commit requires the preparing principal), its fingerprint over the authority epoch, receipts, the per-principal pending limit, and theprincipalIdthe verdict records. The DB trigger is the backstop, so it is updated to the same rule. Reads follow for the same reason: the ruling says owner principals share a chat's safety history, and the review body comes from a read.Partition from the principal row, not stored on safety rows. The acceptance criterion forbids rewriting history, and the existing rows hold principal ids, so the comparison maps a stored principal to its account at check time. The write worker does not know the auth mode, hence "same partition in every mode" rather than calling
accountScopewith the current mode. Within those cases this is narrower than the browser partition, never wider. The cost: a principal row pruned 30 days after expiry leaves an id nobody can vouch for, and that chat is refused for good. Filed as #3962 (needs: decision).Not taken: passing the auth mode into the write worker (it is created in five places that do not know it) and recording the partition on every safety row (a schema change plus a backfill question). Both belong to #3962's options.
Security properties kept
nullare each refused at begin, fork, read, review and in the trigger. A refused begin leaves no collection.history_owner_idand generation, inherits the chat's unresolved occurrences and restriction, and extends the same ledger.safety_sessions.principal_idand earlier records are byte-identical after another login's turn.Review follow-up
Independent security review (gpt-6-astra) at
a34d07125No blocking finding. These all passed: every auth mode, taint retention, the login-bound handles, cursors and receipts, migration 087, and the review widening. Two wording findings, both fixed in the same
CONTRACT:commit (amended):docs/http-api.mdstill said separate owner logins have no equivalence. It now states the account rule, and keeps that a cursor stays with the one login that read it (another login's cursor is refused as expired, 409).docs/integration-contract/http.mdsaid a missing principal shares with nobody. ButsameAccountreturns true for two equal ids before resolving them, and migration 087 keeps the same exact-id exception; both are the existing exact-comparison behaviour, kept as is. The section now says: a principal id always matches itself; two different ids match only when both resolve to the same account partition; a missing or unresolvable principal matches no other id. The same imprecise wording was also corrected in the decision record (session-safety-reviews.md), the comment in migration 087, and thesameAccountJSDoc. Code is unchanged, andgit diffshows only comment lines in those two source files.Collisions
bun scripts/collisions.ts --json --pr 3965ata34d07125: one textual collision, with draft #3622 (durable owner trust Settings publication) indocs/http-api.md.git merge-treeof #3622's head6a814ee73gives four three-way conflict hunks indocs/http-api.md, at the same places both againstorigin/mainand against this branch. So they exist against main already, and this PR adds none:GET /api/sessions/:id/safetyrow next to CONTRACT: feat(ui-server): add durable owner trust Settings publication #3622's/api/trust-settingsrows;To resolve: keep both route families and the account wording, and recount the endpoints. #3622 also conflicts with main in
packages/ui-server/src/app.tsandpackages/ui-server/tests/http-inventory.test.ts; this PR touches neither.At
0838eea7dthe same command also reports draft #3662 (review individual safety triggers in chat) indocs/http-api.md. Merged againstorigin/mainit has no conflicts. Against this branch it has one hunk, created by the P2 fix: #3662 inserts itsentries=1paragraph directly above the old "exact live principal… no equivalence" paragraph that this PR rewrites. To resolve: keep #3662'sentries=1paragraph followed by this PR's account paragraph, and drop the old one. #3662's only new principal comparison is a snapshot/cursor check (s.principalId!==principal.id), which correctly stays bound to one login.Proportionate-containment checklist
dialogue-storage.ts, filed as ui-server: an owner continuing a chat by voice from another device is refused as a dialogue ownership mismatch #3963) or chat deletion, whichchat-history-deletion.mdbinds to the exact principal by decision.safety recording refused one turn before deliveryline naming the check (error.message), and the client getsSAFETY_RECORDING_UNAVAILABLE.safety-account-partition.test.ts"a principal of another account is still refused…" refuses each foreign principal, leaving the chat's history untouched. "an owner login never takes over a chat bound to an agent or to another proxy user" refuses the owner login and then continues the chat with its exact principal.Proof
New file
packages/ui-server/tests/safety-account-partition.test.ts(10 tests, real FULL write worker, Odysseus world).Failing-first, with only
sameAccountand the test file added, on theorigin/mainguards (60d7967): exit 1, 7 fail, 2 pass. Each refusal's cause, from the structured refusal lines:Safety principal mismatchSafety history ownership mismatchSafety fork history ownership mismatchSafetyReadUnavailable("unavailable")SAFETY_SECOND_OWNER_REVIEW_TARGETreceived"unavailable"Fix: 10 pass, 0 fail, exit 0.
Mutations, each applied to the fix, the file re-run, then restored with
git checkout --. The tree was clean afterwards. Every one exits 1:sameAccountreturnstrue("any principal")expected a rejection, but the promise resolved), no takeover, pruned owner unknown, foreign fork, foreign read,SAFETY_FOREIGN_REVIEW_TARGET_REFUSEDsameAccounttrue for any two resolvable principalsSafety principal mismatchSafety history ownership mismatchSafety binding owner mismatchSafety retained owner mismatchSafety fork history ownership mismatchunavailable,unavailable,generation_changed)SAFETY_SECOND_OWNER_REVIEW_TARGET×2,SAFETY_SECOND_OWNER_PREPARES_A_REVIEWreceivedrefused)SAFETY_DECISION_TRIGGER_CHECKS_THE_SESSION/_COLLECTION/_DIALOGUE OWNER(did not throw)safety decision identity or exposure mismatchThe trigger case has a control: each crafted row set refuses the agent's verdict only because of the named record. Setting that record to the agent too admits the same insert.
Two existing tests changed with the rule. Both treated a second password login as a "foreign owner". In the principals model a password login can only be the one owner, and the #3952 ruling makes that login the same account. Each test now asserts the new rule and keeps a genuine other-account refusal:
safety-history.test.ts"cursor scope…": another owner login using the first login's cursor gets 409expired, because the cursor stays with one login (CURSOR_SCOPE_IS_ONE_LOGIN; it was 404). An agent gets 404 (CURSOR_SCOPE_FOREIGN_ACCOUNT).owner-safety-review.test.ts"signed delegated cookies and owner cookies on another account's history cannot mutate it": the agent cookie still gets 403. Another owner login prepares a review (200,OWNER_REVIEW_ANOTHER_LOGIN_IS_THE_SAME_ACCOUNT). A history bound to another account gives 404unavailableto both owner logins (OWNER_REVIEW_FOREIGN_ACCOUNT_HISTORY).sameAccountreturnstruefails both (CURSOR_SCOPE_FOREIGN_ACCOUNTreceived 409,OWNER_REVIEW_FOREIGN_ACCOUNT_HISTORYreceived 200). An exact session read failsCURSOR_SCOPE_IS_ONE_LOGIN(received 404). An exact review target failsOWNER_REVIEW_ANOTHER_LOGIN_IS_THE_SAME_ACCOUNT(received 404).Full local proof. Real exit codes, read from each run's own exit line.
bun run check:pr --base origin/main0838eea7d(ona875fa5f9)NODE_OPTIONS=--max-old-space-size=16384 bun run typecheck0838eea7dbun run api-report0838eea7dsameAccountis not on a public entry point)ui-server/tests/no-console.test.ts0838eea7dsafety-account-partition.test.ts+http-inventory.test.tsd3e1a7053(the review fixes, before the rebase ontoa875fa5f9)bun run test ./packages/ui-server/tests(every ui-server test file)a34d07125(on067d1904b)bun run test ./tests(root suite)a34d07125bun run lint0838eea7d, insidecheck:prBetween
a34d07125and0838eea7donly two things changed: the review follow-up below (wording only: docs, plus comments in migration 087 andaccount-partition.ts, no code) and the rebase ontoa875fa5f9, which touches none of this PR's paths. An earlier fullui-serverrun at the pre-rebase head4e9ce1667had 2 failures (5737 pass, exit 1): the two rewritten tests above. The root suite passed there too (2239 pass, exit 0).{ "version": 1, "kind": "brain-check-pr-receipt", "head": "4776acc93c5cb7ed9beeda5be62273c94ef6b820", "base": "origin/main", "mode": "focused", "startedAt": "2026-11-11T03:35:29.998Z", "finishedAt": "2026-11-11T03:36:36.882Z", "checks": [ { "name": "all lint and leakage gates", "categories": [ "changeset" ], "outcome": "passed", "elapsedMs": 10566.588164 }, { "name": "environment documentation", "categories": [ "changeset" ], "outcome": "passed", "elapsedMs": 118.49214500000016 }, { "name": "pending changeset package names", "categories": [ "changeset" ], "outcome": "passed", "elapsedMs": 123.35830999999962 }, { "name": "contribution changeset", "categories": [ "changeset" ], "outcome": "passed", "elapsedMs": 22.57850099999996 }, { "name": "affected fast invariants", "categories": [ "verify", "unit" ], "outcome": "passed", "elapsedMs": 55966.46769199999 } ] }Checklist
docs/reflect the change, or nothing documented moved. (session-safety-reviews.md,http-api.md)docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed.Anything left open
needs: decision): a chat whose starting owner login was pruned (30 days after it expired) is refused for good, because its principal is unknown. Options there: record the account on safety rows, keep a pruned principal's kind, or owner-facing "start a new chat" copy.dialogue-storage.ts), so continuing a chat by voice from another device is refused. Needs scoping and a ruling on whether option A extends to it.docs/decisions/chat-history-deletion.md): another login cannot delete the chat. Not changed here.🤖 Generated with Claude Code