Skip to content

[Bug] Async continue retry re-appends the caller's input and re-forks the run #11141

Open

Description

@BlueX888

Summary

Agent.acontinue_run (and the streaming variant) re-runs its continuation preparation on every retry attempt: the run is re-forked/truncated via _apply_continue_modifiers, dependencies are re-resolved, and the caller's input is re-appended by _maybe_append_input_message. With retries >= 1, a transient model error on the first attempt therefore appends the caller's instruction twice (visible in the transcript sent to the model) and re-forks the run a second time.

The sync path already does this correctly: continue_run_dispatch performs fork/truncate, dependency resolution and input append once, before _continue_run's retry loop.

Impact

  • The retried model call receives the continuation instruction duplicated (transcript: ['ORIGINAL QUESTION', 'NEW INSTRUCTION', 'NEW INSTRUCTION']).
  • The run is re-forked from the original run on every attempt.
  • Dependency resolution (aresolve_run_dependencies) invokes caller callables — with side effects (LLM/DB calls) — once per attempt, and rewrites run_context.dependencies; per-attempt resolution can change run_input after the first attempt.

Repro

Offline FailOnceModel (fails once with a transient error, then succeeds), retries=1, delay_between_retries=0, invoked via acontinue_run with an input argument; parameterized over stream=False/True and run_response= vs run_id=+session_id:

E  AssertionError: assert ['ORIGINAL QUESTION', 'NEW INSTRUCTION'] == ['ORIGINAL QUESTION', 'NEW INSTRUCTION']
E    Left contains one more item: 'NEW INSTRUCTION'

The retried model call sees the instruction duplicated; the sync continue_run path with the same setup sees it once.

Suggested fix

Set a run_prepared flag: run the fork/truncate + dependency resolution + input append once, before the retry loop, in both _acontinue_run and _acontinue_run_stream — matching continue_run_dispatch. Everything downstream of the preparation stays per-attempt, so a failure during preparation still retries the preparation itself.

Tests

libs/agno/tests/unit/agent/test_continue_run_retries.py (4 variants: stream on/off × run_response/run_id+session_id): asserts a single NEW INSTRUCTION in the transcript, that the retried model call sees one instruction, and forked_from_run_id == first.run_id.

  • On base: 4 failed with the duplicate instruction.
  • With the fix: 4 passed; neighboring run-loop suites 180 passed; full unit/agent 1129 passed (3 pre-existing Windows tmp-file failures reproduce at base); ruff clean. An independent review proved the large diff is whitespace-only reindentation plus exactly six inserted tokens.

Activity

  1. gunjan-l commented on Oct 18, 2026

    @gunjan-l

    Hi team, I would like to work on this issue. Could you please assign it to me and add the ready label? I have analyzed the root cause and have a reproduction and fix ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions