Skip to content

fix(ui): emit safe errors for failed SSE streams#226

Open
EfeDurmaz16 wants to merge 1 commit into
vercel-labs:mainfrom
EfeDurmaz16:fix/ui-stream-error-events
Open

fix(ui): emit safe errors for failed SSE streams#226
EfeDurmaz16 wants to merge 1 commit into
vercel-labs:mainfrom
EfeDurmaz16:fix/ui-stream-error-events

Conversation

@EfeDurmaz16

Copy link
Copy Markdown

What

A FastAPI route can start streaming an agent response before the upstream provider fails. In that case, to_sse() currently propagates the exception, so AI SDK UI receives a truncated response with no protocol error and no [DONE] marker.

This change:

  • emits the existing UIErrorEvent for ordinary stream failures
  • masks server details with An error occurred. by default
  • adds an on_error callback for logging or a deliberate client-facing message
  • closes recovered streams with [DONE]
  • keeps to_stream(), cancellation, and generator shutdown behavior unchanged

Why

The existing web_agent example pipes to_sse() directly into FastAPI StreamingResponse. Once the response has started, an in-band AI SDK UI error chunk is the only structured way to report a provider failure to useChat.

This follows the concrete AI SDK UI interoperability direction discussed in #224.

Verification

  • uv run --frozen pytest -q: 593 passed
  • Ruff format and lint passed
  • mypy and ty passed
  • all repository example checks passed

Suggested release label: fix.

@vercel

vercel Bot commented Jul 20, 2026

Copy link
Copy Markdown

@EfeDurmaz16 is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant