Skip to content

ui-server: contain a safety-recording failure to what it puts at risk and recover automatically #3812

Closed

Description

@schlessera

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) sets safety_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 in safetyBegin (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. safetyBegin fails 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

Scope

Classify each failure and contain it at the narrowest scope that covers the risk:

  1. 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.
  2. 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.
  3. 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 recoverSafetyRecording semantics automatically after in-flight producers have drained.
  4. Boot: existing pending rows or a set failed flag 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.
  5. Update docs/plans/reviewable-session-safety.md:497-506 and docs/decisions/session-safety-reviews.md to record this ruling.

Acceptance criteria

  • A forced error inside safetyBegin refuses 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=1 and 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/tests for each acceptance criterion, with mutation receipts: re-latch brain-wide on a safetyBegin error, 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

  1. added this to the 0.45.0 milestone on Nov 9, 2026
  2. added
    type: fix
    area: ui-server
    priority: p0
    agent-ready
    on Nov 9, 2026
  3. self-assigned this
    on Nov 10, 2026
  4. schlessera commented on Nov 10, 2026

    @schlessera
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-serverpriority: p0type: fix

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions