Skip to content

ThomasKliszowski/cloudflare-ai-chat-recovery-stuck-stream-repro

Repository files navigation

@cloudflare/ai-chat recovery stuck stream repro

Minimal reproduction for a @cloudflare/ai-chat@0.6.2 recovery issue where a browser useAgentChat / AI SDK useChat stream remains stuck after the Durable Object restarts during a response.

What This Shows

  • A React client connects to an AIChatAgent over WebSocket with useAgentChat.
  • The agent has chatRecovery = true.
  • The first response emits text plus a partial tool input chunk, then waits for 45 seconds.
  • If the Worker / Durable Object is restarted during that wait, recovery persists the partial assistant response and schedules a server-side continuation.
  • The continuation completes under a new request id.

With upstream @cloudflare/ai-chat@0.6.2, the original local browser stream may never receive done for its original request id, so useChat stays in a streaming state even after the continuation finishes.

Run

cd /path/to/cloudflare-ai-chat-recovery-stuck-stream
npm install
npm run dev:worker

In another terminal:

cd /path/to/cloudflare-ai-chat-recovery-stuck-stream
npm run dev

Open the Vite URL, usually http://localhost:5173.

Reproduction Steps

  1. Click Start slow stream.
  2. Wait until the page shows Ready for restart.
  3. While the response is still streaming, restart the Worker process running npm run dev:worker:
# stop wrangler dev with Ctrl-C, then start it again
npm run dev:worker
  1. Wait for the browser to reconnect and for the server-side continuation to finish.
  2. Capture the final page state.

The key evidence is the Current Result panel:

  • Expected behavior means the recovered continuation arrived and isStreaming returned to false.
  • Bug reproduced means the recovered continuation arrived, but chat.status / isStreaming still show that the original browser stream is active.

Expected

  • The browser-side useAgentChat / useChat state eventually returns to idle.
  • status is no longer streaming or submitted.
  • isStreaming becomes false.

Actual With 0.6.2

  • The continuation response is broadcast with continuation: true under a new request id.
  • The original local ReadableStream created by WebSocketChatTransport.sendMessages is never closed for the original request id.
  • The React client can keep reporting status: "streaming" / isStreaming: true.
  • Tool-part diagnostics are included only to make the interrupted assistant response visible; the main assertion is the streaming state.

Notes

  • This repro uses React 19 to avoid the separate React 18 static import issue from @cloudflare/ai-chat@0.6.2.
  • The repro flushes partial stream chunks before the pause so local recovery has persisted assistant state to reconstruct after restart.
  • The Worker intentionally uses manual AI SDK UI stream chunks so no model API key is required.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors