Skip to content

fix(claude): show an API error Claude Code records as its answer as a failed request - #3749

Merged
devswha merged 1 commit into
mainfrom
fix/claude-api-error
Nov 12, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/claude-api-error

Conversation

@devswha

@devswha devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner

Change

When the API refuses a request (a rate limit, an overloaded model), Claude Code writes the error into its transcript as an assistant message whose text is the error, marked isApiErrorMessage: true (with error and apiErrorStatus). Ovis drew it as an ordinary answer, so a turn that failed read as if Claude had answered "API Error: …" (agent chat audit, Claude row C20).

Not in this PR: the sidebar status of such a turn, which is herdr's for Claude Code.

Screenshots

After
390 after
1280 after

Before: the same turn rendered as an answer reading "API Error: Request rejected (429) …" (the audit's finding). After: scripts/claude-api-error-qa.ts: the fixture under an isolated HOME, a pane in an isolated herdr session reporting that Claude session, this branch's server and a browser at 1280 and 390. A live Claude run was not made: a cheap one cannot be made to fail without spending the owner's account into a rate limit.

Validation

  • Failing first: server/claude-api-error.test.ts "shows the API error Claude Code recorded as a failed request" fails on main, passes after; "keeps an answer that only quotes an error" passes on both.
  • HERDR_TEST_MODE=unit bun test ./server/claude-api-error.test.ts ./server/claude-incremental.test.ts: pass.
  • bun scripts/claude-api-error-qa.ts (heavy queue, browser): pass.
  • bun run check fast (heavy queue): pass.

@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Claude Code API errors, including rate limits, overloaded requests, and refused requests, now appear in Chat as failed requests instead of answers. The failure displays Claude Code’s original wording, making it clearer when a response did not complete successfully. Error text quoted in a normal assistant response continues to appear as regular text rather than being marked as a failed request.

The transcript parser now marks flagged Claude API-error text as failed rather than as a final answer. Tests and browser QA cover the parsing behavior and failed-request display.

Changes: Claude API Error Handling

Layer / File(s) Summary
Transcript API-error classification
server/claude-transcript.ts, server/fixtures/claude-api-error-2.1.321.jsonl, server/claude-api-error.test.ts
The parser marks assistant text as failed when the transcript entry has isApiErrorMessage: true. Tests check the recorded rate-limit error and verify that unflagged text is not marked as failed.
Chat verification and release note
scripts/claude-api-error-qa.ts, changelog.d/claude-api-error.md
The browser QA script checks for one failed-request row and no page errors at desktop and mobile sizes. The changelog describes the failed-request display behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: jpcarranza94

Merge Risk: Minimal · up to 21e98

Claude Code API errors now appear in Chat as failed requests instead of as answers. The change is narrowly scoped to flagged entries and is covered by tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: API errors that Claude Code records as an answer now show as a failed request. It is specific, single-sentence, and matches the changeset (transcript parsing, fixture,…
Description check Passed The description follows the template. It has a Change section that states the problem and resulting behavior, and a Validation section that lists the commands run and their results. The Change section…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: API errors that Claude Code records as an answer now show as a failed request. It is specific, single-sentence, and matches the changeset (transcript parsing, fixture, tests, changelog).

Full details: Description check

Explanation

The description follows the template. It has a Change section that states the problem and resulting behavior, and a Validation section that lists the commands run and their results. The Change section does not link an issue, but the template asks for a link only for features, and this PR is a fix. The description also includes before/after screenshots and QA notes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d505c75 and 21e9866.

Files selected for processing: 5

  • changelog.d/claude-api-error.md
  • scripts/claude-api-error-qa.ts
  • server/claude-api-error.test.ts
  • server/claude-transcript.ts
  • server/fixtures/claude-api-error-2.1.321.jsonl

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

@devswha
devswha merged commit 39a97dc into main Nov 12, 2026
21 checks passed
@devswha

devswha commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 21e98665375e as 39a97dceeb54 on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Two reviewers at this head: Claude (Opus) CLEAR, Codex Terra CLEAR.

When a Claude Code request fails (an invalid key, an overloaded API), Claude Code records the error text as an assistant entry flagged isApiErrorMessage; Chat showed it as the agent's answer. The reader (server/claude-transcript.ts) now marks that entry failed, so it shows as a failed request like the other agents' do. All three Claude readers go through the one function; no HTTP or WS change. The Opus reviewer put main's file back and saw the new test fail for the missing failed: true; 285 unit tests pass at this head.

Left, LOW (both): scripts/claude-api-error-qa.ts is not listed in scripts/ci-browser.sh, so CI never runs it; it also checks only that a failed-request row exists.

Reports: ~/.cache/ovis-tmp/reports/pr-3749-21e98665-*.report.md.

@devswha
devswha deleted the fix/claude-api-error branch November 12, 2026 13:25
devswha added a commit that referenced this pull request Nov 16, 2026
…ther than DONE, with the failure alert (#3949)

## Change

When the API refuses a request (a rate limit, a cooldown, an overloaded
model), Claude Code ends the
turn with an assistant entry marked `isApiErrorMessage: true`. #3749
shows that entry in Chat as a
failed request, but the sidebar still reads the turn as a green DONE and
sends a finish alert (#3749:
"Not in this PR: the sidebar status of such a turn"). This applies
#3733's Codex rule, which #687
set for OmO and GJC, to Claude Code: an error is a rest, not a finish.

- `server/claude-transcript.ts` `claudeTurnEnd` / `claudeLastTurnEnd`:
the last entry of the
session's own that tells how its turn stands (last 256 KB): `failed` for
an `isApiErrorMessage`
answer, `answered` for an answer, `running` for a prompt, a tool call or
a tool result. Subagent
(`isSidechain`), meta, compaction-summary and local-command entries tell
nothing.
- `server/core/status.ts`: as a Claude pane this server saw work comes
to rest, its transcript (the
one the subagent tracker found) is read at once. An API error makes the
rest a failed one:
`completions.observe(…, "failed")`, the waiting finish alert called off
by the status change, then
`push.onFailed`. herdr's own DONE or `unknown` for the pane reads as
idle until it works again
(`failedRests`, shared with Codex). An answer after it (a retry that got
through) ends the turn on
the `answered` path, which is a finish. An end written after the rest
was told is read at the
next snapshot. Only a turn this server saw run is read, and an answer
ends what it saw, so a pane
found at rest after a restart, or a turn that began while status events
were lost, tells no
failure. When the failed rest is held on the turn's background work
(`background_wait`), the
failure alert waits until that wait ends with no turn after it, since
`onFailed` skips a pane the
  alerts take for working.

Reproduce on main: a Claude Code pane whose account is rate limited (or
any 429/529); send a
prompt; the transcript ends with the `isApiErrorMessage` entry
(`server/fixtures/claude-api-error-2.1.321.jsonl`) and the sidebar shows
DONE with a finish alert.

Related: #3733 (Codex), #3749 (Claude chat part), #3760 (the Codex
follow-up about an end written
after herdr reports rest; the Claude path reads such a late end at the
next snapshot).

## Validation

- New `server/core/claude-status-hub.test.ts` (8): API error → idle and
one failure alert, never
DONE; a retry that answers after the failure → DONE; an error a retry
answered before the rest →
DONE; a normal turn → DONE with no failure alert; an error written after
the rest was told → read
at the next snapshot, then a later answer finishes; a failed turn held
on its subagent → failure
alert once the wait ends; a later turn's failure not seen run → nothing
told; a pane found at rest
after a restart → nothing told. The last three fail with their part of
the fix removed.
- `server/claude-api-error.test.ts`: `claudeTurnEnd` cases.
- Each file on its own with `HERDR_TEST_MODE=unit bun test`:
claude-status-hub, claude-api-error,
codex-status-hub, status, letta-status-hub, completion,
claude-subagents, push, conversation,
server/conventions, scripts/conventions, scripts/changelog-fold: all
pass.
- `bun run typecheck`: pass.
- Not run: `bun run check fast` (build step), the full unit suite to the
end, and the integration
suite (no isolated herdr/PTY host here). No contract test with a live
Claude Code was added.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <[email protected]>
Co-authored-by: devswha <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant