Repository navigation
fix(agents): raw model run retries drop the original prompt after a transient failure - #160803
Conversation
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
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
|
Codex review: needs maintainer review before merge. Reviewed October 1, 2026, 4:14 AM ET / 08:14 UTC (Revision 4). ClawSweeper reviewWhat this changesThe 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 Review scores
Verification
How this fits togetherThe 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
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +4, Tests +13. Total +17 across 2 files. View PR surface stats
Review metricsNone. Technical reviewBest 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. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles) |
|
Maintainer override: the only red on head Coverage for the cut-off job: the exact-head package-boundary compile passed locally for all 125 plugins in 271.6 s ( Proof: isolated Gateways in secretless Docker, with a mock provider that returns 503 on the first request.
|
# Conflicts: # src/agents/embedded-agent-runner/run.session-prompt-state.test.ts
|
@clawsweeper re-review Resolved the actual main merge conflict at 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 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. |
|
🦞👀 Re-review progress:
|
|
Maintainer override: both reds on head
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. |
|
Landed as 4907b0b. Thanks @changeroa! |
|
Thank you for the review!! @obviyus |
…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]>
…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)
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 Gatewayagentcall withmodelRun: 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 reportsok: 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_DIRand a tiny OpenAI-compatible stub: the firstPOST /v1/chat/completionsreturns HTTP 500server_error, and later requests stream back theusermessages they received.openclaw infer model run --gateway --model fakeecho/echo --prompt "TASK-LAMBDA: say hello" --jsonmainTASK-LAMBDA: say helloContinue the current task from the existing transcript, …❌ok: true, textECHO: Continue the current task …TASK-LAMBDA: say helloTASK-LAMBDA: say hello✅ok: true, textECHO: TASK-LAMBDA: say helloStub 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 isECHO: <user messages joined>. Each request'susermessages are logged, and the table above shows those logs.2. Regression test
src/agents/embedded-agent-runner/run.session-prompt-state.test.tsadds "keeps the original prompt for a raw model run retry", parameterized over both raw-run markers ({ modelRun: true }and{ promptMode: "none" }). It callscontinueFromCurrentTranscript()and asserts that the active prompt override stays unset and the prompt isn't flipped to an internal prompt.expected 'Continue the current task from the ex…' to be undefinedMeasured cost
pnpm test src/agents/embedded-agent-runner/run.session-prompt-state.test.ts --maxWorkers=1checks-node-changed-compact-large-23-1(shardagentic-agents-embedded-base-2)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): ✅ passscoped-cleanOriginal-head CI note
The following CI evidence applies to original contributor head
bdad38ed43397034759cc9b4210557e69b7ca384:openclaw/ci-gateis red becausecheck-additional-extension-package-boundarywas 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 logMaintainer 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
d3962d2b5602ca7642db351a05bbdc2e595bd806and original contributor headbdad38ed43397034759cc9b4210557e69b7ca384in 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:TASK-LAMBDAabsent.TASK-LAMBDA: say hello, and no tools.TASK-KAPPAplus 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:compilepassed 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.