Repository navigation
fix(codex): stop sandbox processes surviving termination - #125908
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Landing blockers are resolved on exact head Failure A — QA PGID reuse:
Failure B — CLI child deadlock:
Rebased verification:
ClawSweeper's latest exact-head comment is still |
|
Codex review: found issues before merge. Reviewed August 18, 2026, 1:06 PM ET / 17:06 UTC. ClawSweeper reviewWhat this changesThe PR centralizes Codex sandbox child-process termination, reaping, and backend finalization across process RPCs, streaming HTTP, socket close, and server release. Regression provenancePossible regression — suspected (reviewed change). No predecessor PR is attributed. Merge readinessKeep open: the new remote cleanup path breaks supported Windows MXC sandboxes by running POSIX-only commands, so termination now reports failure there. Likely related people: Dallin Romney (retained lifecycle history) and steipete (recent process-runtime work). Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherThe Codex extension starts sandboxed commands through a local exec server. Termination must clean up the local launcher, remote sandbox descendants, and backend lease before the client receives completion. flowchart LR
A[Codex client] --> B[Sandbox exec server]
B --> C[Child lifecycle owner]
C --> D[Local process tree]
C --> E[Sandbox backend]
E --> F[Remote descendant cleanup]
D --> G[Reap and finalize]
F --> G
G --> H[Termination response]
Decision needed
Why: The generic backend shell API has no POSIX-shell guarantee, and adding a public SDK export also chooses a lasting extension contract. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +157, Tests +319. Total +476 across 9 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Make remote descendant cleanup a backend-owned termination capability, implement the MXC equivalent, and prove both MXC/Windows and POSIX sandbox cleanup before merge. Do we have a high-confidence way to reproduce the issue? Yes, from source: run a Codex sandbox process on Windows with the MXC backend and terminate it; the generic shell invocation receives POSIX-only syntax under cmd.exe and returns an error. Is this the best way to solve the issue? No. A unified child owner is the right boundary, but unconditional POSIX remote cleanup is not a cross-backend solution; cleanup belongs behind a backend capability. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against b9d0e13b5d08. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
f993b4f to
4ec20e9
Compare
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where terminating a Codex sandbox command could acknowledge only a single
SIGTERMwhile a TERM-resistant local wrapper, remote sandbox descendant, or backend lease remained alive.Before this change, process termination, socket loss, and exec-server release could return before descendants were force-killed, reaped, and finalized. After this change, those paths share one child owner that completes remote descendant cleanup, local TERM-to-KILL escalation, child reaping, and backend finalization before termination is acknowledged.
Why This Change Was Made
The sandbox exec server owns each launched process tree and backend lease. A shared
SandboxChildOwnernow carries that ownership through close and finalization for both process RPCs and streaming HTTP helpers. Socket/server cleanup uses the same owner, eliminating the previous split kill/finalize paths and failing closed when a process survivesSIGKILL.Production LOC: +300/-143 (net +157) | Tests: +327/-8
The production growth adds the missing cross-host lifecycle capability: unique remote ownership markers, bounded TERM/KILL/reap verification, one finalization path, and cleanup ownership at connection/server shutdown. Existing duplicated direct-child kill/finalize branches were removed.
User Impact
Codex sandbox termination no longer reports success while resistant descendants or leases remain. Normal cooperative exits still finish without unnecessary force killing; unreaped processes produce an actionable failure instead of a false success.
Evidence
Rebased onto
302d05b988780e70c471a726ff7f8c90e53d25f8. The only rebase conflict was mechanical: current main'sisPidAliveexport and this branch'skillProcessTreeexport were both retained inprocess-runtime.node scripts/run-vitest.mjs extensions/codex/src/app-server/sandbox-exec-server.fs-streaming.test.ts extensions/codex/src/app-server/sandbox-exec-server.fs.test.ts extensions/codex/src/app-server/sandbox-exec-server.http.test.ts extensions/codex/src/app-server/sandbox-exec-server.json-rpc.test.ts extensions/codex/src/app-server/sandbox-exec-server.lifecycle.test.ts extensions/codex/src/app-server/sandbox-exec-server.test.ts— all 78 tests in the current six-file sandbox exec-server inventory passed.pnpm build— full build passed, including all 146 public Plugin SDK subpaths and the SDK surface budget.node scripts/check-changed.mjs— core/extension typechecks, type-aware lint, SDK export/surface gates, dead-code, database-first, architecture, and import-cycle checks passed..agents/skills/autoreview/scripts/autoreview --mode branch --base origin/main --stream-engine-output— clean; no accepted/actionable findings.Direct Codex contract inspection
Personally inspected sibling
openai/codexat02e9bfaac7577a3ab77a40de6b0c3cc37b934576:process/terminate, terminal notifications, and therunningresponse shape: protocol.rs L21-L28, protocol.rs L348-L358.This change strengthens OpenClaw's implementation behind the existing Codex protocol; it does not change protocol fields or public RPC names.