Skip to content

Show Claude Code's API retries as a status row while it retries - #960

Open
zcy22606 wants to merge 1 commit into
hardbeat920:mainfrom
zcy22606:feat/claude-api-retry-status
Open

zcy22606 wants to merge 1 commit into
hardbeat920:mainfrom
zcy22606:feat/claude-api-retry-status

Conversation

@zcy22606

@zcy22606 zcy22606 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #852 (one of the ways a long turn looks stuck).

What changed

  • New pure apiRetryStatusText in claudeProtocol.ts maps Claude Code's system/api_retry line to a short status: Connection error · retrying (7/10)…, API overloaded · …, Rate limited · …, No response from the API · … or API error 500 · ….
  • The Claude adapter shows it as a keyed status row (claude-api-retry), so each retry updates the same row instead of adding new ones, and removes the row as soon as the request produces output, the turn ends, the session stops, or the process exits. It uses the existing keyed-status support in apply.ts, where empty text removes the row.

Why

When an API request fails, Claude Code retries it on its own (up to max_retries, with backoff) and reports every attempt on stdout as {"type":"system","subtype":"api_retry","attempt":7,"max_retries":10,"error_status":null,…}. The adapter ignored these lines, so a dropped connection or an overloaded API showed nothing but the "working" timer for minutes, which looks the same as a hung turn. That is part of what #852 describes ("working vs stuck is impossible to tell"). The Claude Code terminal shows these retries; this shows them in the session too.

UI

One system row in the turn while retries are happening, for example Connection error · retrying (2/10)…. It updates in place and disappears once the reply starts streaming. Nothing changes when there are no retries.

Validation

  • New tests: apiRetryStatusText cases in claudeProtocol.test.ts, and a claudeLive.test.ts case where two retries are followed by output. It checks that the row is shown, updated, and then cleared exactly once. All three fail on main.
  • npm run check:web: vitest (5287 passed, 13 skipped) and tsc --noEmit. No Rust changes.

Checklist

  • I ran npm run check (check:web; no Rust files changed)
  • This PR is small and focused
  • I did not mix unrelated changes

Summary by CodeRabbit

  • New Features
    • Claude API retries now display progress updates, including the attempt count and a status such as rate limited, overloaded, or connection error.
    • Retry status clears when the assistant resumes responding or the session ends.

Claude Code retries a failed API request itself (dropped connection,
rate limit, overload) and prints system/api_retry for each attempt. The
adapter dropped those lines, so a network outage looked like a turn that
froze on "working" for minutes.

Show one keyed status row naming the cause and the attempt, updated in
place, and remove it once the request produces output, the turn ends,
the session stops, or the process exits.
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f0f4590f-3947-4198-aa0d-f9315aa7a7aa
📥 Commits

Reviewing files that changed from the base of the PR and between 226ec5b and 3556c27.

📒 Files selected for processing (4)
  • src/integrations/harness/providers/claude/claude.ts
  • src/integrations/harness/providers/claude/claudeLive.test.ts
  • src/integrations/harness/providers/claude/claudeProtocol.test.ts
  • src/integrations/harness/providers/claude/claudeProtocol.ts

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

📝 Walkthrough

The Claude provider now formats API retry messages and emits keyed retry status events during live sessions. It clears active retry status when other output arrives or when the turn or session ends.

Changes: Claude API retry status

Layer / File(s) Summary
Format retry status text
src/integrations/harness/providers/claude/claudeProtocol.ts, src/integrations/harness/providers/claude/claudeProtocol.test.ts
apiRetryStatusText formats retry messages using the retry reason, HTTP status, and attempt count. Tests cover supported reasons and messages that do not produce status text.
Emit and clear live retry status
src/integrations/harness/providers/claude/claude.ts, src/integrations/harness/providers/claude/claudeLive.test.ts
The live session emits retry text under a keyed status event and clears it when other output arrives or the session or turn ends. The live test checks two retry updates and the final empty status.

Priority: ⬇️ Low

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

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant ClaudeStream
  participant handleLine
  participant apiRetryStatusText
  participant clearApiRetry
  ClaudeStream->>handleLine: api_retry message
  handleLine->>apiRetryStatusText: format retry status
  apiRetryStatusText-->>handleLine: retry text
  handleLine-->>ClaudeStream: keyed status event
  ClaudeStream->>handleLine: assistant reply
  handleLine->>clearApiRetry: clear active retry status
  clearApiRetry-->>ClaudeStream: empty keyed status event
Loading

Suggested reviewers: hardbeat920

Merge Risk: ⚪ Minimal · up to 3556c

Claude Code API retries now appear as a status row that updates in place and clears when output arrives or the turn ends. No merge-blocking risk was identified.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: showing Claude Code API retries as a status row during retries.
Description check Passed The description includes the required What changed, Why, UI, and Checklist sections. It also documents validation results and confirms that the PR is focused.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • 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

Comment @coderabbitai help to get the list of available commands.

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