fix(server): preserve Claude final-result API error text #19136
main fromrefs/pull/19136/head·merged by juliusmarminge View on GitHubA Claude turn can finish with terminal_reason: api_error while placing the useful failure detail in result. T3 previously replaced that detail with a generic repeated-API-error message.
Use trimmed final-result text beginning with API Error: as a fallback, sanitizing the complete message before limiting it to 500 characters. Authentication and usage-window hints, listed errors, HTTP 429/529 messages, and other terminal reasons retain their precedence. The existing Claude adapter applies this for all clients without changing contracts or other providers.
Verification on headless Linux / Node 24:
- Adapter suite: 293 tests passed. Reduced the contribution's 11 added cases to 7, retaining the existing auth/usage regression fixture changes (14 → 10 PR-related executions).
- Before/after: removing the fallback makes both selected regression cases fail; truncating before sanitizing makes the secret-boundary case fail. Both pass with this implementation.
- Server-only typecheck and targeted formatting/lint passed; lint retains one upstream unused-variable warning.
- One independent full-diff review round by Claude Opus 5.5 and Codex GPT-6-Sol found no blocking code issues. The historical redaction-before-truncation finding was rechecked against the source and mutation proof.
Proof uses the running adapter's fake SDK harness and terminal receipts. No live Claude API failure, integrated browser flow, macOS, Windows, iOS, Android, or Electron desktop verification was performed. Screenshots do not demonstrate this result-mapping behavior. CI and maintainer approval remain separate gates.
Thanks to @Marve10s for the focused implementation and initial regression work in #19136. This addresses only final-result error selection from #13399; assistant-only errors and other 429 cases remain outside scope.
Tests: GPT-6-Astra (high); implementation: GPT-6.1-Sol (high); reviews: Claude Opus 5.5 and GPT-6-Sol. Harness: Codex and Claude in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XS
Warning
Review limit reached#
Only developers with an assigned seat can use this organization's usage-based review budget, and seats here are assigned manually. Ask an admin to assign a seat, or change the review continuation mode in Billing.
Next included review available in 11 minutes.
View limit details
-
Limit details: You’ve used all 10 included reviews currently available.
Review configuration:
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
73e04a62-344f-4292-b17c-5523925ffe7e
📥 Commits
-
Reviewing files that changed from the base of the PR and between ca63df8447d3dda4948e7e1dfd254a0b715e0b6f and cc5c96b8a8c68c620e1ffbc04af469ec8fb6ea88.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
-
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Advanced
- Run ID:
9daef661-3992-4fad-af5d-768f0e6509b4
📥 Commits
-
Reviewing files that changed from the base of the PR and between 2143f6e3bfd9883571dcd886477d8a146eb087fb and ca63df8447d3dda4948e7e1dfd254a0b715e0b6f.
📒 Files selected for processing: 2
-
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsapps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
📝 Walkthrough
-
The Claude adapter now uses qualifying API-error result text as a fallback failure message. Tests cover message normalization, fallback cases, failure codes, and classification.
Changes: Claude API-error terminal reporting
Layer / File(s) Summary Extract and validate API-error messages
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts,apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.tsFor api_errorterminal results, the adapter uses trimmed result text beginning withAPI Error:as a fallback hint, capped at 500 characters. Tests cover trimming, truncation, redaction, fallback messages, diagnostic filtering, HTTP 529/429 messages,prompt_too_long, and failure classification.Priority: ➖ Normal
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
juliusmarminge
### Architecture SummaryMerge Risk: ⚪ Minimal · up to
ca63d-
Claude API-error results can retain useful diagnostic text without an identified secret-exposure or message-selection defect. The change is ready to merge after normal checks.
Architecture risk: 🔵 Low · up to
ca63dThe change affects 1 system.
Changed systems:
apps/serverArchitecture concerns No architecture-level concerns identified.
Review details
-
Systems and components
- observed — apps/server (service) was modified; 2 changed files map to changed impact.
Before / after behavior
- observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: Added parameterized expectations for failed terminal API results: preserve and trim API error text, truncate long text to 500 characters, redact quoted secrets before the limit, select the last non-diagnostic listed error, and use fallback messages for empty or ordinary text. The cases also expect fixed messages for HTTP 529 and 429, and for
prompt_too_long; each expects failure codeapi_error_<status>and classusage_limitonly for status 429. - observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: Changed the expired-login test input from the generic
"API Error"to a detailed HTTP 401 credentials-expired message. - observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts: Changed the unrecovered usage-window test input from generic
"API Error"to a detailed HTTP 400 provider-error message; the recovered case remains generic. - observed — Modified behavior in apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:
providerFailureFromResultderives a fallback message forapi_errorsuccess results whose trimmed result starts withAPI Error:, normalizes it throughmakeProviderFailure, and truncates it to 500 characters.terminalResultErrornow receivesfailureHint ?? apiErrorMessage, so an explicit failure hint still takes precedence; other result cases retain the existing structured error handling.
Pre-merge checks:
4-
Check name Status Explanation Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check skipped because no linked issues were found for this pull request. Title check The title clearly and concisely describes the main change: preserving Claude final-result API error text. Description check The description clearly explains the problem, implementation, scope, linked issue, verification results, test environment, and limitations. It is mostly complete and relevant, although it does not inc… Full details: Description check
-
Explanation
The description clearly explains the problem, implementation, scope, linked issue, verification results, test environment, and limitations. It is mostly complete and relevant, although it does not include an explicit maintainer approval comment.
-
✨ Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
-
💡 Codex Review#
Here are some automated review suggestions for this pull request.
Reviewed commit:
2143f6e3bfℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts line 2709OutdatedResolvedby Marve10s(GitHub profile, opens in a new tab)@@ -2702,3 +2702,8 @@27022702 ? "usage_limit"27032703 : "provider_error";27042704 const listedError = resultUserFacingError(message);2705+ const apiErrorMessage =2706+ message.subtype === "success" &&2707+ message.terminal_reason === "api_error" &&2708+ message.result.trim().startsWith("API Error:")2709+ ? message.result.trim().slice(0, 500)Redact API errors before truncating them
When a long API error has a quoted secret crossing the 500-character boundary (for example,
...{"token":"<value...with the closing quote after character 500), slicing here removes the delimiter beforemakeProviderFailuresanitizes the text. Its redactor (packages/provider-core/src/server/failure.ts:119-144) deliberately redacts before bounding and its quoted-secret pattern requires that delimiter, so this path persists and sends the secret prefix instead of[REDACTED]; sanitize the complete result before applying the 500-character limit.Useful? React with 👍 / 👎.
juliusmarminge assignedjuliusmarminge
Taking over this one as maintainer for batch claude-05. I will preserve the focused API-error behavior, reduce regression coverage to the necessary cases, and verify the rebuilt change before pushing here.
juliusmarminge merged this55a8fe9
juliusmarminge closed this
Sign in to join this conversation.
Codex Review Summary#
This comment shows the latest Codex review activity on this pull request.
2143f6eℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.