Skip to content

fix(codex): keep the real answer when a trailing coda follows - #123993

Merged
obviyus merged 6 commits into
mainfrom
fix/codex-keep-prior-final
Aug 15, 2026
Merged

obviyus merged 6 commits into
mainfrom
fix/codex-keep-prior-final

Conversation

@obviyus

@obviyus obviyus commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator

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_answer coda 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}:assistant slot 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 explicit final_answer items after the last tool: both are user-visible answers, and the first one disappeared.

Pinned dependency: @openai/codex 0.147.0 (extensions/codex/package.json:11). Inspected sibling ../codex contract for that protocol: codex-rs/app-server/src/bespoke_event_handling.rs:1276-1278 emits turn/completed.items as TurnItemsView::Summary of last_agent_message only; codex-rs/app-server-protocol/src/protocol/v2/thread_data.rs:274-278 defines that Summary; codex-rs/protocol/src/models.rs:775-776 names FinalAnswer as terminal text for the current turn; codex-rs/protocol/src/items.rs:60-63 and codex-rs/app-server-protocol/src/protocol/v2/item.rs:378 model 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_REPLY envelopes 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_REPLY on 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_answer items ~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 them failed because assistantTexts kept only the coda. final → unphased → later final kept the stale first final. final → unphased → silent final revived the first final instead of the replacement. final → sleep → later final joined both texts. Activity and late-tool cases use a production summary-shaped turn/completed payload ([second final] only).

Post-fix focused:

node scripts/run-vitest.mjs \
  extensions/codex/src/app-server/event-projector.assistant.test.ts \
  extensions/codex/src/app-server/event-projector.commentary.test.ts \
  extensions/codex/src/app-server/run-attempt.turn-watches.test.ts \
  extensions/codex/src/app-server/delivery-no-reply-runtime-contract.test.ts \
  extensions/codex/src/app-server/outcome-fallback-runtime-contract.test.ts \
  extensions/codex/src/app-server/event-projector.dynamic-tools.test.ts

171 passed, including unphased replacement, silent-after-unphased, sleep handoff, JSON silent-payload join, post-handoff NO_REPLY authority, delayed image-generation, and timeout recovery.

node scripts/check-changed.mjs -- <touched files>: Crabbox ci-fast unavailable, local fallback exit 0.

$autoreview --mode local: clean on 64e276b4393.

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.
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@obviyus
obviyus marked this pull request as ready for review August 15, 2026 03:53
@clawsweeper clawsweeper Bot added merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 1:41 AM ET / 05:41 UTC.

ClawSweeper review

What this changes

The PR preserves consecutive Codex final-answer texts after the last native-tool handoff while continuing to suppress silent reply payloads.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep 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
Reviewed head: 496ef229c2b35dc2764baacd5579ca82e3c43f7d
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and well-covered at the projection boundary, with merge readiness limited by the required dependency-contract check.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a member-authored PR; its supplied focused tests and CI are supplemental evidence, while the remaining gate is direct dependency-contract inspection.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a member-authored PR; its supplied focused tests and CI are supplemental evidence, while the remaining gate is direct dependency-contract inspection.
Evidence reviewed 8 items Current-main defect path: Current main reduces assistant text to the last resolved non-commentary item, so an earlier explicit final is discarded when a later coda is recorded.
Changed owner boundary: The branch moves selection into the Codex assistant projection and records a tool-handoff barrier before constructing result text.
Result consumer: Attempt-result construction consumes the projection’s selected texts for the persisted assistant message and transcript snapshot.
Findings None None.
Security None None.

How this fits together

Codex 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]
Loading

Decision needed

Question Recommendation
Should a maintainer with the pinned Codex source checkout verify the 0.147.0 event-ordering contract before this PR is merged? Verify the pinned protocol: Confirm the 0.147.0 item and completed-turn semantics against the Codex source, then merge if they support the barrier design.

Why: Repository policy requires direct sibling-source inspection for this dependency-dependent change, and the required checkout is unavailable here.

Before merge

  • Resolve merge risk (P1) - The plugin’s pinned Codex 0.147.0 event-ordering and completed-turn semantics have not been directly verified from the required sibling source checkout.
  • Resolve merge risk (P1) - This bug fix has a net production increase of 71 lines; the added selection state should be retained only if the protocol contract proves that the completed-turn payload cannot carry the intervening handoff fact.
  • Complete next step (P2) - A maintainer with the required Codex source checkout must verify the pinned protocol contract before merge.
Agent review details

Security

None.

PR surface

Source +71, Tests +348. Total +419 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 73 2 +71
Tests 1 355 7 +348
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 428 9 +419

Review metrics

Metric Value Why it matters
Production versus test delta production +71, tests +348 The patch adds stateful reply-selection logic and focused regression coverage; the production growth needs protocol-contract justification.

Merge-risk options

Maintainer options:

  1. Verify protocol before merge (recommended)
    Check the pinned Codex app-server source to confirm the barrier is keyed to authoritative event ordering.
  2. Pause for dependency evidence
    Hold the PR if a reviewer cannot directly establish that protocol contract.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: The affected Codex path can replace a substantive user answer with a short trailing coda in persisted and delivered output.
  • merge-risk: 🚨 message-delivery: The changed selector controls the assistant text emitted to session history and downstream reply delivery.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a member-authored PR; its supplied focused tests and CI are supplemental evidence, while the remaining gate is direct dependency-contract inspection.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: The available current-main file history names Peter Steinberger on the latest locally available commit touching this projection path; deeper provenance was unavailable locally. (role: recent area contributor; confidence: low; commits: 2ebaebd48473; files: extensions/codex/src/app-server/event-projector-assistant.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Verify the pinned Codex 0.147.0 event contract from the required sibling source checkout.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-15T04:01:19.184Z sha 84227a9 :: needs changes before merge. :: [P1] Keep a later unphased assistant item authoritative
  • reviewed 2026-08-15T04:21:15.503Z sha 3d1f012 :: found issues before merge. :: [P1] Use the payload-level silent-reply predicate
  • reviewed 2026-08-15T04:36:33.361Z sha 4e9962e :: needs changes before merge. :: [P1] Use the payload-level silent-reply predicate
  • reviewed 2026-08-15T05:26:11.754Z sha 496ef22 :: needs maintainer review before merge. :: none

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.
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 15, 2026
A later unphased item must invalidate older finals even when a later
final skips it, and sleep is a native answer barrier.
@obviyus
obviyus merged commit 2e806ef into main Aug 15, 2026
106 of 107 checks passed
@obviyus
obviyus deleted the fix/codex-keep-prior-final branch August 15, 2026 06:06
@obviyus

obviyus commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Merged via squash.

@obviyus

obviyus commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

Landed via squash onto main.

  • Scoped tests: node scripts/run-vitest.mjs extensions/codex/src/app-server/event-projector.assistant.test.ts extensions/codex/src/app-server/event-projector.commentary.test.ts extensions/codex/src/app-server/run-attempt.turn-watches.test.ts extensions/codex/src/app-server/delivery-no-reply-runtime-contract.test.ts extensions/codex/src/app-server/outcome-fallback-runtime-contract.test.ts extensions/codex/src/app-server/event-projector.dynamic-tools.test.ts (171 passed)
  • Changelog: not required; release generation owns CHANGELOG.md
  • Land commit: 64e276b
  • Merge commit: 2e806ef

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.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 16, 2026
…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.
harjothkhara added a commit to harjothkhara/openclaw that referenced this pull request Aug 27, 2026
… 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant