Skip to content

feat: quota tracking and load rotation across subscriptions - #7

Merged
eliahilse merged 2 commits into
mainfrom
feat/usage-tracking
Jul 30, 2026
Merged

feat: quota tracking and load rotation across subscriptions#7
eliahilse merged 2 commits into
mainfrom
feat/usage-tracking

Conversation

@eliahilse

Copy link
Copy Markdown
Owner

Never launch an engine that's out of quota, and spread load across the subs that still have headroom:

  • Cooldown tracking: every engine run records its outcome in ~/.local/state/kyora-review/usage.json. A run that hits a usage limit (detected from vendor error signatures on failed runs only — a finding about rate limiting can't false-positive) puts that engine on cooldown: vendor "try again in N hours/minutes" hints are parsed when present, otherwise cooldownMinutes (default 60). Cooled-down engines are skipped with a log line; --ignore-quota forces them; if the whole panel is cooling, the run no-ops CI-safe instead of burning attempts.
  • Load rotation: --max-engines <n> / maxEngines config runs only the n least-recently-used healthy engines per review — with a 6-engine panel and max-engines: 3, consecutive PRs rotate through different subscription triples.
  • kyora-review usage shows per-engine runs, last outcome, and remaining cooldown; doctor annotates cooldowns inline.
  • CI persistence: the action's cache now carries the state dir alongside ~/.codex, so cooldowns survive between workflow runs. Also fixes the action's auto-detection gap for the new engines: ZAI_API_KEY → glm, QWEN_API_KEY → qwen (and claude-binary install covers both); dropped the dead qwen-code install.
  • 7 new unit tests (26 total).

Stacked on #6 — merge that first and this collapses to the quota changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CQy3ZJ5MyUxo4qjZwA93Na

@eliahilse

Copy link
Copy Markdown
Owner Author

Extended with live usage probes — the selector now asks vendors for remaining quota before launching, falling back to cooldowns wherever the probe can't answer. Live-validated on this machine: claude reports 41% remaining (5h/7d windows, via its own login token from file or macOS Keychain against the OAuth usage API) and glm reports 99% (Z.ai's official monitor endpoint, same key as inference). kimi wired per its documented coding/v1/usages endpoint (validates when a key is added), qwen needs a pasted console cookie (Alibaba gates usage behind console auth — confirmed empirically that the inference key can't read it). codex/grok have no subscription-usage endpoint at all (even CodexBar doesn't poll ChatGPT limits) and stay on the cooldown fallback. Parsers are shape-tolerant with fixtures from the real payloads (34 tests).

eliahilse and others added 2 commits July 30, 2026 23:20
Engine runs record outcomes in local state; a run that hits a usage
limit puts the engine on cooldown (vendor retry-after hints parsed,
cooldownMinutes fallback) and it is skipped until expiry. maxEngines /
--max-engines runs the n least-recently-used healthy engines per
review, rotating load across subscriptions. New usage command; doctor
shows cooldowns; action caches the state dir across CI runs and now
auto-detects glm/qwen from ZAI_API_KEY/QWEN_API_KEY.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQy3ZJ5MyUxo4qjZwA93Na
Optional usageProbe per engine, consulted before selection; a probed
engine at 0% never launches, and probe failure of any kind falls back
to the reactive cooldowns. Claude reads its own login token (file or
macOS Keychain) against the OAuth usage API; glm hits Z.ai's monitor
endpoint with the inference key; kimi uses its documented coding usage
endpoint; qwen needs a pasted console session cookie since Alibaba
gates usage data behind console auth. Codex and grok have no vendor
endpoint for subscription limits and stay on cooldowns.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CQy3ZJ5MyUxo4qjZwA93Na
@eliahilse
eliahilse force-pushed the feat/usage-tracking branch from c3b21b0 to 0262d4a Compare July 30, 2026 21:23
@eliahilse
eliahilse merged commit abc8905 into main Jul 30, 2026
2 checks passed
@eliahilse
eliahilse deleted the feat/usage-tracking branch July 30, 2026 21:24
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