codex-multi-auth icon indicating copy to clipboard operation
codex-multi-auth copied to clipboard

[bug] Sequential scheduling ignores saved order within account priority tiers

Open bujingjing opened this issue 1 month ago • 0 comments

Summary

With schedulingStrategy: "sequential", the priority-tier branch of chooseAccount still ranks subscription accounts by quota reset time and turns the winner into an internal pin. This can send requests to the second saved account even when the first account is healthy, has quota available, and belongs to the same priority tier. An active-account preference can also override saved list order when quota measurements are absent.

The desired order is Account A → Account B → Account C, with automatic fallback when an account is unavailable. No new scheduling option is needed: the existing sequential setting should provide predictable ordering within eligible priority tiers.

Reproduction

  1. Save three enabled subscription accounts in order A, B, C, without a manual pin.
  2. Give A and B priority 0 and C priority 1. Set pluginConfig.schedulingStrategy to "sequential".
  3. Give A healthy quota with 100% remaining and a reset in five hours; give B healthy quota with 50% remaining and a reset in one hour. Both are outside the subscription reserve and neither is rate-limited, cooling down, or policy-blocked.
  4. Route a request through mcodex / the runtime proxy. The priority branch chooses B because its quota resets sooner, before the sequential selector is reached.

This is reproducible directly against source on current main (fafb99c, package version 2.21.0), using synthetic accounts and the existing test/rotation-account-selection.test.ts fixtures. It was originally observed with the installed 2.19.0 package.

Expected Behavior

Within the first eligible priority tier, sequential scheduling uses saved account order and falls back through that order when an account is unavailable. Higher-priority tiers, explicit manual pins, runtime health checks, model eligibility, and quota exhaustion/reserve checks still apply. Hybrid scheduling continues to use quota ranking.

Actual Behavior

The same input selects Account B in both hybrid and sequential modes. Without quota measurements, preferredIndex: 1 also makes sequential mode select B before A.

The cause is in lib/runtime/rotation-account-selection.ts: the policy.priorityByAccount branch unconditionally applies compareSubscriptionQuota, then recursively calls chooseAccount with pinnedIndex set. The pin branch returns before the sequential branch can run.

This is particularly visible with two separate Business logins into the same workspace: getAccountPolicyKey currently derives the key from accountId first, so those saved logins share a priority tier. Separate priority numbers cannot work around the tie in that setup. The proposed ordering fix does not change policy-key identity or migrate policy storage.

Environment

  • codex --version: codex-cli 0.162.1
  • Installed codex-multi-auth: 2.19.0
  • Source reproduction: current main fafb99c / 2.21.0
  • Account pool summary: three enabled subscriptions; priorities 0, 0, 1; sequential scheduling; no manual pin
  • Rotation summary: enabled; native localhost app router in use
  • OS: macOS 26.5.1
  • Installed Node.js: 25.8.0; full PR test run uses supported Node.js 24.21.0

Diagnostic Outputs

Before the source fix, two added regression tests fail:

sequential respects its account ordering strategy
  expected index 0; received index 1
uses saved order even when quota measurements are unavailable
  expected index 0; received index 1

Test Files  1 failed (1)
Tests       2 failed | 37 passed (39)

Live local checks confirmed both Business accounts had 100% quota remaining. The installed package was patched locally and subsequent router traffic used the first saved account. The source PR adds synthetic regression coverage without needing real credentials or consuming account quota.

Compliance Confirmation

  • [x] This report concerns personal local development use of the account manager.
  • [x] This report does not request policy bypasses or prohibited usage; unavailable accounts remain unavailable.
  • [x] This report contains no credentials, account emails, workspace IDs, or runtime tokens.

bujingjing avatar Oct 12 '26 00:10 bujingjing