Skip to content

Surface chat stream errors#6

Open
clyons wants to merge 1 commit into
ericblue:masterfrom
clyons:codex/chat-stream-errors
Open

Surface chat stream errors#6
clyons wants to merge 1 commit into
ericblue:masterfrom
clyons:codex/chat-stream-errors

Conversation

@clyons
Copy link
Copy Markdown

@clyons clyons commented May 11, 2026

Purpose / Big Picture

When chat streaming fails after the HTTP connection has already opened, users should get an actionable error instead of a silent stop or generic stream failure. This change keeps the existing streaming protocol intact, but adds one explicit error path: backend chat exceptions are converted into Server-Sent Event error messages, and the frontend client routes those messages through its existing onError callback.

The goal is to make setup and provider failures easier to diagnose without changing chat behavior when the provider succeeds. This is intentionally independent of provider selection work: it does not add OpenAI support, change Anthropic defaults, or modify how chat responses are generated.

Summary

  • wrap the chat SSE generator so provider/runtime exceptions emit event: error and then [DONE]
  • sanitize obvious API-key/authentication failures to point users at backend/.env
  • teach the frontend streaming client to throw on SSE error events so existing UI error handling can show the message

Notes

  • Two-file change: backend/routers/chat.py and frontend/src/api/client.ts.
  • No database, dependency, environment, model, or provider-selection changes.
  • Successful chat streams continue using the existing status, default message, and [DONE] events.

Validation

  • cd backend && python3 -m py_compile main.py services/*.py routers/*.py
  • make fe-build
  • local backend smoke test on port 8765 with an intentionally invalid Anthropic key; /api/chat returned:
event: status
data: Thinking...

event: error
data: AI provider authentication failed. Check the API key in backend/.env.

data: [DONE]
  • frontend streamChat smoke script confirmed an SSE error event reaches the onError callback.

@clyons clyons changed the title [codex] Surface chat stream errors Surface chat stream errors May 11, 2026
@clyons clyons marked this pull request as ready for review May 11, 2026 01:18
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