Skip to content

Probe hidden Fable quota for Claude routing#44

Merged
lawrencecchen merged 2 commits into
mainfrom
feat-fable-quota-probe
Jul 3, 2026
Merged

Probe hidden Fable quota for Claude routing#44
lawrencecchen merged 2 commits into
mainfrom
feat-fable-quota-probe

Conversation

@lawrencecchen

@lawrencecchen lawrencecchen commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

  • probes Claude Messages headers for the hidden Fable/OAuth-app weekly quota when the normal Claude usage endpoint omits it
  • shows that bucket as Fable wk in sr status
  • routes claude-fable-5 with the hidden Fable weekly pool plus normal Claude session/weekly pools, without cooking non-Fable Claude models on the Fable-only bucket

Tests

  • go test ./...

Root cause

Anthropic can reject Fable with anthropic-ratelimit-unified-7d_oi-status: rejected while /api/oauth/usage still shows ordinary Claude weekly quota. The scheduler only saw the ordinary usage endpoint, so it kept selecting accounts that were exhausted for Fable.


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Probe Anthropic Messages headers to detect the hidden Fable OAuth‑app weekly quota and use it for routing. Show it as “Fable wk” in sr, and score/route claude-fable-5 against this bucket without affecting other Claude models.

  • New Features

    • Add a lightweight /v1/messages probe to read header quotas and backfill the oauth-apps-weekly window when /api/oauth/usage omits it.
    • Display “Fable wk” in sr and label the window with Feature claude-fable-5.
    • Model-aware scoring: if a Fable window exists, compute headroom specifically for claude-fable-5 while keeping other Claude models independent.
  • Bug Fixes

    • Stop selecting Fable-exhausted accounts when the usage endpoint hides the OAuth-app weekly bucket; treat 7d_oi rejected as 100% used.
    • Prevent Fable-only exhaustion from “cooking” non-Fable Claude models.

Written for commit 2dbad97. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@lawrencecchen, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df2f44c7-0da2-4350-a9c4-7e08c6bc826f

📥 Commits

Reviewing files that changed from the base of the PR and between b945d76 and 2dbad97.

📒 Files selected for processing (6)
  • cmd/subrouter/sr.go
  • cmd/subrouter/sr_test.go
  • internal/agents/claude/store.go
  • internal/proxy/claude_ratelimit_routing_test.go
  • internal/proxy/proxy.go
  • internal/proxy/usage_windows_cache_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-fable-quota-probe

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.

@lawrencecchen lawrencecchen merged commit 523959d into main Jul 3, 2026
5 checks passed
@lawrencecchen lawrencecchen deleted the feat-fable-quota-probe branch July 3, 2026 04:36

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dbad97eed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +733 to +734
body := bytes.NewBufferString(`{"model":"` + FableModel + `","max_tokens":1,"messages":[{"role":"user","content":"."}]}`)
req, err := http.NewRequestWithContext(ctx, http.MethodPost, messagesURL, body)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid sending real Fable messages for usage probes

When the OAuth usage endpoint omits the Fable bucket, every fresh status/score fetch falls through to this path and issues a real POST /v1/messages with max_tokens:1. For healthy accounts that request can generate a completion, incur cost, and consume the same Fable quota the router is only trying to observe; with the 2-minute usage-window TTL, dashboard/status polling or reloads can keep spending quota without user traffic. Consider making this passive/opt-in or using a non-generating signal before probing with a billable message.

Useful? React with 👍 / 👎.

Comment thread internal/proxy/proxy.go
ResetAfterSeconds: window.ResetAfterSeconds,
Feature: window.Feature,
})
if provider == accounts.ProviderClaude && hasFableWindow && window.Feature == "" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Copy only account-wide windows into the Fable score

When a Claude response includes a Fable window and also opus-weekly or sonnet-weekly, those windows still have an empty Feature, so this condition copies them into the claude-fable-5 model pool. In that scenario an exhausted Opus/Sonnet weekly bucket makes ForModel("claude-fable-5") score the account as unusable even if the Fable and shared 5h/7d buckets are healthy. Restrict the copy to truly shared windows, or tag Opus/Sonnet with their own features before building model scores.

Useful? React with 👍 / 👎.

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