Repository navigation
fix(codex): keep the real answer when a trailing coda follows - #123993
Conversation
Live persist last-won a single assistant slot, so a trailing final_answer replaced the real summary. Keep explicit finals after the last native tool; phase-less coordination text stays last-wins.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 1:41 AM ET / 05:41 UTC. ClawSweeper reviewWhat this changesThe PR preserves consecutive Codex final-answer texts after the last native-tool handoff while continuing to suppress silent reply payloads. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open for maintainer review: current main still last-selects one assistant text, and this PR targets the correct projection boundary, but the required direct inspection of the pinned Codex source cannot be completed because the sibling checkout is absent in this read-only environment. Priority: P1 Review scores
Verification
How this fits togetherCodex app-server events feed the assistant projection, which builds persisted session messages and delivery text. The changed selection policy determines which completed assistant messages reach the transcript and downstream channels. flowchart LR
A[Codex app-server events] --> B[Assistant projection]
B --> C{Native tool handoff}
C --> D[Select persistable final text]
D --> E[Attempt result]
E --> F[Session transcript]
E --> G[Reply delivery]
Decision needed
Why: Repository policy requires direct sibling-source inspection for this dependency-dependent change, and the required checkout is unavailable here. Before merge
Agent review detailsSecurityNone. PR surfaceSource +71, Tests +348. Total +419 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep one canonical Codex projection selection policy that preserves explicit post-handoff finals, suppresses only shared-contract silent payloads, and records tool invalidation at the event boundary that owns it. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main selects only the final non-commentary item, and the branch test supplies two final-answer events that exercise the loss. Exact Codex event semantics still require direct dependency-source verification. Is this the best way to solve the issue? Unclear; placing the repair in the Codex assistant projection is the right owner boundary, but the barrier’s protocol premise cannot be confirmed without the pinned Codex source. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 49e783da74f9. 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 (4 earlier review cycles)
|
turn/completed.items is a last_agent_message Summary, so result-time tool scans cannot see intervening work. Invalidate persistable finals when native tools arrive, drop trailing silent tokens, and let a later unphased message replace earlier finals.
Delayed native completions must not move the barrier past an answer that arrived while that tool was already active. Dynamic tool calls are the same handoff. If no audible text exists after the barrier, recover the last persistable answer instead of dropping it.
A tool after an audible final starts a new answer segment. If that segment is NO_REPLY, do not revive the pre-tool text. Recover a prior answer only when the post-handoff segment is empty.
Token-only matching missed JSON and reasoning-wrapped NO_REPLY payloads, so a trailing control envelope could join into the visible answer. Use the shared payload-level predicate.
A later unphased item must invalidate older finals even when a later final skips it, and sleep is a native answer barrier.
|
Merged via squash.
|
|
Landed via squash onto main.
No open duplicate issue. Sibling #116604 still open on the same selector for a distinct late-event NO_REPLY race; rebase that before it lands. |
…aw#123993) * fix(codex): keep prior finals when a coda follows without tool work Live persist last-won a single assistant slot, so a trailing final_answer replaced the real summary. Keep explicit finals after the last native tool; phase-less coordination text stays last-wins. * fix(codex): record the native-work barrier from item notifications turn/completed.items is a last_agent_message Summary, so result-time tool scans cannot see intervening work. Invalidate persistable finals when native tools arrive, drop trailing silent tokens, and let a later unphased message replace earlier finals. * fix(codex): make the persistable-text barrier once-per-handoff Delayed native completions must not move the barrier past an answer that arrived while that tool was already active. Dynamic tool calls are the same handoff. If no audible text exists after the barrier, recover the last persistable answer instead of dropping it. * fix(codex): keep a post-handoff silent final authoritative A tool after an audible final starts a new answer segment. If that segment is NO_REPLY, do not revive the pre-tool text. Recover a prior answer only when the post-handoff segment is empty. * fix(codex): classify silent finals with the delivery payload predicate Token-only matching missed JSON and reasoning-wrapped NO_REPLY payloads, so a trailing control envelope could join into the visible answer. Use the shared payload-level predicate. * fix(codex): honor unphased replacement and sleep handoffs A later unphased item must invalidate older finals even when a later final skips it, and sleep is a native answer barrier.
… in Activity Narrowed from the original openclaw#116604 scope after openclaw#123993 landed the delivery-side fix: collectAssistantTexts() now correctly ships the real answer via the persistable-assistant barrier, so the delivered-text hunk and its tests are dropped as redundant (credit: openclaw#123993). What still breaks on main: turn/completed.items is a last-wins last_agent_message summary (codex-rs thread_state.rs track_current_turn_event overwrites it on every completed AgentMessage final), so when a trailing NO_REPLY is the last agent message, finalizeAnswerCandidate selects the silent item and Control UI Activity shows "NO_REPLY" as the operator-visible selected answer while the channel receives the real reply. Fix: when the snapshot-authoritative item is a silent payload, re-derive the selected item through resolveDeliveredAnswerItemId(), an item-id mirror of collectAssistantTexts()'s precedence (audible post-barrier, then any post-barrier persistable, then pre-barrier audible, then the final text item), so Activity names the item delivery actually chose. Two earlier candidate vectors were dropped after inspecting the pinned codex-rs 0.147.0 source: turn.items can never carry more than one item and never a tool item (bespoke_event_handling.rs:1276-1285 is the only production constructor), so a cross-turn snapshot filter would be dead code, and a silence-aware recovery gate would break legitimate silent-turn recovery. Regression test fails on unmodified main with the selected event naming the silent item (progressText "NO_REPLY") and passes with the fix.
Related: #116604
What Problem This Solves
Fixes an issue where Codex users would lose the real reply in Control UI and session history when a later
final_answercoda arrived with no tool work between the two texts. The visible transcript kept only the coda, for example “The summary above already incorporates the final review results.”Why This Change Was Made
Live persist used one
${turnId}:assistantslot and last-won any non-commentary text. That is correct for phase-less coordination text and for a final that later native tool work reopens. It is wrong for two explicitfinal_answeritems after the last tool: both are user-visible answers, and the first one disappeared.Pinned dependency:
@openai/codex0.147.0 (extensions/codex/package.json:11). Inspected sibling../codexcontract for that protocol:codex-rs/app-server/src/bespoke_event_handling.rs:1276-1278emitsturn/completed.itemsasTurnItemsView::Summaryoflast_agent_messageonly;codex-rs/app-server-protocol/src/protocol/v2/thread_data.rs:274-278defines that Summary;codex-rs/protocol/src/models.rs:775-776namesFinalAnsweras terminal text for the current turn;codex-rs/protocol/src/items.rs:60-63andcodex-rs/app-server-protocol/src/protocol/v2/item.rs:378model standalone sleep as an extension-owned public Sleep item. Result-time scans of the completion payload cannot see intervening tools or sleep.The collector records a persistable-text barrier from the first native, dynamic, or sleep handoff notification. After that barrier it walks assistant items in time order: unphased text replaces the current segment, explicit finals accumulate unless they follow a replacement, and silent payloads never replace. The shared delivery silent-payload predicate keeps token, JSON, and reasoning-wrapped
NO_REPLYenvelopes out of an audible answer. A post-handoff silent final stays authoritative. Snapshot identity stays${turnId}:assistant. Activity candidate selection is unchanged.Sibling #116604 still last-wins a silent trailing
NO_REPLYon a distinct late-event race.User Impact
A Codex turn that emits a real answer and then a short coda without more tool work now keeps both texts in the transcript. Dashboard “Worked for” collapse is unchanged and is not the owner of the missing summary.
Already-written rows for old turns are not rewritten. An after-fix Control UI capture of the original session is not available on this head for that reason, and this change is not Telegram-visible.
Evidence
Live Codex rollout on a dashboard session (2026-08-15) contained two
final_answeritems ~46ms apart: a 1394-character PR summary, then the coda above. OpenClaw SQLite kept only the coda. The rollout still had both items. No IPs, tokens, or private endpoints.Pre-fix:
keeps an earlier final answer when a later coda arrives with no tool work between themfailed becauseassistantTextskept only the coda.final → unphased → later finalkept the stale first final.final → unphased → silent finalrevived the first final instead of the replacement.final → sleep → later finaljoined both texts. Activity and late-tool cases use a production summary-shapedturn/completedpayload ([second final]only).Post-fix focused:
171 passed, including unphased replacement, silent-after-unphased, sleep handoff, JSON silent-payload join, post-handoff
NO_REPLYauthority, delayed image-generation, and timeout recovery.node scripts/check-changed.mjs -- <touched files>: Crabboxci-fastunavailable, local fallback exit 0.$autoreview --mode local: clean on64e276b4393.