Repository navigation
fix: stop marking retained Codex background commands as failed - #156764
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: needs maintainer review before merge. Reviewed September 23, 2026, 8:28 PM ET / September 24, 2026, 00:28 UTC (Revision 2). ClawSweeper reviewWhat this changesThe Codex plugin checks its live native terminal inventory when a turn ends and records a still-running command with an unknown outcome instead of a failed tool result. Merge readiness✅ Ready for maintainer review The false failure remains on current main. The branch addresses the prior approval-first review finding, and the supplied live evidence supports the corrected behavior. Priority: P2 Review scores
Verification
How this fits togetherCodex app-server sends command events to OpenClaw’s Codex plugin. The plugin settles each turn into tool results, transcript entries, and diagnostics that users and later turns consume. flowchart LR
A[Codex command events] --> B[Turn settlement]
B --> C[Live terminal inventory]
C --> D{Current owner and matching command?}
D -->|Yes| E[Outcome unknown]
D -->|No| F[Missing result failure]
E --> G[Later process wait]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +193, Tests +171, Docs +9. Total +373 across 11 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep Codex settlement as the single owner of unfinished-command classification, requiring live inventory and current custody before recording an unknown outcome; leave the final exit result to native process wait. Do we have a high-confidence way to reproduce the issue? Yes. The supplied baseline shows a live command handle marked failed before a later turn collected it successfully, and current main still finalizes unfinished tools without consulting the live inventory. This read-only review did not execute the path. Is this the best way to solve the issue? Yes. The branch uses Codex’s existing live inventory and OpenClaw’s current-source custody instead of adding another process registry; registered attempt tests cover the earlier approval-first finding. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against d1a3a33acc1c. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
|
Merged via squash.
|
…law#156764) * fix(codex): preserve unknown outcomes for retained native commands * fix(codex): retain approval-first background command identity
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error. Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path). Thanks @aatreya for the report and the fix. ## What Problem This Solves A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes. ## Fix Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones. ## Evidence Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment) | Scenario | main | this PR | |---|---|---| | silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs | | silent turn + truly missing result | missing-result error | same | | silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call | | visible answer + running command | unchanged | unchanged | The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence. Regression test: `native background outcome: silent retained` fails on main's projector and passes here. The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3). ## Merge danger Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running. Co-authored-by: Ayaan Zaidi <[email protected]>
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error. Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path). Thanks @aatreya for the report and the fix. ## What Problem This Solves A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes. ## Fix Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones. ## Evidence Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment) | Scenario | main | this PR | |---|---|---| | silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs | | silent turn + truly missing result | missing-result error | same | | silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call | | visible answer + running command | unchanged | unchanged | The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence. Regression test: `native background outcome: silent retained` fails on main's projector and passes here. The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3). ## Merge danger Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 9e2de2c) Co-authored-by: RomneyDa <[email protected]> Co-authored-by: vincentkoc <[email protected]>
…196062) Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error. Fixes openclaw#196061. Related: openclaw#156764 (added the neutral retained-command record), openclaw#194757 (separate continuation path). Thanks @aatreya for the report and the fix. ## What Problem This Solves A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes. ## Fix Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones. ## Evidence Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: openclaw#196062 (comment) | Scenario | main | this PR | |---|---|---| | silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs | | silent turn + truly missing result | missing-result error | same | | silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call | | visible answer + running command | unchanged | unchanged | The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence. Regression test: `native background outcome: silent retained` fails on main's projector and passes here. The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3). ## Merge danger Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running. Co-authored-by: Ayaan Zaidi <[email protected]>
Root cause: extensions/codex/src/app-server/event-projector-tool-transcript.ts:601-608 (on main) `synthesizeMissingToolResults` already records confirmed retained command ids as neutral "still running" results, but still counts them as missing tool results, so a silent turn (no visible answer) with a confirmed running native command is failed with the missing-result error. Fixes #196061. Related: #156764 (added the neutral retained-command record), #194757 (separate continuation path). Thanks @aatreya for the report and the fix. ## What Problem This Solves A Codex turn that starts a native background command, gets it confirmed by `thread/backgroundTerminals/list`, and then ends silently (`NO_REPLY`) was marked failed with "OpenClaw recorded a native Codex tool.call without a matching tool.result before the turn completed." That failure skips the normal retention of the live thread, so the next user message is rejected with "Codex thread … still has background work after waiting for cleanup; stop its running work and retry", and the session stays stuck even after the command finishes. ## Fix Confirmed retained command ids are excluded from missing-result error selection and counting. Their neutral running records are unchanged. Genuinely missing results still fail, and a mix of running and missing calls reports only the missing ones. ## Evidence Built Gateway (secretless Docker) running the native Codex harness against a stand-in app-server that follows the Codex app-server protocol: the turn starts a background command that stays running, the inventory confirms it, the turn ends with `NO_REPLY`; then a follow-up message, the command's native completion, and a "continue" message. Main twice, this branch twice, plus controls. Observed lines: #196062 (comment) | Scenario | main | this PR | |---|---|---| | silent turn + running command (x2) | turn fails with missing-result error; follow-up rejected ("still has background work…"); after completion still rejected | turn not failed; follow-up answered on the same live thread; after completion the next message runs | | silent turn + truly missing result | missing-result error | same | | silent turn + running + missing | missing-result error, `missingToolResultCount=2` | missing-result error for the one missing call | | visible answer + running command | unchanged | unchanged | The proof drives the session through `openclaw agent`, which requires a result, so this PR's silent first turn shows that CLI's standard "No answer was returned" notice rather than the missing-result failure. Channel turns such as Discord accept the silence. Regression test: `native background outcome: silent retained` fails on main's projector and passes here. The takeover commit drops the test-line allocation file and folds the regression into the existing table (production +8/-3, tests +7/-3). ## Merge danger Two-way door: classification only, no stored state, config or contract changes; a revert fully undoes it. Blast radius: Codex harness turns that end without a visible answer while a confirmed native command is still running. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 9e2de2c) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes a false failed-tool result when a Codex command yields a process handle, remains running, and the assistant finishes its turn before collecting the command's exit result.
User Impact
A command confirmed as still owned and running now shows Outcome unknown, with text identifying the retained process handle. A later turn can collect that handle's output and exit code. The earlier snapshot stays intact; this does not claim that an unfinished command succeeded. Cancellation and commands without a confirmed live owner keep their existing failure handling.
Why This Change Was Made
Turn settlement treated every missing final native tool result as an orphan. A live reproduction returned a valid handle for a bounded command and finished the assistant turn; OpenClaw marked the command failed even though the next turn collected the same handle successfully with exit code 0.
Settlement now asks the existing native thread inventory about pending commands and correlates the original tool item and process IDs. Approval-first starts can omit the process ID, and Codex suppresses the later canonical start; those commands retain their item identity and obtain the handle from the matching inventory entry. A previously known process ID must still match. The sandbox path also requires the existing current source custody. Queued completions are drained before constructing results, and authority is checked again after awaited work, so a completion race or revoked owner cannot be mistaken for retained work. The existing settlement lifecycle remains the sole owner of draining, abort grace, and cleanup.
The existing unknown-outcome audit diagnostic is retained. The neutral tool result means the final command outcome is not known yet; it is not a new audit-success category. There is no new process registry, persistence format, permission, or historical transcript rewrite.
Evidence
The original registered run-attempt entry failed both the ordinary retained-command regression and the existing real process-custody case: it emitted an error for a live, owned command. The corrected source passes all 39 selected cases, including foreign item/process IDs, genuine orphans, unavailable inventory, completion during the inventory read, revocation during the read, and existing abort/settlement behavior. The approval-first correction adds five cases with a null initial process ID. Against the original PR head, the retained-command and completion-during-inventory cases both failed; all five pass after the fix.
The corrected three-file command took 49.074 seconds wall time. Its routed runs took 13.72 seconds (12 cases) and 33.15 seconds (27 cases). The approval-first retained case took 99 ms. The failing original-head replay took 20.200 seconds, with two failures and ten passes. No sleeps, polling loops, or real-time waits were added. The original head passed all 69 individual hosted checks; that is earlier-head evidence, and fresh CI for this correction must pass before landing.
The corrected candidate passed the full selected
check-changedrun in 235.008 seconds, including extension production/test types, scoped typed lint, formatting, line/assertion guards, plugin boundaries, dead exports, storage guards, and import cycles. A fresh independent Codex review of the complete staged correction and original PR found no actionable P0–P2 issues. Local proof used Node 26.7.0 and pnpm 12.4.2. The approval-first fix is covered by the registered run-attempt boundary tests; the live evidence below covers the original ordinary-command flow, not a newly repeated approval-first live run.Live behavior and screenshots
The baseline used a real bounded native command that returned a handle before the assistant's final answer. The UI incorrectly displayed a failed command; a second real turn joined that same handle, received the final output and exit code 0, and left no orphan.
The same real two-turn flow passed on composed candidate
6d4c0ba6428c, which contains this patch unchanged. A bounded 45-second native command yielded handle31257; the first turn finished while it was still running and its canonical tool result recordedisError: false,status: running, and outcomeunknown. The second turn collected that same handle with nativewrite_stdin, returned the final marker and exit code 0, and launched no replacement command. Native and canonical evidence contained no tool errors, and the exact synthetic process was absent after collection. The original retained result remained neutral in history.The before and after screenshots below show the first-turn tool state for the same controlled flow.
Shared CI hang and upstream repair
CI run 35929054433 failed in Codex settlement cleanup after 55 minutes, including the runner's inherited automatic retry. An independent PR hit the same unchanged 180-second hooks. Local reproduction in the original protocol-validation → settlement order traced a native coordinator deadline waiting on a discarded fake 25 ms timer; background history maintenance then retained the archive queue needed by cleanup. No manual rerun was used to obtain green.
The owning fix landed independently in #156801 as
adf4aff7c87624071b2ddeb4cb92a119c34534c1. This PR now incorporates that fix through current main; all 11 original PR-owned files remain byte-identical. The redundant draft #156868 was closed after verifying the upstream implementation and passing hosted proof. No test budget, retry policy, or assertion was weakened.On the integrated candidate, the exact original protocol-validation → settlement pair passes all 23 cases in 56.44 seconds wall including cold compilation. The native background-outcome and authority siblings pass 27 additional cases in 70.63 seconds wall. Fresh independent review of the complete integrated PR found no actionable P0–P2 issue. The retained auto-merge request was explicitly canceled through native recovery before changing its head; replacement landing used completed current-head gates.
Final validation on
1735b7dd68bf2fe551f7b96217d05a0c66a36bb9: CI run 35937440062 succeeded with 46 successful and 17 skipped jobs, zero failures. The automatic security publisher also passed; no manual test or publisher rerun was needed. Native retained-outcome recovery merged the reviewed head as1c7c6fb3d5753c61aaf9302cc907af21a95f3be8.