fix: detect duplicate tool names in buildToolMap#91
Merged
Conversation
Contributor
Author
|
The build fail for a reason that is unrelated to my changes |
Silent last-wins behavior when two tools share the same name makes debugging extremely difficult, especially when tools come from multiple sources (user tools, plugins, framework-injected tools). buildToolMap now returns an error on duplicate names: goai: duplicate tool name "foo": tool names must be unique Fixes the collision by failing fast at tool registration time.
6f14e97 to
2372b80
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The duplicate-tool-name guard added to buildToolMap is propagated by GenerateObject too, but only GenerateText and StreamText had a test for it. Add TestGenerateObject_DuplicateToolName so the error branch in GenerateObject is covered (fixes codecov/patch).
Contributor
|
/zenflow-review |
Contributor
zenflow reviewFound logic and state management issues in the tool handling code. Critical & High
Medium
request-changes |
Review follow-ups from zenflow-review: - buildToolMap now validates uniqueness across ALL tool names, not just those with an Execute function. The Vercel AI SDK (our reference) keys its tool set by name so collisions are impossible there; this matches that guarantee. The returned map still holds only executable tools. - StreamText's buildToolMap error path now transitions the StateRef StepStarting->StepIdle like the other pre-loop validation errors, so a poller observing the state cannot deadlock.
Contributor
|
/zenflow-review |
Contributor
zenflow reviewFound issues with deadlock-prone error handling in StreamText and API deviation in buildToolMap. Critical & High
Medium
request-changes |
Contributor
|
/zenflow-review |
Contributor
zenflow reviewIdiomatic issues were found regarding tool validation and error handling, but no security issues were detected. Medium
recommendation: comment |
StreamObject passed tools straight to the provider without the duplicate name check applied by GenerateText, StreamText and GenerateObject. Run the same validation so all four entry points behave consistently.
Contributor
|
/zenflow-review |
Contributor
zenflow reviewLGTM - no issues found by either reviewer. |
Contributor
|
Reviewer returned LGTM. Summary of what changed beyond the original fix:
|
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.
Problem
buildToolMapbuilds amap[string]Toolwith a plain loop and no uniqueness check. When two tools share the same name, the last one silently wins — no error, no warning. This is particularly dangerous when tools come from multiple sources: user-supplied tools, plugin-loaded tools, and framework-injected tools.Fix
Changed
buildToolMapsignature to return(map[string]Tool, error). Before inserting into the map, the function now checks for an existing key:All three callers (
GenerateText,StreamText,GenerateObject) propagate the error naturally since they already return errors.Tests
Added
TestBuildToolMap_DuplicateToolName,TestGenerateText_DuplicateToolName, andTestStreamText_DuplicateToolNamedemonstrating the collision detection.Related
See also: zendev-sh/zenflow# — same fix applied to zenflow's AgentRunner tool assembly.