Repository navigation
fix(runtime): require cleanup evidence before releasing owned work - #139657
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 6, 2026, 1:02 AM ET / 05:02 UTC. ClawSweeper reviewWhat this changesThe PR carries cleanup uncertainty through agent, CLI, tool-server, and Gateway lifecycles, retains owned state when closure is unconfirmed, and rechecks authority before retained actions. Merge readiness⛔ Blocked before merge - 3 items remain The cleanup-consumer work remains necessary beyond the merged process foundation. No concrete blocking defect was found in the inspected paths; the maintainer’s explicit acceptance of conservative cleanup refusal resolves the prior intent concern. Priority: P2 Review scores
Verification
How this fits togetherAgent runs launch commands and tool servers whose resources can outlive their returned output. Cleanup owners report whether those resources closed, controlling state release and whether subsequent work may proceed. flowchart TD
A[Agent or CLI invocation] --> B[Commands and tool servers]
B --> C[Returned output]
B --> D[Resource cleanup owners]
D --> E{Closure confirmed?}
E -->|Yes| F[Release owned state]
E -->|No| G[Retain state and refuse replacement]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep cleanup certification with resource owners, preserve completed output and existing plugin disposal, and carry the documented platform and installation validation into the recovery rollout. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main logs cleanup failure or timeout without carrying uncertainty to the outer owner. The PR includes targeted regressions, but this read-only review did not execute them. Is this the best way to solve the issue? Yes for the reviewed boundary: carrying cleanup evidence from existing owners avoids equating returned output with resource closure, while preserving best-effort plugin disposal. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 883d4d65bad1. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
f57f2b4 to
cb3bd2b
Compare
cb3bd2b to
f7bc2ce
Compare
Keep command results and cancellation separate from cleanup uncertainty. MCP, LSP, Codex, CLI and Gateway owners retain cleanup evidence before releasing resources or replacing a prior execution. Keep bounded agent state when closure cannot be confirmed and fence retained host writes. Stage 3 consumer extraction from #135868, following the process foundation in #139517. Remove duplicate cleanup timers, one-use adapters, and the unused asynchronous finalizer callback while preserving plugin disposal compatibility.
f7bc2ce to
5b16717
Compare
|
Merged via squash.
|
Related: #135868
Foundation: #139517 (merged)
What Problem This Solves
Cleanup could be reported as finished after a command returned, a transport exited, or a session left its registry, even though the previous owner had not confirmed resource closure. A later CLI invocation could replace that work, and a bounded agent invocation could release its state too early. Native Codex terminal entries could also disappear before descendant cleanup finished.
This is Stage 3, part 2 of the #135868 split: cleanup evidence and its agent consumers (concern C), including the coupled Gateway close and sidecar lifetime propagation from concern F.
Why This Change Was Made
MCP and LSP use the shared stdio process owner. CLI sessions retain cleanup by execution identity, including after natural retirement or a previous timeout. Codex reports physical transport exit separately from descendant cleanup, and native execution observations remain uncertain when the pinned upstream contract supplies no OS cleanup proof.
One cleanup scope carries failures through nested agent cleanup without replacing the original result or cancellation. Retained host writes recheck their source authority. Gateway lifetime cleanup preserves failures instead of authorizing the next lifecycle. Existing best-effort plugin disposal remains compatible; explicit cleanup joins provide the stronger evidence needed by owned work.
The change removes the old late supervisor join, duplicate cleanup timers and error observers, one-use adapters, and an unnecessary asynchronous finalizer callback. Tests share typed fixtures and exercise real process/output boundaries alongside the relevant refusal and failure cases.
User Impact
Completed output and cancellation outcomes remain available. Cleanup uncertainty retains bounded agent state and locks, prevents replacement of an unclosed CLI session, and prevents unsafe lifecycle completion. This does not enable automatic recovery; activation remains in the later #135868 stage.
Evidence
The selected suites cover CLI, MCP/LSP, embedded runs, Codex, process ownership, agent authority, worker/node-host, Gateway teardown, and memory promotion. Three fixture failures found in the broad run were repaired and their complete relevant suites passed: Gateway shutdown now expects both retained failure phases; CLI replacement awaits its owner; WebSocket fake time starts after a client frame. Final focused correction proof passed 189 tests, with a separate 34-test node-host supplement.
Real macOS tests exercise anchored process groups and scope extinction. A real stdio child receives protocol EOF and drains complete output plus 8,192 Unicode diagnostic lines before successful cleanup. Seven consumer regressions failed on pre-fix production for the intended reasons and passed after repair. The import-cycle check reports zero runtime cycles. Final committed-branch independent review is clean through P2.
Full Linux changed check/build after the embedded-runner reconciliation passed in the configured Blacksmith Testbox (exit 0); its lease completed and stopped. The complete embedded-runner rerun passed 4,442 tests. The subsequent MCP-only reconciliation passed 28 focused tests, including real-child output, with its complete selected core/coreTests gate passing. Final branch review is clean through P2. Exact-head hosted CI is required before landing. Local extension declaration preparation hits parent-checkout dependency resolution; the isolated gate supplies the full check/build proof.
Judged consumer delta: production +1,581/−821 (net +760), tests +2,937/−978 (net +1,959), docs +10/−1, tooling zero. Including #139517, Stage 3 is +1,155 production and +2,593 test lines, compared with the audited source path set's +1,187 production and +2,689 tests. Remaining production growth carries native cleanup evidence, retained failed-owner state, and final-effect authority checks; the campaign still needs offsets elsewhere to reach its cumulative production limit.
Codex's pinned rust-v0.153.4 contract was checked in thread_processor.rs:2362–2423, unified_exec/process_manager.rs:1697–1728, unified_exec/process.rs:240–252, and utils/pty/src/process.rs:219–269. Their termination/list acknowledgments do not certify kernel process extinction. The paired-node exec-server caller also reads the explicit physical-exit field from the new close result.
Windows process utility paths use fixtures; native Windows utility execution was not separately demonstrated. Codex protocol tests use a synthetic app-server and source inspection of rust-v0.153.4. POSIX group ownership does not certify deliberately escaped descendants.
Review follow-through
The conflicts with #139597 and #139616 are reconciled: retain shared attempt setup/resources and a single settlement set, plus MCP shutdown fencing during data-directory preparation and protection against signaling retired owners. The directly affected cleanup suites pass all 53 cases; the final reconciled-head checks and CI are recorded before landing.
ClawSweeper's configuration/data-model flags do not identify a schema or serialized-format change. The file and memory paths add checks of the original invocation's current authority before committing effects. Existing configuration fields, stored provenance fields, and migration versions are unchanged. Retaining state after uncertain cleanup is the intended safety contract; completed command output alone does not authorize releasing it.
The optional MCP
joinCleanuphook preserves existing best-effortdispose. A runtime without the hook remains usable but cannot certify shared cleanup.agent-bundle-mcp-tools.materialize.test.tscovers that case without closing shared peers.agent-exec.state-lock.test.tscovers both fresh temporary state and retained state after uncertainty, plus normal lock release. These are boundary tests, not installed-upgrade proof.The optional rank-up move for a full fresh/existing installation matrix is deferred to the installed recovery matrix in Stage 5. Native Windows execution is also explicitly outside this lane's fixture-only proof. On that platform, as elsewhere, uncertain cleanup may block later owned work even after a command completes; this conservative outcome is intentional and remains documented.
CI caught two test-integration omissions: a Gateway fixture imported a concrete plugin test facade into core, and the new Codex suite lacked full-suite shard registration. The repair exercises the existing trusted-diagnostic service contract through the real service manager with a synthetic service, keeps the same dependency-retention assertions, and registers the Codex suite in its existing attempt shard. All 108 affected tests passed, including unchanged boundary/coverage checks; the selected changed gate and independent review passed. No guard or baseline was relaxed.
The next CI run caught unrelated suppression-inventory line drift from main in
fetch-guard.socks.test.ts. Main repaired it in #139747; this branch rebased onto that merge with an unchanged patch, and both inventory tests passed. No inventory edit was added to this PR.