Repository navigation
Closed
Labels
agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-reactReact chat/files/voice components, stores, WebSocket transport.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.
Milestone
Description
Context
A hosted instance refused every chat turn after a restart. The server log said turn failed code="BACKEND_ERROR" … error="Safety recording requires recovery", and the PWA showed only "The brain refused this message." (packages/ui-react/src/stores/draft-state.ts:902). The root cause could not be traced afterwards:
safety_metasaidfailed=1, reason='capacity', but usage was 304 used rows of a 1,000,000-row limit (SAFETY_LIMITS,packages/ui-server/src/governance/safety-store.ts:10-12). No limit was anywhere near breached.- One
safety_collectionsrow carriedfailure='capacity'. Its turn started more than two hours before the restart and was later closed withgap='host_restart_unknown'. The latch was therefore written while the previous process was running, and the restart only exposed it (beginSafetyCollectionreads the durable flag,safety-store.ts:76). - The error that caused the latch was never stored or logged. That process's logs went with its container, and nothing durable recorded the cause.
The code paths that make this untraceable:
- Any error is classified as capacity.
safetyBegin(packages/ui-server/src/governance/event-writes.ts:32) andsafetyReserve(event-writes.ts:43) calllatchSafety(…, "capacity")for every error that is notChatRetiredError. That includes SQLite errors, bugs, and validation failures such as"Invalid bounded safety identity"(safety-store.ts:72-74).recordandsafetyCommit(event-writes.ts:30,:47) at least distinguishSafetyUnavailablefrom other errors. - A bare
catch {}at boot.migrateSafetyHistory(safety-store.ts:334-348) runs on every database open (packages/ui-server/src/db/client.ts:42). Any failure appending a legacy row latchescapacityand discards the error (safety-store.ts:346). - The latch keeps no cause.
latchSafety(safety-store.ts:37-44) stores onlyreasonand the turn'sfailure: no error name, message, call site or time. Nothing is logged when it fires. - No recovery path.
recoverSafetyRecording(safety-store.ts:376-395) exists, but nothing in production calls it. Recovering meant stopping the server, running a hand-written script against the database, and restarting. - The client cannot tell this refusal apart. A turn refused because recording is latched reaches the user as a generic refusal. The user cannot see that the host needs operator recovery.
Related: #3596 (taint recording and review).
Out of scope
- Changing the fail-closed policy. A latched recorder still refuses turns.
- Changing
SAFETY_LIMITSor what counts as a real capacity breach. - Root-causing this specific incident. The cause is gone; this issue makes the next one traceable.
- The unrelated WebSocket
target.sessionIdparse rejections seen in the same log. - Log retention of a particular deployment.
Scope
- Classify honestly.
capacityis recorded only when a capacity check refused the write. Every other error latchesrecording_failed. This covers the four facades inevent-writes.tsandmigrateSafetyHistory. - Keep the cause durably. On the first latch, store the error class, message, a bounded stack, the call site (
safetyBegin,safetyReserve,safetyCommit,record,migrate,boot-pending, …), the turn id and the time, in the database next tosafety_meta. Later latches increment a counter and do not overwrite the first cause. Store no message content: identifiers and error text only. - Log at latch time. Write one structured stderr line with the same fields when the latch fires.
- Surface it. The authenticated owner status (
/api/status) shows whether recording is latched, since when, its reason and its first cause. The refused turn's error frame carries a distinct code, so the PWA can say recording is paused and needs host recovery. - Operator recovery. Add an owner-authenticated way to run
recoverSafetyRecordinginside the running server, with its existing preconditions and refusals. It records who recovered, when, and the cause it cleared. No restart is needed afterwards.
Acceptance criteria
- A non-capacity error thrown inside
safetyBegin,safetyReserveormigrateSafetyHistorylatchesrecording_failed, notcapacity. Shown by tests that fail on the current tree. - After any latch, the database holds the first cause (class, message, call site, turn id, time) and a latch count. A second latch leaves the first cause unchanged. Both are tested.
- Each latch writes exactly one structured stderr line containing the call site and error message. Asserted in a test.
- Owner
/api/statusreportslatched,since,reasonandcause. An unauthenticated request does not see them. - A turn refused by a latched recorder sends an error frame with a dedicated code, and the PWA shows copy that says host recovery is needed instead of "The brain refused this message."
- The operator recovery succeeds on an idle latched host, and turns are accepted immediately afterwards without a restart. It refuses, without changing state, while a producer or collection is open. The recovery is recorded with actor, time and cleared cause.
-
recoverSafetyRecordinghas a production caller.
Verification
- Unit tests in
packages/ui-server/testsfor classification, cause persistence, the log line and recovery, each shown failing first and with a mutation receipt. - A contract test for the status field and the new error code.
- A browser test for the PWA copy on the new error code.
Contract impact
Additive. There is a new /api/status field, a new WebSocket error code and a new recovery route. Each needs a CONTRACT: commit and an update to the integration-contract component it touches.
Metadata
Metadata
Assignees
Labels
agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-reactReact chat/files/voice components, stores, WebSocket transport.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.
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.CONTRACT: fix(ui-server): drain pre-latch producers, show the retaine…
docs(http-api): count the safety-recording recovery route among the d…
CONTRACT: fix(ui-server): contain a safety-recording failure to what …