Skip to content

feat(routing): preserve account headroom with quota-aware Claude routing - #1

Merged
brycedbjork merged 4 commits into
northbrookfrom
feat/quota-aware-routing
Oct 26, 2026
Merged

brycedbjork merged 4 commits into
northbrookfrom
feat/quota-aware-routing

Conversation

@brycedbjork

@brycedbjork brycedbjork commented Oct 26, 2026 •

Copy link
Copy Markdown

Claude account selection currently follows static priorities, so it cannot spend allowance according to reset timing or preserve capacity for use outside the proxy. This adds routing.strategy: quota-aware for Claude OAuth accounts and configurable per-account reserves matched by email.

New bindings use the highest spendable-quota-per-second score across available accounts, constrained by each account's tightest applicable quota window. Reserves override session affinity, pinned selection, retries, and built-in plugin scheduler delegates. Protected accounts with missing or stale measurements are excluded; other providers keep existing priority-based round-robin behavior.

Normal response headers update quota observations. Background usage probes cover idle accounts, respect rate-limit backoff, and reject stale results from replaced credentials. The policy supports configuration reloads and rejects invalid reserve settings. See NORTHBROOK.md for configuration, scoring, freshness, and accounting limitations.

Validation:

  • Full go test ./... passed.
  • Focused race-detector tests passed.
  • Server build passed with CGO enabled using the matching installed Xcode SDK.
  • Focused tests cover reset-aware ranking across priority tiers, five-hour/weekly/model reserve thresholds, stale quota, explicit and inferred affinity, unchanged Codex routing, configuration reload validation, and probe snapshot races.

Live verification: installed the fork locally with a 20% Gmail Claude reserve, populated quota observations for all three Claude accounts, and verified real Codex HTTP, Codex WebSocket, and Claude responses.

Also synchronized an existing upstream cancellation test after Linux CI exposed its immediate-assertion race; no production cancellation behavior changed.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

Adds quota-aware routing for Claude OAuth accounts. The change adds reserve and freshness settings, account scoring, quota snapshots, and background refresh. It also adds configuration validation, documentation, tests, and a Northbrook GitHub Actions test-and-build workflow.

Changes: Quota-Aware Routing

Layer / File(s) Summary
Quota configuration and validation
internal/config/config_types.go, internal/config/quota_routing.go, internal/config/parse.go, internal/config/config_load.go, sdk/cliproxy/builder.go, internal/config/quota_routing_test.go, config.example.yaml
Adds quota-aware policy and reserve settings, duration defaults, and validation for strategy, Home dispatch, durations, and reserves. Config loading and building return validation errors. Tests cover validation and YAML round-tripping.
Quota-aware account selection
sdk/cliproxy/auth/selector_quota.go, sdk/cliproxy/auth/selector.go, sdk/cliproxy/auth/conductor_selection.go, sdk/cliproxy/auth/selector_quota_test.go, NORTHBROOK.md
Scores eligible Claude OAuth accounts using applicable quota windows and applies reserve checks. Integrates eligibility with affinity, fallback, and scheduler paths. Tests cover scoring, reserves, priority behavior, and affinity. The documentation describes routing behavior and operational limits.
Runtime wiring and quota refresh
sdk/cliproxy/service_config.go, sdk/cliproxy/service_lifecycle.go, sdk/cliproxy/service_quota.go, sdk/cliproxy/service_quota_test.go
Stores quota policy in runtime state and constructs the quota-aware selector. Adds a background worker that fetches Claude OAuth usage data, parses quota headers, and records valid snapshots. Tests cover parsing and configuration reloads.

Northbrook Test and Build Workflow

Layer / File(s) Summary
Northbrook test and build checks
.github/workflows/northbrook.yml
Adds push and manual workflow triggers. The workflow checks out the repository, sets up Go, runs go test ./..., and builds ./cmd/server.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Service
  participant AnthropicOAuthUsageEndpoint
  participant claudeUsageHeaders
  participant Manager
  Service->>AnthropicOAuthUsageEndpoint: request Claude OAuth usage data
  AnthropicOAuthUsageEndpoint-->>Service: return usage response
  Service->>claudeUsageHeaders: parse usage response
  claudeUsageHeaders-->>Service: return quota headers
  Service->>Manager: ObserveQuotaHeaders(snapshot, headers, observedAt)
Loading

Suggested reviewers: luispater

Merge Risk: Moderate · up to c3d87

Mixed-provider requests can select accounts contrary to their configured priorities, and an unresponsive usage probe can prevent protected accounts from receiving fresh quota data. Fix both before merging quota-aware routing.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

pipkin-bot[bot]

This comment was marked as outdated.

@pipkin-bot pipkin-bot 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 new issues

Adds quota-aware routing for Claude OAuth accounts, ranking accounts by spendable allowance and reset timing while enforcing per-email reserves ahead of affinity, pinned selection, retries, and built-in scheduler delegates. Introduces background usage probes with rate-limit backoff and stale-credential safeguards, validated reloadable configuration, documentation, CI, and focused tests, while retaining priority-based routing for other providers and synchronizing an existing cancellation test.

Still open from earlier reviews (2)
Review details
  • Reviewed fa786b0 with 5 passes: rules, bugs, history, comments, spec.

Reply with @pipkin-bot to ask about a finding, or comment @pipkin-bot review to run the review again.

@brycedbjork
brycedbjork merged commit a21744a into northbrook Oct 26, 2026
5 checks passed
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