published fresh until

AI SDK: how do I resume a chat reply lost on refresh?

Summary When users may reload or lose connection during a long AI reply, store the stream in Redis with resumable-stream, track an activeStreamId per chat, add a GET resume route that returns 204 when idle, and pass resume to useChat. Add a separate stop endpoint because stop() only closes the connection. Not tried by WhatWorks.

Not for stream arriving all at once; stream dying on a timeout

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

A user reloads, closes a laptop, or drops off Wi-Fi in the middle of a long reply. The partial answer is lost and, if the model was still generating, you paid for tokens nobody saw.

What the AI SDK docs describe (as fetched October 2026)

The "Chatbot resume streams" page lists three requirements: the resumable-stream package, Redis to store the UI message stream, and a persistence layer (a database) that records each chat's activeStreamId.

  • Client: pass resume to useChat; on mount the hook checks for an active stream and reconnects. By default a resumed stream is treated as a full replay; if your endpoint sends only remaining chunks set resumeStreamIsReplay: false on the transport, but use a full replay after a page reload because active text and reasoning continuation requires the same chat instance.
  • Server, GET route (for example app/api/chat/[id]/stream/route.ts): read the chat; if activeStreamId is null return new Response(null, { status: 204 }); otherwise return streamContext.resumeExistingStream(chat.activeStreamId) with the UI message stream headers.
  • POST route: create the stream in consumeSseStream, save the activeStreamId, and clear it in onEnd when generation finishes.

The stop button gotcha

The docs say that with resumable streams, stop() and client aborts only close the HTTP connection: the server keeps generating so the client can reconnect. A real stop button needs a dedicated endpoint that saves the partial assistant message, cancels the work producing the stream, and clears activeStreamId only if it still matches the stream being stopped. Call it only on explicit user action, not from route cleanup, and do not auto-reconnect after the user stops.

Tian Pan's November 2025 article describes the same architecture in general terms (generator writes chunks to a Redis Stream, a consumer forwards over SSE, clients resume from their last position) and adds a cancel path via AbortController so abandoned generations stop costing money.

A prompt for your agent

Add resumable streams to the chat route following the AI SDK "resume streams" docs: Redis-backed resumable-stream, activeStreamId stored on the chat row, a GET resume route that returns 204 when idle, and resume on useChat. Then add a separate stop endpoint that cancels generation and clears activeStreamId only if it matches. Do not auto-reconnect after an explicit stop.

Mistakes to avoid

  • Adding resume and keeping stop() as the only cancel path, so "stopped" chats keep billing.
  • Forgetting to clear activeStreamId on finish, so every reload tries to resume a finished stream.
  • Treating it as a UI feature: it needs Redis and a column in your chat table.

Limits

Source is the AI SDK documentation; I did not run it and the docs do not report cost or reliability numbers. It adds an infrastructure dependency (Redis).

Sources

Primary source: the AI SDK page Chatbot resume streams, read on 18 October 2026.

  • Confirms: the three requirements (resumable-stream, Redis, a stored activeStreamId), resume on useChat, resumeStreamIsReplay: false for partial-chunk endpoints, the GET route returning 204 when idle and otherwise resumeExistingStream, the POST route saving the id in consumeSseStream and clearing it in onEnd, stop() only closing the connection while generation continues, a dedicated stop endpoint that saves the partial message and clears the id only if it still matches, and no auto-reconnect after a stop.
  • Not covered: Tian Pan's article (secondary, not re-opened) and any cost or reliability figures.

Started from a post by @Vercel AI SDK docs, packaged by the editor. Original post

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# AI SDK: how do I resume a chat reply lost on refresh?
Summary: When users may reload or lose connection during a long AI reply, store the stream in Redis with `resumable-stream`, track an `activeStreamId` per chat, add a GET resume route that returns 204 when idle, and pass `resume` to `useChat`. Add a separate stop endpoint because `stop()` only closes the connection. Not tried by WhatWorks.
Copy for agent
get the whatworks thread ai-chat-reply-lost-on-refresh-resumable-streams-stop-button and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ai-chat-reply-lost-on-refresh-resumable-streams-stop-button
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks