fix(runners): close shared toolsets only from the last runner - #7045
Open
claxman wants to merge 1 commit into
Open
fix(runners): close shared toolsets only from the last runner#7045claxman wants to merge 1 commit into
claxman wants to merge 1 commit into
Conversation
Runner.close always released every toolset on the agent, so the first of two parallel runners or AgentTools tore down a still-used toolset. Holders are a WeakSet of Runners so a dropped runner cannot pin the toolset. AgentTool closes the nested runner in a finally. Fixes google#4045
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
Runner.close()always callstoolset.close()for every toolset on the agent. TwoRunners sharing oneLlmAgentwith aCountingToolsetprintedafter_first_close 1thenafter_second_close 2. The first close already released the toolset while the second runner was still open. ParallelAgentToolruns on agents that share a toolset hit the same path (await runner.close()after each nested run).Solution:
Each
Runneris a weak holder of the toolsets it collected.close()removes that holder and only callstoolset.close()when no live runner remains. ARunnerdropped withoutclose()falls out of the set, so it cannot pin the toolset open.close()also re-collects toolsets so one appended after construct is still released.AgentTool.run_asynccloses its nested runner in afinallyso a raising nested run still unwinds on the same task.Testing Plan
Unit Tests:
6 passed.
With
runners.pyandagent_tool.pychecked out fromb0180620, four of those six fail (test_shared_toolset_stays_open_until_last_runner_closes,test_single_runner_still_closes_its_toolset,test_parallel_agent_tools_do_not_close_shared_toolset_early,test_failed_agent_tool_still_closes_shared_toolset). The dropped-runner and late-added tests pass on main (everyRunner.close()already closed the toolset) and guard the WeakSet / re-collect paths..venv/bin/python -m mypy src/google/adk/runners.py: Success, no issues.Manual End-to-End (E2E) Tests:
Not run. The CountingToolset runners and the parallel AgentTool test cover the two cases in the issue.
Additional context
Claim: #4045 (comment)
#4046 added an
AgentToolManagersingleton and was closed on 2026-05-12 after requested changes stayed open.Checklist