fix(tools): raise clear error for duplicate tool names in tool_runner#1535
Open
Zawwarsami16 wants to merge 1 commit into
Open
fix(tools): raise clear error for duplicate tool names in tool_runner#1535Zawwarsami16 wants to merge 1 commit into
Zawwarsami16 wants to merge 1 commit into
Conversation
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.
I was poking around
tool_runnerand noticed that the runner accepts duplicate tool names without complaining. If you pass two tools that happen to share a name (say, two differentget_weatherimpls imported from different modules), the second silently overwrites the first in_tools_by_name = {tool.name: tool for tool in tools}, and your first tool is gone before the request is even built. The API would reject the duplicate, but only with a generic 400 after the round trip, and by then you have no idea which side of your code was wrong.This patch adds an upfront check in
BaseToolRunner.__init__that walks the tools, collects any names that show up more than once, and raises aValueErrorlisting them. It runs before any HTTP work, so you get the error at the call site oftool_runner(...)instead of inside a request handler. Behaviour for unique names is unchanged. I left the_tools_by_namedict comprehension in place and just added the validation pass above it.Three new tests in
tests/lib/tools/test_runners.pycover the sync runner, the async runner, and the case where multiple distinct names each have duplicates (the error should list all of them).uv run pytest tests/lib/ -n autoreports 496 passed, 1 skipped, 1 xfailed, anduv run ruff check . && uv run pyright && uv run mypy .are clean.