fix(claude): name the usage limit on retried turns too #10546
main fromrefs/pull/10546/head·opened View on GitHubCloses #10544.
What Changed#
A Claude turn retried while the account is still limited now fails with the same sentence as the first limited turn, "Claude usage limit reached. Send the message again once the limit resets.", instead of falling back to "Claude gave up after repeated API errors."
The CLI sends rate_limit_event with status: "rejected" only when the limit state changes, so #10321's latch saw it on the first turn and nothing on the retries. Those turns still carry an assistant message with error: "rate_limit" (the same channel the sign-out latch already reads), so the adapter now records that too and the result names the limit. A boolean on the turn state rather than a sentinel in the rejected-window set, which recovery events add to and delete from by window id.
Why#
Three consecutive turns on one thread: the first said the limit, the next two said the provider gave up. Users read the second sentence as an outage and retry harder.
UI Changes#
None beyond the sentence: the failed turn's banner and row are the ones #10321 introduced. Before, from the report in #10544:
Verification#
vp test run apps/server/src/provider/Layers/ClaudeAdapter.test.ts— 120 tests pass, three new: a turn with only the assistantrate_limiterror names the limit in both the runtime error and the turn's error message; two consecutive turns in one session (first with therate_limit_event, second with only the assistant error) both name it; an assistantserver_errorstill yields the generic message. Reverting the condition fails exactly the two new positive cases.- Server typecheck clean on the touched file; lint and format clean.
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes (message-only change; before shown, after is the sentence #10321 already renders)
- I included a video for animation/interaction changes (nothing moves)
Built with Claude Fable 5.1 in Claude Code, with an Opus subagent.
🤖 Generated with Claude Code
Note
Fix ClaudeAdapter to name usage limit on retried turns with assistant-only rate-limit errors#
Adds rateLimitedAssistantMessage to the per-turn state in ClaudeAdapter.ts, set when an assistant SDK message reports a rate_limit error. The adapter now includes this flag alongside rejectedRateLimitTypes when building the failure hint for result processing, so a failed turn is classified as a usage-limit error even when no rate_limit_event was emitted (e.g. on a retry).
- Other assistant error values (e.g.
server_error) keep the generic repeated-API-error message. - Adds test fixtures and cases in ClaudeAdapter.test.ts covering assistant-only rate limits, repeated usage limits across turns, and non-limit assistant errors.
Summary by CodeRabbit#
- Bug Fixes
- Improved usage-limit error reporting for Claude interactions.
- Repeated rate-limit failures now consistently display the usage-limit message instead of a generic API error.
- Non-rate-limit errors continue to show the appropriate generic failure message.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
Approvability#
Verdict: Approved at
4a5f39dMacroscope's review found this PR approvable — This narrowly scoped Claude adapter fix only improves the error message for retried usage-limited turns, preserving existing handling for authentication and other API errors. It includes targeted regression coverage and introduces no schema, deployment, security, billing, or configuration changes.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Team
Run ID:
5e6aa7d5-49c3-432a-bcf5-469bc3d20a06📥 Commits
Reviewing files that changed from the base of the PR and between 1d1bf50405ccca8fdb8b57879d9def379e27a550 and 4a5f39d8c05374bd463b83a010e6b889df4a9d8b.
📒 Files selected for processing (2)
apps/server/src/provider/Layers/ClaudeAdapter.test.tsapps/server/src/provider/Layers/ClaudeAdapter.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough#
The Claude adapter now records
rate_limitassistant errors per turn. Failed turns use the usage-limit message when this signal is present, including retries without a newrate_limit_event. Tests cover limited and non-limit failures.Changes#
Claude usage-limit reporting
Layer / File(s) Summary Track assistant rate-limit state
apps/server/src/provider/Layers/ClaudeAdapter.tsClaudeTurnStaterecords assistant-reportedrate_limiterrors. Synthetic and real turns initialize the flag. Failed-turn reporting checks this flag alongside rejected rate-limit events.Validate usage-limit messages
apps/server/src/provider/Layers/ClaudeAdapter.test.tsTests cover initial limited turns, repeated limited turns without a new rate_limit_event, and generic reporting forserver_error.Estimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: ⚪ Minimal · up to
4a5f3Claude turns that report a rate-limit assistant error now consistently show the usage-limit guidance, while non-limit API failures retain the generic error message. No current merge-blocking risk remains.
Suggested reviewers:
juliusmarminge,t3dotgg🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Linked Issues check ✅ Passed The changes satisfy issue #10544by detecting assistant-only rate-limit errors on retried turns, preserving the usage-limit message, and retaining the generic message for non-limit errors. Tests cover…Out of Scope Changes check ✅ Passed The changes are limited to Claude adapter error classification and focused tests. No unrelated product or UI changes are included. Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2… Description check ✅ Passed The description clearly explains what changed, why it changed, verification performed, and UI impact. It includes the required sections and completes the checklist. The unchecked video item is appropr… Title check ✅ Passed The title is concise, specific, and accurately describes the main change: usage-limit errors are named on retried Claude turns. ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
Comment `@coderabbitai help` to get the list of available commands.juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes