Repository navigation
fix: gateway kill leaves Codex tool processes running - #107721
Conversation
69311cf to
1f2974b
Compare
1f2974b to
9cafd35
Compare
|
Codex review: needs real behavior proof before merge. Reviewed August 28, 2026, 10:09 PM ET / August 29, 2026, 02:09 UTC. ClawSweeper reviewWhat this changesThe PR makes explicit Codex-run cancellation wait for the matching turn, terminate only that thread’s native background terminals, and join cleanup before releasing attempt resources. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 5 items remain No introduced lifecycle defect was found, but this dependency-backed PR cannot receive a merge/proof-sufficiency verdict here because the required sibling Codex source is unavailable for direct protocol verification. Priority: P1 Review scores
Verification
How this fits togetherThe Codex plugin runs app-server turns for OpenClaw agents. Cancellation flows from the attempt lifecycle to Codex’s thread-scoped terminal API before the route, subscription, and client lease are released. flowchart LR
A[Gateway cancellation] --> B[Codex attempt]
B --> C[Interrupt matching turn]
C --> D[Thread terminal inventory]
D --> E[Terminate thread terminals]
E --> F[Verify inventory empty]
F --> G[Release attempt resources]
Decision needed
Why: The patch’s correctness depends on a third-party app-server protocol, and local policy requires direct sibling-source inspection that this read-only environment cannot perform. Before merge
Agent review detailsSecurityNone. PR surfaceSource +80, Tests +132, Docs +8. Total +220 across 11 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the thread-owned cleanup design, but cite direct Codex 0.149.x and 0.150.1 source/types for the list and terminate RPC contract before landing. Do we have a high-confidence way to reproduce the issue? No independent current-main runtime reproduction was possible in this read-only environment. Current-main source shows the direct interrupt-completion path, and the PR supplies a production-path live trace, but its Codex contract was not independently inspectable. Is this the best way to solve the issue? Unclear: OpenClaw lifecycle reading supports thread-scoped cleanup as the right owner boundary, but direct Codex protocol verification is required before calling it the best confirmed solution. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against bf94ec5e7e5f. 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
HistoryReview history (5 earlier review cycles)
|
|
This pull request has been automatically marked as stale due to inactivity. |
Codex turn interruption deliberately leaves native background terminals running. Wait for the matching turn to stop, terminate that thread's terminals through the app-server API, and join cleanup before releasing the attempt. Surface cleanup failures without retiring shared peer threads. Keep existing host process scopes and background gateway jobs unchanged. Verified with 412 focused tests and an authenticated live Codex run with a concurrent peer thread on the same app-server. Co-authored-by: Ming Yoo <[email protected]>
b1b44a9 to
217b366
Compare
Close cancellation admission synchronously when cleanup takes ownership, including when finalization throws before freezing its terminal outcome. This keeps late aborts from replacing the joined cleanup promise during resource release or masking the original finalization error. Move the existing terminal freeze instead of adding another lifecycle flag. Verified the regression fails before the change; all 413 Codex tests pass.
|
@clawsweeper re-review The PR is rewritten on current main. The body now includes direct Codex 0.150.1/0.144.4 source verification, inspectable authenticated live observations, 413 passing tests, and the resolution of the previous shared-client and process-scope findings. The remaining repair uses thread-owned native terminal RPCs and freezes cancellation admission before attempt teardown; the destructive fallback and Windows-specific process-tree changes are gone. |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Merged via squash.
|
* fix(codex): stop native terminals on run cancellation Codex turn interruption deliberately leaves native background terminals running. Wait for the matching turn to stop, terminate that thread's terminals through the app-server API, and join cleanup before releasing the attempt. Surface cleanup failures without retiring shared peer threads. Keep existing host process scopes and background gateway jobs unchanged. Verified with 412 focused tests and an authenticated live Codex run with a concurrent peer thread on the same app-server. Co-authored-by: Ming Yoo <[email protected]> * fix(codex): freeze cancellation before attempt teardown Close cancellation admission synchronously when cleanup takes ownership, including when finalization throws before freezing its terminal outcome. This keeps late aborts from replacing the joined cleanup promise during resource release or masking the original finalization error. Move the existing terminal freeze instead of adding another lifecycle flag. Verified the regression fails before the change; all 413 Codex tests pass. --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Ming Yoo <[email protected]>
What Problem This Solves
Stopping an active OpenClaw Codex run could leave its native shell command running after the turn reported
interrupted. This remains reproducible on the current Codex app-server: a command continued writing its heartbeat after the matchingturn/completedevent.Codex deliberately separates turn interruption from terminal termination. Directly checked upstream
rust-v0.150.1:abort_all_taskscancels the turn, while native terminal cleanup and identity-checked terminal termination are separate operations. Existingthread/unsubscribeonly releases the connection subscription; it does not terminate native terminals. The terminal list returns the complete inventory whenlimitis omitted. The list/terminate protocol and inventory default were also verified inrust-v0.144.4, the original PR's dependency version, and the supported external minimumrust-v0.149.0plusrust-v0.149.1: RPC types, list/terminate owners, and full-inventory default. Those relevant source files are identical between 0.149.0 and 0.149.1.Changes
Reworked the original PR on current main, which already contains process-scope lifecycle and app-server retirement improvements. The remaining repair belongs in the Codex plugin's attempt cancellation owner:
gateway_processjobs. Document the ownership boundary and cleanup failure behavior.The earlier generic process-scope, PID/PGID, Windows fallback, and whole-app-server cancellation changes are removed. They were unnecessary for the remaining owner defect and introduced stale process-identity and peer-cancellation risks. No core supervisor, configuration, dependency, or persistence changes remain.
Production delta: +80/-3 (net +77); tests/support: +183/-48 (net +135); docs: +8. Production growth supplies the missing native terminal-owner operation and its awaited lifecycle; generic host process scopes cannot replace that protocol contract. Thanks @mingyooagi for the report and initial implementation; co-author credit is preserved.
Evidence
git diff --checkpass. Fresh independent Codex autoreview found no actionable P0–P2 findings.runCodexAppServerAttempt, real Codex 0.150.1, isolated state, two threads sharing the same app-server: cancellation settled in 170 ms; the target process was already dead, its completion marker was absent, and the peer remained alive/listed with its heartbeat advancing and turn still active. No owned test processes survived cleanup. This exercises the actual production attempt and provider, not a mocked app-server.Sanitized authenticated live result:
{ "result": "PASS", "codexVersion": "0.150.1", "platform": "darwin", "cancellationMs": 170, "terminalOutcome": "aborted", "targetAliveWhenAttemptSettled": false, "targetCompletionMarkerExists": false, "peerAlive": true, "peerInventoryCount": 1, "peerHeartbeatAdvanced": true, "peerTurnCompleted": false, "survivingOwnedProcesses": 0 }Full Gateway and Control UI proof
On final head
21d3b2efb193e138190b15349c4245444a4e9da6, built the production runtime and UI, launched the normal Gateway CLI with isolated state, and started two conversations throughchat.send. Both native ticking commands were observed as children of the same real Codex 0.150.1 app-server. Clicked the rendered Stop generating button in Chrome, then repeated in an isolated Playwright Chromium context with a 6.32-second video: its Working/Active state disappeared, its command exited, and no completion marker was written. The peer stayed active and its heartbeat advanced. In the recorded repeat, the UI sentchat.abort, showed Interrupted, and the target process was confirmed gone within 313 ms while the peer kept running. All task processes, the browser, and listeners were then cleaned up.This full Gateway/UI lane uses a local fixture Responses model; it is separate from the authenticated provider/production-attempt proof above. Runtime and UI builds passed after linking the worktree's missing UI dependency directory to the already-installed matching dependencies; no packages or operator state were changed.
{ "result": "PASS", "entry": "Control UI Stop generating -> chat.abort", "uiAndProcessConfirmationMs": 313, "sameCodexAppServer": true, "targetAlive": false, "targetCompletionMarkerExists": false, "targetChatState": "aborted", "targetLifecycleStatus": "cancelled", "targetWaitStatus": "error", "peerAlive": true, "peerHeartbeatBefore": 307, "peerHeartbeatAfter": 308, "peerTerminalEvents": 0, "survivingOwnedProcesses": 0 }agent.waitretains the existing cancellation projection (status: error); chat and lifecycle carry the structured aborted/cancelled state. This is unchanged core behavior, not a terminal-cleanup failure.Review follow-through
The previous ClawSweeper review was against the superseded 42-file implementation. Its protocol-contract request is addressed by direct upstream source references above; its shared-client destruction and failed-scope recovery findings are addressed by removing those paths. The Windows-specific process-tree changes were also removed, so their requested containment proof does not apply to this rewritten patch. Native Windows execution remains an explicitly untested platform.
The refreshed review also requested a maintainer contract check because its environment could not obtain Codex source. That check was completed directly: the methods exist in the supported dependency, omitted
limitreturns the full inventory, andterminated: falserequires the final inventory check to distinguish a natural exit from failed termination. No equivalent confirmed lifecycle API absorbs the missing operation: unsubscribe only drops a subscription, while thread removal shuts down the conversation. The existingbackgroundTerminals/cleanonly submits a queued operation;SessionIo::submit_with_idacknowledges enqueueing, not terminal exit. Using it would require another asynchronous completion/polling mechanism, whereas per-terminal termination already supplies the awaitable owner contract. Cleanup failures intentionally remain visible errors after resource release; reporting ordinary cancellation would conceal unconfirmed process cleanup. The regression and existing cancellation/transport suites cover this boundary.Proof boundaries
The full Gateway/Control UI proof is now complete; the earlier source-loader startup limitation was resolved by the normal built runtime. Before/after captures and the recorded Stop flow were inspected locally. Public image/video publication is blocked by the test workstation's capture-sharing policy: upload authorization for that environment was not established, so media stays local and the sanitized observed trace is supplied above. Native Windows behavior was not live-tested. The guarantee follows Codex's terminal ownership; it does not claim cleanup of arbitrary commands that deliberately detach from that ownership. This PR does not add a whole-server kill fallback when thread cleanup cannot be confirmed.
AI-assisted: yes.