fix(ai-client): prevent infinite tool call loop when finishReason is stop#412
fix(ai-client): prevent infinite tool call loop when finishReason is stop#412AlemTuzlak merged 2 commits intomainfrom
Conversation
…stop When the server-side agent loop executes a tool and the model finishes with finishReason 'stop', the client should not auto-send another request. The model is done — no continuation needed. Previously, the client checked only if the last message part was a tool-result and all tools were complete, triggering auto-send regardless of finishReason. This caused infinite loops with non-OpenAI providers that respond minimally after tool execution.
🚀 Changeset Version Preview1 package(s) bumped directly, 10 bumped as dependents. 🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit 1b5c400
☁️ Nx Cloud last updated this comment at |
|
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 (2)
📝 WalkthroughWalkthroughA patch release for Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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 docstrings
🧪 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 |
@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: |
Summary
finishReason: 'stop', the client no longer auto-sends another requesttool-resultand all tools were complete — it didn't checkfinishReasonRoot cause
The
ChatClient.streamResponse()continuation logic at the end of a successful stream:When a server tool executes and the model responds with
finishReason: 'stop', the last part in the message istool-result(fromTOOL_CALL_END.result).areAllToolsComplete()returnstrue. The client auto-sends, the model calls the tool again, and the cycle repeats.Fix
Check
finishReasonbefore auto-sending:When the model says
stop, it's done — no continuation needed.Test plan
pnpm --filter @tanstack/ai-client run test:lib— 198 tests passrecommendGuitarclient tool)Generated with Claude Code
Summary by CodeRabbit
Bug Fixes