fix: streaming textdone events - #1165
Merged
BenjaminMichaelis merged 6 commits intoAug 7, 2026
Merged
Conversation
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
force-pushed
the
benjaminmichaelis/fix-streaming-textdone-events
branch
from
June 1, 2026 23:55
485e433 to
5b05fa1
Compare
…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
marked this pull request as ready for review
August 7, 2026 06:29
Contributor
There was a problem hiding this comment.
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.ErrorCodeto clients for both JSON (non-started) and SSE (mid-stream) error responses. - Extends
ChatBackendUnavailableExceptionto carry a structuredErrorCode, and updates call sites to use namedinnerException. - 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. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
BenjaminMichaelis
deleted the
benjaminmichaelis/fix-streaming-textdone-events
branch
August 7, 2026 06:46
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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:
ChatBackendUnavailableExceptionto include anErrorCodeproperty, 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.ChatBackendUnavailableExceptioninLocalChatServiceto consistently use the newinnerExceptionparameter name for clarity. [1] [2] [3]Client error propagation:
ChatControllerto propagate the specificErrorCodefromChatBackendUnavailableExceptionin both standard and streaming error responses, ensuring clients receive accurate error details.Ensure that your pull request has followed all the steps below: