Preserve Codex output after missing turn completion#99217
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Codex review: needs maintainer review before merge. Reviewed July 3, 2026, 8:04 AM ET / 12:04 UTC. Summary PR surface: Source +944, Tests +3089, Docs +7. Total +4040 across 56 files. Reproducibility: yes. for review purposes: current main lacks the recovery path, upstream Codex defines Review metrics: 2 noteworthy metrics.
Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land after maintainer accepts the bounded recovery and finalization semantics; keep the upstream Codex terminal-event root cause tracked separately. Do we have a high-confidence way to reproduce the issue? Yes for review purposes: current main lacks the recovery path, upstream Codex defines Is this the best way to solve the issue? Yes: because upstream still owns reliable AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 8abc633cf8e2. Label changesLabel justifications:
Evidence reviewedPR surface: Source +944, Tests +3089, Docs +7. Total +4040 across 56 files. View PR surface stats
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
|
Added the after-fix behavior proof requested in the PR body. It now includes the PR-head command output summary for:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
b5d5a2a to
c532277
Compare
|
PR body is now updated for current head @clawsweeper re-review |
c532277 to
ab0d134
Compare
|
Fixed in @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
ab0d134 to
e82b799
Compare
|
Proof/status update for current head
Proof boundary: this PR proves OpenClaw recovery behavior for the missing- |
Dependency graph guard clearedThis PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh
|
|
Maintainer takeover complete. I kept the contributor history, updated the branch through GitHub's non-force update path, and applied the canonical tree as Canonical changes:
Updated proof:
Conflict status: the contributor head had not moved during takeover. |
|
Maintainer takeover complete. I rebased the contributor work onto current Additional audit fixes:
Final review and proof:
The contributor PR head remained unchanged during review. The guarded takeover published the verified tree as a signed commit, then GitHub merged current @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Adding a production data point that matches this issue's scope ("completed output lost + run left ambiguously active"), with two details that may help narrow it down: the loss reproduces without any native thread rotation, and the stuck-session recovery is what ultimately discards the completed reply. Environment: OpenClaw 2026.6.11 (e085fa1), Timeline (2026-07-03, single incident, all evidence from transcripts/trajectory/diagnostic logs)
Sanitized diagnostic excerpts (JSON-lines gateway diagnostic log): Observations
Suggestion (aligns with this issue's "freeze accepted completion / abort ownership" direction)Before stuck-session recovery force-clears an embedded run, it could check the transcript for a completed final assistant message that has no delivery mirror — and either hand it back to the reply-delivery path or at least surface it explicitly, instead of discarding it as part of the abort. In our incident the answer existed for 11 minutes before the recovery destroyed it. Happy to share more sanitized trajectory/diagnostic detail if useful. |
|
Merged via squash.
|
Summary
Canonicalizes the missing Codex
turn/completedrecovery started in #99167 and extended here. Thanks to @100yenadmin for the original report, reproduction evidence, and implementation./stop, restart, or subagent controls cannot misclassify a finalizing run.This mitigates lost final replies when Codex emits a genuine terminal assistant item but omits
turn/completed. It does not claim to fix the upstream Codex event omission.What Problem This Solves
Completion and cancellation cross several asynchronous boundaries. A narrow timeout fallback can accidentally revive stale pre-tool text, discard newer id-less output, duplicate backend cancellation, or turn a successfully recovered reply into an aborted result while final hooks or delivery are still running.
The canonical fix makes candidate freshness, terminal side effects, abort ownership, and finalization ownership explicit. Recovery succeeds only for the newest completed assistant result after all relevant work has settled.
P0 Regression Audit
The takeover review found and fixed three proof or runtime gaps beyond the contributor head:
/stopduringagent_endcould convert accepted success into abort. The accepted outcome is now frozen through finalization.ResponseItem::Message.id. Pending typed/raw echo pairing could therefore discard a newer id-less post-tool final and return stale pre-tool text. Pairing is invalidated only when later work truly supersedes the candidate, with focused positive and negative regressions.Repeated autoreview is clean after these fixes. A full gateway-project A/B run showed the same three suite-order/environment failures on this branch and exact base; the affected tests passed in isolation on both, so they are not attributed to this PR.
Evidence
116bb037d396d8bf4623c0c411513c67b742acef.daf6d5ce3ab0e6c2ccb8a0bbd90e5129b25b09f9.36dd9ee3c3c188cc0619f0a3277c64c4b96a9615.681183d911cee5b7348da7cecb215c9f9c258bbf.7f29539a99b3a54e92601eb37a788e20679a81899cc1380ddce5b8e6a8294a10.blacksmith-testbox/tbx_01kwkngrb4w4pp0rq60b4wxh21.28652114082.blacksmith-testbox/tbx_01kwkngvxbgj14fkv9fr6smfw6.28652117396.pnpm check:changed && pnpm build.aws/run_55458f5381b9/cbx_40a108919c40.coral-lobster/c7a.32xlarge.0.142.4.CRABBOX-CANONICAL-509F22.CRABBOX_FAULT_TOOL_OBSERVED,CRABBOX_FAULT_INJECT pre_tool_terminal_assistant,CRABBOX_FAULT_OBSERVED post_tool_typed_final,CRABBOX_FAULT_DROP method=turn/completed, andCRABBOX_PROOF missing_turn_completed=pass.Behavior addressed: Preserve the newest completed Codex assistant reply when
turn/completedis missing, without stale-candidate revival, newer-output suppression, duplicate cancellation, or abort/finalization ownership regressions.Real environment tested: AWS Crabbox Linux
c7a.32xlargewith real Codex app-server authentication and Codex CLI0.142.4; Blacksmith Testbox through Crabbox for the full changed-surface matrix and repository gates.Exact steps or command run after this patch: Sync and hash the exact rebased 56-file overlay, launch the live OpenClaw Codex app-server path, complete a baseline turn, call the real
sessions_listtool withlimit=1andincludeLastMessage=false, inject stale pre-tool assistant text, preserve the genuine post-tool assistant completion, drop onlyturn/completed, and wait for OpenClaw recovery. The published PR head was then verified to have the identical Git tree.Evidence after fix: The real tool call completed, the genuine post-tool reply returned
CRABBOX-CANONICAL-509F22, the proxy logged the stale-candidate injection and deliberateturn/completeddrop, and the run emittedCRABBOX_PROOF missing_turn_completed=pass.Observed result after fix: OpenClaw returned the newest post-tool assistant text instead of stale
I will check.orturn_completion_idle_timeout; the run ended successfully and the one-shot lease stopped.What was not tested: An organic upstream Codex omission without fault injection, live macOS/Windows execution, or a raw-only post-tool completion. In the observed real Codex tool turn, the post-tool final used the typed assistant lane; the id-less raw pairing path is covered by focused protocol regressions.
Related
Refs #87744 and #88312. Supersedes the narrower approach in #99167.