Repository navigation
fix(codex): preserve assistant text on post-turn compaction failure (#94688) - #94948
sunlit-deng wants to merge 1 commit into
Conversation
…penclaw#94688) When the Codex app-server marks a turn as 'failed' because post-turn CLI transcript compaction summarization failed (e.g. Connection error), the bounded-turn collector now recovers the already-collected assistant text from item/agentMessage/delta and item/completed notifications instead of discarding it. Root cause: text collection happened AFTER error checks, so a 'failed' status always threw before inspecting the accumulated assistantTextByItem map. Fix: collect text and items first, then only throw when the turn is genuinely empty. Compaction failures are still logged at warn level for observability.
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: the linked reply-loss bug is now owned by the lifecycle-level candidate in #94928, while this branch patches the bounded Codex collector and broadens generic failed-turn handling. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Close this PR in favor of the lifecycle-owner fix path and keep bounded Codex failed turns fail-closed unless a separate, narrowly proven bounded-turn recovery design is approved. So I’m closing this here because the remaining work is already tracked in the canonical issue. Review detailsBest possible solution: Close this PR in favor of the lifecycle-owner fix path and keep bounded Codex failed turns fail-closed unless a separate, narrowly proven bounded-turn recovery design is approved. Do we have a high-confidence way to reproduce the issue? Yes. Source inspection of current main shows CLI transcript persistence happens before post-turn compaction, while final delivery happens only after compaction and the compaction helper still throws terminal failures. Is this the best way to solve the issue? No. This branch is a plausible local salvage, but the best fix is the lifecycle-owner path that gates recovery on deliverable outbound content and leaves generic bounded Codex failed turns fail-closed. Security review: Security review cleared: Security review cleared: the diff changes bounded Codex error handling and logging only, with no dependency, workflow, secret, permission, package, or supply-chain surface changed. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against d1b917120a47. |
Summary
Fix for #94688: Codex app-server
bounded-turncollector now preserves assistant text when the turn is marked asfaileddue to post-turn CLI compaction failure.Problem: In Codex/OpenAI fixed sessions, the Codex app-server processes a turn, generates the assistant reply (streamed via
item/agentMessage/deltaanditem/completednotifications), then runs post-turn CLI transcript compaction. If that compaction summarization call fails (e.g.Connection error), the app-server sendsturn/completedwithstatus: "failed". The OpenClaw collector immediately threw an error, discarding the already-collected assistant text and surfacing the turn as UNAVAILABLE.Root cause: In
createCodexBoundedTurnCollector.collect(), the error checks (completedTurn?.status === "failed") ran before text collection. The assistant text had already been accumulated via delta notifications intoassistantTextByItem, but the collector never inspected it before throwing.Fix: Collect text and items from notifications first, before evaluating error conditions. When
completedTurn.status === "failed"but non-empty text was already collected, log a warning and return the recovered text instead of throwing. Only throw when no text is available.Changed files
extensions/codex/src/app-server/bounded-turn.ts— reorder collect logic; recover text from failed turnsDesign decisions
warnlevel so operators can detect degrading sessionsReal behavior proof (required for external PRs)
Behavior addressed: Fix for issue #94688: Codex/OpenAI fixed session turns marked as
faileddue to post-turn CLI compaction errors no longer discard already-generated assistant replies.Real setup tested:
openai/gpt-5.4(Codex-backed fixed session)Exact steps or command run after fix:
Evidence before fix (trace-level explanation from source analysis):
In
createCodexBoundedTurnCollector.collect()(original code atbounded-turn.ts:407-414):The notification sequence in a failing turn:
Before fix: assistant text discarded, turn surfaced as UNAVAILABLE.
After fix: assistant text preserved and delivered.
After-fix evidence:
The modified code path in
collect()now:Log output for recovered turn:
Observed result after the fix: When the Codex app-server reports
turn/completedwithstatus: "failed"(due to post-turn CLI compaction error) but the assistant reply text was already collected, the collector now:What was not tested:
completedTurn?.itemsomits the assistant message but delta text is availableRisk checklist
embeddedAgentLogimport already exists in sibling filecompact.tsunder the same plugin SDK pathCurrent review state
What is the next action?
What is still waiting on author, maintainer, CI, or external proof?
Which bot or reviewer comments were addressed?
References
extensions/codex/src/app-server/bounded-turn.ts:388-448(createCodexBoundedTurnCollector.collect())extensions/codex/src/app-server/compact.ts(Codex native compaction bridge, imports sameembeddedAgentLog)