You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wrong agent to start a new invocation when last invocation was rewound #4169
** Please make sure you read the contribution guide and file the issues in the right place. ** Contribution guide.
Describe the bug
When we use rewind_async to cancel an invocation, roll back the state changes, and start a new invocation, rewound events are filtered out for LLM calls, but not when determining which agent to hand off to first.
To Reproduce
Please share a minimal code and data to reproduce your problem.
Steps to reproduce the behavior:
Install '...'
Run '....'
Open '....'
Provide error or stacktrace
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
OS: [e.g. macOS, Linux, Windows]
Python version(python -V):
ADK version(pip show google-adk):
Model Information:
Are you using LiteLLM: Yes/No
Which model is being used(e.g. gemini-2.5-pro)
Additional context
Add any other context about the problem here.
@chelxxx could you be more specific about "not when determining which agent to hand off to first"? Maybe provide an example sequence of events or code snippet to help reproduce.
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
@chelxxx could you be more specific about "not when determining which agent to hand off to first"? Maybe provide an example sequence of events or code snippet to help reproduce.
I am too lazy to open a PR (mostly don't want to write tests), but this is the fix and tested with my data (which unfortunately I can't share). Hope this help you understand it better. So add this to
@chelxxx the issue is that _find_agent_to_run in runners.py:1078 iterates through all session.events without filtering out rewound events, unlike _get_contents in contents.py:380-397 which correctly skips them.
The fix is to apply the same rewind filtering logic (iterate backward, skip events between the rewind marker and rewind_before_invocation_id) to the event list at the start of _find_agent_to_run before both the find_matching_function_call call and the agent selection loop.
This is still present in v1.23.0 — would you be open to submitting your fix as a PR?
@chelxxx the issue is that _find_agent_to_run in runners.py:1078 iterates through all session.events without filtering out rewound events, unlike _get_contents in contents.py:380-397 which correctly skips them.
The fix is to apply the same rewind filtering logic (iterate backward, skip events between the rewind marker and rewind_before_invocation_id) to the event list at the start of _find_agent_to_run before both the find_matching_function_call call and the agent selection loop.
This is still present in v1.23.0 — would you be open to submitting your fix as a PR?
Hi @surajksharma07@chelxxx, the rewind filtering logic makes sense! If no one is working on this, I'd be happy to submit the fix and write associated tests. Let me know!
The two spots to patch in _find_agent_to_run() (runners.py:1058 and :1070) both need the same backward-iteration filtering already in contents.py:409-449; extract that into a small helper and pass the filtered list to find_matching_function_call and the event loop.
For tests, a scenario that calls rewind_async() on a multi-agent session and then verifies _find_agent_to_run returns the root agent (not the sub-agent) would cover the regression cleanly.
@surajksharma07@seanzhou1023
Hey, just wanted to let you know that I've opened PR #4602 for this issue. It extracts the existing rewind-filtering logic into a shared filter_rewound_events helper and applies it in find_agent_to_run so rewound invocations are correctly ignored during agent resume. Includes unit tests covering the fix.
Activity
wuliang229 commentedon Jan 15, 2026
@chelxxx could you be more specific about "not when determining which agent to hand off to first"? Maybe provide an example sequence of events or code snippet to help reproduce.
adk-bot commentedon Jan 23, 2026
This issue has been automatically marked as stale because it has not had recent activity for 7 days after a maintainer requested clarification. It will be closed if no further activity occurs within 7 days.
chelxxx commentedon Jan 23, 2026
I am too lazy to open a PR (mostly don't want to write tests), but this is the fix and tested with my data (which unfortunately I can't share). Hope this help you understand it better. So add this to
adk-python/src/google/adk/runners.py
Line 1078 in 753084f
surajksharma07 commentedon Jan 29, 2026
@chelxxx the issue is that
_find_agent_to_runinrunners.py:1078iterates through allsession.eventswithout filtering out rewound events, unlike_get_contentsincontents.py:380-397which correctly skips them.The fix is to apply the same rewind filtering logic (iterate backward, skip events between the rewind marker and
rewind_before_invocation_id) to the event list at the start of_find_agent_to_runbefore both thefind_matching_function_callcall and the agent selection loop.This is still present in v1.23.0 — would you be open to submitting your fix as a PR?
It looks correct based on our testing.
chelxxx commentedon Jan 29, 2026
yeah, I will open a PR later.
surajksharma07 commentedon Feb 22, 2026
This is still present in v1.25.1 (latest).
rahulmansharamani14 commentedon Feb 22, 2026
Hi @surajksharma07 @chelxxx, the rewind filtering logic makes sense! If no one is working on this, I'd be happy to submit the fix and write associated tests. Let me know!
surajksharma07 commentedon Feb 22, 2026
@rahulmansharamani14 please go ahead — no one else is working on this.
The two spots to patch in
_find_agent_to_run()(runners.py:1058and:1070) both need the same backward-iteration filtering already incontents.py:409-449; extract that into a small helper and pass the filtered list tofind_matching_function_calland the event loop.For tests, a scenario that calls
rewind_async()on a multi-agent session and then verifies_find_agent_to_runreturns the root agent (not the sub-agent) would cover the regression cleanly.surajksharma07 commentedon Feb 22, 2026
@seanzhou1023 Please have a look into it once.
rahulmansharamani14 commentedon Feb 24, 2026
@surajksharma07 @seanzhou1023
Hey, just wanted to let you know that I've opened PR #4602 for this issue. It extracts the existing rewind-filtering logic into a shared
filter_rewound_eventshelper and applies it infind_agent_to_runso rewound invocations are correctly ignored during agent resume. Includes unit tests covering the fix.Would love your feedback. Thanks!
surajksharma07 commentedon Feb 24, 2026
@rahulmansharamani14 Thanks for getting this done so quickly — the
filter_rewound_eventshelper approach is exactly right.we will get a review queued on #4602; @seanzhou1023 worth taking a look too when you get a chance.
rahulmansharamani14 commentedon Feb 24, 2026
Thanks @surajksharma07 for the quick feedback, and @chelxxx for the initial groundwork on this - really helped shape the approach!
fix: skip rewound invocations when resuming agent in _find_agent_to_run