Skip to content

fix: preserve original message body on fallback retries - #58301

Closed
yelog wants to merge 1 commit into
openclaw:mainfrom
yelog:fix/58219-fallback-retry-body-preservation
Closed

yelog wants to merge 1 commit into
openclaw:mainfrom
yelog:fix/58219-fallback-retry-body-preservation

Conversation

@yelog

@yelog yelog commented Mar 31, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolveFallbackRetryPrompt() replaced the message body with a generic "Continue where you left off..." recovery prompt when sessionHasHistory was true. For inter-agent sessions_send messages, this silently discarded the actual task content, breaking multi-agent communication.
  • Changed to always return the original body on fallback retries instead of substituting the recovery prompt.

Changes

  • src/agents/command/attempt-execution.ts: Modified resolveFallbackRetryPrompt() to always preserve the original body.
  • src/agents/command/attempt-execution.test.ts: Updated test expectation to verify original body is preserved.

Closes #58219

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

greptile-apps Bot commented Mar 31, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent message-loss bug in the fallback-retry path: resolveFallbackRetryPrompt was substituting the original body with a generic recovery prompt ("Continue where you left off...") whenever sessionHasHistory was true. For inter-agent sessions_send calls this discarded the actual task, leaving the fallback model with a meaningless hint instead of the real work item. The fix always returns the original body, which may result in the task appearing twice in the transcript when history already exists, but that is strictly better than losing the content.

  • Core fix (attempt-execution.ts): resolveFallbackRetryPrompt now unconditionally returns params.body — the recovery-prompt branch is removed and replaced with a clear explanatory comment.
  • Test update (attempt-execution.test.ts): The one test that expected the recovery-prompt string is updated to expect the original body; all other cases were already correct.
  • Minor clean-up opportunity: The if (!params.sessionHasHistory) guard (line 129) is now dead code because both it and the subsequent return statement return the same value. The sessionHasHistory parameter and the associated await sessionFileHasContent() call in agent-command.ts can be removed in a follow-up. Additionally, two tests in the suite cover the identical scenario (isFallbackRetry: true, sessionHasHistory: false) and one can be removed.

Confidence Score: 5/5

Safe to merge — the fix is correct and well-reasoned; only minor style clean-up remains.

No P0 or P1 issues found. The behavioural change (always send original body instead of recovery prompt) is the intended fix and is sound. The only remaining findings are P2 style notes: dead code left behind after the simplification and a duplicate test case. Neither affects correctness or runtime behaviour.

No files require special attention; the dead-code and duplicate-test observations are minor clean-up suggestions.

Important Files Changed

Filename Overview
src/agents/command/attempt-execution.ts Removed the recovery-prompt substitution in resolveFallbackRetryPrompt; now always returns params.body. Dead code branch left behind at line 129.
src/agents/command/attempt-execution.test.ts Updated test expectation to verify original body is preserved; introduced a duplicate test case for the sessionHasHistory=false scenario.

Comments Outside Diff (1)

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

    P2 Duplicate test case

    This test (isFallbackRetry: true, sessionHasHistory: false) is identical in parameters and expected result to the one at lines 29–37 ("preserves original body for fallback retry when session has no history (subagent spawn)"). One of them can be removed to keep the suite non-redundant.

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/command/attempt-execution.test.ts
    Line: 66-74
    
    Comment:
    **Duplicate test case**
    
    This test (`isFallbackRetry: true, sessionHasHistory: false`) is identical in parameters and expected result to the one at lines 29–37 ("preserves original body for fallback retry when session has no history (subagent spawn)"). One of them can be removed to keep the suite non-redundant.
    
    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.ts
Line: 129-131

Comment:
**Dead code branch after the fix**

After this change, `resolveFallbackRetryPrompt` always returns `params.body` regardless of `sessionHasHistory`. The early-return guard at line 129 is now a no-op — it returns the same value as the final `return params.body` on line 142. The function can be simplified:

```suggestion
  return params.body;
```

(and the `sessionHasHistory` parameter can be dropped from both the function signature and its call-site in `runAgentAttempt`, along with the now-wasted `await sessionFileHasContent(sessionFile)` in `agent-command.ts`)

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

---

This is a comment left during a code review.
Path: src/agents/command/attempt-execution.test.ts
Line: 66-74

Comment:
**Duplicate test case**

This test (`isFallbackRetry: true, sessionHasHistory: false`) is identical in parameters and expected result to the one at lines 29–37 ("preserves original body for fallback retry when session has no history (subagent spawn)"). One of them can be removed to keep the suite non-redundant.

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

Reviews (1): Last reviewed commit: "fix: preserve original message body on f..." | Re-trigger Greptile

Comment on lines 129 to 131
if (!params.sessionHasHistory) {
return params.body;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dead code branch after the fix

After this change, resolveFallbackRetryPrompt always returns params.body regardless of sessionHasHistory. The early-return guard at line 129 is now a no-op — it returns the same value as the final return params.body on line 142. The function can be simplified:

Suggested change
if (!params.sessionHasHistory) {
return params.body;
}
return params.body;

(and the sessionHasHistory parameter can be dropped from both the function signature and its call-site in runAgentAttempt, along with the now-wasted await sessionFileHasContent(sessionFile) in agent-command.ts)

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/command/attempt-execution.ts
Line: 129-131

Comment:
**Dead code branch after the fix**

After this change, `resolveFallbackRetryPrompt` always returns `params.body` regardless of `sessionHasHistory`. The early-return guard at line 129 is now a no-op — it returns the same value as the final `return params.body` on line 142. The function can be simplified:

```suggestion
  return params.body;
```

(and the `sessionHasHistory` parameter can be dropped from both the function signature and its call-site in `runAgentAttempt`, along with the now-wasted `await sessionFileHasContent(sessionFile)` in `agent-command.ts`)

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

@yelog
yelog force-pushed the fix/58219-fallback-retry-body-preservation branch from 966a1b4 to 7585c1c Compare April 1, 2026 05:12
@aisle-research-bot

aisle-research-bot Bot commented Apr 1, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 1 potential security issue(s) in this PR:

# Severity Title
1 🟡 Medium Fallback retry re-sends full user/task prompt, risking duplicate tool/command execution
1. 🟡 Fallback retry re-sends full user/task prompt, risking duplicate tool/command execution
Property Value
Severity Medium
CWE CWE-840
Location src/agents/command/attempt-execution.ts:121-142

Description

resolveFallbackRetryPrompt now always returns the original body during fallback retries even when session history exists.

This can cause the same high-privilege instruction set to be presented again as a new prompt on retries (provider/model failover, timeout recovery), which can lead to:

  • Duplicate side effects (e.g., running the same tool calls/commands again) if the first attempt partially completed before failing/timeouting.
  • Increased success probability of malicious/injected instructions because they are re-introduced verbatim rather than relying on transcript history.

Vulnerable code:

if (!params.sessionHasHistory) {
  return params.body;
}
...
return params.body;

Because runAgentAttempt uses this value as effectivePrompt, retries will re-submit the original prompt content to the model even when prior context is already present in activeSession.messages history (embedded runner calls activeSession.prompt(effectivePrompt)).

Recommendation

Revert to not re-sending the full body when there is already persisted session history, or make retries explicitly non-repeating.

Safer options:

  1. Only resend body when history is missing, otherwise use a recovery prompt:
export function resolveFallbackRetryPrompt(params: {
  body: string;
  isFallbackRetry: boolean;
  sessionHasHistory?: boolean;
}): string {
  if (!params.isFallbackRetry) return params.body;
  if (!params.sessionHasHistory) return params.body;
  return "Retry: continue from the transcript. Do not repeat actions already completed; inspect history and resume.";
}
  1. If the body must be resent for inter-agent tasks, wrap it with an explicit retry guard:
  • Instruct the model to check transcript/tool results and avoid repeating non-idempotent actions
  • Include a unique request ID and require tools/command steps to be idempotent/deduplicated against it

This reduces risk of repeated commands or tool misuse caused by failover retries.


Analyzed PR: #58301 at commit f02de46

Last updated on: 2026-04-01T12:14:51Z

@yelog
yelog force-pushed the fix/58219-fallback-retry-body-preservation branch from 7585c1c to 1e7ec3f Compare April 1, 2026 08:47

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e7ec3f180

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Preserving the original body is safe: the fallback model may see a
// duplicate in transcript history, but that is strictly preferable to losing
// the message content entirely.
return params.body;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep continuation prompt when retry already has history

On fallback retries where sessionHasHistory is true, this now returns the original task body, which re-injects the full user request as a new turn instead of a continuation cue. The fallback loop is explicitly designed to avoid duplicate user-message injection (src/agents/agent-command.ts:750-752), so this change can cause duplicate execution of side-effecting work when failover happens after history is already persisted. The original-body path should remain limited to retries without persisted history.

Useful? React with 👍 / 👎.

resolveFallbackRetryPrompt() replaced the message body with a generic
"Continue where you left off..." recovery prompt when sessionHasHistory
was true. For inter-agent sessions_send messages, this silently
discarded the actual task content, breaking multi-agent communication.

Always return the original body on fallback retries instead of
substituting the recovery prompt.

Closes openclaw#58219
@yelog
yelog force-pushed the fix/58219-fallback-retry-body-preservation branch from 1e7ec3f to f02de46 Compare April 1, 2026 12:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f02de46ab9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

// Preserving the original body is safe: the fallback model may see a
// duplicate in transcript history, but that is strictly preferable to losing
// the message content entirely.
return params.body;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore continuation prompt when history already exists

Returning params.body on every fallback retry re-injects the original user task into the same session for each model candidate, which can cause duplicate execution of side-effecting instructions when the first model already received the prompt but failed (for example timeout/rate-limit after tool calls started). The fallback loop is explicitly tracking retry index to avoid this duplicate user-turn behavior, so this change regresses existing-session retries and can produce repeated actions instead of true continuation.

Useful? React with 👍 / 👎.

@altaywtf

Copy link
Copy Markdown
Member

Superseded by #66029, which merged on April 14, 2026. Closing this older duplicate in favor of the landed fix.

@altaywtf altaywtf closed this Apr 14, 2026
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.

sessions_send: isFallbackRetry replaces message content with recovery prompt

2 participants