Skip to content

fix(agents): raw model run retries drop the original prompt after a transient failure - #160803

Merged
obviyus merged 2 commits into
openclaw:mainfrom
changeroa:contrib/modelrun-retry-keeps-prompt
Oct 1, 2026
Merged

obviyus merged 2 commits into
openclaw:mainfrom
changeroa:contrib/modelrun-retry-keeps-prompt

Conversation

@changeroa

@changeroa changeroa commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #160264
Related: #155018. Same continuation step, but a different reason the history is missing: that issue is a non-raw isolated cron run on native Codex.

What Problem This Solves

Fixes: a raw model run (openclaw infer model run --gateway, or the Gateway agent call with modelRun: true / promptMode: "none") quietly answers the wrong question after a transient provider failure. The automatic retry sends only the internal "continue from the existing transcript" instruction, without the user's prompt, and the run still reports ok: true.

User Impact

User impact: when a raw model run hits a timeout, server_error, overload, or rate limit, the retry now resends the original prompt. Callers get an answer to their actual task instead of a successful-looking reply like "I can't see the earlier transcript…".

Normal (non-raw) sessions behave exactly as before.

Why This Change Was Made

On a transient failure, the same-model retry calls continueFromCurrentTranscript(), which swaps the prompt for a continuation instruction. That's the right move for normal sessions, because their retry reloads the transcript. Raw model runs deliberately start every attempt without transcript history (attempt-history-prepare.ts), so after the swap the model sees neither history nor task.

The fix is a 4-line guard in session-prompt-state.ts. For raw runs (modelRun === true || promptMode === "none", the same test used elsewhere in the runner), continueFromCurrentTranscript() leaves the original prompt in place. Raw runs have no tools and no transcript side effects, so resending the prompt is replay-safe.

Evidence

1. Real Gateway reproduction (before → after)

This follows the issue's recipe. It uses an isolated OPENCLAW_STATE_DIR and a tiny OpenAI-compatible stub: the first POST /v1/chat/completions returns HTTP 500 server_error, and later requests stream back the user messages they received.

openclaw infer model run --gateway --model fakeecho/echo --prompt "TASK-LAMBDA: say hello" --json
Request 1 (→ 500) Retry request sent to the provider CLI result
main TASK-LAMBDA: say hello Continue the current task from the existing transcript, … ❌ ok: true, text ECHO: Continue the current task …
this PR TASK-LAMBDA: say hello TASK-LAMBDA: say hello ✅ ok: true, text ECHO: TASK-LAMBDA: say hello
Stub server and config used

openclaw.json (isolated state dir):

{
  "agents": { "defaults": { "model": { "primary": "fakeecho/echo" } } },
  "models": {
    "mode": "merge",
    "providers": {
      "fakeecho": {
        "baseUrl": "http://127.0.0.1:18999/v1",
        "apiKey": "stub-key",
        "api": "openai-completions",
        "models": [{ "id": "echo", "name": "Echo" }]
      }
    }
  },
  "gateway": { "mode": "local", "port": 18790, "bind": "loopback" }
}

Stub behavior: request 1 → 500 {"error":{"type":"server_error"}}. Every later request → SSE stream whose text is ECHO: <user messages joined>. Each request's user messages are logged, and the table above shows those logs.

2. Regression test

src/agents/embedded-agent-runner/run.session-prompt-state.test.ts adds "keeps the original prompt for a raw model run retry", parameterized over both raw-run markers ({ modelRun: true } and { promptMode: "none" }). It calls continueFromCurrentTranscript() and asserts that the active prompt override stays unset and the prompt isn't flipped to an internal prompt.

node scripts/run-vitest.mjs src/agents/embedded-agent-runner/run.session-prompt-state.test.ts
Result
without the fix ❌ 2 failed: expected 'Continue the current task from the ex…' to be undefined
with the fix ✅ 17 passed (17), including the existing normal-session continuation test

Measured cost

Where Measurement
Local, one worker: pnpm test src/agents/embedded-agent-runner/run.session-prompt-state.test.ts --maxWorkers=1 53.6 s wall with a cold transform cache. Vitest reports 47.9 s, of which 91% is transform.
CI, checks-node-changed-compact-large-23-1 (shard agentic-agents-embedded-base-2) The two new cases took 5 ms (modelRun: true) and 3 ms (promptMode: "none"). The whole 17-test file took about 91 ms of test time.

The new cases reuse the file's existing createState() fixture. They add no Gateway boot, timers, or new imports.

3. Checks

  • node scripts/check-changed.mjs (tsgo core + core tests, oxlint, oxfmt, line-cap / max-lines ratchets): ✅ pass
  • Codex autoreview (branch mode, P1): scoped-clean

Original-head CI note

The following CI evidence applies to original contributor head bdad38ed43397034759cc9b4210557e69b7ca384:

  • openclaw/ci-gate is red because check-additional-extension-package-boundary was cancelled at the job time limit. Its log shows all 125 plugin compile progress rows, followed by cancellation; it does not show the complete boundary job passing. job log

Maintainer verification (2026-10-01)

No overlap with Pash/Sarah changes. Thanks to @Oldrich333 for the reproduction and @changeroa for the focused fix.

Independently exercised built main d3962d2b5602ca7642db351a05bbdc2e595bd806 and original contributor head bdad38ed43397034759cc9b4210557e69b7ca384 in a secretless Node 24.21.0 Docker container, with isolated Gateway profiles and an OpenAI-compatible mock returning HTTP 503 on the first request of each turn. Captured provider request bodies show:

  • Main raw infer retry: only the continuation instruction, with TASK-LAMBDA absent.
  • Candidate raw infer retry: original TASK-LAMBDA: say hello, and no tools.
  • Normal Gateway agent control on both revisions: queued TASK-KAPPA plus the same continuation instruction.

The focused 17-case prompt-state suite passed (36.35 s wrapper wall time). Replacing only the prompt-state owner with its pre-fix version made exactly the two raw-run cases fail; the other 15 passed. No product changes beyond the contributor commit were needed.

Cancelled compile coverage on original contributor head: OPENCLAW_EXTENSION_BOUNDARY_CONCURRENCY=4 pnpm run test:extensions:package-boundary:compile passed in the same secretless container: all 125 plugins, 271.565 s. That hosted run had one cancelled job and no failing test/check job other than the aggregate CI gate.

Conflict-resolved head

Merged main only to resolve a real conflict, preserving the contributor commit and main's intentional test deletions. On fbc1917c3958582dfc5632625bb0d8fbf2610d20, the focused suite passed all 12 remaining cases (29.85 s wrapper wall time). Rebuilt isolated Gateway proof again confirmed raw infer resends the original task after HTTP 503, while the normal agent retry preserves its queued original task and continuation. Compiled state/config/database paths were checked before startup. Exact-head review request and proof.

Transient same-model recovery replaced the prompt with the transcript
continuation instruction. Raw model runs (modelRun / promptMode "none") load
no transcript history, so the retry sent neither history nor task and still
returned ok. Leave the original prompt in place for raw runs.

Closes openclaw#160264
@clawsweeper

clawsweeper Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Sep 28, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 4:14 AM ET / 08:14 UTC (Revision 4).

ClawSweeper review

What this changes

The branch preserves the original prompt when a raw model run retries and adds regression coverage for both raw-run markers.

Merge readiness

✅ Ready for maintainer review

Keep open: the fix remains necessary, the conflict-resolved patch has no blocking findings, and the recorded Gateway proof covers raw-run recovery and normal-session continuation.

Likely related people: Peter Steinberger and Vincent Koc (unverified routing candidates).

Priority: P1
Reviewed head: fbc1917c3958582dfc5632625bb0d8fbf2610d20

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, correct repair with strong before/after Gateway evidence and retained regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The recorded isolated Gateway and real OpenAI-compatible transport exercise prompt-state retry selection after injected 500/503 failures: raw infer sends the original task after the fix, and normal agent continuation retains its task. Exact-head verification covers the conflict-resolved branch; tests supplement that proof. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The recorded isolated Gateway and real OpenAI-compatible transport exercise prompt-state retry selection after injected 500/503 failures: raw infer sends the original task after the fix, and normal agent continuation retains its task. Exact-head verification covers the conflict-resolved branch; tests supplement that proof. No stored-data contract changes.
Evidence reviewed 9 items Verified introduced patch: The pinned merge-base-to-head delta adds a raw-run guard to the existing prompt-state owner and two parameterized regression cases. It introduces no dependency, configuration, schema, or authority changes.
Production retry flow: Transient recovery invokes transcript continuation at line 458. Raw history preparation resets model messages, while dispatch selects activePrompt.override or the original params.prompt. Returning before activating the continuation therefore preserves the task through the existing production path.
Documented raw-run boundary: Gateway model runs explicitly exclude transcript history, bootstrap context, tools, and bundled MCP servers. The CLI supplies modelRun true and promptMode none; attempt.ts uses the same predicate as the patch. The exercised OpenAI-compatible transport does not depend on the Codex harness; the related native Codex cron report describes separate behavior.
Findings None None.
Security None None.

How this fits together

The embedded agent runner sends Gateway model requests to providers and manages recovery after transient failures. Its prompt-state owner chooses whether a retry sends the original task or continues an existing transcript.

flowchart TD
  A[Gateway model request] --> B[Provider attempt]
  B --> C[Transient failure]
  C --> D[Retry prompt selection]
  D --> E[Raw run original prompt]
  D --> F[Normal session continuation]
  E --> G[Provider retry]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +4, Tests +13. Total +17 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 4 0 +4
Tests 1 13 0 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 17 0 +17

Review metrics

None.

Technical review

Best possible solution:

Keep raw-run retries faithful to the original task while normal sessions continue their existing transcript through the same prompt-state owner.

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

Yes: the isolated Gateway command with a first-request 500 or 503 provider fault gives a concrete reproduction, and current-main source supports the mechanism; this review did not execute it.

Is this the best way to solve the issue?

Yes: the guard repairs prompt selection at its existing owner, matches the raw-run predicate, and preserves normal-session behavior with focused regression and Gateway control evidence.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: Transient provider failures can make an existing Gateway raw model workflow return a successful-looking answer without its original task.
  • 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. Sufficient (live_output): The recorded isolated Gateway and real OpenAI-compatible transport exercise prompt-state retry selection after injected 500/503 failures: raw infer sends the original task after the fix, and normal agent continuation retains its task. Exact-head verification covers the conflict-resolved branch; tests supplement that proof. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded isolated Gateway and real OpenAI-compatible transport exercise prompt-state retry selection after injected 500/503 failures: raw infer sends the original task after the fix, and normal agent continuation retains its task. Exact-head verification covers the conflict-resolved branch; tests supplement that proof. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced patch: The pinned merge-base-to-head delta adds a raw-run guard to the existing prompt-state owner and two parameterized regression cases. It introduces no dependency, configuration, schema, or authority changes. (src/agents/embedded-agent-runner/run/session-prompt-state.ts:277, fbc1917c3958)
  • Production retry flow: Transient recovery invokes transcript continuation at line 458. Raw history preparation resets model messages, while dispatch selects activePrompt.override or the original params.prompt. Returning before activating the continuation therefore preserves the task through the existing production path. (src/agents/embedded-agent-runner/run/attempt-recovery.ts:458, fbc1917c3958)
  • Documented raw-run boundary: Gateway model runs explicitly exclude transcript history, bootstrap context, tools, and bundled MCP servers. The CLI supplies modelRun true and promptMode none; attempt.ts uses the same predicate as the patch. The exercised OpenAI-compatible transport does not depend on the Codex harness; the related native Codex cron report describes separate behavior. Public docs: docs/cli/infer.md. (docs/cli/infer.md:116, fbc1917c3958)
  • Still necessary on current main: At fetched main af80e86, continueFromCurrentTranscript still activates the continuation prompt unconditionally. Current main does not contain this repair. (src/agents/embedded-agent-runner/run/session-prompt-state.ts:276, af80e86b3a2a)
  • Latest-release check: The v2026.9.7 source at the supplied release SHA also has unconditional continuation. Its blob was inspected through GitHub REST after local historical-blob inspection failed; no shipped fix was established. (src/agents/embedded-agent-runner/run/session-prompt-state.ts, c074824a27c9)
  • Exact-head production-boundary proof: The captured PR body provides before/after provider-request observations through real isolated Gateways and the OpenAI-compatible transport. The exact-head comment fix(agents): raw model run retries drop the original prompt after a transient failure #160803 (comment) records secretless Docker verification after HTTP 503: raw infer resends TASK-LAMBDA, while normal agent recovery retains queued TASK-KAPPA and continuation. This exercises the changed prompt-state behavior through final provider requests rather than a mocked transport client. (fbc1917c3958)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (3 earlier review cycles)
  • reviewed 2026-09-29T00:01:18.668Z sha bdad38e :: needs maintainer review before merge. :: none
  • reviewed 2026-09-29T00:40:00.312Z sha bdad38e :: needs changes before merge. :: none
  • reviewed 2026-09-29T01:05:32.227Z sha bdad38e :: needs maintainer review before merge. :: none

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: the only red on head bdad38ed43397034759cc9b4210557e69b7ca384 is check-additional-extension-package-boundary, which was cut off at the 20-minute job cap (https://github.com/openclaw/openclaw/actions/runs/36499934014/job/109188662370). No test or check job failed. ClawSweeper's exact-head review is ready, with no findings.

Coverage for the cut-off job: the exact-head package-boundary compile passed locally for all 125 plugins in 271.6 s (OPENCLAW_EXTENSION_BOUNDARY_CONCURRENCY=4). This 4-line change in session-prompt-state.ts doesn't touch any plugin package boundary.

Proof: isolated Gateways in secretless Docker, with a mock provider that returns 503 on the first request.

  • main: the raw model-run retry sent only the continuation prompt and returned ok: true with the wrong answer.
  • This head: the retry resent the original prompt and returned the right answer.
  • Normal agent retry: keeps the queued prompt plus the continuation on both.
  • Regression tests: reverting the owner change produces exactly 2 raw-run failures; with the fix, all 17 pass.

# Conflicts:
#	src/agents/embedded-agent-runner/run.session-prompt-state.test.ts
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

Resolved the actual main merge conflict at fbc1917c3958582dfc5632625bb0d8fbf2610d20, preserving the contributor commit and main's intentional test deletions. The raw-run regression cases remain.

Secretless Docker verification on this exact head: the focused prompt-state suite passed all 12 cases (29.85 s wrapper wall time). A rebuilt isolated Gateway against a mock returning HTTP 503 first then success resends TASK-LAMBDA: say hello for raw infer; the normal agent control still preserves queued TASK-KAPPA with transcript continuation. Compiled state/config/database paths were checked before startup. No stored-data or schema changes are introduced by this fix.

The earlier before/after and reverted-owner evidence remains in the PR body. The earlier CI and package-boundary timing apply to the previous head, not this merge head.

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Maintainer override: both reds on head fbc1917c3958582dfc5632625bb0d8fbf2610d20 (run 36834574705, 0 cancelled) are unrelated to this diff. ClawSweeper's exact-head review is ready.

Main was merged into this PR only to resolve a real test conflict, and the contributor commit is kept. After the merge, the focused regression passes 12/12 in Docker. A rebuilt isolated Gateway resends the original prompt on a raw retry after a 503, and an ordinary agent retry is unchanged.

@obviyus
obviyus merged commit 4907b0b into openclaw:main Oct 1, 2026
164 of 168 checks passed
@obviyus

obviyus commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

Landed as 4907b0b. Thanks @changeroa!

@changeroa

Copy link
Copy Markdown
Contributor Author

Thank you for the review!! @obviyus

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…ransient failure (openclaw#160803)

Transient same-model recovery replaced the prompt with the transcript
continuation instruction. Raw model runs (modelRun / promptMode "none") load
no transcript history, so the retry sent neither history nor task and still
returned ok. Leave the original prompt in place for raw runs.

Closes openclaw#160264

Co-authored-by: Ayaan Zaidi <[email protected]>
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 6, 2026
…ransient failure (openclaw#160803)

Transient same-model recovery replaced the prompt with the transcript
continuation instruction. Raw model runs (modelRun / promptMode "none") load
no transcript history, so the retry sent neither history nor task and still
returned ok. Leave the original prompt in place for raw runs.

Closes openclaw#160264

Co-authored-by: Ayaan Zaidi <[email protected]>
(cherry picked from commit 4907b0b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: XS 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]: infer model run (modelRun) transient retry sends only the continuation prompt; original prompt lost, run returns ok

2 participants