Skip to content

fix(codex): stop recovery warnings after delivered final replies - #153758

Closed
Tosko4 wants to merge 5 commits into
openclaw:mainfrom
Tosko4:fix/codex-finalization-20260920
Closed

Tosko4 wants to merge 5 commits into
openclaw:mainfrom
Tosko4:fix/codex-finalization-20260920

Conversation

@Tosko4

@Tosko4 Tosko4 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Update 2026-10-20 (head fa48c1a159, after merging current main 8318dc331a; previous head 3012a431e4 on main 38e352c6e8): main now owns the main fix of this PR. #173945 makes core skip settled-turn capture after a confirmed final reply (sourceReplyFinal: true) and still request it after progress-only sends. To keep one owner for that rule, I dropped this PR's duplicate guard in run-attempt-finalize.ts; that file is now identical to main. What this PR still adds:

  • bounded failure-stage diagnostics in settled-turn-context.ts: a history_read_failed capture warning now carries stage (before_read, load_worker, read or after_read). Fixed labels only; no exception text, transcript content or paths.
  • native regression coverage against the pinned Codex 0.162.1 executable for message-tool delivery with final=true / final=false: native delivery receipt, turn/interrupt only after a final send, binding history coverage advancing, and a same-thread resume that uses the corrected transcript.

Test scope change (review item): the native case no longer makes or asserts the capture decision. Its callback used to capture only when the test parameter said final=false, which bypassed core. That decision belongs to core's requestSettledTurnFinalizationContext, and src/agents/embedded-agent-runner/run/settled-turn-finalization.test.ts already covers delivered, pending and missing delivery against the real owner. Extension tests may not import core (lint:plugins:no-extension-test-core-imports), so the case now sets onSettledTurn = undefined and keeps only the native delivery and history checks. The Gateway trace below shows the real core decision driving capture.

Re-merge with main (fa48c1a159): main's #178243 rewrote both settled-turn test files, so the merge conflicted in tests only. I kept main's new structure and re-added only this PR's cases: the after_read closure expectation and the before_read/read stage test on main's capture() helper, and the native message-delivery case on main's in-file helpers. I dropped this PR's earlier move of those helpers into test-support; test-support now only gains the fixture's message phase. settled-turn-context.ts is byte-identical to 3012a431e4 and main has not touched it since 38e352c6e8, so the Gateway proof below still applies to this production code.

Validation on fa48c1a159:

  • settled-turn-context.test.ts: 23/23 passed.
  • settled-turn-finalizer.native.test.ts with OPENCLAW_LIVE_CODEX_SETTLED_FINALIZATION=0: 11/11 passed.
  • Core settled-turn-finalization.test.ts: 33/33 passed.
  • tsgo:extensions and tsgo:extensions:test pass. oxlint, oxfmt and git diff --check are clean on the changed files.
  • pnpm check:changed: 29 steps passed, including extension typecheck, test typecheck, extension test core-import guard, plugin boundaries, lint and import cycles. 2 steps failed outside this diff, in files it does not touch or reference: the max-lines suppression ratchet (three ui/ files) and Knip unused exports (scripts/ios-release-e2e.ts, src/infra/database-engine/contract.ts, src/agents/embedded-agent-runner/run/terminal-preparation.test-support.ts, ui/).
  • One bounded independent review of the merge resolution (Claude Opus 5.5, P2 threshold, origin/main..fa48c1a159) came back scoped-clean.

Real behavior proof (disposable QA Gateway, exact head vs base): I ran pnpm openclaw qa suite --provider-mode mock-openai --runtime-pair openclaw,codex --scenario group-progress-then-empty-finalization twice: once from a clean build of 3012a431e4 and once from a clean build of the merge base 38e352c6e8 (current main without this PR).

What is real: the built Gateway child (dist/index.js gateway run, loopback port, its own temp state, config and workspace), the qa-channel transport, the pinned Codex 0.162.1 app-server process, core's delivery-aware recovery decision, and the Codex plugin's capture path.

What is synthetic: the model is QA Lab's loopback mock-openai provider. The read failure is injected with a NODE_OPTIONS=--import preload. It replaces only the Worker started for codex/session-history.worker.js with one that throws at startup; every other worker is untouched. It fired exactly once per run, in the Codex cell. With the real worker running, projectCodexSettledHistoryInWorker fails at the read stage.

The trace comes from the Codex cell. The progress-only message send ends without a final answer, so core requests capture:

# base 38e352c6e8 (main without this PR)
[agent/embedded] codex settled-turn finalization context capture failed reason=history_read_failed
[agent/embedded] codex settled-turn finalization context is unavailable runId=<run> threadId=<thread> turnId=<turn> reason=context_unavailable
[agent/embedded] settled post-tool turn lacked a final answer: runId=<run> sessionId=<session> provider=openai/gpt-5.6-luna — running isolated finalization
[agent/embedded] settled-turn finalization failed: ... error=Codex settled-turn finalization context is unavailable — preserving failed recovery

# head 3012a431e4 (this PR)
[agent/embedded] codex settled-turn finalization context capture failed reason=history_read_failed stage=read
[agent/embedded] codex settled-turn finalization context is unavailable runId=<run> threadId=<thread> turnId=<turn> reason=context_unavailable
[agent/embedded] settled post-tool turn lacked a final answer: runId=<run> sessionId=<session> provider=openai/gpt-5.6-luna — running isolated finalization
[agent/embedded] settled-turn finalization failed: ... error=Codex settled-turn finalization context is unavailable — preserving failed recovery

# structured file log on head (hostname and trace ids removed)
{"1":{"reason":"history_read_failed","stage":"read"},"2":"codex settled-turn finalization context capture failed","_meta":{"runtime":"bun","logLevelName":"WARN"}}

I also ran a control on head without the fault. It logs no capture-failure warning: capture succeeds, and core's isolated finalization posts a recovered reply. So the new field appears only on the failure path, and the rest of the recovery flow is the same as on base.

Caveats, stated plainly:

  • The scenario's own assertions fail in both cells on base, on head and in the no-fault control, for reasons unrelated to this diff: the openclaw cell reports "write-then-empty turn did not run settled-turn finalization", and the codex cell expects no recovery after a progress-only send, which predates fix(codex): session stays busy after a message-tool reply and sends two empty finals #173945. I used the scenario only as a real Gateway driver.
  • In the Codex mock cell, QA Lab's catalog route made two host-side requests to the public OpenAI endpoint with QA's generated placeholder key. Both were rejected with 401 on base, on head and in the control. No real credentials were present anywhere in the run.

Raw Gateway logs, QA artifacts and the fault preload are kept locally and can be shared on request. The original description below predates #173945; its "now excludes it from capture" now describes core's behavior.


Related: #152786

What Problem This Solves

Fixes misleading recovery warnings and unnecessary transcript reads after Codex has already delivered the final reply through the source message tool.

User Impact

Confirmed final replies no longer start unused settled-turn context capture. Progress-only sends still leave answer recovery available. No configuration, storage, permission, or delivery-policy changes are required.

Why This Change Was Made

Codex can finish locally after a successful message-tool send without producing a native assistant final. Capture previously treated that legitimate result as an unanswered tool turn. The existing authoritative sourceReplyFinal receipt now excludes it from capture.

When capture is genuinely required, generic failures retain a bounded stage diagnostic; no exception text, transcript content, or paths are logged. This does not suppress necessary recovery, infer delivery from a private final, or claim to repair independently unavailable recovery context.

Evidence

Current head: see the update above (unit, native and core suites; exact-head Gateway trace with base comparison).

Earlier candidates, before #173945 and with this PR's own guard, which has since been removed:

  • The native attempt regression failed before the guard: an already-delivered final still produced a recovery context.
  • 14 native-attempt/refresh cases passed, including final and progress-only sends, preserved history coverage, interruption failures, cancellation and refresh handoff.
  • 32 capture/context cases passed, including immutable evidence, omitted history bounds, before/after-read authority and privacy-safe failure diagnostics.
  • 42 existing native-history cases passed.

Current native suite: 11/11 passed against the actual pinned native executable and the production attempt, dynamic-tool and host-settlement path. The two message-delivery cases (final=true and final=false) check native delivery, interruption, history coverage and same-thread resume. They do not assert the capture decision, which core owns and tests. All nine existing native closure, side-fork, source-ownership and summary cases also pass.

  • The native evidence uses one private loopback Responses fixture and a synthetic local delivery receipt. The native process and the SQLite transcript and binding operations are real; the model provider and external message transport are not. Test credentials are synthetic.
  • Live Telegram delivery and the root cause of a separately observed capture failure are not claimed as verified by this patch.
Redacted native test result (head 3012a43)
stock Codex settled-turn finalization ownership
  keeps real native history coverage after message (final=true)  PASS
  keeps real native history coverage after message (final=false) PASS
  existing native closure, side-fork, ownership and summary cases PASS
Test Files  1 passed (1)
Tests       11 passed (11)
Duration    157.08s

The message-delivery cases assert native terminal success, no timeout, the confirmed source-reply receipt, durable coverage and same-thread resumed input. You can reproduce this with the repository native test runner and OPENCLAW_LIVE_CODEX_SETTLED_FINALIZATION=0. It needs no external credentials and sends no Telegram message.

@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@clawsweeper

clawsweeper Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds privacy-safe failure-stage diagnostics and native Codex message-delivery history coverage.

Example: A progress-only message send requires recovery, but the history worker fails.

  • Before: The capture warning reports reason=history_read_failed.
  • After: The warning also reports stage=read, while recovery behavior remains unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused, correct diagnostic change with relevant Gateway evidence and distinct native continuity coverage; exact-head CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The supplied isolated Gateway comparison exercises the production Codex capture path with a real pinned app-server and injected worker failure, showing stage=read only on head; the unchanged production module permits reuse after the test-only merge resolution.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot distinguish where an unknown Codex recovery-context capture failure occurred.
Reason: Fixed stage labels improve diagnosis without exposing private error details or adding another recovery-policy owner.

Merge readiness

✅ Ready for maintainer review

This PR retains useful diagnostics and native history coverage beyond the merged core fix, with no actionable correctness or security findings.

Priority: P3
Reviewed head: fa48c1a1590f4d9d7a35b25b69caee728f710d98

Before merge

None.

Findings

None.

Agent review details

How this fits together

Core decides whether a settled tool turn needs recovery; the Codex plugin captures verified history and returns detached context or an unavailable result with bounded diagnostics.

flowchart TD
A[Settled Codex turn] --> B[Core delivery decision]
B --> C[Codex context capture]
C --> D[History worker]
D --> E[Verified context]
C --> F[Bounded failure warning]
E --> G[Isolated finalization]
Loading

Technical review

Best possible solution:

Land the focused diagnostic extension and native history coverage once the existing exact-head CI gate passes.

Do we have a high-confidence way to reproduce the issue?

Current-main source logs unknown capture failures without stage information, and the supplied Gateway base/head trace demonstrates the added read-stage diagnostic.

Is this the best way to solve the issue?

The patch extends the existing diagnostic owner with fixed labels and preserves core's sole ownership of capture eligibility.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9b3ebd7f5a27.

Provenance checked

  • History rejection diagnostics keeps the original intent (13cb0ba: Preserve safe, typed rejection reasons while withholding transcript content and exception text.)
  • Core-owned capture eligibility keeps the original intent (fix(codex): session stays busy after a message-tool reply and sends two empty finals #173945: Avoid eager history capture when confirmed delivery means no finalization is needed.)
  • Native fixture structure keeps the original intent (a3267d4: Reduce repeated test scaffolding while retaining distinct behavior coverage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 283d5e6 adds extensions/codex/src/app-server/settled-turn-context.ts:70 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 283d5e6fe371; files: extensions/codex/src/app-server/settled-turn-context.ts)
  • 송은우: Raw commit 13cb0ba adds extensions/codex/src/app-server/settled-turn-context.ts:46 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 13cb0bafd53c; files: extensions/codex/src/app-server/settled-turn-context.ts)
  • joshavant: Raw commit 6eea20c adds extensions/codex/src/app-server/settled-turn-context.ts:121 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6eea20ce181e; files: extensions/codex/src/app-server/settled-turn-context.ts)

PR surface

Source +8, Tests +172. Total +180 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 3 178 6 +172
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 187 7 +180

Review metrics

Metric Value Why it matters
Production versus test changes Production +9/-1; tests and fixtures +178/-6 Production growth is limited to bounded diagnostics; most test growth exercises native delivery and durable history continuity through existing fixtures.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: The remaining change improves diagnostics and regression coverage without changing user delivery or recovery policy.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (6 earlier review cycles)
  • reviewed 2026-09-20T14:27:28.919Z sha 025b1d4 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-20T15:19:42.863Z sha 175f73d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T21:43:58.001Z sha 175f73d :: blocked before merge. :: none
  • reviewed 2026-10-06T21:52:42.838Z sha 175f73d :: blocked before merge. :: none
  • reviewed 2026-10-20T06:11:45.271Z sha fd51a03 :: needs real behavior proof before merge. :: [P3] Stop manufacturing the capture decision in the native regression
  • reviewed 2026-10-20T07:47:09.079Z sha 3012a43 :: needs maintainer review before merge. :: none

Reviewed October 20, 2026, 7:36 AM ET / 11:36 UTC (Revision 7).

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 20, 2026
@VACInc

VACInc commented Sep 21, 2026

Copy link
Copy Markdown
Member

Related: #154930 merged into main and silences the host-generated missing-summary fallback for cron-triggered runs. Release availability and deployment are unverified.

This does not replace the final-delivery receipt guard or capture diagnostics here. Silencing a later cron placeholder does not avoid the unnecessary transcript read and recovery warning after a confirmed final send. Keeping this PR open for that independent capture behavior.

@Tosko4

Tosko4 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 20, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
…ssage regression

Capture eligibility after a delivered final belongs to core's
requestSettledTurnFinalizationContext and its own suite. The native case now
keeps only native delivery and history continuity checks.
@Tosko4

Tosko4 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 20, 2026
Resolve settled-turn test conflicts with openclaw#178243: keep main's flattened
context test and in-file native helpers; re-add only the PR's stage
diagnostics cases and native message history-coverage case.
@Tosko4

Tosko4 commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @Tosko4 for identifying this and following the delivery ownership changes. The reported warning-after-final-delivery bug is already fixed on main by #173945 (acd2763). I verified current main ea17c53: core reconciles committed delivery before requesting capture, skips capture/finalization for delivered or pending replies, and both Codex capture warnings remain inside that deferred callback. The existing core regression covers delivered/pending/missing states and final versus progress receipts. Closing the original bug as fixed; the remaining bounded stage diagnostics and native history-continuity coverage are useful separate improvements, as your updated description explains.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S 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.

3 participants