All articles

English

October 25, 20265 min read

Streaming AI Interfaces: Cancellation, Recovery, and Honest Progress

A streaming response needs more than a typing effect. Design explicit states, useful stop and retry behavior, durable message identity, and accessible progress feedback.

Portrait of Tran Kim Dat

Tran Kim Dat

Software Engineer

Archival v0 chat interface from Vercel's September 2024 AI SDK 3.4 article; an example of an AI SDK-powered interface.
Archival v0 chat interface from Vercel's September 2024 AI SDK 3.4 article; an example of an AI SDK-powered interface. Image: Vercel. Original source - Full-size image

Streaming makes an AI product feel faster because people can start reading before generation finishes. It also reveals new failure modes: a partial answer can look final, a retry can duplicate work, and a stop button can disappear while a server-side operation is still running. The interface needs a clear account of what has happened and what remains uncertain.

Consider an illustrative research assistant that retrieves documents and drafts an answer. Its user does not need a live view of every internal event. They do need to know whether the request was accepted, whether useful work is progressing, and whether the displayed answer completed successfully.

Define states before adding the typing effect

Separate the request lifecycle from the message content. A useful application model includes idle, submitted, retrieving, streaming, completed, cancelled, and failed states. These are proposed product states; map them to the transport and SDK events available in your implementation rather than assuming the SDK exposes each one directly.

The AI SDK's chat interface documents submitted, streaming, ready, and error states. Those provide a starting point, while server-owned events can explain additional work such as retrieval. Avoid deriving status from whether the assistant's text happens to be empty: a valid request may spend time searching before any answer tokens arrive.

  • Submitted: confirm that the request has been accepted and keep a stop action available.

  • Retrieving: describe the current step only when an actual event supports it.

  • Streaming: display partial text with a clear in-progress status.

  • Completed: mark the response as finished and enable final-answer actions.

  • Cancelled or failed: retain useful partial text and explain its incomplete state.

Give messages and runs stable identities

Use separate identifiers for the conversation, user message, generation run, and assistant response. A user message may have several generation attempts. If those attempts share only a text value, reconnects and retries become difficult to reconcile. Persist the relationship so the UI can display which answer came from which attempt.

The following TypeScript type describes an application-level persistence contract, not an AI SDK event format. It deliberately allows a failed or cancelled run to retain partial content. Completing the transport and completing the application task should not be conflated.

type GenerationRun = {
  id: string;
  conversationId: string;
  userMessageId: string;
  assistantMessageId: string;
  status: "submitted" | "streaming" | "completed" | "cancelled" | "failed";
  partialText: string;
  lastSequence: number;
  errorCode: "timeout" | "provider_error" | "connection_lost" | null;
};

Sequence numbers become useful when your own event protocol supports replay: the client can ignore duplicate events and request progress after its last acknowledged event. Do not promise resumability unless the server retains the necessary state and the transport actually supports it. Reconnecting to a page is different from resuming a generation.

Make cancellation honest

Stopping the browser's fetch is only one part of cancellation. Propagate the signal through the request handler and provider adapter where supported. If the request has already enqueued background work, cancellation needs an explicit server-side mechanism. A disconnected client does not prove that every downstream task stopped.

Keep any partial answer visible and label it as interrupted. The user should be able to copy it or start another attempt without mistaking it for a complete result. If a tool has already committed a write, do not imply that stopping generation undid that operation. Show the recorded outcome of the write separately.

Distinguish retrying from resuming

Retry starts a new attempt. Resume continues a known attempt from retained state. Give these actions different semantics even if the UI uses simple language. Blindly resending the whole conversation after a connection failure can trigger another tool call or create a second assistant message while the first run still exists.

Before starting a replacement attempt, ask the server for the known run's status. If the run completed, load its stored result. If it failed, create a new run linked to the original user message. Protect any tool writes with idempotency and check whether they already happened before retrying them.

The AI SDK persistence guide demonstrates storing and loading chat messages, but explicitly leaves production concerns such as authorization to the application. Conversation access must be checked on every read and write. A guessed conversation identifier must never grant access to another person's messages.

Expose useful progress without inventing certainty

Show progress labels tied to observable events: searching documents, reading selected sources, or drafting the answer. Avoid fabricated percentages when there is no measurable amount of remaining work. A plain explanation of the current step is more useful than a progress bar that stalls at the same number on every request.

Keep controls stable as content grows. A stop button should remain easy to reach; a retry button should appear where the failure occurred. Auto-scroll only while the reader is near the latest message. Once they scroll up to inspect a source, preserve their position and offer a jump-to-latest control.

Treat accessibility and performance as part of correctness

Do not announce every token through a live region. Announce meaningful status changes and make the completed answer easy to navigate with headings and links. Preserve keyboard focus when a message updates, label icon controls, and avoid a blinking cursor animation for users who prefer reduced motion.

Batch rendering when needed so long streams do not force expensive rich-text parsing on every tiny chunk. Keep incomplete code fences and links from breaking the layout. Validate the final content before enabling actions that assume a complete structured result. Measure time to first useful content as well as total completion time.

Verify the uncomfortable paths

  • Disconnect before the first token and halfway through a response.

  • Stop during retrieval, generation, and a separately recorded tool operation.

  • Reload while a run is active and inspect whether the stored state agrees with the UI.

  • Retry after a timeout without duplicating an accepted write.

  • Read a long answer on a narrow screen with keyboard navigation and reduced motion.

A good streaming interface makes unfinished work understandable. Readers can tell what is provisional, stop work deliberately, recover from interruptions, and trust the final state. The visual effect matters, but the real product is the state model behind it.

Continue reading

Keep structured results behind a validation boundary

Primary sources

AI SDK UI: chat status, cancellation, regeneration, and rendering updates

AI SDK UI: chat message persistence and application responsibilities

Continue reading

More field notes.

View all articles
Langfuse experiments table showing selected runs, model metadata, latency and error counts.
EnglishOct 25, 2026

LLM Evaluation as a Release Gate: From Good Demos to Regression Tests

Build an evaluation process that catches AI regressions before release: representative datasets, deterministic checks, calibrated reviewers, and explicit quality budgets.

AI · developer-tools · evaluation · reliability · testing

Read article
The AI SDK developer tools interface from Vercel's AI SDK 6 article, used to inspect model calls and their outputs.
EnglishOct 25, 2026

Structured LLM Outputs: Schemas, Validation, and Safe Application Boundaries

Move AI output into application logic safely: small schemas, explicit uncertainty, runtime validation, semantic checks, and server-owned authorization before any action.

AI · TypeScript · architecture · llm · security

Read article
The retrieval-augmented generation pipeline published in Neon's January 2025 pgrag article.
EnglishOct 25, 2026

RAG with PostgreSQL: Retrieval, Permissions, and Answers You Can Verify

A practical design for PostgreSQL-backed RAG: versioned ingestion, permission-aware retrieval, useful citations, and separate tests for search quality and answer quality.

AI · PostgreSQL · RAG · architecture · security

Read article

Have a product worth building carefully?

Start a conversation