Skip to content

fix(codex): tool turns lose their final answer after a transient retry - #178102

Closed
gloss-dandelion-cult wants to merge 3 commits into
openclaw:mainfrom
karmaterminal:codeagent/up-155396
Closed

gloss-dandelion-cult wants to merge 3 commits into
openclaw:mainfrom
karmaterminal:codeagent/up-155396

Conversation

@gloss-dandelion-cult

@gloss-dandelion-cult gloss-dandelion-cult commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #155396
Related: #181779 (the stranded-reply retry, which has no recorder; composes with this PR, see below)

What Problem This Solves

Fixes: a Codex tool turn delivers no final answer (provenance_rejected → context_unavailable → harness failure) when a transient same-model retry or another same-run continuation ran the tools on a new native turn.

User Impact

User impact: channel and scheduled Codex turns that hit a provider overload, then finish their tools without a final message, now get the normal tool-free summary instead of a failed run. Settled-turn capture rejections now log which provenance check failed.

Why This Change Was Made

After a transient retry the runner suppresses the prompt it already persisted (attempt-normalization.ts) but keeps that run's transcript recorder. So the retried native turn has no <turn>:prompt identity, while the verifier required one for the active turn. Capture now anchors on the prompt the recorder persisted on the earlier native turn. The verifier still requires that row in history, in order, with matching source evidence, and still binds the tool boundary to the active turn. Duplicate, drift, mirror-prefix and foreign-turn checks are unchanged. Each verifier rejection site now reports its own reason instead of a shared provenance_rejected.

#181779 (merged) handles the other suppressed-prompt case: the stranded-reply retry, which has no recorder, so no prompt row exists anywhere; it anchors on the turn's first mirrored row. The two never overlap: promptSuppressed needs no recorder, and promptIdentity comes from one. Main is merged into this branch with both anchors kept. The suppressed path gets its own two reasons (provenance_unexpected_prompt, provenance_foreign_anchor) because this PR retires the shared provenance_rejected.

Evidence

Behavior or issue addressed: #155396. A direct-channel Codex turn completes its tools after a reason=overloaded transient retry, ends with no final text, and fails with capture failed reason=provenance_rejected → context is unavailable → Codex agent harness failed; not falling back.

Before evidence: reproduced on main 7299b241097f in the isolated Gateway run below. It is the same log sequence as the issue, and the agent run ends with status: "error" and no payloads after the tool already ran once.

Real environment tested: an isolated Gateway built from this branch at 11dd11cc4fb6, and the same Gateway from main 7299b241097f as the control. Each had its own state dir, config and loopback port, with channels skipped and the bundled Codex plugin on the pinned native Codex app server 0.162.1 (homeScope: "agent", tools.exec.mode: "full"). Native Codex pointed at a local scripted Responses server via -c openai_base_url=…. One user message was sent with openclaw agent --agent main --session-id … --message … --json, so it went through the full embedded runner, its transient retry and settled-turn finalization. Linux x86-64, Node 26.12.1.

Exact steps or command run after this patch: the scripted provider decides from request content only:

  1. the first fresh request → response.failed with server_is_overloaded (the transient overload);
  2. the next fresh request → one exec_command that appends AMBER-731 to a marker file;
  3. the request carrying that tool output → completes with no output (the empty final);
  4. a request carrying the finalizer's omitted-context developer notice → the summary text.

Every model request reached that local server. There was no real model call and nothing reached a real endpoint. Commands, config and provider script are in the details below.

Evidence after fix:

this branch 11dd11cc4fb6 main 7299b241097f
provider requests 4: overloaded, tool call, empty final, finalizer 3: overloaded, tool call, empty final (finalizer never asked)
marker file (tool effect) AMBER-731 × 1 AMBER-731 × 1
capture no warning capture failed reason=provenance_rejected
agent result status: "ok", payload "The receipt command ran once: AMBER-731." status: "error", payloads []

The finalizer request on this branch carried message, message, function_call, function_call_output, message: the persisted user prompt, the retried turn's tool call and its output, then the finalizer's notice.

Observed result after fix: the overloaded turn is retried once, the retried turn's tool runs exactly once, and its empty final is recovered by one tool-free finalizer turn whose answer is the run's only reply. On main the same run loses its answer after doing the work.

Native regression (pinned Codex app server, CI-runnable): settled-turn-finalizer.native.test.ts › "same-run continuation after a transient provider overload". The first native turn persists and annotates the prompt; the provider fails it as overloaded (asserted: failed, 503 OVERLOADED, replay-safe, one request). The retry keeps the recorder and suppresses the prompt; the tool runs on a new native turn with no final text. Settled evidence must hold the persisted prompt, the call and its output, and the finalizer persists one answer without repeating the command. With the fix reverted it fails 3/3 with Native turn lost its settled-tool evidence; with the fix it passes 10/10. The whole summary suite passes 7/7. A live-provider variant runs under OPENCLAW_LIVE_CODEX_SETTLED_FINALIZATION=1, with the overload still scripted.

Unit coverage: settled-turn-context.test.ts asserts the specific reason at every fail-closed site. It also covers continuation capture against the persisted prompt, a continuation whose persisted prompt is missing from history (rejected), and #181779's suppressed path, including the two new reasons.

Checks at 11dd11cc4fb6: pnpm tsgo:extensions; vitest over 24 files that touch the verifier, capture, history-rejection, worker runtime or the finalizer (313 tests); oxlint, oxfmt --check and the line-cap ratchet on the 8 changed files. All pass.

What was not tested: a live provider. My account has no OpenAI key on this host, so the model replies are scripted (only the overload is scripted in the live variant, which I have not run). I also did not test a real chat channel (Telegram/Discord); delivery here is the openclaw agent result.

Redacted Gateway logs

This branch:

[agent/embedded] transient same-model retry 1/8 for openai/gpt-5.6-sol reason=overloaded: delayMs=1190 runId=<run> sessionId=<session>
[agent/embedded] settled post-tool turn lacked a final answer: runId=<run> sessionId=<session> provider=openai/gpt-5.6-sol — running isolated finalization
(no capture failure, no harness failure)
agent: {"status":"ok","summary":"completed","result":{"payloads":[{"text":"The receipt command ran once: AMBER-731."}]}}
marker: AMBER-731

main:

[agent/embedded] transient same-model retry 1/8 for openai/gpt-5.6-sol reason=overloaded: delayMs=877 runId=<run> sessionId=<session>
[agent/embedded] codex settled-turn finalization context capture failed reason=provenance_rejected
[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-sol — running isolated finalization
[agents/harness] Codex agent harness failed; not falling back to embedded OpenClaw backend harnessId=codex provider=openai modelId=gpt-5.6-sol error="Codex settled-turn finalization context is unavailable"
[agent/embedded] settled-turn finalization failed: runId=<run> sessionId=<session> provider=openai/gpt-5.6-sol error=Codex settled-turn finalization context is unavailable — preserving failed recovery
agent: {"status":"error","summary":"failed","stopReason":"error","result":{"payloads":[]}}
marker: AMBER-731

Provider phases, in order (this branch): overloaded → tool-call → empty-final-after-tool → finalizer-summary. On main: the first three only.

Run recipe
export OPENCLAW_STATE_DIR=<isolated dir> OPENCLAW_CONFIG_PATH=<isolated dir>/openclaw.json \
  OPENCLAW_GATEWAY_PORT=19451 OPENCLAW_SKIP_CHANNELS=1 OPENCLAW_GATEWAY_TOKEN=<local token>
node <scripted-provider>.mjs 18555 &
node scripts/run-node.mjs gateway --port 19451 --verbose &
node scripts/run-node.mjs agent --agent main --session-id proof-178102 \
  --message "Create the amber inventory receipt: run the receipt command once, then tell me the receipt." --json
{
  gateway: { mode: "local", bind: "loopback", port: 19451, auth: { mode: "token" } },
  tools: { exec: { mode: "full" }, web: { search: { enabled: false } } },
  plugins: { entries: { codex: { enabled: true, config: { appServer: {
    command: "<node_modules>/@openai/[email protected] linux-x64 vendor binary",
    homeScope: "agent",
    args: ["app-server", "-c", "openai_base_url=\"http://127.0.0.1:18555/v1\""],
  } } } } },
  agents: { defaults: {
    workspace: "<isolated dir>/workspace",
    model: { primary: "openai/gpt-5.6-sol" },
    models: { "openai/gpt-5.6-sol": { agentRuntime: { id: "codex" } } },
  } },
}

The provider answers GET /v1/responses with 426, and POST /v1/responses with SSE (response.created, then response.output_item.done when there is an item, then response.completed or response.failed), choosing the phase as in steps 1–4 above.


🍃 frond-gloss, via Claude Code · https://claude.ai/code/session_01PiKbtQbHKKfq82arnmwBYp

…d prompt

A same-run continuation (transient retry, compaction, plugin refresh)
suppresses its internal prompt, so its new native turn has no prompt
identity and settled-turn capture always failed with provenance_rejected.
Anchor capture on the prompt this run already persisted, keep the tool
boundary bound to the active turn, and give each verifier rejection site
its own diagnostic reason.

Refs openclaw#155396
@clawsweeper

clawsweeper Bot commented Oct 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR anchors Codex continuation recovery to the run’s persisted prompt and adds specific provenance rejection diagnostics.

Example: A provider overload triggers a retry that runs a receipt command once, writes AMBER-731, and finishes without assistant text.

  • Before: Recovery rejects the missing current-turn prompt and returns an error with no answer.
  • After: Recovery validates the earlier persisted prompt and returns “The receipt command ran once: AMBER-731.” without repeating the command.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Focused, useful recovery repair with shipped CLI fault-injection proof and preserved rejection contracts; inherited red CI still blocks ordinary landing.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Exact-head isolated Gateway CLI output exercises native Codex against a real loopback Responses transport with an injected overload, one completed command, and an empty final; recovery returns one answer with one marker line, while the pinned-base control fails capture. This resolves the previous review’s missing Gateway proof; model responses are scripted and no live channel or external model is claimed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A Codex agent completes tools after a transient retry but returns no useful final answer.
Reason: The canonical retry mismatch is source-verified and reported in production; the repair preserves the existing fail-closed recovery contract.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it fixes a verified continuation-recovery defect still present on main, with no introduced correctness findings. The exact-head CI gate remains red on a failure also observed on the pinned base.

Priority: P1
Reviewed head: 11dd11cc4fb62f9645948b043c08705acde7ddbb

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Codex plugin translates native turns into OpenClaw transcript evidence; its history verifier supplies bounded, validated context to the existing tool-free finalizer.

flowchart LR
  A[User request] --> B[Embedded runner]
  B --> C[Native Codex retry]
  C --> D[Transcript mirror]
  D --> E[Settled history verifier]
  E --> F[Tool free finalizer]
  F --> G[Recovered answer]
Loading

Technical review

Best possible solution:

Retain this focused recorder-backed prompt handoff through the existing verifier and tool-free finalizer.

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

The current-main suppression-to-verifier path deterministically lacks the required current-turn prompt; production transcript evidence and the contributor’s pinned-base Gateway control corroborate it, without executing target code during this review.

Is this the best way to solve the issue?

The patch fixes the handoff at the existing capture owner, preserves native tool identities and integrity checks, and adds no parallel recovery mechanism.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3183356530eb.

Provenance checked

  • Settled-turn prompt identity changes intended behavior with a stated reason (ea3e77d: Worker-side verification requires ordered, matching transcript evidence through the settled tool boundary; the new module encoded a same-native-turn prompt requirement.)
  • Safe rejection diagnostics keeps the original intent (13cb0ba: Expose typed rejection categories without transcript content or arbitrary exception text.)
  • Lazy finalization capture keeps the original intent (acd2763: Core requests expensive settled context only when finalization is needed and while the attempt scope remains alive.)
  • Recorder-less prompt suppression keeps the original intent (7c374d4: Anchor a genuinely promptless internal turn at its first mirrored row while retaining prior conversation separately.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ea3e77d adds extensions/codex/src/app-server/settled-turn-evidence.ts:18 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ea3e77de827d; files: extensions/codex/src/app-server/settled-turn-evidence.ts)
  • Sukhdeep: Raw commit 7c374d4 adds extensions/codex/src/app-server/settled-turn-evidence.ts:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7c374d4539b2; files: extensions/codex/src/app-server/settled-turn-evidence.ts)
  • Baris Albayrak: Raw commit bceb739 adds extensions/codex/src/app-server/settled-turn-evidence.ts:25 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: bceb73905bf3; files: extensions/codex/src/app-server/settled-turn-evidence.ts)

PR surface

Source +33, Tests +241. Total +274 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 57 24 +33
Tests 4 287 46 +241
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 344 70 +274

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A verified provider-retry path loses the final answer after tools have already completed, affecting channel and scheduled agent workflows.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • 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 (1 earlier review cycle)
  • reviewed 2026-10-20T05:46:55.373Z sha 4550173 :: needs real behavior proof before merge. :: none

Reviewed October 24, 2026, 9:13 AM ET / 13:13 UTC (Revision 2).

gloss-dandelion-cult and others added 2 commits October 24, 2026 05:28
Brings in openclaw#181779, which anchors a prompt-suppressed (recorder-less) turn's
settled evidence at its first mirrored row. It and this branch's continuation
anchor edit the same verifier; both are kept:

- settled-turn-evidence.ts: SettledTurnMessages carries both promptIdentity
  (a same-run continuation's persisted prompt) and promptSuppressed. The two
  never coexist: promptSuppressed needs no recorder, promptIdentity comes from
  one. The verifier keeps this branch's per-site reasons; the suppressed path
  gets its own two (provenance_unexpected_prompt, provenance_foreign_anchor)
  instead of the shared provenance_rejected this branch retired.
- session-history-worker-runtime.ts: forwards both fields.
- settled-turn-context.test.ts: main's restructured file, with this branch's
  reason assertions and continuation cases ported into its helpers, plus a
  foreign-anchor case for the suppressed path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PiKbtQbHKKfq82arnmwBYp
Adds a "same-run continuation after a transient provider overload" scenario
to the native finalizer suite, on the pinned Codex app server. This is the
path openclaw#155396 reported. The first native turn persists and annotates the
user's prompt, then the provider fails the response as server_is_overloaded
before any output. The attempt ends failed with 503 OVERLOADED, replay-safe,
after one provider request. The retry keeps the recorder and suppresses the
prompt (what attempt-normalization.ts sets after a persisted prompt), and runs
the tool on a new native turn with no final text. Settled evidence must
capture the persisted prompt, the call and its output, and the tool-free
finalizer must persist one answer without repeating the command.

The native fixture gains an "overload" phase. It stays scripted under the
live-provider variant, so only the model's real turns go to OpenAI.

With the fix reverted, the scenario fails with "Native turn lost its
settled-tool evidence" (3 of 3 runs). With the fix it passes 10 of 10.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PiKbtQbHKKfq82arnmwBYp
@gloss-dandelion-cult

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The head is now 11dd11cc4fb6: main is merged (with #181779, both anchors kept) and there is a native app-server regression. The body has the requested real-behavior proof: an isolated Gateway with native Codex, an injected provider overload, completed tool work and an empty final. It shows the recovered reply and one tool effect, against main as the control.

🍃 frond-gloss, via Claude Code · https://claude.ai/code/session_01PiKbtQbHKKfq82arnmwBYp

@clawsweeper

clawsweeper Bot commented Oct 24, 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: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 24, 2026
steipete added a commit that referenced this pull request Oct 25, 2026
Preserve the recorder-backed original prompt when a same-run Codex continuation suppresses another prompt after a transient retry. Carry its identity through capture and worker verification so the existing tool-free finalizer can return the completed work without repeating tools. Keep the recorder-free recovery path and provenance checks intact.

The continuation regressions fail on the base and pass with the fix, including real native execution with SQLite and an exactly-once command effect. The focused regressions pass again after integrating main's unrelated typecheck repair.

Carries forward #178102 through a credited replacement because its organization-owned fork rejected maintainer pushes. Related: #155396; broader diagnostics remain outside this repair.

Co-authored-by: gloss-dandelion-cult <[email protected]>
@steipete

Copy link
Copy Markdown
Contributor

Thanks @gloss-dandelion-cult for the fix and the detailed reproduction and proof. The reviewed change landed through credited replacement #183077 as f120b9b.

The organization-owned fork rejected maintainer pushes, so the replacement preserved your contributor commits and credit while carrying the focused repair through validation and landing. Closing this original PR in favor of the landed replacement.

@steipete steipete closed this Oct 25, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 25, 2026
…183077)

Preserve the recorder-backed original prompt when a same-run Codex continuation suppresses another prompt after a transient retry. Carry its identity through capture and worker verification so the existing tool-free finalizer can return the completed work without repeating tools. Keep the recorder-free recovery path and provenance checks intact.

The continuation regressions fail on the base and pass with the fix, including real native execution with SQLite and an exactly-once command effect. The focused regressions pass again after integrating main's unrelated typecheck repair.

Carries forward openclaw#178102 through a credited replacement because its organization-owned fork rejected maintainer pushes. Related: openclaw#155396; broader diagnostics remain outside this repair.

Co-authored-by: gloss-dandelion-cult <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
Preserve the recorder-backed original prompt when a same-run Codex continuation suppresses another prompt after a transient retry. Carry its identity through capture and worker verification so the existing tool-free finalizer can return the completed work without repeating tools. Keep the recorder-free recovery path and provenance checks intact.

The continuation regressions fail on the base and pass with the fix, including real native execution with SQLite and an exactly-once command effect. The focused regressions pass again after integrating main's unrelated typecheck repair.

Carries forward #178102 through a credited replacement because its organization-owned fork rejected maintainer pushes. Related: #155396; broader diagnostics remain outside this repair.

Co-authored-by: gloss-dandelion-cult <[email protected]>

Release adaptation: stable captures settled context at a single call site (main moved it into onSettledTurn); applied the continued-prompt evidence prefix and promptIdentity there. Ported the continuation evidence unit case to stable's captureContext; main's native overload-continuation scenario depends on main-only native fixture changes and was not ported.

(cherry picked from commit f120b9b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

[Bug]: Ordinary Codex tool turns can fail closed on provenance_rejected during final-answer recovery

2 participants