fix(shared): a model-scoped Claude limit no longer blocks other Claude models#32016

open1
main
GitHub fork: fix/claude-model-scoped-limit
opened4d agobyNna-zar
View on GitHubTwo-way sync enabledPR last imported 10h ago

Problem

When Claude's model-scoped weekly bucket is used up (Weekly · Fable, window id seven_day_fable), T3 Code treats every Claude model as out of usage. New-thread selection falls back to the other provider, and text generation skips Claude, even though models such as Opus 5.5 still work. Reproduction details: #32015.

The cause is exhaustedUsageWindow in packages/shared/src/usageLimits.ts. It has model-aware cases for cursor, antigravity and opencode, but claudeAgent falls through to default: return exhausted[0].

Change

Add a claudeAgent case. A seven_day_<model> window, which claudeUsageResponseToLimits builds from the CLI's model_scoped entries, now blocks only a selected model whose slug contains that model name. For example, seven_day_fable blocks claude-fable-5-1 but not claude-opus-5-5. Session (five_hour), overall Weekly (seven_day) and Monthly spend still block every Claude model, as before.

Scope and approval

Fixes #32015. This is a small, focused fix for an obvious bug: one switch case beside the existing per-driver cases, plus table rows in the existing test. It changes no contracts or UI.

Verification

  • Added four claudeAgent rows to the existing "matches %s pools %s to %s" table in packages/shared/src/usageLimits.test.ts:
    • Fable bucket at 100% with Opus selected: Opus stays selected.
    • Fable bucket at 100% with Fable selected: falls back.
    • Overall seven_day at 100% with Opus selected: falls back.
    • five_hour at 100% with Opus selected: falls back.
  • vp test run packages/shared/src/usageLimits.test.ts: 66 passed. With the fix reverted, the Fable-bucket/Opus row fails as expected (1 failed, 65 passed).
  • vp check on both files and vp run typecheck in packages/shared both pass.
  • Not checked: the running app against a live account whose Fable limit is used up.

Written with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

Checks

24 successful · 9 skipped
All checks passed
b41ef48

Added 1 commit

  • fix(shared): a model-scoped Claude limit no longer blocks other Claude modelsb41ef48
Synced from GitHub

Approvability

Verdict: Approved at b41ef48

Macroscope's review found this PR approvable — Claude model-specific weekly limits now affect only the matching model, preventing unnecessary fallback for other Claude models. Global limits and existing provider eligibility safeguards remain unchanged.

You can add or adjust custom eligibility rules. Learn more.

Synced from GitHub

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Claude Agent fallback selection now filters model-scoped weekly usage windows using the specified model. Tests cover Fable and Opus model cases.

Changes: Claude usage fallback

Layer / File(s)Summary
Filter exhausted windows by model
packages/shared/src/usageLimits.ts, packages/shared/src/usageLimits.test.ts
exhaustedUsageWindow excludes model-scoped weekly windows when their scope does not match the specified Claude model. Tests cover Fable and Opus models, plus exhausted session and weekly windows.

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

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

Suggested labels: bugfix

Suggested reviewers: juliusmarminge

Merge Risk: External image Minimal · up to b41ef

Model-specific limits are filtered for the selected Claude model. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check nameStatusExplanation
Title checkPassedThe title clearly describes the fix for model-scoped Claude limits.
Description checkPassedThe description covers the problem, change, scope, approval rationale, verification results, and unchecked live scenario. It identifies the model and harness.
Linked Issues checkPassed[#32015] exhaustedUsageWindow matches model-scoped Claude weekly windows against the selected model. Other exhausted windows still apply to all models. The fallback tests cover Fable and Opus, overa…
Out of Scope Changes checkPassed[#32015] The shared limit check and fallback tests directly support the Claude model-scoped usage fix. The summary identifies no unrelated changes.
Full details: Linked Issues check

Explanation

[#32015] exhaustedUsageWindow matches model-scoped Claude weekly windows against the selected model. Other exhausted windows still apply to all models. The fallback tests cover Fable and Opus, overall weekly usage, and session usage. The shared function also addresses the reported server selection path.

Finishing Touches

Generate unit tests (beta)

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

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

External image Recent review info

External image Run configuration

External image Commits

Reviewing files that changed from the base of the PR and between 6577c6b6185167c0e502fa01f9e8e8f2dee6ff25 and b41ef487658d2929a7753982e450033d32bc7e50.

External image Files selected for processing: 2

  • packages/shared/src/usageLimits.test.ts
  • packages/shared/src/usageLimits.ts

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

Synced from GitHub

Note

Written by Claude Opus 5.5 in Claude Code, on behalf of saviocmc.

This is the same fix as #28676, opened on Nov 1: the same claudeAgent case in exhaustedUsageWindow, with only a code comment added here. I'm not the author of either PR. I hit this bug and tested the fix.

Both PRs list a live check against an account with a spent Fable limit as not done. I ran that check on #28676 with Weekly · Fable at 0% left and the account-wide weekly at 42% left. With Fable as the default and Opus as the fallback, a new thread started on Fable before the change and on Opus 5.5 after it, with the fallback notice. Since the logic is identical, the same result applies here. Details and screenshots: https://github.com/pingdotgg/t3code/pull/28676#issuecomment-6629281230