Skip to content

ui-sdk: run interactive and voice turns in a governed writable worker with read-only protected paths #1649

Closed

Description

@schlessera

Guardrail class: G1 (system integrity). This is the epic's default profile. While it is missing, the ordinary hosted way of working stays blocked.

Settled overlap guarantee (maintainer, 2026-10-12)

The maintainer ruling supersedes the previous overlapping-worker blocker: governed peers have equal authority and may consume one another's configuration/steering edits immediately. Those edits are G7, journaled and revertible through #1652/#1658. Restricted, strict and maintenance workers, and host-side readers, receive immutable startup snapshots of the configuration they consume. A later governed edit reaches them at their next launch. Runtime proof must cover every consumer, including transitive configuration inputs and absence at startup.

Approved snapshot architecture (maintainer, 2026-10-12)

The second maintainer ruling permits complete read-only startup views for restricted, strict and maintenance workers and host readers. Configuration runs from that view, including arbitrary local imports, configured resources and absence. Legitimate writes use a separately named server-validated authoritative path; writable outputs never replace the configuration execution view. Governed peers retain their live visibility, with G7 journal attribution supplied by the journal siblings. A bounded configuration format and serialization behind governed turns are not adopted.

The earlier standalone native and Docker measurements established why freezing individual filenames was insufficient. They are retained as historical evidence, not as production implementation or proof that the separate write path is impossible. The architecture question is settled; implementation and complete consumer/runtime proof remain on this issue.

Bounded output staging (maintainer, 2026-10-12)

The third ruling
settles the remaining capacity policy. Output staging has its own validated,
host-configurable 256 MiB per-worker allowance. Its aggregate budget
(default allowance × maximum concurrent sessions, with an explicit override)
extends the existing runtime-state/turn-temp admission ledger. A worker unable
to reserve it refuses as worker_state_busy with Retry. It is separate from
turn temp. Writes beyond the allowance fail with a named error; the note's
limits list and hosting guide disclose the enforcing value.

Read-only startup inputs, private writable copies and Git adapter data must
all fit that staging capacity. Oversized starting copies refuse before worker
execution. No unbounded host-backed overflow fallback is permitted.

The historical native and Docker measurements demonstrated 8 MiB of staging
written beyond a 1 MiB private turn-temp control; they are the failing-first
regression, rather than current behavior. Draft #1723 now enforces staging
with a separately reserved bounded tmpfs, preserves both startup-view rulings,
and captures fixed ignore-parser bytes without copying unrelated repository
contents. Full runtime proof, independent review, ready-PR CI and merge
verification remain required before this issue closes.

Operational state outside the brain (maintainer, 2026-10-12)

The fourth ruling requires the operational database and other private server state outside the brain for every hosted profile. Boot refuses with a named message and migration steps before opening state or executing brain code. The refusal is reflected on the status surface. No strict private-state exclusions are introduced and the masks remain intact. The decision record and hosting guide document the requirement.

The preserved database-layout proof is now a boot-factory regression covering existing/new databases, linked database files and missing parents, and private poke-token state under both governed and strict profiles. It asserts named refusal, migration guidance, unchanged existing database bytes, no new state and no brain-code execution. Both-host failing-first and restored mutation receipts are required, alongside the complete original acceptance proof. Hosts also need util-linux nsenter and setns permitted in their namespace seccomp profile.

PR #1723 now integrates both isolated cleanup/directory-mode fixes, operational-state alias checks and live main, including the host sync mirror and CLI mount topology. Cleanup uses descriptor-anchored private copies and cannot retain the gate or staging reservation. Directory modes finalize after children, preserve newer peer modes and process all pending directories after an error. The identity/mode recheck and chmod are separate syscalls. When a peer removes parent search permission, held parent handles and kernel dentry paths permit unchanged children to finalize; moved held inodes are refused. Private-state descendant aliases are refused, and in-memory operational masks preserve private turn-temp capacity.

The fresh independent GPT-6.1-Sol combined review completed and its three reproducible findings have behavioral regressions and native/Docker guard mutations. Host sync retains immutable configuration inputs, validates local output publication and never gives its credentialed transport a brain mount. Full selected matching-head hosted proof is complete on the current implementation below; no merge is claimed. Coordinator owns merge; this invocation performed no merge and no push after merge.

Context

Decision: docs/decisions/governed-writable-workers.md (sections "Profiles", "Protected paths" and "How the mounts enforce it").

Current implementation checkpoint: 5f7471602cc5d6afd4fdc932bf59ed41357b7c70. The launcher selects governed live mounts or immutable startup inputs (workerCommand, packages/ui-sdk/src/server/worker-launcher.ts:439-550). Claude restores native writes for governed text turns while keeping strict/voice restrictions (disallowedTools, packages/ui-backend-claude/src/sdk-options.ts:223-225). Pi's hosted tools use server RPC locks and governed direct writes (const resources = createSessionResources, packages/ui-backend-pi/src/worker-entry.ts:106-119). The host probe tests the selected profile (export function probeWorkerHost, packages/ui-sdk/src/server/worker-launcher.ts:1066-1163).

#1626 adds packages/ui-sdk/src/server/worker-sandbox.ts, which resolves the writable areas as a named-mount list and checks for hardlinks and nested mounts. This profile is built on that list.

Measured 2026-10-11 (receipts):

  • Read-only sub-mounts alone are defeated by renaming an ancestor (context/, .git/).
  • Self-binding each ancestor makes that rename fail with EBUSY.
  • A protected name that is absent can still be created.

Scope

  • Profile resolution. Interactive and voice turns default to governed. strict is the 0.41 view plus backends: the worker sandbox leaves no persistent writable place for scratch, workspaces or file outputs #1626's named areas. Autonomous turns stay restricted, unchanged. Until the policy file exists, built-in defaults select the profile.
  • Mounts. Under governed, the launcher binds the brain read-write. Each existing protected path (the decision's tier A and tier B tables) is mounted with --ro-bind. Each protected ancestor below the root is self-bound read-write. Missing protected directories (context/policies/, .git/hooks/, .git/info/, node_modules/) are created empty before launch. All of these are entries in backends: the worker sandbox leaves no persistent writable place for scratch, workspaces or file outputs #1626's mount list.
  • Guard. A protected path that is a symlink, has nlink > 1 or is another mount makes that turn run as strict. The capabilities note gives the reason, and a governance event is recorded (or logged, until Epic: productive, governed interactive and voice turns #1636's event store lands).
  • Quarantine. At turn end, any tier A or tier B file that appeared during the turn is moved into a host-private quarantine directory beside DB_PATH and removed from the brain. The manifest is the durable one from the host-boundary sibling issue.
  • Masks. Host runtime and home directories are masked (/run, /var/run, /var/lib, /tmp/.X11-unix, homes except the brain's path, /root, /mnt, /media, /srv), so no host Unix socket is reachable.
  • Runtime rebinds. After the masks, the worker's runtime is re-bound read-only file by file, as restrictedReadPaths does (export function restrictedReadPaths, packages/ui-sdk/src/server/worker-launcher.ts:1176-1202): Bun, the backend entry and its node_modules chains, and the bundled agent CLI. A runtime installed under a home directory or /srv keeps working.
  • Launch visibility. Governed peers may consume one another’s configuration changes immediately. Every other configuration consumer executes from its immutable complete startup view. Quarantine still reconciles newly created protected names at turn end and after crashes.
  • Writer gate. governed and strict turns hold the shared writer gate, introduced by the host-boundary issue, while they run.
  • Claude. Under governed, the Write, Edit and NotebookEdit disallow is lifted. Under strict it stays.
  • Pi. Under governed, bash runs in the brain root, the direct write_file/edit_file tools are used, and the tool lock is the server's keyed lock, taken over the worker RPC.
  • Probe. probeWorkerHost gains a governed mode. It asserts that a protected sentinel is unchanged and that an unprotected sentinel was written. The per-turn gate probes the mode the turn will use.

Out of scope

  • The policy file and profile selection from it (sibling issue).
  • The journal and revert, budgets, egress, and .env masking (siblings).
  • Any change to autonomous or restricted turns.
  • Any unsandboxed fallback.

Acceptance criteria

  • In an interactive governed turn, for both adapters, Bash, brain add and the native write tools change a Markdown file in the brain. An integrated test observes the change from outside the worker.
  • In the same turn, writing a protected file, renaming an ancestor of context/policies/ or of .git/hooks/, hardlinking a protected file and renaming over a protected file each fail. The protected bytes and directory membership are unchanged when observed from outside. These cases extend tests/policy-write-boundary.test.ts.
  • A .mcp.json created during a turn (when it was absent at launch) is in quarantine after the turn and absent from the brain. An overlapping governed peer may consume the new configuration; an already-launched restricted, strict or maintenance snapshot consumer, or host reader, must retain its startup configuration. Tests cover these orderings and G7 recording.
  • With Bun installed under a masked home directory in a fixture, the worker still launches. A test covers this.
  • From inside a governed worker, a walk of the visible filesystem finds no socket outside the approved relay sockets, on a fixture host with a socket under /run. A test covers this.
  • A protected path that is a hardlink or a symlink makes the turn run as strict, and a test asserts the reason.
  • Voice turns keep VOICE_ALLOWED_TOOLS. A voice test proves Bash and raw writes are still unavailable while capture works.
  • Two concurrent pi sessions serialize git add && git commit on the server lock. A test with an injected delay proves no interleaving.
  • Mutation receipts: drop one ancestor self-bind and the ancestor-rename case fails; drop the /run mask and the socket test fails.

Verification

bun run test for the ui-sdk, backend and ui-server packages. The integrated proof in tests/policy-write-boundary.test.ts on a supported Linux host. bun run check:pr --base origin/main. Update docs/hosting/agent-workers.md to describe both profiles.

Contract impact

Internal launcher and backend behaviour. The tool roster in hosted governed turns changes: native write tools come back. That is additive, but record it in the integration contract's backend notes. Minor changeset.

Implementation prerequisites #1626/#1641 and #1648/#1694 are merged.

2026-10-12 correction: verified the code citations against main bdb1d6db384a38434c4218dc91fb442bfa34a872, replaced stale anchors, removed merged blocker lines, and recorded the reproduced overlapping-worker trust gap. The two release-default questions are already settled in the decision record.

2026-10-12 correction: folded the complete-view/separate-write-path ruling into the current body and removed the superseded active-peer masking requirement. Configuration execution coverage and authoritative-write proof remain required.

2026-10-12 correction: refreshed context citations against main after #1703 and recorded the reproduced output-staging G1 budget gap. Implementation and required proof remain open.

2026-10-12 correction: folded the third output-staging ruling into the specification and replaced the superseded decision request.

2026-10-12 correction: recorded the reproduced strict/database privacy conflict after the third ruling; no weaker mask or new placement policy was selected.

2026-10-12 correction: folded the fourth operational-state placement ruling into the specification; the superseded layout decision request is resolved.

2026-10-12 correction: recorded the alias checkpoint and exact local evidence, refreshed implementation citations, and folded the two reproduced runtime findings and isolated-patch coordination into remaining verification. Full hosted proof and merge are not claimed complete.

2026-10-12 integration correction: folded the completed isolated patches, current-main sync integration, independent-review fixes and separate-syscall publication limits into current behavior. Native/Docker combined proof, local preflight and matching-head hosted identities are recorded below when complete. Historical receipts retain their original trees.

Current combined proof at the integrated head above: native 881 tests / 53 files / 6281 assertions; nonroot Docker 881 / 53 / 6283, zero failures/skips. Main-warning integration 9 / 4 / 83 on each host. Strict types, API reports, citations and 18-package minor 0.42.0 plan pass. Final bun run check:pr --base origin/main passes 843 / 43 / 5351. Native bwrap 0.12.0/nsenter 2.42.3; Docker bwrap 0.9.0/nsenter 2.39.3. Docker uses UID 1000, init, a closed local dummy-interface namespace and no effective/ambient capabilities before application execution; no cgroup enforcement is claimed. The previous ready run 38281280002 on 3eb4fc3 failed four unit shards; its checkout and failing fixtures are preserved, not counted green. Corrections now include per-brain maintenance output lifecycle serialization, cancelled Git-preparation refusal, deferred refresh shutdown before database closure, sparse startup cloning within the unchanged bounded staging allowance, and operational-state fixture placement. Frozen snapshot and every separately named maintenance output/strict area copy preserve secret-link masks while permitted writes remain usable. Native and Docker actual failing-first and mutation receipts cover these changes. Final ready CI38293568642/attempt1 now passes every selected job on the exact head/tree above; all14 actual job checkouts are f662098, parents215182681+5f7471602, treec5e5ba154. Retention is empty; contract38293512179/attempt1/job114958980891 passes. All #1649 acceptance and selected proof are complete, PR #1723 was merged by the coordinator at 5876df6c81e8fe5e32f6bf1b97fa41397b29492e; its tree matches the tested tree. Issue/PR closure and milestone 0.42.0 are read back. This invocation did not merge or push after merge. Paid-live and intentional variant/fallback markers are excluded from passed counts; no #1649 runtime proof is skipped. Serialized project-board automation is separate and may remain pending. No acceptance criterion is transferred to a sibling and no clean post-fix independent review is claimed.

Activity

  1. added this to the 0.42.0 milestone on Oct 11, 2026
  2. added
    type: feat
    area: ui-sdk
    area: ui-server
    area: backends
    priority: p0
    agent-ready
    blocked
    security
    on Oct 11, 2026
  3. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Checked against #1641 (for #1626), which merges first. This issue's scope is unchanged, and #1641 implements none of it. Three things to know before starting here:

    • The mount list is real. prepareWorkerSandbox (packages/ui-sdk/src/server/worker-launcher.ts) resolves a WorkerSandbox with named areas (scratch, workspaces) and a home mode. Its areas option lets a caller choose which areas a worker gets. workerCommand binds exactly the writable ones after --ro-bind brain brain, and workerSandboxNote renders the agent's note from the same object. Protected-path binds for governed belong in that list.
    • The guards to reuse. In packages/ui-sdk/src/server/worker-sandbox.ts, realBrainDirectory (an lstat on every segment, never through a link) and mountPointsUnder already exist. So does scanForOutsideLinks: a descriptor-anchored walk that counts names per inode, reads names as bytes, and detects a tree changing under it. CONTRACT: fix(backends): give hosted workers persistent writable scratch, workspaces and a per-turn home #1641's review found that any host-side check-then-act on an agent-writable directory is a race. The prune, the file routes and the walk now go through /proc/self/fd/<fd>/<name> with O_NOFOLLOW. The quarantine and launch reconciliation here should use the same pattern.
    • The citations will be stale after CONTRACT: fix(backends): give hosted workers persistent writable scratch, workspaces and a per-turn home #1641. On that branch: "--ro-bind", brain, brain is at worker-launcher.ts:161 (not 135), export function probeWorkerHost is at :334 (not 185), and export function restrictedReadPaths is at :407 (not 258). Claude's disallowedTools is at sdk-options.ts:195 (not 188). Pi's lock: toolLockFromKeyed(createKeyedLock()) is at worker-entry.ts:73 and shellCwd: WORKER_SCRATCH at :77 (not 71 and 75). Re-verify them at pickup.
  4. schlessera commented on Oct 11, 2026

    @schlessera
    OwnerAuthor

    Coordination from #1654 (PR #1695): the capabilities note has a slot for the governed profile line. WorkerProfile and PROFILE_LINES in packages/ui-sdk/src/server/worker-sandbox.ts are keyed by profile; adding governed makes the compiler require its line, rendered from the resolved protected-path list (with each reason). #1654's remaining criterion (governed note lists exactly the resolved protected paths; a test mutates the list) stays open on #1654, blocked by this issue.

  5. 52 remaining items

  6. schlessera commented on Oct 12, 2026

    @schlessera
    OwnerAuthor

    Merged #1723 as 5876df6c81e8fe5e32f6bf1b97fa41397b29492e for 0.42.0. The squash is on main, has parent 215182681b888f30ab8f3c2dbdb0dcec130c497b, and its tree c5e5ba154ea4350e70ad30f9c33fca6a3256e2dc exactly matches the tested combined checkout.

    Ready CI run38293568642, attempt1: all14 selected jobs passed on actual checkout f66209831df41e66175508a462e48254f5645104, whose parents are the recorded base and head 5f7471602cc5d6afd4fdc932bf59ed41357b7c70. The retention ledger is empty. The PR records each job identity, native/Docker runtime matrices, actual behavioral mutations and final independent source review.

    Governed writes, complete immutable startup consumers, bounded staging and operational-state placement are delivered. Policy, journal/revert, budgets and other explicitly separate programme siblings remain open. Main-push run38296257252 passed all 14 selected jobs on the actual squash checkout 5876df6c81e8fe5e32f6bf1b97fa41397b29492e; each job checkout was verified from its execution log. Release publishing remains a separate maintainer-terminal action.

  7. removed their assignment
    on Oct 12, 2026
  8. removed
    agent-ready
    on Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: backendsarea: ui-sdkarea: ui-serverpriority: p0securitytype: feat

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions