Repository navigation
Description
Context
Found while working #3387 (scope item 3: "Record whether a server crash between spawn and release also closes the writer and releases a live gated child").
Observed. It does. The status-gated live launch gates the payload with bubblewrap --block-fd 4 (workerBootstrap, packages/ui-sdk/src/server/worker-launcher.ts:969-976). The server holds the only writer of that gate FIFO (createWorkerStatusPipeSteps, packages/ui-sdk/src/server/worker-status.ts). bubblewrap starts the sandbox on the gate's EOF as it does on a byte. When the server process dies between spawn and release(), the kernel closes the writer, and the gated sandbox process passes the gate and runs a payload whose setup (state population, folder-mount qualification) never finished.
--die-with-parent does not prevent it. bubblewrap's gated child outlives the outer bubblewrap's death. A probe in the #3387 work killed the outer bwrap, waited for it to be reaped, then closed the gate. The sandbox child was still in state S, and the payload ran with and without --die-with-parent.
Reproduction (Bun 1.4.4, 16 CPUs, bubblewrap 0.11.1, rootless container with no network). A child "server" creates the status pipe, spawns bwrap --json-status-fd 3 --block-fd 4 --unshare-user --unshare-pid [--die-with-parent] --bind / / --proc /proc -- /bin/sh -c 'printf Odysseus > "$0"' <marker> through the launcher's exec 3>…; exec 4<… shell, and reads the verified child PID. It is then SIGKILLed. The payload wrote its marker 20/20 without --die-with-parent and 20/20 with it.
The #3387 fix covers refusals the server itself handles (a refused gate stays open until every gated process is confirmed dead). It cannot cover the server's own death, because the gate's lifetime is the server's descriptor.
Scope
- Make the non-helper status-gated launch fail closed on holder/server death before authorization, using the selected explicit-token gate in a trusted pre-payload wrapper. Only a complete affirmative
goline from the server-owned release channel authorizes agent startup; EOF, malformed/partial input, read failure or wrapper failure cannot release it. - Scope the descriptor exception to the trusted wrapper only: a dedicated read-only release channel may reach that wrapper, and must be closed before any agent/payload-controlled code executes. Preserve payload stdin byte-for-byte and the unchanged general bootstrap filter. Do not expose the release writer, host authority/status/mount handles or a reusable gate descriptor to the payload.
- Keep status/PID/mount authentication and all setup qualification ahead of release. If retaining bubblewrap's outer setup gate, treat it solely as a setup/status barrier, not authorization for agent execution; it must not consume or manufacture the final gate's affirmative authorization. No implicit success, automatic release, fallback on error or equivalent new launch path may bypass the final gate.
- Record the scoped amendment and rejected alternatives in
docs/decisions/policy-write-boundary.md, and reconcileSTATE_GATE/workerBootstrapcomments. The prior descriptor rule remains binding for the agent payload; this permits only the trusted, short-lived pre-payload gate needed for the measured crash case. No external keeper, persistent daemon, new public seam or broader descriptor inheritance is selected.
All mechanism/policy choices are resolved by the maintainer ruling below. Exact internal FD numbers/plumbing may be chosen during implementation within these constraints; inability to satisfy them is a refusal/return for review, not permission to broaden the exception.
Out of scope
- The server-handled refusal-ordering repair owned by ui-sdk: a refused status-gated launch closes the start gate before its sandbox dies, so the payload can still run #3387. Preserve/coordinate with its implementation and regression coverage; its current open state is not proof that repair has reached main.
- The separate-UID identity-helper path. Its gate lives in the helper process, and whether that helper's own death fails closed is a separate question.
Acceptance criteria
- A real-process test starts the non-helper status-gated launch, waits for an authenticated/observable pre-release state, SIGKILLs the process holding the release writer and proves no payload marker/effect occurs. Include a crash before setup/qualification finishes and after setup but before release. Use explicit synchronization and observe cleanup/child exit; absence of a marker immediately after SIGKILL is not sufficient proof. Record the failing-first payload-marker assertion on the inspected unpatched path and the restored passing run; a module-load, namespace-permission or pre-spawn failure does not prove the gate.
- EOF, complete wrong token, truncated token/no complete affirmative line, read failure and wrapper termination before release never execute the payload. Tests exercise the real launch/wrapper, not only a token predicate. No automatic approval follows a status notification, parent death, timeout or cleanup. A valid explicit release after qualified setup is the positive control: it starts the intended payload exactly once.
- The final gate is fixed trusted code before any payload/agent-controlled runtime, repository hook/import, PATH lookup or environment-driven startup code. Validate executable and launch inputs under the existing bootstrap/namespace policy; malformed/unavailable gate setup refuses. No untrusted party can mint release by writing the gate.
- Payload stdin remains byte-identical, including data already queued while the gate waits. The release token is carried on a separate dedicated channel rather than consuming application input. Probe the payload after exec to prove the gate FD and all other non-protocol control/status/host handles are absent; preserve existing descriptor rejection and authenticated PID/start-time/namespace checks. Do not weaken tests merely to admit the new pre-payload exception.
- Refusal/cleanup and wrapper/outer-process death cannot turn the final gate into an EOF release. Keep ui-sdk: a refused status-gated launch closes the start gate before its sandbox dies, so the payload can still run #3387's refusal-ordering guarantees and test coverage, including scheduling variation, without assuming that killing the outer bwrap proves every sandbox descendant dead. Test teardown observes/reaps or otherwise proves termination of owned processes; no success claim from a cleanup timeout.
- Scope guarantees accurately: death before affirmative release never authorizes the payload. This does not prove every post-release server-death behavior or the separate-UID helper's own crash behavior, both outside this issue's selected mechanism. Preserve existing post-release and helper controls without claiming qualification here.
- Update the relevant decision record in the implementation with the selected mechanism, narrow descriptor exception, proof boundary and rejected external-keeper/flag-only alternatives; repair cited source ranges affected by changes. No new unrelated policy/architecture choice is required before implementation.
Verification
Run keyless/offline real Linux process/namespace tests on a host with permitted user namespaces, using only fictional Odysseus marker files in temporary owned paths. Record the source SHA, actual Bun/bubblewrap versions, relevant platform conditions and commands. No provider key, network access or real deployment is required.
Run the new crash-gate test plus bun run test packages/ui-sdk/tests/governed-worker.test.ts packages/ui-sdk/tests/worker-status.test.ts packages/ui-sdk/tests/worker-state-mount.test.ts. Include #3387's refused-launch-gate.test.ts once available on the implementation base; it is not present in inspected main 5a0ce18fdcecf0a6c5b83487c865a3f73806d5d0, so do not invent a passing run or silently omit equivalent refusal coverage. Exercise sync/async/direct/probe entry paths where shared gate plumbing changes and document which retain their existing gate.
Keep a failing-first crash/marker witness and a restored mutation that accepts EOF or bypasses the explicit-token check, proving the named payload-never-starts assertion fails for the intended reason. Use a valid-release positive control and real payload FD/stdin checks so a gate that never launches anything cannot pass. Preserve existing qualification deadlines, refusal assertions and namespace/descriptor guards. Run affected typecheck/lint and bun run check:pr --base origin/main (or the actual immediate parent if implementing as a reviewed dependent layer). No runtime reproduction/test completion is claimed by this decision triage.
Contract impact
No public CLI/MCP/wire/worker API change is expected; this selects an internal security correction and scoped existing decision-record amendment. Do not introduce a public gate/supervisor API or weaken existing supported semantics. Apply the appropriate user-visible security-fix changeset during implementation. If actual supported schema/API changes are needed, classify/document them under the normal contract policy rather than assuming this ruling authorizes a break.
Remove needs: decision and add agent-ready: no other needs: label remains. #3387 is related work to coordinate with, not an invented completed prerequisite or a reason to claim its repair delivered. Preserve priority p1/security, assignment and any actual release commitment; this review itself schedules no release.
Decision — maintainer, 2026-11-02
Selected A: explicit-token gate in a trusted wrapper before agent code starts. Require affirmative server authorization on a dedicated release channel; EOF/invalid input refuses. Permit that channel only in the short-lived trusted wrapper and close it before agent/payload execution, with application stdin unchanged. The accepted cost is the narrowly documented descriptor-rule amendment and its proof burden; no agent-facing descriptor exception follows.
Rejected B, an additional external per-launch keeper: it adds another trusted process/lifecycle and its own keeper-death qualification without eliminating the requirement for a crash-safe authorization boundary. No new permanent daemon or elevated helper is approved. Do not replace the final gate with a flag-only change: upstream bubblewrap v0.11.1's --block-fd and --userns-block-fd reads ignore EOF/read results, while --sync-fd tracks lifetime rather than conveying affirmative startup authorization. Source: upstream bubblewrap v0.11.1, block gate, sync descriptor. The local installed binary reports 0.11.1; source review is not proof of a new gate implementation.
At inspected main 5a0ce18fdcecf0a6c5b83487c865a3f73806d5d0, the existing stdin gate is STATE_GATE (packages/ui-sdk/src/server/worker-launcher.ts:56-58), the live status setup is workerBootstrap (packages/ui-sdk/src/server/worker-launcher.ts:960-982), and the FIFO/release ownership is createWorkerStatusPipeSteps (packages/ui-sdk/src/server/worker-status.ts:15-70). The trusted descriptor filter is packages/ui-sdk/src/server/worker-entry.ts; inspect it before changing plumbing. Update moved citations and the dated policy-write-boundary alternatives alongside the implementation. The new final gate may reuse the existing fail-closed token concept, but must not consume payload stdin or assume unverified FD inheritance through Bun/bwrap.
2026-11-02 interactive mechanism ruling: selected A and folded it into scope, explicit acceptance criteria and real-process verification. All current decisions on this issue are resolved. Remove needs: decision and add agent-ready because no other needs prerequisite remains. The original report's reproduction is retained as reported evidence; this triage does not implement or claim a newly reproduced/measured fix, mutation receipt or release.
Activity
schlessera commentedon Nov 2, 2026
Decision (maintainer, 2026-11-02): A — an explicit-token gate in a trusted wrapper before agent code starts. Only complete affirmative server authorization releases it. EOF, malformed/partial input, read failure or wrapper failure must refuse startup.
The descriptor exception is narrowly scoped: the trusted wrapper may receive a dedicated read-only release channel, closes it before agent/payload execution, and preserves payload stdin byte-for-byte. Keep the general bootstrap filter, authenticated PID/mount qualification, resource limits and no-agent-control-FD rule. No external keeper/daemon, broad inheritance exception or flag-only fallback is selected. Bubblewrap's existing EOF-opening barrier is not final startup authorization.
Folded the choice into the body with the scoped policy-write-boundary amendment, real crash/invalid-input/positive-release/stdin/FD proof obligations and rejection rationale. #3387 still owns server-handled refusal ordering and is currently open; coordinate without claiming its repair already on main. The helper's own death and broader post-release guarantees remain outside this issue.
Remove
needs: decisionand addagent-ready: no other needs label or actual external prerequisite remains. This records the approved mechanism; it does not implement or claim new reproduction/mutation/runtime proof or a release commitment.schlessera commentedon Nov 3, 2026
Spike: fail-closed start gate when the gate holder dies (for the ruling)
Recommendation: candidate 1, an in-sandbox start gate on fd 4 that needs an explicit
goline, replacing bubblewrap's--block-fd. It was the only mechanism that failed closed in every server-death probe with no new process and no leaked process, and it adds about 0.5 ms to startup. A keeper (candidate 2) doesn't close the hole. It moves it to the keeper. No bubblewrap 0.11.1 option fails closed by design.Why
--die-with-parentdoes not help (bubblewrap 0.11.1 source)From
bubblewrap.cat tagv0.11.1:PR_SET_PDEATHSIGfor itself right after clone (handle_die_with_parent ();, line 3188). That is why it dies with the server.--block-fd(read (opt_block_fd, b, 1), lines 3504-3509). It arms its own parent-death signal only after that read: indo_init(line 624) and before exec (line 3605).readreturns 0 on EOF and bubblewrap ignores the result and continues. The man page's--die-with-parenttext ("kills all bwrap sandbox processes … when bwrap or bwrap's parent dies",bwrap.xml:586-592) does not hold during the gate window.Probe
--network none, unconfined seccomp/AppArmor andsystempaths=unconfined. The host/usr(bubblewrap 0.11.1, dash, coreutils) was mounted read-only, the probe ran as uid 1000 (not container root), and Bun 1.4.4 on 16 CPUs.createWorkerStatusPipeStepsdoes. It spawns through the launcher'sexec 3>"$1"; exec 4<"$2"shell with/proc/<server>/fd/Nsources, reads the--json-status-fdchild PID, closes the status writer, then reports "armed".printf Odysseusmarker and for surviving trial processes.--block-fd 4--block-fd 4+--die-with-parentgogate on fd 4, no--block-fd--die-with-parentgthen diedgo(no newline) then diedgo\n)/proc/self/fd25/25)--block-fd+--sync-fd 5+--die-with-parent--userns-block-fd 4+--info-fd+--die-with-parentCreating newroot failed: Value too large for defined data type(uid never mapped)--userns-block-fd, control (server writessetgroups/uid_map/gid_map, then a byte)Latency, release to payload start (n=50 each):
--block-fdp50 1.41 ms / p90 1.85 ms. In-sandbox gate p50 1.89 ms / p90 2.18 ms. The cost is one extra dashexec. The time from spawn to the authenticated status line was unchanged (14-17 ms median in every row).Candidates
1. In-sandbox
gogate on fd 4 (recommended).--block-fd 4and keep--json-status-fd 3. The launch shell still opens fd 4. bubblewrap passes it through, and its PID-1 reaper closes extra descriptors in itself only. The payload command gets a prefix:/bin/sh -c 'IFS= read -r go <&4 && [ "$go" = go ] || exit 125; exec 4<&-; exec "$@"'.release()writesgo\ninstead ofg.STATE_GATEmoved off stdin./bin/sh, before any payload exists, and it is closed beforeexec "$@". The FIFO is unlinked, and the server's/proc/<pid>/fdpath does not resolve in the sandbox's private/proc.createWorkerFreezeralready recognises a bwrap reaper root, and the identity kill in fix(ui-sdk): keep a refused start gate closed until its sandbox is dead #3396 still ends the whole namespace through its PID 1. Before release, the reaper cannot exit while the gate shell is blocked, so "the PID cannot exit/recycle before verification" still holds.workerBootstrap, one release byte, the existingSTATE_GATEtext on fd 4 instead of fd 0, applied to every status launch (not onlygated()).--block-fdfrom its own pipe (worker-identity-program.ts,'--block-fd', str(gate_read)). If the helper dies before release, it most likely has the same hole (not probed here). The same in-sandbox gate would close it if the helper passedgate_readinto the sandbox, which is worth a separate issue if the ruling picks this option.2. Trusted keeper outside the server. It works only while the keeper outlives the server. The hole moves to the keeper's descriptor: a keeper SIGKILLed with the server released the payload 25/25. That is the common case for a cgroup or process-group stop or an OOM kill that takes both.
PR_SET_PDEATHSIGfires on the death of the parent thread, not the process, is cleared by credential changes, and needs agetppid()recheck at setup. Bun cannot set it on a child without a helper (setpriv --pdeathsig).3. bubblewrap options (0.11.1).
--block-fd: proceeds on EOF (lines 3504-3509).--sync-fd: a lifetime signal out of the sandbox, held by PID 1 (lines 3552-3598). It is not a gate: 24/25 ran.--userns-block-fd:--info-fd, and the server would have to write the child'ssetgroups/uid_map/gid_mapitself.4. Others considered.
--block-fd, because the first byte releases the gate. With an in-sandbox reader it is candidate 1 plus timers that dash'sreadcannot do (no-t). Rejected as a superset of 1.PR_SET_PDEATHSIGin the child before the--block-fdread, or refuse on EOF): worth reporting upstream, but the project cannot depend on a future bubblewrap. It doesn't replace 1.Draft decision-record amendment (
docs/decisions/policy-write-boundary.md)The same change also touches the
STATE_GATEcomment (packages/ui-sdk/src/server/worker-launcher.ts:46-56) and "Worker startup status" indocs/hosting/agent-workers.md, which says bubblewrap closes both descriptors before the payload runs.The probe scripts are local to the spike and not committed. I can attach them on request. No labels were changed.
schlessera commentedon Nov 3, 2026
Decision (maintainer, 2026-11-03): approve candidate 1 from the spike (#3392 (comment)), together with its drafted amendment to
docs/decisions/policy-write-boundary.md.--block-fd./bin/shreads one line from fd 4 and requires exactlygo. It then closes fd 4 and execs the payload. End-of-file, a partial line or any other line exits 125.release()writesgo\n.STATE_GATEcomment and the "Worker startup status" section ofdocs/hosting/agent-workers.md.schlessera commentedon Nov 3, 2026
Claiming (token
claim-3392-7617f26b). Implementing the approved candidate 1 on branchfix/3392-gate-holder-death, stacked on #3396 (fix/3387-gate-kill-order) because #3396 is still open and changes the same launcher/status code; its kill-before-close ordering stays as a second guard.Path collisions reported by
scripts/collisions.ts: #3396 (base), #3369/#3393/#3394 (docs/hosting/agent-workers.md), #3371/#3400 (docs/decisions/policy-write-boundary.md).schlessera commentedon Nov 3, 2026
Implementation is up as #3408 (draft, ready to confirm). It is stacked on #3396 (
fix/3387-gate-kill-order), which is still open.gogate replaces--block-fd, andrelease()writesgo\n. ui-sdk: a refused status-gated launch closes the start gate before its sandbox dies, so the payload can still run #3387's ordering stays as a second guard. The decision-record amendment is dated 2026-11-03.START_GATEmutations are each caught: accept EOF, accept a partial line, keep fd 4 open, skip the token check.Closesdoes not fire while fix(ui-sdk): keep a gated payload out when the gate holder dies before release #3408 targets the parent branch.The claim stays with this issue's PR. It will be released if this invocation ends before the merge.
fix(ui-sdk): keep a gated payload out when the gate holder dies befor…
schlessera commentedon Nov 3, 2026
#3408 is retargeted to
mainnow that #3396 has squash-merged (2a09d3be0). The new head is98490547c: the same single commit rebased onto44041ca64(git range-diffreports it identical), with #3396's commits dropped. The PR body now closes this issue directly. Rebase receipts: typecheck passes,gate-holder-crash11/11,refused-launch-gate3/3, andcheck:pr --base origin/mainpasses.governed-workerhas one host-only failure, which is identical on unpatched main. It stays a draft, ready to confirm.