fix(ai): use toolCallId for parallel tool execution tracking#11966
Open
delta575 wants to merge 2 commits intovercel:mainfrom
Open
fix(ai): use toolCallId for parallel tool execution tracking#11966delta575 wants to merge 2 commits intovercel:mainfrom
delta575 wants to merge 2 commits intovercel:mainfrom
Conversation
When tracking outstanding tool executions, use `toolCall.toolCallId` instead of `generateId()`. This fixes an issue where frameworks that override `generateId` for message grouping (returning the same ID for all tools in a request) would cause the `outstandingToolResults` Set to track only one tool. Problem: - Frameworks like @convex-dev/agent override `generateId` to return a constant `pendingMessageId` for message association purposes - This caused `outstandingToolResults.add(generateId())` to add the same ID multiple times, but Sets ignore duplicates - When the first tool completed and deleted the ID, the Set became empty - Stream closed prematurely, losing results from other tools Solution: - Use `toolCall.toolCallId` which is guaranteed unique per tool call from the LLM - This ensures each tool execution is tracked independently Test verification: - Test fails without fix: only 1 of 3 results captured - Test passes with fix: all 3 results captured Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4 tasks
5 tasks
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.
Background
Split from #11907 per review feedback to separate from the close guard fix.
The generateId parameter serves a valid purpose: allowing frameworks to control message IDs for grouping. For example, @convex-dev/agent overrides it to return the same ID for all messages in a request:
However, generateId() was also being used internally to track outstanding tool executions via a Set. When a framework returns the same ID for message grouping, the Set tracks only one entry instead of N tools:
Tool A: outstandingToolResults.add("msg-123") → Set: {"msg-123"}
Tool B: outstandingToolResults.add("msg-123") → Set: {"msg-123"} (duplicate ignored)
Tool C: outstandingToolResults.add("msg-123") → Set: {"msg-123"}
Tool B completes: outstandingToolResults.delete("msg-123") → Set: {} (empty!)
attemptClose() sees empty set → closes stream prematurely
Tool A and C results are LOST
Summary
Use toolCall.toolCallId instead of generateId() for tool execution tracking.
toolCallId is unique per tool call from the LLM and is the correct identifier for tracking individual tool executions. This separates the concerns of message ID generation (user-controlled) from internal tool execution tracking (implementation detail).
Manual Verification
The included test deterministically reproduces the issue:
Also tested end-to-end with @convex-dev/agent and Gemini 2.5 Flash with 5+ parallel tool calls.
Checklist
pnpm changesetin the project root)Related Issues