Skip to content

fix: recognize 'hit your limit' as retryable error pattern#3398

Open
mauriciozaffari wants to merge 6 commits intocode-yeongyu:devfrom
mauriciozaffari:fix/hit-limit-error-pattern
Open

fix: recognize 'hit your limit' as retryable error pattern#3398
mauriciozaffari wants to merge 6 commits intocode-yeongyu:devfrom
mauriciozaffari:fix/hit-limit-error-pattern

Conversation

@mauriciozaffari
Copy link
Copy Markdown

@mauriciozaffari mauriciozaffari commented Apr 13, 2026

Summary

Anthropic's rate limit error "You've hit your limit · resets 5pm (UTC)" is not recognized as retryable by either the model-fallback or runtime-fallback error classifiers, preventing automatic fallback to alternative providers.

Changes

  • Add "hit your limit" and "hit the limit" to RETRYABLE_MESSAGE_PATTERNS in src/shared/model-error-classifier.ts (used by model-fallback)
  • Add /hit.{0,10}(?:your|the)?.{0,5}limit/i regex to RETRYABLE_ERROR_PATTERNS in src/hooks/runtime-fallback/constants.ts (used by runtime-fallback)

Context

When Anthropic returns this error, the log shows:

[background-agent] Session error - no retry: {
  "errorName":"APIError",
  "errorMessage":"Claude Code returned an error result: You've hit your limit · resets 5pm (UTC)",
  "hasFallbackChain":true,
  "canRetry":false
}

The fallback chain exists (hasFallbackChain: true) but canRetry is false because neither classifier matches the "hit your limit" phrasing. The existing patterns cover "over limit", "rate limit", and "rate_limit" but miss this specific Anthropic wording.

Testing

  • bun run typecheck passes
  • bun run build passes

Summary by cubic

Recognize Anthropic “You’ve hit your limit”, Gemini “spending cap”, and generic “usage limit” messages so cross‑provider fallback triggers reliably. Decouples error handling so quota/billing/usage STOP errors trigger fallback, while same‑provider retries stay unchanged.

  • Bug Fixes
    • Add “hit your/the limit” to RETRYABLE_MESSAGE_PATTERNS; add runtime regex for hit.*limit, usage.*limit, and spending.*cap.
    • Add isStopModelError; update shouldRetryError to return true for retryable and STOP errors; classify “spending cap” and “usage limit has been reached” as STOP.
    • Expand tests for new patterns, STOP vs retryable behavior, and fallback selection.

Written for commit 00cb572. Summary will update on new commits.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

All contributors have signed the CLA. Thank you! ✅
Posted by the CLA Assistant Lite bot.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Safe addition of specific Anthropic rate limit error patterns to retryable classifiers, enabling intended fallback behavior without risk of regression.

@mauriciozaffari
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Apr 13, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/shared/model-error-classifier.ts">

<violation number="1" location="src/shared/model-error-classifier.ts:53">
P2: `spending cap` is a quota/billing exhaustion signal, so it should not be classified as retryable.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

…er fallback

STOP errors (quota/billing/usage exhaustion) now trigger cross-provider
fallback via shouldRetryError(), since a different provider may still work.
Only NON_RETRYABLE errors (user aborts, validation, syntax) block fallback.

isRetryableModelError() remains unchanged for same-provider retry logic
in token-limit-detection.

Add isStopModelError() to identify provider exhaustion errors.
Add 'usage limit has been reached' to STOP_MESSAGE_PATTERNS.
Remove 'usage limit' from RETRYABLE_MESSAGE_PATTERNS (belongs in STOP).
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 3 files (changes from recent commits).

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.

spending cap is a quota/billing exhaustion signal indicating the
provider cannot serve further requests. It belongs in STOP patterns
(triggers cross-provider fallback) not RETRYABLE patterns (same-provider
retry).
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 2 files (changes from recent commits).

Auto-approved: Recognizes Anthropic and Gemini-specific quota errors as retryable for cross-provider fallback. The logic correctly separates transient retries from provider-exhaustion fallbacks.

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