Skip to content

fix(coderd/x/chatd/chaterror): extract plain-text provider error bodies - #27597

Merged
johnstcn merged 8 commits into
mainfrom
fix-anthropic-aibudget-classify
Jul 29, 2026
Merged

fix(coderd/x/chatd/chaterror): extract plain-text provider error bodies#27597
johnstcn merged 8 commits into
mainfrom
fix-anthropic-aibudget-classify

Conversation

@johnstcn

@johnstcn johnstcn commented Jul 28, 2026

Copy link
Copy Markdown
Member

Follows up #27538.

Fixes an issue where chaterror would not classify a plain-text aibridge budget error 403 as ChatErrorKindUsageLimit.

Root cause: Anthropic adapter drops the body from ProviderError.Message, and providerErrorResponseMessage extracted only JSON.

  • Parses the dumped response with http.ReadResponse (strips headers, de-chunks, leaves non-dump payloads like Google's raw messages whole).
  • When JSON extraction yields nothing, falls back to the trimmed first line of the body.
  • Falls back on Content-Type: text/plain only, and never on valid JSON as Detail is user-facing.
  • Adds an end-to-end regression test that Anthropic-shaped 403 budget error → usage_limit, not retryable (was auth).
  • Adds table-driven test cases: HTML skipped, whitespace skipped, first-line-only, JSON-without-message, chunked, Google raw message.

Generated by Coder Agents on behalf of @johnstcn.

@johnstcn
johnstcn marked this pull request as ready for review July 28, 2026 22:22

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

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.ReadResponse to 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/plain bodies (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.

@johnstcn
johnstcn merged commit 5d2a69d into main Jul 29, 2026
33 of 34 checks passed
@johnstcn
johnstcn deleted the fix-anthropic-aibudget-classify branch July 29, 2026 09:38
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants