Partial UIMessage collection on abort or error
Nobody has claimed this yet.
- 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
onAbortand/oronErrorcallback that receives the partial messages. - Or a modified
onFinishthat 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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