Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
098db3b
CONTRACT: fix(ui-server): contain a safety-recording failure to what …
schlessera Nov 10, 2026
349af4e
CONTRACT: feat(ui-server): show the owner the safety recorder and an …
schlessera Nov 10, 2026
8e575ff
feat(ui-react): say a message was refused because safety recording fa…
schlessera Nov 10, 2026
8cc0688
fix(ui-server): schedule recovery from any latch and keep in-flight r…
schlessera Nov 10, 2026
97fb38c
fix(ui-server): never let recovery clear a loss that named no chat (#…
schlessera Nov 10, 2026
88e5805
docs: regenerate the ui-sdk API report and cover the safety status ro…
schlessera Nov 10, 2026
b354226
fix(ui-server): keep a refused tool result's loss with its chat (#3812)
schlessera Nov 10, 2026
ed5a027
CONTRACT: fix(ui-server): drain pre-latch producers, show the retaine…
schlessera Nov 10, 2026
8e426bf
test(ui-react): a second chat stays usable beside a recording gap, in…
schlessera Nov 10, 2026
511e94a
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
e162f73
fix(ui-server): record a stopped turn's tool result, and gap every re…
schlessera Nov 10, 2026
688e039
fix(ui-server): gap every admitted tool call whose result is never re…
schlessera Nov 10, 2026
0085b9b
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
6e0c92b
fix(ui-server): keep an allowed call owed until its result is recorde…
schlessera Nov 10, 2026
c5aab59
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
b0f12a4
docs: say an allowed call stays owed until its result is recorded, an…
schlessera Nov 10, 2026
9e6802a
test(ui-server): resolve the Pi gate's extension factory the way its …
schlessera Nov 10, 2026
862316a
docs(http-api): count the safety-recording recovery route among the d…
schlessera Nov 10, 2026
8abd1d0
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
54b389b
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
a04ba5d
fix(ui-server): let only a recorded result settle an admitted call, a…
schlessera Nov 10, 2026
d088575
docs: re-anchor citations into the files this PR moves (#3812)
schlessera Nov 10, 2026
4162c87
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
5808ed4
fix(ui-server): let the host's denial of a call's only admission sett…
schlessera Nov 10, 2026
d039d73
docs: re-anchor citations the narrowed admission rule moved (#3812)
schlessera Nov 10, 2026
758cc4c
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
c68a17b
docs: re-anchor citations into protocol.ts and app.ts that this PR mo…
schlessera Nov 10, 2026
07165d5
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
a5c7ed8
fix(ui-server): count a reused call id under another tool as a new ad…
schlessera Nov 10, 2026
663b904
docs: re-anchor citations the per-tool admission count moved (#3812)
schlessera Nov 10, 2026
a4ab6c5
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
a1f99f7
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
7ad2bb7
docs: re-anchor the share-size citations this PR moves (#3812)
schlessera Nov 10, 2026
ebb3022
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
077d60b
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
e92aa12
Merge origin/main into fix/3812-proportionate-safety-recording
schlessera Nov 10, 2026
6c7331b
chore(scripts): re-audit inbound.ts after it gained the refusal reaso…
schlessera Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .changeset/3812-safety-recording-containment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
"@schlessera/brain-ui-server": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-react": minor
---

A safety-recording failure now restricts only what it puts at risk, and the host recovers by itself (#3812, #3810).

- **One turn, before delivery.** A failed safety begin, or a refused record of a tool's input before the tool runs, refuses only that turn with the new `SAFETY_RECORDING_UNAVAILABLE` error. The chat and the brain stay usable. When the refusal is for spent room, it says what to do: start a new chat (`safety_recording_chat_full`), or that retrying won't help (`safety_recording_brain_full`). Room that running turns or pending writes still hold is a plain retryable refusal.
- **One chat, after delivery.** Lost evidence marks only that chat with a permanent `recording_failed` gap. That includes a tool result whose record fails or whose report the host refuses: the runtime may already keep it in its session. Stopping a turn while a tool runs still records that tool's result. Every tool call the host admits owes its result's record until that record is written or the call is proved never to have run. Only one thing proves that: the host's own denial (for example a denied permission card) of the only call ever admitted under that id, with no allow before it. So a call whose result never arrives (a turn stopped before the runtime reported it, or a server that died mid-tool) leaves the gap, and so does a call refused any other way. A denied permission card leaves the chat as it was. A permission grant is never usable before the host's last check of the call has passed. A turn's end waits for a result record already under way, and a result's record and its settlement are written together. The chat keeps running under its tainted policy; other chats are untouched.
- **The brain, only when the evidence store cannot take a scoped fact.** New turns still run, restricted, each with a permanent gap written before anything is sent. The server keeps retrying and clears the latch itself once the gaps are durable and every turn that predates the latch has ended, including one begun restricted under an earlier latch. A turn is refused only if even its restricted start cannot be written (`safety_recording_paused`).
- **Boot** resolves a set latch and pending reservations automatically instead of refusing every turn.
- **Diagnosable.** Each latch keeps its first cause and a count in the database, logs one structured line, and is shown to the owner as `safetyRecording` on `/api/status`, also while only the server process holds it (`cause.durable: false`). Errors are no longer all labelled `capacity`. Every recovery is recorded with who or what ran it.
- **Owner fallback.** `POST /api/status/safety-recording/recover` runs the same recovery when nothing is open.
- **PWA.** A message refused this way says that safety recording failed, is paused, or has no room left and what to do, instead of "The brain refused this message."
2 changes: 1 addition & 1 deletion api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7684,7 +7684,7 @@ signatures (every public export and the types it is made of)
entries: FileEntry[];
}
FirstPartyFailureClass (packages/ui-sdk/src/protocol.ts)
type FirstPartyFailureClass = "authentication_failed" | "oauth_org_not_allowed" | "account_on_hold" | "verification_required" | "billing_error" | "subscription_required" | "auth_failure" | "rate_limit" | "overloaded" | "server_error" | "invalid_request" | "model_not_found" | "max_output_tokens" | "cloud_credential_error" | "worker_host_unsupported" | "session_too_large" | "worker_resource_limit" | "worker_state_busy" | "worker_state_exceeded" | "worker_state_save_refused" | "journal_capacity" | "journal_unavailable" | "budget_exceeded" | "budget_unavailable" | "input_safety_unavailable" | "unknown";
type FirstPartyFailureClass = "authentication_failed" | "oauth_org_not_allowed" | "account_on_hold" | "verification_required" | "billing_error" | "subscription_required" | "auth_failure" | "rate_limit" | "overloaded" | "server_error" | "invalid_request" | "model_not_found" | "max_output_tokens" | "cloud_credential_error" | "worker_host_unsupported" | "session_too_large" | "worker_resource_limit" | "worker_state_busy" | "worker_state_exceeded" | "worker_state_save_refused" | "journal_capacity" | "journal_unavailable" | "budget_exceeded" | "budget_unavailable" | "input_safety_unavailable" | "safety_recording_unavailable" | "safety_recording_paused" | "safety_recording_chat_full" | "safety_recording_brain_full" | "unknown";
FirstRequestCacheUsage (packages/ui-sdk/src/protocol.ts)
export interface FirstRequestCacheUsage {
inputTokens: number | null;
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ requires one enforcement mechanism with different named memberships for voice
and unattended work. Keep that requirement when implementing availability
control. Existing mandatory backend conformance supports safe rejection of an
unsupported restricted request; silently ignoring it is forbidden. The current
optional inputs are (`enforceAllowedTools?: boolean`, `packages/ui-sdk/src/server/backend.ts:642`) and (`noGrantSurface?: boolean`, `packages/ui-sdk/src/server/backend.ts:666`). These are permission primitives,
optional inputs are (`enforceAllowedTools?: boolean`, `packages/ui-sdk/src/server/backend.ts:684`) and (`noGrantSurface?: boolean`, `packages/ui-sdk/src/server/backend.ts:708`). These are permission primitives,
not a claim of filesystem or network containment.

The ordinary Claude assembly loads project settings and appends bridge tools
Expand All @@ -85,7 +85,7 @@ is historical. Preserve subscription billing and the selected runtime identity.
Pi disables built-in tools but currently loads resources and extensions
(`createSessionResources`, `packages/ui-backend-pi/src/session-resources.ts:29-149`)
and gates extension calls (`createPermissionGate`,
`packages/ui-backend-pi/src/permission-gate.ts:103-134`). Removing four curated
`packages/ui-backend-pi/src/permission-gate.ts:105-154`). Removing four curated
tools cannot prove that extensions, MCP, scratch writers or in-process code have
no egress or write access. Both first-party runtimes owe executable evidence;
the plan's earlier “pi is easy” claim is not a containment result.
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/claude-2.1.287-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ The backend builds the actual turn options and production permission handlers
The explicit ask lives in
(`enforcementHookFor`, `packages/ui-backend-claude/src/permission-hooks.ts:289-330`)
and is registered under enforcement in
(`...(enforced ?`, `packages/ui-backend-claude/src/permission-hooks.ts:715-718`).
(`...(enforced ?`, `packages/ui-backend-claude/src/permission-hooks.ts:766-769`).

`scripts/measure-claude-enforcement.ts` runs `createClaudeBackend().startTurn()`
and forwards to the SDK resolved from that backend. Its query wrapper only
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ than refuses on a mismatch.**
first proof of that.
- **Where it shows.** `/api/status`, which is behind the auth guard and already
reports the source commit (`Operational status`,
`packages/ui-server/src/routes/health.ts:65-83`), and the run record. Not
`packages/ui-server/src/routes/health.ts:73-91`), and the run record. Not
`/api/health`: it is public and deliberately carries no version
(`Public liveness probe`, `health.ts:15-17`). Not `brain doctor`: it runs on
(`Public liveness probe`, `health.ts:19-21`). Not `brain doctor`: it runs on
the user's machine against a different binary.

Why warn rather than refuse an unmeasured pair, given that what was measured is
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/design-kit/sessions-and-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ event deletes the whole set. Draft content never enters this record (§5).
null, no time is printed.
- **`lastActiveAt` and `lastTouched` are never read.** A newer
`lastActiveAt` can mean that a new turn started
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1749-1779`),
(`export interface ChatSession`, `packages/ui-sdk/src/protocol.ts:1753-1783`),
and `lastTouched` is LRU bookkeeping for buffer eviction.

**Merging snapshots and live frames.**
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/hardening.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ instead, and treat 8 as the question it was answering.
production (`adapter.adapt(msg)`,
`packages/ui-backend-claude/src/turn-stream.ts:103`) and U33 changes frame
consumption
(`handleServerMessage`, `packages/ui-react/src/ws-client/inbound.ts:187`), the
(`handleServerMessage`, `packages/ui-react/src/ws-client/inbound.ts:188`), the
same symptom could come from either, so they are **0.34.0** (seam) and **0.34.1** (splits), each its own
image. For the same reason the cron bin and emitters (U13/U14) ship as
**0.33.0** with the denylist unchanged and the allowlist (U21) as
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/http-api-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The source audit on 2026-09-30 used
public ceremonies (`authGuard`, `packages/ui-server/src/app.ts:1040`), and the
WebSocket admission is separate (`"/ws"`, `packages/ui-server/src/app.ts:1261`).
Static serving is conditional (`if (options.staticRoot)`,
`packages/ui-server/src/app.ts:1283-1304`). That order establishes access;
`packages/ui-server/src/app.ts:1285-1306`). That order establishes access;
it does not select compatibility status.

A hermetic real-app launch, with temporary brain root, in-memory database,
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/live-conversation.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ tool admission and execution, permissions, cancellation, terminal state and
resynchronization. Engine task requests are advisory until mapped to committed
user input. No native search, code-execution or alternate permission loop is
enabled. Both adapters can delegate through the existing `AgentBackend`
(`export interface AgentBackend`, `packages/ui-sdk/src/server/backend.ts:784-827`);
(`export interface AgentBackend`, `packages/ui-sdk/src/server/backend.ts:826-882`);
the host serializes work in a session and uses capability-checked follow-ups.

The [voice-permission decision](voice-permission.md) binds this interface.
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/proportionate-containment.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ Ruled by the maintainer on 2026-11-09 (#3812). Tracked under #3813.
A hosted instance refused every turn in every chat. One turn's safety-recording
write had failed, and the guard reacted by setting one durable flag for the
whole brain (`latchSafety`,
`packages/ui-server/src/governance/safety-store.ts:37-44`). From then on, turn
`packages/ui-server/src/governance/safety-store.ts:115-125`). From then on, turn
admission threw for every chat, including new chats that had never seen
untrusted input (`beginSafetyCollection`,
`packages/ui-server/src/governance/safety-store.ts:70-76`). The error that
`packages/ui-server/src/governance/safety-store.ts:193-202`). The error that
set the flag was recorded as "capacity" while the store was at a fraction of a
percent of its limits, and its real cause was never stored. The only way back
was to stop the server and run `recoverSafetyRecording` from a script, a
Expand Down
84 changes: 84 additions & 0 deletions docs/decisions/session-safety-reviews.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,90 @@ and failure capacity before ingestion; stop/restrict before overflow loses a
signal. A failed pending write must not disappear into apparently normal state,
including across restart. No test count or arbitrary cleanup TTL proves safety.

### A recording failure restricts what it puts at risk (#3812)

Ruled by the maintainer on 2026-11-09, under
[proportionate containment](proportionate-containment.md). "Restricted" means
running under the tainted policy, not refusing.

- **Before delivery** (a failed collection begin, or a refused record of a
tool's input, which the backend awaits before the tool runs): the one turn
is refused with `SAFETY_RECORDING_UNAVAILABLE`. Nothing latches. A tool's
result is never before delivery: its bytes exist when it is recorded, and a
runtime may keep them in its own session (the Claude runtime replays them
on resume), so a result that cannot be recorded is lost after delivery.
A refusal for spent room says what frees it: a full chat needs a new chat
(`safety_recording_chat_full`), and a full brain cannot be helped by a
retry (`safety_recording_brain_full`). The room for first turns not yet in
a chat is full only when ended collections alone fill it; room that a
running turn or a pending write holds frees itself, so that refusal is a
plain retry.
- **Lost after delivery**: the turn's own collection takes the failure and its
first cause, so its chat keeps a permanent gap projected as
`recording_failed` and that producer stops. Other chats are unaffected. A
reservation still open when its collection ends becomes the same gap.
Between a tool running and its result's record, nothing may skip both: a
stopped turn still records the result (stopping refuses new tools, never a
record, and a collection's end waits, bounded, for a record already under
way), a report the host refuses before its record (a malformed or
replayed Pi report) and a result for a call whose input record failed both
leave the gap. The host does not rely on the runtime to report a result:
the Claude runtime dispatches neither result hook for a turn stopped while
a tool runs, and still keeps that call in its session. So every call
`begin()` admits is an obligation, recorded before the tool runs. Its
durably recorded result discharges it. A refusal discharges it only when
it proves the call never ran, which needs all three of:
1. it is the backend's own denial before the call could run: a Claude
permission callback deny (a denied permission card) or `PreToolUse`
hook deny, a Pi permission deny or gate block;
2. it is the id's only admission: the runtime asked once to admit a call
under that id, under one tool name (each admission is counted per tool
name before anything of it is decided, whichever hook of it starts
first, so a reused id under another tool counts even when its hooks
differ);
3. the backend never let a call under that id run.

Anything else proves nothing, and only the recorded result discharges:
a second admission of the id, under the same tool name or another (the
installed Claude runtime admits two calls under one id, and runs a bare
`allowedTools` entry or a rewrite hook's allow without asking), an allow followed by a refusal, a rejected
request (a stopped turn, a replayed Pi request), or an id whose
admissions the backend never reported. Such a call leaves the gap even
if it never ran. A rejected `begin()` discharges nothing by itself; the
denial the backend returns on it does. A `begin()` rejected before its
obligation is durable owes nothing. The counts and allows live in the
turn's collector, not on the obligation row: an admission can be denied
before any row exists, only that collector discharges, and a restart gaps
every open obligation. A refusal also refuses every later admission and
allow under its id. Each backend's allow (the Pi dispatcher's, the Pi
gate's pass, the Claude permission callback's) is checked by the
collector before the call can run, and the Pi dispatcher publishes a
call's grant only after that check, so no concurrent request can use a
grant for a call the check then refuses. A result's last record and its
discharge commit together. A collection that ends owing one, however it
ended, and an obligation still open at boot, leave the same permanent
gap.
- **Evidence store unwritable** (the chat fact cannot commit): the brain
latches through the emergency reserve, or, when even that fails, in the
host process. New turns still begin, each with a permanent
`recording_failed` gap committed before delivery, and run restricted. A turn
is refused only when that restricted begin itself cannot commit
(`safety_recording_paused`). The host keeps retrying, backing off to once a
minute, and clears the latch itself with `recoverSafetyRecording` semantics
once every producer that predates it has ended, failed or not; only turns
begun restricted after that latch run beside it.
- **Boot** resolves a set latch and pending reservations after restart
classification, gaps first. A legacy row that cannot migrate gaps its own
turn. The server never boots into refusing every turn.

Every latch keeps its first cause (class, message, bounded stack, call site,
turn, time) and a count, logs one structured line, and is visible to the owner
on `/api/status`, also while only the host process holds it. Every recovery is recorded with its trigger, actor, time and
cleared cause. The owner route (#3810) is a fallback with the strict
quiescence precondition. Only a capacity check classifies a failure as
`capacity`. No gap ever clears, and nothing here lets an unrecorded input
become clean.

## Human authority and policy publication

Initially **only a live password-mode human owner** may commit a verdict or
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/voice-permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ matters because a reader cannot otherwise tell a live hazard from a fixed one.

**Closed, by #141 (`42a4d86`), which closed #124.** A turn now declares
`StartTurnRequest.enforceAllowedTools`
(`enforceAllowedTools?: boolean`, `packages/ui-sdk/src/server/backend.ts:642`)
(`enforceAllowedTools?: boolean`, `packages/ui-sdk/src/server/backend.ts:684`)
— the declaration this record asked for, by that name — and under it:

- The input-rewrite hooks no longer grant. `createAgentHook` and `createRtkHook`
Expand Down
2 changes: 2 additions & 0 deletions docs/http-api-coverage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ row's real mounting check. They do not establish mounting by themselves.
| `POST /api/schedules/proposals/:id/approve` | `mounted supported handler: POST /api/schedules/proposals/:id/approve` | K |
| `POST /api/share` | `mounted supported handler: POST /api/share` | J, Q |
| `GET /api/status` | `mounted supported handler: GET /api/status` | T |
| `POST /api/status/safety-recording/recover` | `mounted supported handler: POST /api/status/safety-recording/recover` | T |
| `POST /api/status/worker-host` | `mounted supported handler: POST /api/status/worker-host` | T |
| `GET /api/voice/keyterms` | `mounted supported handler: GET /api/voice/keyterms` | N |
| `GET /api/voice/overrides` | `mounted supported handler: GET /api/voice/overrides` | N |
Expand Down Expand Up @@ -198,6 +199,7 @@ cover start refusal, mid-turn partial work, overlapping observations and leases.
- `a failing host boots anyway, logs the named requirement once, and /api/status reports it` ([source](../packages/ui-server/tests/worker-host-status.test.ts)), (`a failing host boots anyway, logs the named requirement once, and /api/status reports it`, `packages/ui-server/tests/worker-host-status.test.ts:66-83`)
- `re-runs the real probe and records what it found, in both directions` ([source](../packages/ui-server/tests/worker-host-status.test.ts)), (`re-runs the real probe and records what it found, in both directions`, `packages/ui-server/tests/worker-host-status.test.ts:160-176`)
- `is behind the auth guard` ([source](../packages/ui-server/tests/worker-host-status.test.ts)), (`is behind the auth guard`, `packages/ui-server/tests/worker-host-status.test.ts:178-187`)
- `the status route shows the recorder to the owner only, and recovery requires the owner` ([source](../packages/ui-server/tests/safety-containment.test.ts)), (`the status route shows the recorder to the owner only, and recovery requires the owner`, `packages/ui-server/tests/safety-containment.test.ts:275-290`)
- `boots, warns once in the log, and keeps the warning on /api/status and through Check again` ([source](../packages/ui-server/tests/worker-host-status.test.ts)), (`boots, warns once in the log, and keeps the warning on /api/status and through Check again`, `packages/ui-server/tests/worker-host-status.test.ts:214-231`)

**A — Password access and revocation.**
Expand Down
Loading
Loading