fix(coderd/x/chatd/chaterror): extract plain-text provider error bodies - #27597
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates chaterror’s provider error body extraction so plain-text HTTP response dumps (notably aibridge’s Anthropic 403 “AI budget” errors) can be surfaced as user-facing detail and used for correct error-kind classification.
Changes:
- Parse dumped HTTP responses with
http.ReadResponseto strip status/headers and de-chunk bodies before message extraction. - When JSON message extraction yields nothing, fall back to the trimmed first line of
Content-Type: text/plainbodies (but never for valid JSON). - Add regression and table-driven tests covering plain-text, HTML, whitespace, chunked, and non-dump “raw message” payload scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
coderd/x/chatd/chaterror/provider_error.go |
Adds robust HTTP response dump parsing and safe plain-text fallback to improve provider error detail extraction and downstream classification. |
coderd/x/chatd/chaterror/classify_test.go |
Adds end-to-end and table-driven regression tests to ensure Anthropic-style budget errors classify as usage_limit and validates dump parsing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
DanielleMaywood
approved these changes
Jul 29, 2026
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Follows up #27538.
Fixes an issue where
chaterrorwould not classify a plain-text aibridge budget error 403 as ChatErrorKindUsageLimit.Root cause: Anthropic adapter drops the body from
ProviderError.Message, andproviderErrorResponseMessageextracted only JSON.http.ReadResponse(strips headers, de-chunks, leaves non-dump payloads like Google's raw messages whole).Content-Type: text/plainonly, and never on valid JSON asDetailis user-facing.usage_limit, not retryable (wasauth).