Skip to content

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

Closed
mauriciozaffari wants to merge 7 commits into
code-yeongyu:devfrom
mauriciozaffari:fix/hit-limit-error-pattern
Closed

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

Conversation

@mauriciozaffari

@mauriciozaffari mauriciozaffari commented Apr 13, 2026

Copy link
Copy Markdown

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 kicks in reliably. Split retry logic 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; move “spending cap” and “usage limit has been reached” to STOP patterns.
    • Expand tests for new patterns, STOP vs retryable behavior (isStopModelError, isRetryableModelError), and fallback provider selection.

Written for commit 7175c57. Summary will update on new commits.

@github-actions

github-actions Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

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

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

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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.

Comment thread src/shared/model-error-classifier.ts Outdated
…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).

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

Copy link
Copy Markdown

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).

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

Copy link
Copy Markdown

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.

github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 19, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 19, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 19, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 19, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 19, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 20, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 21, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 22, 2026
github-actions Bot added a commit to Vacbo/oh-my-opencode that referenced this pull request Apr 22, 2026
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