fix(chat): reconcile errored reconnect streams#1963
Open
mattzcarey wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: eb79893 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
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.
Summary
useAgentChatto reconcile a server turn after the AI SDK client has enterederror, rather than limiting reconnect probes toreadyresume: falseagents,@cloudflare/ai-chat, and@cloudflare/thinkWhy
isServerStreamingtracks server broadcasts independently from the AI SDK chat status. If a client-side failure moved the chat toerrorand the terminal server frame was missed, every later reconnect was rejected by thestatus === "ready"re-probe guard. The server could finish normally while the client remained stuck in a streaming state until reload.Removing that guard alone is not sufficient:
STREAM_RESUME_NONEcan mean either global inactivity or that another live connection owns an active continuationactiveResponserace fixed in fix(chat): serialize reconnect-driven resumes to stop activeResponse race (#1837) #1838Resume requests therefore carry optional probe IDs that direct server responses echo.
STREAM_RESUME_NONEalso carries an optional reason (idleorcontinuation-owned). The hook clears fallback streaming state only after a correlatedidleresponse. These fields are additive: older clients ignore them, while uncorrelated responses still settle the transport without being treated as authoritative global-idle evidence.Testing
pnpm --filter agents exec vitest --run --project react src/react-tests/resume-overlap-race.test.tsxpnpm --filter agents run test:reactpnpm --filter agents run test:chatpnpm --filter @cloudflare/ai-chat exec vitest --run src/tests/ws-transport-resume.test.tspnpm --filter @cloudflare/ai-chat run test:reactpnpm --filter @cloudflare/think run test:reactpnpm run checkCloses #1914