Skip to content

Send an error event when a UI stream fails - #379

Open
anbuzin wants to merge 1 commit into
mainfrom
fix-sse-error-frame
Open

anbuzin wants to merge 1 commit into
mainfrom
fix-sse-error-frame

Conversation

@anbuzin

@anbuzin anbuzin commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Adds an error event and a [DONE] to to_sse, and then reraises the error.

try:
    async for chunk in ai.ui.ai_sdk.to_sse(agent_stream):
        yield chunk  # before: the response stops; after: an error event, then [DONE]
except Exception:
    logger.exception("Agent stream failed")  # the same exception, before and after

Related to #226.

When the event stream raised, to_sse stopped with no error event and no
[DONE] marker, so the AI SDK UI client saw only a broken response.

to_sse now sends an error event with a fixed text and the [DONE] marker,
then raises the same exception. The caller can still catch and log it,
and no server detail reaches the client. Cancellation and to_stream are
unchanged.
@anbuzin anbuzin added the fix Bug fix label Nov 30, 2026
@vercel

vercel Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-python Ready Ready Preview, v0 Nov 30, 2026 9:48pm UTC

This branch was successfully deployed

1 active deployment
Preview — 264e1b0f Deployed Nov 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant