fix(ai): ignore a repeat TOOL_CALL_START for an already-tracked toolCallId - #1197
fix(ai): ignore a repeat TOOL_CALL_START for an already-tracked toolCallId#1197citizen204 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
ChangesRepeated tool-call start handling
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change ignores duplicate tool-call start events while preserving accumulated arguments and preventing duplicate execution; no actionable merge-blocking risk remains beyond normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…allId AG-UI's TOOL_CALL_START carries no index, and a non-first-party or malformed producer can send a second START for a toolCallId that is already being tracked by ToolCallManager. Without a guard: - a repeat with the same index overwrites the slot, wiping any TOOL_CALL_ARGS already accumulated (arguments reset to '') - a repeat with a missing/different index inserts a duplicate map row, so getToolCalls() returns the id twice and the engine runs the tool twice Skip the repeat instead. First-party adapters emit START only once per call, so this only changes behavior for custom/malformed streams. Fixes TanStack#1187
2eecfc8 to
8f93f0b
Compare
|
View your CI Pipeline Execution ↗ for commit 8f93f0b ☁️ Nx Cloud last updated this comment at |
Summary
ToolCallManager.addToolCallStartEventkeyed its internal map byindex(event.index ?? map.size), but AG-UI'sTOOL_CALL_STARTcarries no index. A non-first-party or malformed producer sending a second START for atoolCallIdalready being tracked could either wipe accumulatedTOOL_CALL_ARGS(same index — overwrites the slot, resettingargumentsto'') or insert a duplicate row (missing/different index —getToolCalls()then returns the id twice and the engine runs the tool twice). First-party adapters emit START only once per call and are unaffected.Fixes #1187
Changes
packages/ai/src/activities/chat/tools/tool-calls.ts:addToolCallStartEventnow skips the event if a tool call with the sametoolCallIdis already tracked.packages/ai/tests/tool-call-manager.test.ts: two regression tests — a repeat START with the same explicit index (accumulated arguments must survive) and a repeat START with no index (must not duplicate the row)..changeset/tool-call-manager-repeat-start.md: patch changeset.Ran
vitest run tests/tool-call-manager.test.tsinpackages/ai— 31 passed (29 existing + 2 new).Summary by CodeRabbit
Bug Fixes
Tests