fix(ai-client): drop queued resume when run is superseded #2181
main fromrefs/pull/2181/head·opened View on GitHubCloses #2178
Summary#
- In
ChatClient.resumeInterruptsUnsafeForGeneration(packages/ai-client/src/chat-client.ts), verify inside thequeuePostStreamActioncallback thatthis.lastResume?.runId === target.runIdbefore dispatching the deferred resume. - If a newer run (such as
reload()) replaces or clearslastResumewhile the queued action is waiting, resolvefalseand skip the stale resume request instead of sending an outdatedparentRunId/resumepayload. - Added a regression test in
packages/ai-client/tests/chat-client-resume.test.tscovering resolving a prior interrupt whilereload()is streaming and ends on a new interrupt pause.
Verification#
pnpm nx run @tanstack/ai-client:buildpnpm nx run-many --projects=@tanstack/ai-client --targets=test:oxlint,test:types,test:lib
Summary by CodeRabbit#
- Bug Fixes
- Prevented a queued resume from starting an extra connection when a reload has replaced the paused interrupt.
- The active interrupt now remains in place while the reload completes, avoiding an unintended continuation from an outdated resume. This helps keep the conversation aligned with the latest streamed response.
- 1
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
willnie9(GitHub profile, opens in a new tab) linked this to fix #2178
tanstack-source added labelsbug
No actionable comments were generated in the recent review.
Walkthrough
-
The deferred resume action now checks whether its target run is still active. If a reload replaces the paused interrupt before the action runs, the action resolves with
falseand does not start another continuation. A regression test covers this sequence.Changes: Stale deferred resume
Layer / File(s) Summary Guard deferred resumes and test reload replacement
packages/ai-client/src/chat-client.ts,packages/ai-client/tests/chat-client-resume.test.tsThe deferred action skips the continuation when its target run no longer matches the active resume target. The regression test checks that resolving the stale interrupt during a reload does not open another connection or replace the newer interrupt. Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Suggested reviewers:
alemtuzlak,tombeckenham
Merge Risk:
Minimal · up tob5cbb-
This change stops the client from sending a stale resume request for an interrupt whose run has been superseded by a reload. Same-run resumes keep working. A regression test covers the reported scenario, and no merge-blocking risk is identified.
Pre-merge checks:
3 · 1-
Failed checks: 1 inconclusiveCheck name Status Explanation Resolution Linked Issues check Requirement [ #2178]: drop a queued resume when its run is no longer the paused run, so no stale request with the old parentRunId and resume payload is sent. The PR summary and AI-generated summary bot…Provide readable source for packages/ai-client/src/chat-client.ts at the reviewed head (or a diff of the changed blobs) so the reviewer can confirm that the queued action in resumeInterruptsUnsafeForGeneration performs the lastResume.runId … Passed checks: 3 passed-
Check name Status Explanation Title check The title names the main change: a queued resume is dropped when its run has been superseded, in the ai-client package. The conventional-commit prefix fits the fix. It matches the summary and the link… Description check The description covers the change in ChatClient.resumeInterruptsUnsafeForGeneration, the regression test, and the verification commands. It links issue #2178. The template checklist and Release Impact…Out of Scope Changes check The PR changes two files, as the summaries state: a small guard (about +4 lines) in packages/ai-client/src/chat-client.ts inside the queued post-stream action of resumeInterruptsUnsafeForGeneration, a… Full details: Title check
-
Explanation
The title names the main change: a queued resume is dropped when its run has been superseded, in the ai-client package. The conventional-commit prefix fits the fix. It matches the summary and the linked issue
#2178.
Full details: Description check
-
Explanation
The description covers the change in ChatClient.resumeInterruptsUnsafeForGeneration, the regression test, and the verification commands. It links issue
#2178. The template checklist and Release Impact sections are not filled in. The author did not state whether docs or a changeset were added, and did not state whether the change affects published code. The summary and verification sections are complete.Resolution
Consider completing the template checklist and Release Impact sections. State whether a changeset was added for the published
@tanstack/ai-clientpackage, and whether docs were updated or are not needed.
Full details: Out of Scope Changes check
-
Explanation
The PR changes two files, as the summaries state: a small guard (about +4 lines) in packages/ai-client/src/chat-client.ts inside the queued post-stream action of resumeInterruptsUnsafeForGeneration, and a regression test (about +101 lines) in packages/ai-client/tests/chat-client-resume.test.ts. The guard implements the directly linked issue
#2178. The test covers the issue's reported scenario and supports that change. The test diff contains no unrelated edits. No unrelated behavior change is shown. The chat-client.ts source diff could not be read, so this verdict relies on the summary for that file's contents. Those summaries do not describe any additional behavior change.
-
Full details: Linked Issues check
-
Explanation
Requirement [
#2178]: drop a queued resume when its run is no longer the paused run, so no stale request with the old parentRunId and resume payload is sent. The PR summary and AI-generated summary both state that the queued action in resumeInterruptsUnsafeForGeneration (packages/ai-client/src/chat-client.ts) now checks this.lastResume?.runId === target.runId and resolves false on mismatch. This matches the issue's suggested fix. However, the source diff for chat-client.ts could not be read: the changed blobs are missing from the checkout, and the head file read is truncated before resumeInterruptsUnsafeForGeneration. The guard therefore rests on the PR description and summary, not on reviewed source. The regression test in packages/ai-client/tests/chat-client-resume.test.ts (read from the diff) follows the issue's repro: it queues resolveGenericInterrupt(client) during a reload() stream, expects contexts to have length 3 after the reload, and expects only interrupt-2 to remain pending. The test would fail without the guard, but its result was not run here. The issue's optional question about clearing interrupts in reload() is not a stated acceptance criterion and is not addressed, which is acceptable.Resolution
Provide readable source for packages/ai-client/src/chat-client.ts at the reviewed head (or a diff of the changed blobs) so the reviewer can confirm that the queued action in resumeInterruptsUnsafeForGeneration performs the lastResume.runId === target.runId check and resolves false on mismatch. Confirm that the guard does not block the case where an approval is answered while its own run's stream is still open, which the issue requires to keep working.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/ai
- Branch: main
- File: .coderabbit.yaml
- Commit: 361b9e7
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
fe14ce57-6e53-4185-bb2a-1bd5052a02a4
Commits-
Reviewing files that changed from the base of the PR and between 361b9e73b70a9fbd8da360c441e7ee54f5a199fe and b5cbb6f181cc71347456c901169ede85891157ea.
Files selected for processing: 2-
packages/ai-client/src/chat-client.tspackages/ai-client/tests/chat-client-resume.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
-
-
This change is useful. It fixes #2178, which the pull request already links. No open pull request does the same work.
TanStack Source bot, value agent
github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
Thanks for the PR, @willnie9! 🙌 @tombeckenham will take a look.
Automated pre-review checks
- ✅ CI passing
- ✅ No merge conflicts
- ⚠️ No changeset found — run
pnpm changesetif this changes published packages - ⚠️ No E2E test changes detected — behavior changes need coverage under
testing/e2e/(see CONTRIBUTING)
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: author
View your CI Pipeline Execution ↗ for commit b5cbb6f181cc71347456c901169ede85891157ea
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 4m 25s View ↗ nx run-many --targets=test:coverage --projects=...✅ Succeeded <1s View ↗ nx run-many --targets=build --exclude=examples/...✅ Succeeded 23s View ↗ 💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗
☁️ Nx Cloud last updated this comment at
2026-11-18 13:05:43UTC@tanstack/ai
npm i https://pkg.pr.new/@tanstack/ai@2181@tanstack/ai-acp
npm i https://pkg.pr.new/@tanstack/ai-acp@2181@tanstack/ai-angular
npm i https://pkg.pr.new/@tanstack/ai-angular@2181@tanstack/ai-anthropic
npm i https://pkg.pr.new/@tanstack/ai-anthropic@2181@tanstack/ai-bedrock
npm i https://pkg.pr.new/@tanstack/ai-bedrock@2181@tanstack/ai-byteplus
npm i https://pkg.pr.new/@tanstack/ai-byteplus@2181@tanstack/ai-claude-code
npm i https://pkg.pr.new/@tanstack/ai-claude-code@2181@tanstack/ai-client
npm i https://pkg.pr.new/@tanstack/ai-client@2181@tanstack/ai-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-cloudflare@2181@tanstack/ai-code-mode
npm i https://pkg.pr.new/@tanstack/ai-code-mode@2181@tanstack/ai-code-mode-snippets
npm i https://pkg.pr.new/@tanstack/ai-code-mode-snippets@2181@tanstack/ai-codex
npm i https://pkg.pr.new/@tanstack/ai-codex@2181@tanstack/ai-cohere
npm i https://pkg.pr.new/@tanstack/ai-cohere@2181@tanstack/ai-compaction
npm i https://pkg.pr.new/@tanstack/ai-compaction@2181@tanstack/ai-computer-local
npm i https://pkg.pr.new/@tanstack/ai-computer-local@2181@tanstack/ai-computer-playwright
npm i https://pkg.pr.new/@tanstack/ai-computer-playwright@2181@tanstack/ai-computer-sandbox
npm i https://pkg.pr.new/@tanstack/ai-computer-sandbox@2181@tanstack/ai-computer-use
npm i https://pkg.pr.new/@tanstack/ai-computer-use@2181@tanstack/ai-devtools-core
npm i https://pkg.pr.new/@tanstack/ai-devtools-core@2181@tanstack/ai-durable-stream
npm i https://pkg.pr.new/@tanstack/ai-durable-stream@2181@tanstack/ai-effect
npm i https://pkg.pr.new/@tanstack/ai-effect@2181@tanstack/ai-elevenlabs
npm i https://pkg.pr.new/@tanstack/ai-elevenlabs@2181@tanstack/ai-event-client
npm i https://pkg.pr.new/@tanstack/ai-event-client@2181@tanstack/ai-fal
npm i https://pkg.pr.new/@tanstack/ai-fal@2181@tanstack/ai-gemini
npm i https://pkg.pr.new/@tanstack/ai-gemini@2181@tanstack/ai-grok
npm i https://pkg.pr.new/@tanstack/ai-grok@2181@tanstack/ai-grok-build
npm i https://pkg.pr.new/@tanstack/ai-grok-build@2181@tanstack/ai-groq
npm i https://pkg.pr.new/@tanstack/ai-groq@2181@tanstack/ai-harness
npm i https://pkg.pr.new/@tanstack/ai-harness@2181@tanstack/ai-harness-cli
npm i https://pkg.pr.new/@tanstack/ai-harness-cli@2181@tanstack/ai-isolate-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-isolate-cloudflare@2181@tanstack/ai-isolate-daytona
npm i https://pkg.pr.new/@tanstack/ai-isolate-daytona@2181@tanstack/ai-isolate-e2b
npm i https://pkg.pr.new/@tanstack/ai-isolate-e2b@2181@tanstack/ai-isolate-node
npm i https://pkg.pr.new/@tanstack/ai-isolate-node@2181@tanstack/ai-isolate-quickjs
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs@2181@tanstack/ai-isolate-quickjs-bun
npm i https://pkg.pr.new/@tanstack/ai-isolate-quickjs-bun@2181@tanstack/ai-llmgateway
npm i https://pkg.pr.new/@tanstack/ai-llmgateway@2181@tanstack/ai-lovable
npm i https://pkg.pr.new/@tanstack/ai-lovable@2181@tanstack/ai-mcp
npm i https://pkg.pr.new/@tanstack/ai-mcp@2181@tanstack/ai-memory
npm i https://pkg.pr.new/@tanstack/ai-memory@2181@tanstack/ai-mistral
npm i https://pkg.pr.new/@tanstack/ai-mistral@2181@tanstack/ai-muse
npm i https://pkg.pr.new/@tanstack/ai-muse@2181@tanstack/ai-neon
npm i https://pkg.pr.new/@tanstack/ai-neon@2181@tanstack/ai-octane
npm i https://pkg.pr.new/@tanstack/ai-octane@2181@tanstack/ai-ollama
npm i https://pkg.pr.new/@tanstack/ai-ollama@2181@tanstack/ai-ollaya
npm i https://pkg.pr.new/@tanstack/ai-ollaya@2181@tanstack/ai-openai
npm i https://pkg.pr.new/@tanstack/ai-openai@2181@tanstack/ai-opencode
npm i https://pkg.pr.new/@tanstack/ai-opencode@2181@tanstack/ai-openrouter
npm i https://pkg.pr.new/@tanstack/ai-openrouter@2181@tanstack/ai-perplexity
npm i https://pkg.pr.new/@tanstack/ai-perplexity@2181@tanstack/ai-persistence
npm i https://pkg.pr.new/@tanstack/ai-persistence@2181@tanstack/ai-preact
npm i https://pkg.pr.new/@tanstack/ai-preact@2181@tanstack/ai-react
npm i https://pkg.pr.new/@tanstack/ai-react@2181@tanstack/ai-reactor
npm i https://pkg.pr.new/@tanstack/ai-reactor@2181@tanstack/ai-remix
npm i https://pkg.pr.new/@tanstack/ai-remix@2181@tanstack/ai-sandbox
npm i https://pkg.pr.new/@tanstack/ai-sandbox@2181@tanstack/ai-sandbox-blaxel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-blaxel@2181@tanstack/ai-sandbox-boxd
npm i https://pkg.pr.new/@tanstack/ai-sandbox-boxd@2181@tanstack/ai-sandbox-cloudflare
npm i https://pkg.pr.new/@tanstack/ai-sandbox-cloudflare@2181@tanstack/ai-sandbox-daytona
npm i https://pkg.pr.new/@tanstack/ai-sandbox-daytona@2181@tanstack/ai-sandbox-docker
npm i https://pkg.pr.new/@tanstack/ai-sandbox-docker@2181@tanstack/ai-sandbox-e2b
npm i https://pkg.pr.new/@tanstack/ai-sandbox-e2b@2181@tanstack/ai-sandbox-local-process
npm i https://pkg.pr.new/@tanstack/ai-sandbox-local-process@2181@tanstack/ai-sandbox-railway
npm i https://pkg.pr.new/@tanstack/ai-sandbox-railway@2181@tanstack/ai-sandbox-sprites
npm i https://pkg.pr.new/@tanstack/ai-sandbox-sprites@2181@tanstack/ai-sandbox-upstash-box
npm i https://pkg.pr.new/@tanstack/ai-sandbox-upstash-box@2181@tanstack/ai-sandbox-vercel
npm i https://pkg.pr.new/@tanstack/ai-sandbox-vercel@2181@tanstack/ai-skills
npm i https://pkg.pr.new/@tanstack/ai-skills@2181@tanstack/ai-solid
npm i https://pkg.pr.new/@tanstack/ai-solid@2181@tanstack/ai-svelte
npm i https://pkg.pr.new/@tanstack/ai-svelte@2181@tanstack/ai-typesafe
npm i https://pkg.pr.new/@tanstack/ai-typesafe@2181@tanstack/ai-utils
npm i https://pkg.pr.new/@tanstack/ai-utils@2181@tanstack/ai-vercel-gateway
npm i https://pkg.pr.new/@tanstack/ai-vercel-gateway@2181@tanstack/ai-vertex
npm i https://pkg.pr.new/@tanstack/ai-vertex@2181@tanstack/ai-vue
npm i https://pkg.pr.new/@tanstack/ai-vue@2181@tanstack/ai-worldlabs
npm i https://pkg.pr.new/@tanstack/ai-worldlabs@2181@tanstack/openai-base
npm i https://pkg.pr.new/@tanstack/openai-base@2181@tanstack/preact-ai-devtools
npm i https://pkg.pr.new/@tanstack/preact-ai-devtools@2181@tanstack/react-ai-devtools
npm i https://pkg.pr.new/@tanstack/react-ai-devtools@2181@tanstack/solid-ai-devtools
npm i https://pkg.pr.new/@tanstack/solid-ai-devtools@2181@tanstack/svelte-ai-devtools
npm i https://pkg.pr.new/@tanstack/svelte-ai-devtools@2181commit:
b5cbb6fAlemTuzlak approved these changes
Sign in to join this conversation.
⚠️ No Changeset found#
Latest commit: b5cbb6f181cc71347456c901169ede85891157ea
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR