Repository navigation
Description
Summary
When Codex account quotas are unprimed / unknown, pool auto-switch can rotate the active account to __main__ even though:
- the previously active pool account is still the intended one, and
__main__may already be weekly-exhausted.
This breaks the expected sequential model (burn current account → switch at threshold% used → next account) and can produce cooling down / 429 storms and surprising account switches.
Environment
@bitkyc08/opencodex2.7.40codexAccountMode: poolautoSwitchThreshold: 80(default)- multiple ChatGPT Pro accounts in the pool + main login
- Linux, proxy on
127.0.0.1:10100 - Clients: Hermes Agent via OpenAI-compatible
POST /v1/chat/completions(and general Codex traffic)
Observed logs
[codex-routing] quota unknown for active "chatgpt-XXXXXXXX"; rotating to "__main__" (all candidates unknown, threshold=80)
[codex-routing] quota unknown for active "__main__" and no eligible rotation target; staying put
After this, traffic can stick on MAIN (or thrash) instead of staying on the healthy pool account until real weekly usage hits the threshold.
Root cause (code)
File: src/codex/routing.ts
- Unknown usage is scored as 100 (
CODEX_UNKNOWN_USAGE_SCORE = 100insrc/codex/quota.ts). - In
applyQuotaAutoSwitch, unknown active usage is therefore treated as ≥ threshold (80) even when the account is not actually near weekly limit. pickLowerUsageAccountcannot prefer another unknown account (100 < 100never wins).- Deadlock guard then calls
pickNextUnknownAccount(). getEligiblePoolAccounts()unshifts__main__first, soeligible[0]for unknown rotation is almost always MAIN.
Relevant logic (2.7.40):
// applyQuotaAutoSwitch
const activeUsage = computeCodexUsageScore(quota, ...);
if (activeUsage < threshold) return active; // unknown=100 → false when threshold=80
// ... pickLowerUsageAccount fails among unknowns ...
if (isUnknownUsage(activeUsage)) {
const next = pickNextUnknownAccount(config, active, now);
// next is often __main__ because getEligiblePoolAccounts unshifts MAIN
}// getEligiblePoolAccounts
ids.unshift(MAIN_CODEX_ACCOUNT_ID);// pickNextUnknownAccount
return eligible.length > 0 ? eligible[0]! : null; // MAIN if presentExpected behavior
For pool + threshold auto-switch:
- Stay on the current active account while usage is known and < threshold.
- If quota is unknown, do not treat it as 100% used and do not rotate just because it is unknown. Prefer priming quotas and staying put.
- If unknown-rotation remains as a last resort, do not prefer MAIN by list order. Prefer non-main pool accounts first; only consider MAIN if no other eligible account exists.
- Weekly-exhausted MAIN should not become the catch-all target when pool accounts are healthy but unprimed.
Suggested fix
Minimal options (any one is a large improvement):
A (preferred): If isUnknownUsage(activeUsage), stay on active and rely on existing primeCodexPoolQuotas pre-route priming. Do not rotate on unknown alone.
B: Score unknown as “not over threshold” (e.g. treat unknown as 0 for threshold comparison, while still marking unknown separately).
C: If keeping unknown-rotation, change pickNextUnknownAccount to prefer id !== MAIN_CODEX_ACCOUNT_ID before falling back to MAIN; and/or stop unshifting MAIN to the front for this path.
D: Never auto-select MAIN when its last known weekly usage is ≥ threshold / exhausted (even if currently unknown in-memory).
Local workaround we applied
We patched applyQuotaAutoSwitch to stay put when active quota is unknown, and made pickNextUnknownAccount prefer non-main (defense in depth). After restart + ocx account refresh openai, sequential threshold behavior is usable again.
Happy to open a PR if you want this upstreamed.
Impact
- Multi-account Pro pools unexpectedly jump to MAIN
- Users see rate-limit / “cooling down” / provider failures despite other pool accounts having low weekly %
- Breaks “one account until 80%, then next” operational model
Activity
github-actions commentedon Jul 28, 2026
Issue closed: use an issue template
Thanks for taking the time to submit this issue. It was closed automatically because it was not opened with a recognized issue template (Bug report, Feature request, Documentation, or Provider compatibility). Freeform and API-opened issues cannot skip this check.
Please edit the issue to add:
See the Contributing guide for details.
Once the report passes the automated checks, it will be reopened automatically unless a maintainer has changed its state.
github-actions commentedon Jul 28, 2026
Automated translation bookkeeping — detected language: English.