Fix AI assistant crash when the AI server errors mid-stream#4942
Open
elias-ba wants to merge 1 commit into
Open
Fix AI assistant crash when the AI server errors mid-stream#4942elias-ba wants to merge 1 commit into
elias-ba wants to merge 1 commit into
Conversation
Security Review ✅
|
2b63c6c to
8bab657
Compare
Streaming AI requests keep the response body as a lazy stream, but the error handler assumed a decoded map and keyed into it directly. A non-success status from a streaming endpoint therefore crashed the handler and discarded the background job, masking the real error. Return a clean error message unless the body is a plain map with a string "message"; any other shape (a stream body, or a nested or non-string message) falls back to a generic message, and the failing HTTP status is logged. Fixes #4941
8bab657 to
4c9f21d
Compare
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
The AI assistant talks to the Apollo AI server over a streaming connection. When that server replied with an error status, the code that handles errors assumed it was dealing with an ordinary JSON response and tried to read a field off it. Over a streaming connection the response body isn't a plain object, so this crashed, the background job was discarded, and the real error was hidden from the user.
This fixes the error handler so an error response over a streaming connection now returns a clean error message instead of crashing. The failing HTTP status is also included in the log so the underlying cause is easier to trace.
Closes #4941
Validation steps
Additional notes for the reviewer
AI Usage
Please disclose whether you've used AI anywhere in this PR (it's cool, we just
want to know!):
You can read more details in our
Responsible AI Policy
Pre-submission checklist
/reviewwith Claude Code):owner,:admin,:editor,:viewer)