Skip to content

fix(agents): preserve original prompt on model fallback retry (#65760) - #66029

Merged
altaywtf merged 2 commits into
openclaw:mainfrom
WuKongAI-CMU:fix/fallback-retry-preserve-prompt-65760
Apr 14, 2026
Merged

altaywtf merged 2 commits into
openclaw:mainfrom
WuKongAI-CMU:fix/fallback-retry-preserve-prompt-65760

Conversation

@WuKongAI-CMU

Copy link
Copy Markdown
Contributor

Summary

When a model call fails and OpenClaw triggers a fallback retry, `resolveFallbackRetryPrompt()` replaced the entire original user body with the fixed string `"Continue where you left off. The previous model attempt failed or timed out."` This discarded the original task instruction entirely, forcing the fallback model to reconstruct the task from session history alone — sometimes impossible (e.g. freshly spawned subagent where only the last message survives), sometimes just wrong.

Prepend the retry context to the original body instead so the fallback model has both the recovery signal AND the task:

```
[Retry after the previous model attempt failed or timed out]

\`\`\`

The existing subagent-spawn branch (no persisted session history) is unaffected — that path still returns `params.body` verbatim.

Credit to #65760 for a clean root-cause trace (incl. pointer to `attempt-execution.helpers.ts:resolveFallbackRetryPrompt`).

Closes #65760.

Changes

  • `src/agents/command/attempt-execution.helpers.ts` — prepend retry prefix to `params.body` instead of replacing it
  • `src/agents/command/attempt-execution.test.ts` — update the matching test to assert the new prefixed form; leave other tests (first attempt, no-history subagent) untouched

Test plan

  • Updated test exercises the fallback-with-history path directly
  • No-history subagent test still asserts `originalBody` return
  • First-attempt test still asserts `originalBody` return
  • Minimal diff, no surrounding refactor

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Apr 13, 2026
@greptile-apps

greptile-apps Bot commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes resolveFallbackRetryPrompt to prepend [Retry after the previous model attempt failed or timed out] to the original params.body rather than replacing the body entirely, so fallback models receive both the recovery signal and the original task instruction. The change is minimal and correct; the call site in attempt-execution.ts is unaffected.

Confidence Score: 5/5

Safe to merge — one-line logic fix with well-scoped tests; only finding is a duplicate test case.

The only finding is a P2 duplicate test; all logic is correct and the implementation matches the described intent.

No files require special attention.

Comments Outside Diff (1)

  1. src/agents/command/attempt-execution.test.ts, line 70-78 (link)

    P2 Duplicate test case

    This test is identical to the one at line 33 ("preserves original body for fallback retry when session has no history (subagent spawn)") — both call resolveFallbackRetryPrompt with isFallbackRetry: true, sessionHasHistory: false and assert originalBody. One of them can be removed.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/command/attempt-execution.test.ts
    Line: 70-78
    
    Comment:
    **Duplicate test case**
    
    This test is identical to the one at line 33 ("preserves original body for fallback retry when session has no history (subagent spawn)") — both call `resolveFallbackRetryPrompt` with `isFallbackRetry: true, sessionHasHistory: false` and assert `originalBody`. One of them can be removed.
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/command/attempt-execution.test.ts
Line: 70-78

Comment:
**Duplicate test case**

This test is identical to the one at line 33 ("preserves original body for fallback retry when session has no history (subagent spawn)") — both call `resolveFallbackRetryPrompt` with `isFallbackRetry: true, sessionHasHistory: false` and assert `originalBody`. One of them can be removed.

```suggestion
});
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix(agents): preserve original prompt on..." | Re-trigger Greptile

@altaywtf altaywtf self-assigned this Apr 14, 2026
@altaywtf
altaywtf force-pushed the fix/fallback-retry-preserve-prompt-65760 branch 2 times, most recently from 8e193e3 to d38eb62 Compare April 14, 2026 20:39
Intern Dev and others added 2 commits April 14, 2026 23:39
…aw#65760)

When a model call fails and OpenClaw triggers a fallback retry,
resolveFallbackRetryPrompt() replaced the entire original user body with
the fixed string "Continue where you left off. The previous model
attempt failed or timed out." This discarded the original task
instruction entirely, forcing the fallback model to reconstruct the task
from history alone — sometimes impossible, sometimes just wrong.

Prepend the retry context to the original body instead so the fallback
model has both the recovery signal and the task instruction:

    [Retry after the previous model attempt failed or timed out]

    <original body>

The existing subagent-spawn branch (no persisted session history) is
unaffected — that path still returns params.body verbatim.

Update the matching test to assert the new prefixed form.

Closes openclaw#65760
@altaywtf
altaywtf force-pushed the fix/fallback-retry-preserve-prompt-65760 branch from d38eb62 to ba919d1 Compare April 14, 2026 20:40
@altaywtf
altaywtf merged commit 70b67b0 into openclaw:main Apr 14, 2026
39 of 42 checks passed
@altaywtf

Copy link
Copy Markdown
Member

Merged via squash.

Thanks @WuKongAI-CMU!

kvnkho pushed a commit to kvnkho/openclaw that referenced this pull request Apr 17, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request May 13, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…aw#65760) (openclaw#66029)

Merged via squash.

Prepared head SHA: ba919d1
Co-authored-by: WuKongAI-CMU <[email protected]>
Co-authored-by: altaywtf <[email protected]>
Reviewed-by: @altaywtf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: resolveFallbackRetryPrompt discards original user prompt on model fallback retry

2 participants