Skip to content

fix(chat): reconcile errored reconnect streams#1963

Open
mattzcarey wants to merge 1 commit into
mainfrom
fix/1914-server-streaming-reconnect
Open

fix(chat): reconcile errored reconnect streams#1963
mattzcarey wants to merge 1 commit into
mainfrom
fix/1914-server-streaming-reconnect

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

  • allow useAgentChat to reconcile a server turn after the AI SDK client has entered error, rather than limiting reconnect probes to ready
  • correlate resume probes across replacement sockets and distinguish globally idle agents from active continuations owned by another connection
  • retain reconnect-open edges while status or an existing resume settles, retransmit an in-flight handshake on the new socket, and serialize mount/reconnect/tool/public resume entry points
  • add real-hook regression coverage for the reported client-error/server-still-running split, plus reconnect races, StrictMode, tool continuations, agent replacement, and resume: false
  • ship patch changesets for agents, @cloudflare/ai-chat, and @cloudflare/think

Why

isServerStreaming tracks server broadcasts independently from the AI SDK chat status. If a client-side failure moved the chat to error and the terminal server frame was missed, every later reconnect was rejected by the status === "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:

Resume requests therefore carry optional probe IDs that direct server responses echo. STREAM_RESUME_NONE also carries an optional reason (idle or continuation-owned). The hook clears fallback streaming state only after a correlated idle response. 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.tsx
  • pnpm --filter agents run test:react
  • pnpm --filter agents run test:chat
  • pnpm --filter @cloudflare/ai-chat exec vitest --run src/tests/ws-transport-resume.test.ts
  • pnpm --filter @cloudflare/ai-chat run test:react
  • pnpm --filter @cloudflare/think run test:react
  • pnpm run check

Closes #1914


Open in Devin Review

@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb79893

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch
@cloudflare/think Patch
@cloudflare/agent-think Patch

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

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1963

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1963

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1963

create-think

npm i https://pkg.pr.new/create-think@1963

hono-agents

npm i https://pkg.pr.new/hono-agents@1963

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1963

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1963

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1963

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1963

commit: eb79893

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isServerStreaming can stick true forever: stream resume-on-open only re-arms from "ready", so an errored client never recovers the done frame

1 participant