vercel / vercel/ai

Partial UIMessage collection on abort or error

Open
#7,253 5 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

ai/ui bug task-identify-issue-type-done
Dominant language
TypeScript
Stars
26.9k
Forks
5.2k
Avg merge
17h 48m
Merged PRs (30d)
516

Description

Description

Currently, createUIMessageStream only invokes the onFinish callback when the stream completes successfully.

In cases where the stream is aborted (e.g., by the user) or an error occurs mid-way, we don’t get access to any partial UIMessages that were emitted before termination.

In long-running sessions that involve side effects (e.g., saving to disk, modifying state, committing to a DB, etc.), losing this in-progress output is problematic and can result in lost work or inconsistent state.

It would be valuable to have:

  • An onAbort and/or onError callback that receives the partial messages.
  • Or a modified onFinish that is always called, with an additional argument indicating whether the stream was aborted, failed, or completed.

I’m considering maintaining a partialMessages: ResponseMessage[] variable by collecting the output from onStepFinish. However, I’m not sure if there’s a util function available to convert ResponseMessage[] into a valid UIMessage.

+don't want to lose the usage data when error or abort occurs.

thanks!

AI SDK Version

Currently, using v5, but the issue existed in v4 as well.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at createUIMessageStream and inspect how onFinish and onStepFinish behave when a stream aborts or errors. Determine the intended callback or completion-state contract, including preservation of partial UI messages and usage data, and consider the issue resolved when both termination paths expose that information consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
ai, api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.