fix(ai): emit TOOL_CALL_START/ARGS during continuation re-executions#372
fix(ai): emit TOOL_CALL_START/ARGS during continuation re-executions#372DiegoGBrisa wants to merge 5 commits intoTanStack:mainfrom
Conversation
Continuation re-executions (pending tool calls from message history) only emit TOOL_CALL_END, skipping TOOL_CALL_START and TOOL_CALL_ARGS. This causes clients to store tool calls with empty arguments, leading to infinite re-execution loops. Two tests added: - Single pending tool call emits full START → ARGS → END sequence - Batch of pending tool calls each emit full START → ARGS → END sequence
…re-executions Pending tool calls resumed from message history only emit TOOL_CALL_END, causing clients to store empty arguments and triggering infinite re-execution loops. Emit the full START → ARGS → END sequence using the arguments from the original ToolCall objects.
🦋 Changeset detectedLatest commit: ec66e30 The changes in this PR will be included in the next version bump. This PR includes changesets to release 29 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds emission of full tool-call chunks during continuation re-executions: an Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
|
View your CI Pipeline Execution ↗ for commit ec66e30
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-anthropic
@tanstack/ai-client
@tanstack/ai-devtools-core
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-groq
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-openrouter
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/typescript/ai/src/activities/chat/index.ts (1)
1027-1034: Populateargson the syntheticTOOL_CALL_ARGSchunk.At continuation time you already have the full serialized arguments, so emitting only
deltamakes these synthetic chunks a little less expressive than the adapter-emitted ones. Settingargstoo keeps raw stream consumers from needing a continuation-only code path.💡 Suggested change
const args = argsMap.get(result.toolCallId) ?? '{}' chunks.push({ type: 'TOOL_CALL_ARGS', timestamp: Date.now(), model: finishEvent.model, toolCallId: result.toolCallId, delta: args, + args, })🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/typescript/ai/src/activities/chat/index.ts` around lines 1027 - 1034, The synthetic TOOL_CALL_ARGS chunk currently only sets delta and omits the full args; update the chunk created in the continuation path (the block using argsMap.get(result.toolCallId) and pushing into chunks) to also set an args property with the serialized arguments (the same value you pull from argsMap, e.g., args or parsed equivalent) so consumers see the full arguments on the synthetic chunk alongside delta, model, toolCallId, and timestamp.packages/typescript/ai/tests/chat.test.ts (1)
722-801: Add one regression for the mixed pending/wait branch too.These cases cover the path where pending server tools finish and the engine proceeds to the next model call. The new
argsMapplumbing is also used when continuation pauses again forneedsClientExecutionorneedsApproval, so I’d add one assertion there thatTOOL_CALL_STARTandTOOL_CALL_ARGSare still emitted for the completed server tool.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/typescript/ai/src/activities/chat/index.ts`:
- Around line 1027-1034: The synthetic TOOL_CALL_ARGS chunk currently only sets
delta and omits the full args; update the chunk created in the continuation path
(the block using argsMap.get(result.toolCallId) and pushing into chunks) to also
set an args property with the serialized arguments (the same value you pull from
argsMap, e.g., args or parsed equivalent) so consumers see the full arguments on
the synthetic chunk alongside delta, model, toolCallId, and timestamp.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 09507dd7-efca-4f4a-8822-f6c0d6ef6b33
📒 Files selected for processing (3)
.changeset/fix-continuation-chunk-emission.mdpackages/typescript/ai/src/activities/chat/index.tspackages/typescript/ai/tests/chat.test.ts
Intentionally omitting args — adapter-emitted TOOL_CALL_ARGS chunks only use delta, so the synthetic chunks match the same shape. Adding a non-standard field would require consumers to handle continuation chunks differently from regular ones. |
Summary
Continuation re-executions (pending tool calls resumed from message history) only emit
TOOL_CALL_END, skippingTOOL_CALL_STARTandTOOL_CALL_ARGS. This causes clients to store tool calls with emptyarguments, leading to infinite re-execution loops.
buildToolResultChunksnow accepts an optionalargsMapparametercheckForPendingToolCalls), emits the fullSTART → ARGS → ENDsequence per tool call using the arguments from the originalToolCallobjectsprocessToolCalls) is unaffected — the adapter stream already emitsSTART/ARGSTest plan
START → ARGS → ENDsequenceSTART → ARGS → ENDsequenceSTART < ARGS < ENDper tool callSummary by CodeRabbit
Bug Fixes
Tests