Skip to content

Conversation

@ibetitsmike
Copy link
Contributor

When sendMessage failed before the stream started (e.g., invalid model, API key missing), the error was only shown as a toast which could be easily missed. The user would see their message in the chat but no response, with no indication of what went wrong.

Changes

  • Modified agentSession.streamWithHistory to emit a stream-error chat event when the stream fails to start
  • Added emitStreamError helper method that converts SendMessageError to StreamErrorMessage
  • Also emit stream-error when no model is specified

Why

The user would:

  1. Type a message and hit send
  2. See their message appear in the chat
  3. See a toast (which might auto-dismiss or be missed)
  4. Wonder why the assistant never responded

Now the error is clearly visible in the chat conversation itself.

Testing

  • Added integration test to verify stream-error is emitted on early model validation failure
  • Existing sendMessageError unit tests continue to pass

Generated with mux

@chatgpt-codex-connector
Copy link

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@ammario
Copy link
Member

ammario commented Dec 9, 2025

If we do this I suggest changing the terminology on the frontend to be clear it doesn't map to an ai-sdk stream-error. E.g we could call it chat-error. Also this code is entwined with the auto retry logic so take care that doesn't regress. Otherwise I think this is the right architecture.

When a chat message fails before streaming starts (e.g., invalid model,
missing API key), emit a 'chat-error' event so the error is visible in
the chat UI, not just as an easily-missed toast.

- Add ChatErrorMessage schema, type, and type guard
- Add emitChatError method in agentSession for pre-stream failures
- Handle chat-error in WorkspaceStore and StreamingMessageAggregator
- Add ChatErrorMessage UI component (displays 'Error' vs 'Stream Error')
- chat-error is never auto-retryable (requires user action to fix)
- Update retry eligibility to show retry UI for chat-error

Distinguishes from stream-error which occurs during AI SDK streaming and
may be transient/auto-retryable.

_Generated with `mux`_
@ibetitsmike ibetitsmike force-pushed the mux-chat-message-error-handling branch from af745f8 to 91d77a6 Compare December 9, 2025 10:06
@ibetitsmike ibetitsmike requested a review from ammario December 9, 2025 10:24
@ibetitsmike
Copy link
Contributor Author

@codex review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +619 to +623
metadata: {
partial: true,
error: data.error,
errorType: data.errorType,
timestamp: Date.now(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Surface chat-error messages instead of stream-error

In handleChatError the pre-stream error is stored as a plain MuxMessage with only error metadata and no chat-error type, so getDisplayedMessages will still convert it into a stream-error entry. That means the new chat-error UI/logic never triggers: pre-stream failures such as unsupported providers or missing API keys are classified as retryable stream errors, allowing auto-resume to keep retrying instead of forcing user action.

Useful? React with 👍 / 👎.

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.

2 participants