Skip to content

fix: streaming textdone events - #1165

Merged
BenjaminMichaelis merged 6 commits into
mainfrom
benjaminmichaelis/fix-streaming-textdone-events
Aug 7, 2026
Merged

fix: streaming textdone events#1165
BenjaminMichaelis merged 6 commits into
mainfrom
benjaminmichaelis/fix-streaming-textdone-events

Conversation

@BenjaminMichaelis

@BenjaminMichaelis BenjaminMichaelis commented Jun 1, 2026

Copy link
Copy Markdown
Member

Description

This pull request improves error handling and observability for AI chat streaming responses, focusing on better diagnostics and structured error reporting. The main changes include enhanced logging for streaming failures, more detailed error codes in exceptions, and improved propagation of error information to clients.

Enhanced error logging and diagnostics:

  • Added tracking of streaming update types and new logging methods (LogStreamingResponseErrorUpdate, LogStreamingResponseTerminalUpdate) to capture detailed sequences of events leading to streaming errors or failures, aiding in troubleshooting and monitoring. [1] [2] [3] [4] [5]

Error handling improvements:

  • Updated ChatBackendUnavailableException to include an ErrorCode property, allowing more granular identification of error conditions. The exception now defaults to "chat_unavailable" but can be set to more specific codes for different streaming failures.
  • Updated all usages of ChatBackendUnavailableException in LocalChatService to consistently use the new innerException parameter name for clarity. [1] [2] [3]

Client error propagation:

  • Modified ChatController to propagate the specific ErrorCode from ChatBackendUnavailableException in both standard and streaming error responses, ensuring clients receive accurate error details.

Ensure that your pull request has followed all the steps below:

  • Code compilation
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary

Propagate stream failure categories (error, failed, incomplete) via
ChatBackendUnavailableException.ErrorCode and return specific message/code
in both JSON and SSE error responses.
Adjust LocalChatService to use named innerException argument after
ChatBackendUnavailableException constructor expansion.
Log streaming error, failed, and incomplete terminal updates with
response id, status, error code/message, and incomplete reason to
make production failures diagnosable before merge.
Capture the recent streaming update type sequence in terminal stream
failure logs (error, failed, incomplete) to improve diagnosis of
opaque upstream stream errors.
@BenjaminMichaelis
BenjaminMichaelis force-pushed the benjaminmichaelis/fix-streaming-textdone-events branch from 485e433 to 5b05fa1 Compare June 1, 2026 23:55
…ming responses

Exception details are now only in server logs (already logged via LogChatStreamErrorBeforeResponseStarted
and LogChatStreamErrorMidStream). The errorCode from ChatBackendUnavailableException is still
forwarded as it is a controlled application-level value.
@BenjaminMichaelis
BenjaminMichaelis marked this pull request as ready for review August 7, 2026 06:29
@BenjaminMichaelis
BenjaminMichaelis requested a lite review from Copilot August 7, 2026 06:29
@BenjaminMichaelis BenjaminMichaelis changed the title Benjaminmichaelis/fix streaming textdone events fix: streaming textdone events Aug 7, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves diagnostics and client-visible error reporting for AI chat streaming, with a focus on making streaming failures easier to understand and troubleshoot across the chat service layer and the web controller.

Changes:

  • Propagates ChatBackendUnavailableException.ErrorCode to clients for both JSON (non-started) and SSE (mid-stream) error responses.
  • Extends ChatBackendUnavailableException to carry a structured ErrorCode, and updates call sites to use named innerException.
  • Adds structured logging around streaming terminal/error updates, including a recent update-type sequence for better observability.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
EssentialCSharp.Web/Controllers/ChatController.cs Uses exception ErrorCode when returning JSON/SSE error payloads during streaming.
EssentialCSharp.Chat.Shared/Services/LocalChatService.cs Updates exception construction to use named innerException with the new constructor signature.
EssentialCSharp.Chat.Shared/Services/ChatBackendUnavailableException.cs Adds an ErrorCode property and constructor support for structured error codes.
EssentialCSharp.Chat.Shared/Services/AIChatService.cs Adds logging for streaming failure updates and throws ChatBackendUnavailableException with more specific error codes.

Comment thread EssentialCSharp.Chat.Shared/Services/AIChatService.cs Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@BenjaminMichaelis
BenjaminMichaelis merged commit 5a4f691 into main Aug 7, 2026
5 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the benjaminmichaelis/fix-streaming-textdone-events branch August 7, 2026 06:46
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