Repository navigation
Description
Context
A hosted instance became unusable: every turn in every chat was refused with "Safety recording requires recovery". A single turn's safety-write error had set a brain-wide durable flag, and the flag stayed set until an operator stopped the server and ran a script. Diagnostics for that failure are #3810. This issue changes the behaviour itself.
How it works today:
latchSafety(packages/ui-server/src/governance/safety-store.ts:37-44) setssafety_meta.failed=1. That is one flag for the whole brain.- Once the flag is set,
beginSafetyCollection(safety-store.ts:76) and the in-memory check insafetyBegin(packages/ui-server/src/governance/event-writes.ts:139) throw. Turn admission (packages/ui-server/src/ws/session-run/backend-entry.ts:118) therefore refuses every turn, including new chats that never saw untrusted input. - The latch is set even when nothing was lost.
safetyBeginfails before any input reaches the model (event-writes.ts:32), so no unrecorded evidence can exist, yet the whole brain is latched. - Recovery (
recoverSafetyRecording,safety-store.ts:378-395) needs no judgment. It marks the affected collections with a permanent gap (recording_failed_recovered), so those chats stay restricted, and then clears the flag. No production code calls it. - The plan text says "latch restricted state … stop the producer and require recovery … restart begins restricted until the host proves recovery" (
docs/plans/reviewable-session-safety.md:497-506). The code reads "restricted" as "refused".
Decision (maintainer, 2026-11-09): containment is proportionate. A safety-recording failure restricts what it actually puts at risk, never more. Recovery that needs no judgment is automatic. An uncertain chat runs restricted, under its tainted policy, instead of being refused, unless the restricted policy itself cannot be enforced.
Out of scope
- Weakening taint semantics. Unknown or incomplete coverage still never becomes clean, and a gap stays permanent on the affected chat.
- The diagnostics, cause recording and owner recovery route (ui-server: a latched safety recorder keeps no cause, mislabels errors as capacity, and has no recovery path #3810). This issue needs only the automatic path. ui-server: a latched safety recorder keeps no cause, mislabels errors as capacity, and has no recovery path #3810's manual route remains as a fallback.
SAFETY_LIMITSvalues.- Other security guards. They are audited separately.
Scope
Classify each failure and contain it at the narrowest scope that covers the risk:
- Failure before delivery (
safetyBegin, or a reservation failure before any input bytes are delivered): refuse that one turn with a retryable error. No latch. The chat and the brain stay usable. - Evidence lost after delivery (an exposure was delivered but its occurrence or verdict could not be recorded): record a permanent coverage gap on that chat, so it is tainted and restricted until reviewed, and stop that producer. Other chats are unaffected.
- Evidence store unwritable (a database write or emergency-reserve failure that leaves the host unable to record anything): a brain-wide restriction. New turns run under the restricted (tainted) policy, and turns are refused only if even that cannot be enforced. The host keeps trying to write. Once a write succeeds and the gap facts are durable, it clears the brain-wide state itself, applying the
recoverSafetyRecordingsemantics automatically after in-flight producers have drained. - Boot: existing pending rows or a set
failedflag are resolved automatically at startup (gap facts written, chats restricted). The server never boots into a state where every turn is refused for something it can resolve itself. - Update
docs/plans/reviewable-session-safety.md:497-506anddocs/decisions/session-safety-reviews.mdto record this ruling.
Acceptance criteria
- A forced error inside
safetyBeginrefuses only that turn. The next turn in the same chat, and a turn in another chat, both run. Shown by a test that fails on the current tree. - A lost post-delivery occurrence leaves that chat restricted, with a permanent gap that projects as
recording_failed. A second chat stays unrestricted, and its turns run normally. Tested. - With the evidence store forced unwritable, new turns run under the restricted policy instead of being refused. Once writes succeed again, the brain-wide state clears automatically, with no restart and no operator action. Affected chats keep their gaps. Tested.
- A database with
safety_meta.failed=1and no open producers boots, recovers automatically, and admits turns. Covered by a test of exactly the incident state:failed=1,reason='capacity', no pending rows, no open collections. - Turns are refused outright only when restricted policy enforcement itself is unavailable. That case is enumerated in code and tested.
- Each automatic recovery writes an audit record (scope, cause, time) and one structured log line.
- The plan and the decision record state the ruling.
Verification
- Failing-first unit and integration tests in
packages/ui-server/testsfor each acceptance criterion, with mutation receipts: re-latch brain-wide on asafetyBeginerror, skip the auto-recovery, refuse instead of restrict. - A browser test that a second chat stays usable while one chat carries a recording gap.
Contract impact
Possibly additive. A new retryable refusal code for a pre-delivery failure, and the projection reasons unchanged. If the wire recording_failed semantics in docs/integration-contract/http.md:446 change, that is a CONTRACT: commit.
Related: #3810 (diagnostics and manual recovery), #3596 (session safety epic).
Activity
schlessera commentedon Nov 10, 2026
Claimed (claim-3812-1794279863). Working #3812 and #3810 together on branch
fix/3812-proportionate-safety-recording, aiming for one PR that closes both. #3812's restrict-before-refuse ruling supersedes #3810's out-of-scope line "A latched recorder still refuses turns"; #3810's cause recording, honest classification, status surfacing, distinct error code, PWA copy and owner recovery fallback stay in scope.fix(ui-server): keep a refused tool result's loss with its chat (#3812)
CONTRACT: fix(ui-server): drain pre-latch producers, show the retaine…
test(ui-react): a second chat stays usable beside a recording gap, in…
fix(ui-server): record a stopped turn's tool result, and gap every re…
fix(ui-server): gap every admitted tool call whose result is never re…
fix(ui-server): keep an allowed call owed until its result is recorde…
docs: say an allowed call stays owed until its result is recorded, an…
fix(ui-server): let only a recorded result settle an admitted call, a…
docs: re-anchor citations into the files this PR moves (#3812)
fix(ui-server): let the host's denial of a call's only admission sett…
docs: re-anchor citations the narrowed admission rule moved (#3812)
docs: re-anchor citations into protocol.ts and app.ts that this PR mo…
fix(ui-server): count a reused call id under another tool as a new ad…
docs: re-anchor citations the per-tool admission count moved (#3812)
docs: re-anchor the share-size citations this PR moves (#3812)
chore(scripts): re-audit inbound.ts after it gained the refusal reason (
CONTRACT: fix(ui-server): contain a safety-recording failure to what …