Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/shell-taint-behind-proxy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-server": minor
---

**Breaking (pre-1.0, #3429):** on a governed or strict turn whose worker runs behind the turn egress proxy, shell commands no longer taint the session through the command classifier. Such a turn stops recording `taint` with `source: "fetching_command"` or `"unclassified_command"`; the proxy's `egress_connection` taint, recorded at the first admitted connection other than the inference relay, is the shell signal there. An ordinary command such as `brain diagram --help` or `cat notes/x.md` leaves the session clean, while web tools, other MCP servers, `workspaces/` and inbox reads through file tools, and marked files still taint. Turns without the proxy keep the classifier unchanged. Known gap: on a proxied turn, a shell command that reads an untrusted local file without opening a connection does not taint.
2 changes: 1 addition & 1 deletion docs/decisions/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ suppressed-per-model Action; unknown usage cannot become a guessed zero.
Subscription billing moves the turn counter even when spend is zero. The activity
sum exposes unpriced runs (`sumEffectiveCost`,
`packages/ui-server/src/activity/store.ts:179-194`) and settles only after execution
(`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:756`).
(`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:765`).
Retrospective totals alone cannot enforce admission.

The maintainer's [2026-10-01 ruling on #678](https://github.com/schlessera/brain-kit/issues/678#issuecomment-5926691626)
Expand Down
47 changes: 40 additions & 7 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ unmet rather than relaxed.

**Why.** Every governed turn queues an automatic index refresh after it
(`host.governedTurns?.refresh(host.workerLock)`,
`packages/ui-server/src/ws/run-session.ts:934`). The refresh usually finishes
`packages/ui-server/src/ws/run-session.ts:938`). The refresh usually finishes
while the next turn runs, so that turn's finish observation found a rewritten
`brain.db` and copied a whole new version of it into retained objects, inside
the observation's worker hold. #2831 measured 36 versions of a ~120 MB index in
Expand Down Expand Up @@ -2096,7 +2096,7 @@ limits from the same policy inputs and states independent hard limits.

**What exists.** The audit trail is the Activity span record: tool name, the
full input up to its cap, output and approval decisions
(`"tool_input"`, `packages/ui-server/src/activity/recorder.ts:344`).
(`"tool_input"`, `packages/ui-server/src/activity/recorder.ts:353`).

**What changes:**

Expand Down Expand Up @@ -3775,7 +3775,9 @@ Before the egress proxy lands, Bash commands classified as fetching (`curl`,
`wget`, `git clone` and `fetch`, the `brain` scrape and import commands, and
Chromium) taint the session. Any Bash call that the classifier cannot rule out
as network-free also taints it. Erring towards taint costs only tighter
outward rules.
outward rules. Where the proxy runs, the classifier is off and the proxy's
connection taint is the shell signal (superseded 2026-11-03, see
[below](#shell-classifier-off-behind-the-proxy)).

Taint is sticky for the session, because that content stays in the context
window. A tainted session runs under tighter rules:
Expand All @@ -3794,9 +3796,10 @@ pi-web-access's `fetch_content` and `web_search`; a file tool or brain-kit
document reader whose normalized path is under `.brain-ui/inbox/` or
`workspaces/`, or a search whose output names a file there (an absolute path
outside the brain and the strict area root counts any such segment); a
fetching or unclassified Bash call; and any MCP tool whose server is not
fetching or unclassified Bash call (only on a turn without the egress proxy
since 2026-11-03, see below); and any MCP tool whose server is not
brain-kit's own `brain` or `brain-ui`
(`inputTaintSource`, `packages/ui-server/src/activity/ingestion-taint.ts:82-92`).
(`inputTaintSource`, `packages/ui-server/src/activity/ingestion-taint.ts:88-99`).
The fixed list of external-content MCP sources is therefore "every other MCP
server", following the rule above that erring towards taint costs only tighter
rules (maintainer ruling, 2026-10-22). The first source is the session's one
Expand Down Expand Up @@ -3832,6 +3835,35 @@ widens: deny and `allowlist` mode still apply first (`prepareTurnEgress`,
native storage have no proxy, so the Bash classifier remains their shell rule
and nothing narrows their egress.

<a id="shell-classifier-off-behind-the-proxy"></a>

**Shell classifier off behind the proxy — 2026-11-03
([#3429](https://github.com/schlessera/brain-kit/issues/3429)).** This
supersedes the unconditional Bash classifier in the implemented note above.
The classifier tainted on every shell call it could not prove network-free,
so almost every governed session was tainted by its first ordinary command
(`brain diagram --help`, `cat notes/x.md`) without reading anything
untrusted. On a turn whose worker runs behind the turn egress proxy, the
proxy already taints at the first admitted connection other than the
inference relay, before its first byte, whatever program made it. That turn
now records neither `fetching_command` nor `unclassified_command`: once the
proxy is up, the host tells the turn's recorder
(`recorder?.setEgressProxied();`, `packages/ui-server/src/ws/run-session.ts:747`),
and its shell calls skip the classifier
(`const command = shellProxied ? null : commandTaintSource(tool, input);`,
`packages/ui-server/src/activity/ingestion-taint.ts:90`). A `curl` on such a
turn taints through the proxy's `egress_connection` record. Every non-shell
source (web tools, other MCP servers, untrusted areas, marked files) still
taints there. A turn without the proxy keeps the classifier unchanged
(maintainer ruling A on #3429; B, keeping the fetching classification, and
C, the current behaviour, were rejected).

Known gap, accepted by that ruling: on a proxied turn, a shell command that
reads an untrusted local file without opening a connection (`cat
workspaces/x/README`, or a marked file) does not taint. Path detection is not
extended to shell arguments, because parsing them is the shell classifier
this ruling removes. File tools reading the same path still taint.

**Files the user marks untrusted — 2026-11-02
([#2673](https://github.com/schlessera/brain-kit/issues/2673)).** A user can
mark a brain file untrusted from Files, and the recorder above then treats an
Expand All @@ -3844,8 +3876,9 @@ first source (`fileSource`,
still names its own source first, and an absolute path outside the brain's
host path is not matched against marks. A mark is looked up when the call
completes; a lookup that fails counts as marked
(`const marked: MarkedLookup`, `packages/ui-server/src/activity/recorder.ts:236-242`).
Shell reads are covered only by the Bash rules above, reads are never
(`const marked: MarkedLookup`, `packages/ui-server/src/activity/recorder.ts:244-250`).
Shell reads are covered only by the Bash rules above, which do not apply on a
turn behind the egress proxy (the known gap above); reads are never
blocked, and a session that read the file before it was marked is not
tainted retroactively.

Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/session-principals.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Both reviewers verified every row below against the source.
| WS upgrade | `ws/connection.ts:262-264` | `createWsUpgrade` ignores the request context |
| WS admission | `ws/connection.ts:84` | `clients.add(ws)` — the socket's identity is unknown |
| Turn record | `ws/run-session.ts:136-144` | recorder built from `{turnId, sessionId, billing}`; `RunningTurn` (`ws/turns.ts:55-77`) has no actor |
| Follow-up queue | `QueuedFollowUp`, `ws/turns.ts:61-103`; `slot.queue.push(entry)`, `run-session.ts:1125` | queued entries re-mint `turnId` in the same slot and may come from another socket |
| Follow-up queue | `QueuedFollowUp`, `ws/turns.ts:61-103`; `slot.queue.push(entry)`, `run-session.ts:1129` | queued entries re-mint `turnId` in the same slot and may come from another socket |
| Password login | `acquirePasswordVerification(key)`, `auth.ts:739` | argon2id verify, failure counting, in-flight reservation, then `issueSessionCookie` |
| Passkey login | `issueLoginSession`, `packages/ui-server/src/middleware/passkeys.ts:441` | assertion verified, then `issueSessionCookie`; `row.id` is in scope |
| Passkey **registration** | `INSERT INTO passkey_credentials`, `packages/ui-server/src/db/account-writes.ts:31-36` | inserts a credential; calls **neither** helper |
Expand Down Expand Up @@ -204,7 +204,7 @@ credentials, not people.
(`upsertRollup`, `activity/sql.ts:19-24`) — the rollup is what survives span
pruning, so cost-by-actor dies at prune time without it. The precedent is
profile/billing: a root-span attr that the rollup reads (`spanId: rootSpanId`,
`activity/recorder.ts:253-268`). Nullable for cron (`origin: "cron"`,
`activity/recorder.ts:261-276`). Nullable for cron (`origin: "cron"`,
`activity/span-sink.ts:102`, `cron/run-job.ts:113`) and for pre-migration rows;
nothing is backfilled.

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 @@ -490,7 +490,7 @@ An approval given by voice must be as reviewable afterwards as one given by
tapping a card. Most of that already exists: every decision is written as an
append-only `approval_decision` event carrying the principal, the decision and
the request kind, and it patches the span
(`onApprovalDecision`, `packages/ui-server/src/activity/recorder.ts:684-699`),
(`onApprovalDecision`, `packages/ui-server/src/activity/recorder.ts:693-708`),
fed from the bridge's
`recorded()` wrapper
(`const recorded`, `packages/ui-server/src/ws/bridge.ts:414-429`).
Expand Down
6 changes: 5 additions & 1 deletion docs/hosting/agent-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1620,7 +1620,11 @@ inference relay taints the session too, and a tainted session's new
connections reach only `taint.egress.allow` and hosts its proxies already
admitted. Refusals are `egress_denial` events with reason `taint_allowlist`.
Without the proxy (hosts without managed native storage) nothing narrows
egress, and the capabilities note says so. Files the
egress, and the capabilities note says so. On a turn behind the proxy, the Bash
classifier above is off: the proxy's connection taint is the shell signal, so
ordinary commands such as `brain diagram --help` leave the session clean, and
a shell read of an untrusted file that opens no connection does not taint it
(#3429). Files the
user marks untrusted are not a source yet. The rules are in
[the decision record](../decisions/governed-writable-workers.md#untrusted-input-g6).

Expand Down
2 changes: 1 addition & 1 deletion docs/http-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ read by any authenticated principal.
| `strict_fallback` | 1 | `path`, `reason` | A turn ran under `strict` instead of `governed` because a protected path is a `symlink`, a `hardlink` or a `mount_point`. |
| `revert_conflict` | 1 | `conflicts`, `restored` | A revert skipped paths that changed after the reverted turn. Each conflict is `{ path, state }`, with `state` one of `changed`, `deleted`, `created` or `type_changed`; `restored` counts the paths it did restore. |
| `outward_action` | 1 | `tool`, `input`, `inputTruncated`, `action`, `target`, `historyRewrite`, `tainted`, `decision`, `rule` | An action outside the brain in the user's name, allowed or not. `action` is `git_push`, `gh_write`, `mcp_tool`, `http_write` or `outward_host_connect`; `decision` is `policy_allowed`, `approved`, `declined` or `refused`; `rule` is the matching `outward.allow` rule or `null`. |
| `taint` | 1 | `source`, `tool`, `detail` | The untrusted input that tainted the session. `source` is `web_fetch`, `web_search`, `staged_share`, `workspace_read`, `mcp_document`, `user_marked`, `egress_connection`, `fetching_command` or `unclassified_command`. |
| `taint` | 1 | `source`, `tool`, `detail` | The untrusted input that tainted the session. `source` is `web_fetch`, `web_search`, `staged_share`, `workspace_read`, `mcp_document`, `user_marked`, `egress_connection`, `fetching_command` or `unclassified_command`. The last two come only from a turn without the turn egress proxy (#3429). |
| `provider_unavailable` | 1 | `provider`, `capability`, `command`, `degradedTo` | A worker command needed a provider whose key the host withheld from the worker. Recorded from the token the CLI prints ([CLI contract](integration-contract/cli.md#withheld-provider-keys-additive-0440-1666)), one event per distinct token in a tool result and at most 20 per turn. `capability` is `embeddings`, `completions`, `reranking` or `image`; `command` is the shell command, or the tool's name for any other tool; `degradedTo` names the fallback used (`keyword_search`, `keyword_index`, `lifecycle_order`) or is `null`. The token is text in tool output, so the event is a diagnostic, not proof. |
| `resource_limit` | 1 | `limits`, `fatal` | A worker hit a resource limit. Each limit is `{ limit, source, value, events }`: `limit` is `processes`, `memory`, `pids`, `file_size`, `data`, `cpu` or `open_files`; `source` is `rlimit` or `cgroup`; `value` is the configured limit; `events` counts the hits the source reported, or is `null`. `fatal` says whether the worker died of it. |
| `roadblock` | 1 | `category`, `family`, `signature`, `failures`, `resolution`, `remedy`, `waste`, `eventIds` | One classified roadblock episode, written when its turn ends ([classification](decisions/governed-writable-workers.md#roadblocks)). An episode opens at a failed step and closes at the next successful call of the same `family`, or at turn end. `family` is the tool family: `shell:<program>` (with the subcommand for multi-command programs, such as `shell:git push`), `file_write`, `file_read`, `search`, `web`, `brain_write`, `subagent`, `mcp:<server>:<tool>` or `tool:<name>`; a governance event with no call has `budget`, `scope`, `network`, `policy` or `outward`. `category` is `tool_error`, `shell_nonzero`, `fs_denied`, `permission_denied`, `policy_block`, `budget`, `scope_cap`, `network_refused` or `retry`. It is `retry` when the episode repeated a near-identical failed input, and otherwise the first failure's category. `signature` is the grouping key `<family>\|<target>\|<category> <detail>` of the first failure, for example `file_write\|.brain/*\|fs_denied EROFS .brain/*`. The target is the command's program and, for multi-command programs, its subcommand (`<script>` for a program run by path); the directory a path sits in, by its last name, when that is one of the brain's structural or write areas (`<dir>` otherwise); or a URL's scheme (`https-url`). A signature therefore never carries file names, arguments, hosts, user-chosen directory names or absolute roots. The detail after the category is the error code and target area, `exit <code>`, or the deciding rule or limit, so equal signatures mean the same roadblock. Each failure is `{ toolCallId, signature, category }`, where `toolCallId` is `null` for a governance event with no call. `resolution` is `{ toolCallId, signature }` or `null`. `remedy` is `guidance` when a call the turn could already make resolved the episode. It is `abandoned` for exactly one unresolved failure with no retry followed by an eligible later success; repeated unresolved failures or turn-temp workarounds remain `capability`. `waste` is `{ tokens, costUsd, ms }`, measured from the first failed call's start to the resolving call's start; unresolved waste stops at the first successful call starting strictly after the last failure was known, otherwise at turn end. That accounting boundary does not create semantic resolution. Usage is sampled at that boundary; final usage cannot fill an earlier bound. Unknown tokens or cost are `null`, never 0. `eventIds` names the governance events the episode drew on. |
Expand Down
15 changes: 15 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,21 @@ same-commit update of the index or relevant authoritative component. How they ar

The reasoning is in [decisions/contract-versioning.md](decisions/contract-versioning.md).

## Shell taint behind the egress proxy (breaking before 1.0, #3429)

On a turn whose worker runs behind the turn egress proxy
(`runtime.workerHost.governed.egress.active`), the `taint` governance event no
longer records `source: "fetching_command"` or `"unclassified_command"`. The
proxy's `egress_connection` taint, recorded at the first admitted connection
other than the inference relay, is the shell signal there. Every other source
keeps its meaning, and a turn without the proxy keeps the shell classifier.
Consumers must not expect a shell command alone to taint a proxied session; a
shell read of an untrusted file without a connection does not taint it. No
payload shape or kind changes. See the
[governance events component](integration-contract/http.md#shell-taint-behind-the-egress-proxy-breaking-3429)
and the [decision](decisions/governed-writable-workers.md#shell-classifier-off-behind-the-proxy).
This is a pre-1.0 breaking minor under the maintainer ruling recorded on #3429.

## Explicit local chat deletion (additive, #3230)

An authenticated owner can delete its own chat's local history with
Expand Down
9 changes: 9 additions & 0 deletions docs/integration-contract/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,15 @@ that refused a path the turn's provider folder masks hide: the tool as the
agent called it, the brain-relative path, the `providers` rule and the policy
hash. One event is written per refused call.

<a id="shell-taint-behind-the-egress-proxy-breaking-3429"></a>

**Shell taint behind the egress proxy (breaking before 1.0, #3429).** On a
turn behind the turn egress proxy, `taint` is no longer recorded with
`source: "fetching_command"` or `"unclassified_command"`; the proxy's
`egress_connection` source covers shell network access there. A turn without
the proxy still records both. The payload shape and version are unchanged, and
stored events keep their recorded sources.

The kinds and each kind's payload are versioned separately. A payload change
that is not purely additive bumps that kind's `schemaVersion`, and stored
events keep the version they were written with, so a new version or a new
Expand Down
6 changes: 3 additions & 3 deletions docs/plans/async-collaboration-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ Stated before the requirements because five of them derive from it.
`persistSession: false`; pi provides `SessionManager.inMemory`. Drive this mode
with a synthetic checkpoint bridge and server-selected authority; the
recorder accepts autonomous origin and keeps runtime identity separate from an interactive session
(`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:126-204`).
(`export function createTurnRecorder(`, `packages/ui-server/src/activity/recorder.ts:132-210`).
- R25. **Autonomous work gets its own pool** (`MAX_AUTONOMOUS_RUNS`, default 2) — but a second
counter alone does not deliver "interactive always wins". The host cap applies only when
starting WS sessions (`const cap = host.maxConcurrentSessions();`, `packages/ui-server/src/ws/run-session.ts:1336-1348`), and an autonomous
starting WS sessions (`const cap = host.maxConcurrentSessions();`, `packages/ui-server/src/ws/run-session.ts:1340-1352`), and an autonomous
turn can hold a path write lock while an interactive turn waits or is denied at 30 seconds
(`export function createTurnLockBinding(`, `packages/ui-backend-claude/src/turn-lock.ts:27-119`). Required: an admission controller
with reserved interactive capacity and hybrid yield at an explicit denial-risk
Expand Down Expand Up @@ -343,7 +343,7 @@ Stated before the requirements because five of them derive from it.
policy proposals, and discuss-session digest construction when those v2 features ship. Revision 1's "T2 is the entire
bill" was false.
- R41. **Budgets are enforced by reservation at claim time, not by summing history.**
`rollupRun` runs in `finish()` (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:756`), so cost exists only after a
`rollupRun` runs in `finish()` (`store.rollupRun(runId);`, `packages/ui-server/src/activity/recorder.ts:765`), so cost exists only after a
run ends: two runs can both start under the cap and finish over it, and unknown effective
costs are excluded from the sum (`export function sumEffectiveCost(`, `packages/ui-server/src/activity/store.ts:179-194`) so the query **fails open**.
Required: transactional reservations on claim, in-flight reservations counted, settlement at
Expand Down
Loading
Loading