refactor: run Claude and Codex on one fixed account each

The deployment has a single Claude OAuth credential and a single Codex
ChatGPT account, so the N-account rotation machinery only added state
files, cooldown bookkeeping and code paths that never ran.

Removed:
- Claude token rotation (token-rotation.ts, token-rotation-base.ts):
  rotate-on-limit, per-token cooldowns, token-rotation-state.json.
  CLAUDE_CODE_OAUTH_TOKENS is still read, but only its first entry.
- Codex account rotation (codex-token-rotation.ts): account pool,
  rotate-on-429/auth, dead-auth/cooldown tracking, round-robin advance,
  d7 auto-rotate, codex-rotation-state.json, manual account switch.
- Account index plumbing in token-refresh, claude-credentials-path
  (CLAUDE_ACCOUNTS_DIR / ~/.claude-accounts/<n>), Claude/Codex usage
  collectors, the dashboard rows and the Codex warm-up.
- provider-retry.ts rotation loops and the Codex retry path.

Kept:
- Codex exclusive auth lease (one Codex run at a time), the 15-minute
  waitForCodexAuthLease, and a usage-poll lease that skips while a run
  holds the account (codex-auth.ts).
- Session auth copy and write-back of refreshed tokens
  (syncCodexSessionAuthBack, syncClaudeSessionAuthBack).
- Codex auth path: ~/.codex-accounts/0/auth.json, else ~/.codex/auth.json
  (now resolved per run, so a re-login needs no restart).
- Claude token refresh loop, CLAUDE_CREDENTIALS_PATH and the
  CLAUDE_TOKEN_REFRESH_* / CLAUDE_USAGE_USE_HOME_CREDENTIALS flags; an
  auth-expired run still force-refreshes the token and retries once.
- Error classification (classifyClaudeTrigger, classifyCodexTrigger).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-10-01 20:00:46 +09:00
parent f127ac7a2b
commit a9eab5cb94
58 changed files with 1691 additions and 5547 deletions

View File

@@ -139,13 +139,14 @@ describe('codex-usage-collector fallback account usage', () => {
}) as never;
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const codexAuth = await import('./codex-auth.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
const result = await usage.refreshActiveCodexUsage();
const result = await usage.refreshCodexUsage();
expect(rotation.getCodexAccountCount()).toBe(1);
expect(codexAuth.getCodexAuthPath()).toBe(
path.join(fallbackCodexHome, 'auth.json'),
);
expect(capturedCodexHome).toBe(fallbackCodexHome);
expect(result.fetchedAt).toEqual(expect.any(String));
expect(result.rows).toEqual([
@@ -176,10 +177,8 @@ describe('codex-usage-collector fallback account usage', () => {
}) as never;
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
await usage.refreshActiveCodexUsage();
await usage.refreshCodexUsage();
expect(captured).not.toBeNull();
expect(captured!.cmd).toBe(process.execPath);
@@ -203,13 +202,12 @@ describe('codex-usage-collector fallback account usage', () => {
throw new Error('must not spawn while the account is leased');
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const codexAuth = await import('./codex-auth.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
const held = rotation.claimCodexAuthLease();
const held = codexAuth.claimCodexAuthLease();
expect(held).not.toBeNull();
try {
const result = await usage.refreshActiveCodexUsage();
const result = await usage.refreshCodexUsage();
expect(result.fetchedAt).toBeNull();
expect(childProcess.spawn).not.toHaveBeenCalled();
} finally {
@@ -241,11 +239,9 @@ describe('codex-usage-collector fallback account usage', () => {
}) as never;
}) as unknown as typeof childProcess.spawn);
const rotation = await import('./codex-token-rotation.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
const result = await usage.refreshActiveCodexUsage();
const result = await usage.refreshCodexUsage();
// Usage must be applied (not swallowed by a TypeError), and the lone weekly
// window is shown as 7d while the missing 5h window renders as unknown.
@@ -317,11 +313,9 @@ describe('codex-usage-collector fallback account usage', () => {
}) as unknown as typeof childProcess.spawn);
try {
const rotation = await import('./codex-token-rotation.js');
const usage = await import('./codex-usage-collector.js');
rotation.initCodexTokenRotation();
const result = await usage.refreshActiveCodexUsage();
const result = await usage.refreshCodexUsage();
expect(result.fetchedAt).toEqual(expect.any(String));
expect(result.rows).toEqual([