Repository navigation
CONTRACT: fix(ui-server): keep a chat's safety history with its account after the starting login is pruned (#3962) - #4128
Merged
Conversation
…nt after the starting login is pruned (#3962) Principal cleanup deletes a login 30 days after it expires or is revoked. A chat's safety records then named a principal nobody could vouch for, so `sameAccount` refused every later login and the chat could never be continued. Under the maintainer's ruling (option A), the account is stored with the safety history. Migration 089 adds `principal_account` beside `principal_id` on safety_sessions, safety_collections and dialogue_owners. The server writes it from the principal's own row when it writes the record (`principalAccount`), never from a request: 'owner' for an owner login, NULL for a principal that is only itself. Legacy rows gain it only where a principal row still proves it at upgrade; already-pruned history stays unknown. `sameAccount` takes a record's stored account and uses it only when the principal row is gone. Corrupt evidence, or a stored account a live row contradicts, matches nobody. The caller is still a bare id that proves its account by its own current row, so a pruned, expired or revoked login gains nothing. Admission, fork, binding, reads, review target/eligibility and the safety_decision_identity trigger all pass the stored evidence. Attribution, records, verdicts, gaps and generations are not rewritten, and nothing enters the provider-facing conversation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 17, 2026
Merged
Owner
Author
Independent reviewReviewed head 1bcb99f against base 40779d4. Reviewer: agent. 1 finding: 0 fixed, 0 filed, 0 rejected, 1 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4128,
"head": "1bcb99fdaafe450c2ef86e47bee2ec71b7c4a309",
"base": "40779d4983def309fc5a036ce585c581a68839c1",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-server/migrations/089_safety_durable_account.sql:75: The dialogue-owner rejection evaluates to NULL when principal_account is NULL and its principal is foreign or pruned. NOT EXISTS then ignores that owner, allowing a verdict the ownership guard should refuse. Reproduced with the actual trigger for both a live foreign agent and a pruned unknown principal. Coalesce the account comparison before negating it."
}
]
} |
…ccount in the decision trigger (#3962) Inside the dialogue owner's NOT EXISTS, d.principal_account='owner' is NULL when the account is NULL, so the whole rejection term was NULL and a foreign or pruned dialogue owner no longer refused the verdict. Every account comparison in 089's trigger now uses IS, as do the dialogue owner's principal and generation comparisons, so no term in a negated clause can be NULL. The positive session and collection clauses only ever refused on NULL. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
Independent reviewReviewed head 1bcb99f against base 40779d4. Reviewer: agent. 1 finding: 1 fixed, 0 filed, 0 rejected, 0 without a disposition. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4128,
"head": "1bcb99fdaafe450c2ef86e47bee2ec71b7c4a309",
"base": "40779d4983def309fc5a036ce585c581a68839c1",
"reviewer": "agent",
"outcome": "findings",
"findings": [
{
"summary": "packages/ui-server/migrations/089_safety_durable_account.sql:75: The dialogue-owner rejection evaluates to NULL when principal_account is NULL and its principal is foreign or pruned. NOT EXISTS then ignores that owner, allowing a verdict the ownership guard should refuse. Reproduced with the actual trigger for both a live foreign agent and a pruned unknown principal. Coalesce the account comparison before negating it.",
"disposition": "fixed",
"commit": "5a5b7b5d359c8ec1b0b5f7fa3ae40e16c2b3a1a6"
}
]
} |
Owner
Author
Independent reviewReviewed head b0dec6e against base 7dfadc2. Reviewer: agent. No findings. {
"version": 1,
"kind": "brain-review-receipt",
"pr": 4128,
"head": "b0dec6e6150add5da4865a1f0f71765b8a83f1f9",
"base": "7dfadc217c406255935f7fc626594acf2c2e8b9a",
"reviewer": "agent",
"outcome": "no-findings",
"findings": []
} |
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 #3962
What changed
A chat now stays continuable after the owner login that started it is pruned. Principal cleanup deletes a login 30 days after it expires or is revoked (
prunePrincipals). The chat's safety records then named a principal nobody could vouch for, so #3952'ssameAccounttreated it as unknown and refused every later turn by every login (Safety principal mismatch, orSafety history ownership mismatchonce the chat had a voice owner), for good. Under the maintainer's ruling (option A, 2026-11-11), the host now stores the account with the safety history. Migration 089 addsprincipal_accountbesideprincipal_idonsafety_sessions,safety_collectionsanddialogue_owners. The server writes it from the principal's own row when it writes the record (principalAccount):ownerfor an owner login, NULL for a principal that is only itself. Another owner login keeps continuing, binding, forking, reading and reviewing that history and its taint.principal_idattribution, records, verdicts, gaps and generations are not rewritten.Safety history ownership mismatchbeginSafetyCollection(dialogue owner)dialogue_ownersSafety principal mismatchbeginSafetyCollectionsafety_sessionsSafety fork history ownership mismatchbeginSafetyCollection(fork source)safety_sessionsSafety binding owner mismatchbindSafetyCollectionSafety retained owner mismatchbindSafetyCollectiondialogue_ownersand the turn's collectionSafetyHistory.authorizesafetyReviewTarget,eligiblesafety_decision_identitytriggerWhy this shape
The rule.
sameAccount(db, bound, principal)now takes a record{ principalId, account }as well as a bare id. A live principal row decides by itself, exactly as in #3952. The stored account counts only when the row is gone. Evidence that is corrupt (a value no host writes), or that a live row contradicts (ownerstored, but the row is an agent), matches nobody, not even its own principal. The caller is always a bare id, so it proves its account only by its own current row. The stored account is evidence, never a credential: a pruned, expired or revoked login regains nothing, andSafetyHistory'svalidcheck and the host's auth still gate the caller.durableAccountis the accountaccountScopegives in every auth mode (today onlyowner), so the stored value never depends on the mode the host runs in now, and an ambient, agent or system principal stays only itself.Columns on the history rows, not a principal→account table. A table keyed by principal id that outlives
prunePrincipalsis a login tombstone, which is option B and was not selected. Columns on the records keep the evidence with the history, and they disappear when chat deletion removes the history.dialogue_ownersgets the column too, because the safety checks compare against the dialogue owner's principal; otherwise any chat with a voice owner would stay stuck after pruning. #3963 (voice continuation across logins) will reuse the same column and rule; this PR does not change voice's exact-principal comparisons.Legacy rows. 089 sets
owneronly where a principal row still proves it at upgrade (kind='owner'). A row whose principal is already gone keeps NULL and stays unknown: deleted proof is not reconstructed, and there is no owner-by-default backfill. 081'ssafety_catalog_discoverytrigger inserted by position, so 089 recreates it with a column list.Contract. This is additive.
docs/integration-contract/http.mdgains the #3962 section, anddocs/http-api.mdand the decision record (session-safety-reviews.md) state the rule, so the commit isCONTRACT:. No CLI, MCP or HTTP shape changes. One narrowing is named there: a record with contradictory evidence is refused even for its own principal, but no released host writes such a record. The durable decision record itself is #3978.Proof
Failing first. The new continuation tests were run against the base code (
git checkout origin/main -- packages/ui-server, without 089, the new tests kept):With the change:
safety-account-partition.test.ts17 pass, 0 fail.Mutations, each restored (
cmpagainst the backup):account: null)Safety principal mismatch,Safety history ownership mismatch) and thesameAccounttable (pruned {ship, owner} / home: expected true)ownerSAFETY_PRUNED_FOREIGN_REFUSED: unknown-login,SAFETY_PRUNED_LEGACY_OWNER_IS_UNKNOWN,SAFETY_FOREIGN_PRINCIPAL_REFUSED,SAFETY_FOREIGN_FORK_REFUSED, thesameAccounttables (6 tests)SAFETY_BAD_ACCOUNT_TRIGGER_REFUSED: corruptWhat the tests cover (
packages/ui-server/tests/safety-account-partition.test.ts, realrevokePrincipal/prunePrincipalspath):history_owner_id. It inherits the unresolved occurrence and restriction, late-binds an unbound turn, reads the chat and the pruned login's turn, forks with the taint, and prepares and commits a review on the pruned login's occurrence through the trigger. Session, collection and record rows are unchanged. The stale prunedPrincipalobject is refused asunauthorized.nullare refused at begin (with and without a voice owner), reads and review target. A refused turn leaves no collection, and an unrelated chat beginsnormal.admiral) and contradicted (owneron an agent's row) evidence is refused for another owner login and for the recorded principal itself, at begin, read, review target and the trigger. An unrelated chat staysnormal.safetyBegininput carryingprincipalAccount/principal_account/account: "owner"for an agent, a proxy user, a system or an unknown principal stores NULL.owner. The ship's session, collection and dialogue owner stay NULL, and the records are unchanged.Other suites. Every
safety-*,dialogue-*,principal*,chat-deletion*,chat-lifecycle,chat-session-owner,session-routes-*,session-safety-boundaries,owner-safety-review,live-safety-admission,http-principal-boundaries,host-publication-safety,app-writer-cleanup,ws-conversation,ws-chat-deletionanddbtest passes. Two existing tests needed updates:safety-ledger.test.tsinserteddialogue_ownersrows by position (now with a column list), and its upgrade replay now replays 089 with the 081/085 tables it extends.Provider-history guard.
packages/ui-backend-{claude,pi}/tests/provider-history.test.tscannot run on this host. Itsbwrapis refused user namespaces (No permissions to create a new namespace), and it fails identically on the base code. No ownership metadata is on the provider path: the change touches only host SQLite rows and the checks that read them, and hosted CI runs the guard.bun run typecheck,bun run lint(all gates clean) andbun run buildpass.{"version":1,"kind":"brain-check-pr-receipt","head":"b0dec6e6150add5da4865a1f0f71765b8a83f1f9","base":"origin/main","mode":"focused","startedAt":"2026-11-17T02:04:00.791Z","finishedAt":"2026-11-17T02:05:37.624Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":16840.763912000002},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":116.92536000000109},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":109.04503400000249},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":24.874313000000257},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":79722.988186}]}Independent review follow-up
The review of
1bcb99fdahad one finding, fixed in5a5b7b5d359c8ec1b0b5f7fa3ae40e16c2b3a1a6. Its disposition is posted at the reviewed head. In 089'ssafety_decision_identitytrigger, inside the dialogue owner'sNOT EXISTS,d.principal_account='owner'is NULL when the account is NULL. That made the whole rejection term NULL, so a dialogue owner naming a foreign agent or a pruned unknown principal with no stored account did not refuse the verdict.the decision trigger refuses a verdict when the chat's dialogue owner is another account or unknown, with no stored accountfailed on1bcb99fdawithSAFETY_DECISION_TRIGGER_REFUSES_NULL_ACCOUNT_DIALOGUE_OWNER: foreign agent/Received function did not throw.IS 'owner', and the dialogue owner's principal and generation comparisons useIS/IS NOT, so no term in the negated clause can be NULL.EXISTSconditions, where a NULL only refuses, and they now useIStoo.kind<>'owner'insideNOT EXISTSis safe becauseprincipals.kindisNOT NULL(011). The TypeScriptsameAccounthas no three-valued logic.d.principal_account='owner'on that one line turns the same test red on the same assertion (17 pass / 1 fail). Restored:safety-account-partition,safety-ledger,owner-safety-review,safety-reviewsandsafety-history-reviewgive 119 pass / 0 fail.origin/mainwas merged in (clean, no rebase).Proportionate containment (changed guard)
SAFETY_REFUSAL_CONTAINED_TO_ITS_CHAT,SAFETY_BAD_ACCOUNT_CONTAINED).safety recording refused one turn before deliveryrecord, naming the check (Safety principal mismatchand so on).normal.Collisions
bun scripts/collisions.ts --json --pr 4128at1bcb99fda: one textual collision, with draft #3622 (6a814ee73) indocs/http-api.md.git merge-treeof #3622 gives 4 conflict hunks indocs/http-api.mdagainst both this head andorigin/main, with the same conflicted file set (docs/http-api.md,docs/integration-contract/package-api.md,packages/ui-server/src/app.ts,packages/ui-server/tests/http-inventory.test.ts). They already exist against main, and this PR adds none. Every other report is closure-only (shared test-closure paths, no shared files): #3056, #3059, #3069, #3581, #4002, #4036, #4102, #4106, #4112, #4113, #4115, #4118, #4122, #4123, #4124, #4126. Migration numbering: #4002 adds089_reference_acquisitions.sql. The runner keys on filename, and the two 089 files touch independent tables, so either order is safe.Checklist
0.45.0..changeset/3962-safety-durable-account.md, minor).CONTRACT:commit.docs/reflect the change.Anything left open
app.ts,owns) still compares the chat's catalog owner by bare id, so it refuses after pruning. It was outside this issue's listed safety paths.dialogue_owners.principal_accountfor voice continuation; voice's own exact-principal comparisons are unchanged here.🤖 Generated with Claude Code