fix(ai-client): settle status to ready on a message-less terminal run (#421)#749
fix(ai-client): settle status to ready on a message-less terminal run (#421)#749valeriudev wants to merge 1 commit into
Conversation
📝 WalkthroughWalkthroughAdds a fallback in ChatClient.streamResponse to set status to "ready" when auto-continuation doesn't run for message-less terminal RUN_FINISHED events, documents the fix in a changeset, and adds Vitest regression tests for the primary and related edge cases. ChangesStatus settlement for message-less terminal runs
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/ai-client/tests/chat-client-client-tool-status.test.ts (1)
1-175: ⚡ Quick winMove this unit test alongside the source file to match repo test-placement rules.
This test should live next to
packages/ai-client/src/chat-client.tsas a*.test.tssibling instead of underpackages/ai-client/tests/.As per coding guidelines,
**/*.test.ts: “Place unit tests alongside source code in*.test.tsfiles”.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/ai-client/tests/chat-client-client-tool-status.test.ts` around lines 1 - 175, The test file packages/ai-client/tests/chat-client-client-tool-status.test.ts must be moved next to the implementation to follow repo rules: relocate it to packages/ai-client/src/chat-client.test.ts (sibling of chat-client.ts), update any relative imports accordingly (ensure imports of ChatClient, createMockConnectionAdapter, createTextChunks, createToolCallChunks and ConnectConnectionAdapter still resolve), and run the tests to confirm paths are correct; no code changes to tests themselves are required beyond adjusting import paths.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/ai-client/tests/chat-client-client-tool-status.test.ts`:
- Around line 1-175: The test file
packages/ai-client/tests/chat-client-client-tool-status.test.ts must be moved
next to the implementation to follow repo rules: relocate it to
packages/ai-client/src/chat-client.test.ts (sibling of chat-client.ts), update
any relative imports accordingly (ensure imports of ChatClient,
createMockConnectionAdapter, createTextChunks, createToolCallChunks and
ConnectConnectionAdapter still resolve), and run the tests to confirm paths are
correct; no code changes to tests themselves are required beyond adjusting
import paths.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f381bc11-2412-407a-b197-4b345d135993
📒 Files selected for processing (3)
.changeset/chat-client-tool-status-ready.mdpackages/ai-client/src/chat-client.tspackages/ai-client/tests/chat-client-client-tool-status.test.ts
When a continuation run after a client tool call closes with a bare
RUN_FINISHED{stop} and no assistant message, the processor's onStreamEnd
never fires, so status stayed stuck at submitted. Normalize status to
ready on the terminal, non-continuing path.
Fixes TanStack#421
e274294 to
a9f1eb9
Compare
Fixes #421
🎯 Changes
useChatstayed in a non-ready status after a client tool call when the continuation run closed with a bareRUN_FINISHED { finishReason: 'stop' }and no assistant message.Status only reaches
readythrough the processor'sonStreamEndcallback, whichStreamProcessor.finalizeStream()fires only when an assistant message exists — so a message-less terminal run left status stuck atsubmitted. The fix normalizes status toreadyinstreamResponse's finally block on the terminal, non-continuing path, guarded onstatus !== 'ready'so the normalonStreamEndpath is a no-op. Kept inai-clientrather than the core processor:onStreamEndis message-scoped by design (enforced by existing processor tests) and status is a client-owned concern.Regression coverage in
chat-client-client-tool-status.test.ts: the #421 repro, an exactly-oncereadyguard on the normal text path, and the first-run bare-RUN_FINISHEDcase.✅ Checklist
@tanstack/ai-client:test:lib,test:types,test:eslint).🚀 Release Impact
@tanstack/ai-clientpatch).