Repository navigation
coderouter: serve stored usage in account status - #13978
lawrencecchen wants to merge 1 commit into
Conversation
GET /api/coderouter/accounts decrypted a credential and called ChatGPT's usage endpoint for every active Codex account on every request, so status took 1.4-3.9 s. Readings are now stored on coderouter_accounts. A reading under 30 s old is served as is; an older one is served and refreshed after the response by one claiming instance; one over 10 min old, or a missing one, is read before answering. The refresh still sets cooldowns from limit_reached, which is what routing reads.
|
All contributors have signed the CLA ✍️ ✅ |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: manaflow-ai/cmux/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (5)
Included review availability: Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe change adds persistent account usage caching and refresh coordination. The usage service serves stored readings, refreshes missing or very old readings before responding, and defers refreshes for stale readings. ChangesAccount usage cache
Priority: ⚪ Not assessed Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant Caller
participant accountsWithUsage
participant deferAfterResponse
participant claimAccountUsageRefresh
participant readCodexUsage
participant CODEX_USAGE_URL
participant storeAccountUsage
Caller->>accountsWithUsage: Request account usage
accountsWithUsage->>deferAfterResponse: Schedule stale account refresh
deferAfterResponse->>claimAccountUsageRefresh: Claim eligible account IDs
deferAfterResponse->>readCodexUsage: Read claimed accounts
readCodexUsage->>CODEX_USAGE_URL: Fetch provider usage
readCodexUsage-->>deferAfterResponse: Return usage or error
deferAfterResponse->>storeAccountUsage: Persist reading or error
Suggested reviewers: Merge Risk: ⚪ Minimal · up to The accounts endpoint now serves stored usage readings, refreshes stale ones in the background, and still uses cooldowns for routing. No blocking issues were found, and the new migration only adds nullable columns in the project's standard format. As the author notes, apply and rehearse the migration on the database before deploying this code. 🚥 Pre-merge checks | ✅ 24 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (24 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 23.53% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 17 functions across 4 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Status: its migration now ships on its own in #14073, because — Ibex g1 🌿 |
|
Review status (Leo's maintainer sweep). No push from me. CI is green and the branch merges cleanly with main. It also merges cleanly with #13977, which touches the same Review:
Still blocking, and it needs a human: the description says the |
…14073) Four nullable columns on `coderouter_accounts` for #13978's stored quota readings. Split out so production can migrate before any code selects them: the Vercel build does not migrate, and the production target of `cloud-vm-migrate.yml` applies migrations from `main`, so shipping the file and its reader together leaves a window where status reads fail on missing columns. Nothing reads these columns until #13978 merges. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Merge order status: the migration PR #14073 merged at 02:06Z. — Ophelia g1 🍄 |
|
Migration rollout status:
#13978 must not merge until production has run, because its — Ibex g1 🌿 |
Measured before:
GET /api/coderouter/accountstook 1.4-3.9 s, of whichprovider(one KMS decrypt plus onechatgpt.com/backend-api/wham/usageread per active Codex account, 80 for cmux) was 1.2-2.1 s.Readings are now stored on
coderouter_accounts(usage,usage_error,usage_fetched_at,usage_refresh_claimed_at):after()); a claim column means one instance refreshes each account, not every concurrent viewer;crnever shows a long-stale quota.usageAgeSecondsnow reports the oldest reading served andcacheMaxAgeSecondsis 30; the CLI already prints both ("Usage cached Ns ago"). Routing does not read these numbers: it usescooldown_until, set by the proxy on 429 and still set by a refresh that seeslimit_reached.Trade-off:
crcan show quota up to 10 min old (labelled with its age);cr --watchstays within about 60 s.Schema-dependent: the migration
20260923120000_coderouter_account_usage_cache(four nullableADD COLUMNs, no backfill, no lock beyond the brief ALTER) must be rehearsed on the PlanetScalestagingbranch and applied tomainbefore this merges, because merging deploys code that selects the new columns.Third of three coderouter latency PRs (#13976, #13977).
Tests: new
tests/coderouter-account-usage.test.ts(fresh, stale plus claim, missing and too-old, stored error and skipped accounts, failed store);bun test tests/coderouter-*.test.ts(428 pass);bun run typecheck; eslint;verify-migration-preflight.sh --schema-only(drizzle-kit check passes). The migration SQL was not run against a real Postgres.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Caches Codex quota reads for coderouter status so
GET /api/coderouter/accountsno longer waits on one KMS decrypt plus one ChatGPT usage call per active Codex account (up to ~80 for cmux); status dropped from 1.4–3.9s to well under a second.Readings are now stored on
coderouter_accountsand served by age:crnever shows a long-stale quota.Routing still uses
cooldown_until, which refreshes keep setting onlimit_reached; the cache only feeds status display.usageAgeSecondsreports the oldest reading served andcacheMaxAgeSecondsis 30, socrcan show quota up to 10min old butcr --watchstays within about 60s.Migration: the
20260923120000_coderouter_account_usage_cachemigration (four nullableADD COLUMNs, no backfill) must be applied to PlanetScalemainbefore this merges, since the merged code selects the new columns.Written for commit 0d4d682. Summary will update on new commits.
Summary by CodeRabbit