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

@@ -5,17 +5,14 @@ import type { AgentOutput } from './agent-runner.js';
// ── Mocks ──────────────────────────────────────────────────────
vi.mock('./agent-error-detection.js', () => ({
classifyClaudeAuthError: vi.fn(() => ({ category: 'none', reason: '' })),
classifyRotationTrigger: vi.fn(() => ({ shouldRetry: false, reason: '' })),
classifyClaudeTrigger: vi.fn(() => ({ shouldRetry: false, reason: '' })),
detectClaudeProviderFailureMessage: vi.fn(() => ''),
isClaudeUsageExhaustedMessage: vi.fn(() => false),
isClaudeOrgAccessDeniedMessage: vi.fn(() => false),
isClaudeAuthExpiredMessage: vi.fn(() => false),
isClaudeAuthError: vi.fn(() => false),
}));
vi.mock('./codex-token-rotation.js', () => ({
detectCodexRotationTrigger: vi.fn(() => ({
shouldRotate: false,
classifyCodexTrigger: vi.fn(() => ({
triggered: false,
reason: '',
})),
}));
@@ -27,14 +24,14 @@ vi.mock('./session-recovery.js', () => ({
import {
classifyClaudeAuthError,
classifyRotationTrigger,
classifyClaudeTrigger,
detectClaudeProviderFailureMessage,
isClaudeUsageExhaustedMessage,
isClaudeOrgAccessDeniedMessage,
isClaudeAuthExpiredMessage,
isClaudeAuthError,
classifyCodexTrigger,
} from './agent-error-detection.js';
import { detectCodexRotationTrigger } from './codex-token-rotation.js';
import {
shouldRetryFreshCodexSessionOnAgentFailure,
shouldRetryFreshSessionOnAgentFailure,
@@ -82,7 +79,7 @@ beforeEach(() => {
category: 'none',
reason: '',
});
vi.mocked(classifyRotationTrigger).mockReturnValue({
vi.mocked(classifyClaudeTrigger).mockReturnValue({
shouldRetry: false,
reason: '',
});
@@ -91,8 +88,8 @@ beforeEach(() => {
vi.mocked(isClaudeOrgAccessDeniedMessage).mockReturnValue(false);
vi.mocked(isClaudeAuthExpiredMessage).mockReturnValue(false);
vi.mocked(isClaudeAuthError).mockReturnValue(false);
vi.mocked(detectCodexRotationTrigger).mockReturnValue({
shouldRotate: false,
vi.mocked(classifyCodexTrigger).mockReturnValue({
triggered: false,
reason: '',
});
vi.mocked(shouldRetryFreshCodexSessionOnAgentFailure).mockReturnValue(false);
@@ -443,7 +440,7 @@ describe('evaluateStreamedOutput', () => {
describe('evaluateStreamedOutput error handling', () => {
describe('error → Claude rotation trigger', () => {
it('returns rotation trigger with retryAfterMs', () => {
vi.mocked(classifyRotationTrigger).mockReturnValue({
vi.mocked(classifyClaudeTrigger).mockReturnValue({
shouldRetry: true,
reason: '429',
retryAfterMs: 30000,
@@ -467,7 +464,7 @@ describe('evaluateStreamedOutput error handling', () => {
});
it('suppresses error forward when shortCircuitTriggeredErrors is set', () => {
vi.mocked(classifyRotationTrigger).mockReturnValue({
vi.mocked(classifyClaudeTrigger).mockReturnValue({
shouldRetry: true,
reason: '429',
});
@@ -481,7 +478,7 @@ describe('evaluateStreamedOutput error handling', () => {
});
it('skips rotation check when output was already seen', () => {
vi.mocked(classifyRotationTrigger).mockReturnValue({
vi.mocked(classifyClaudeTrigger).mockReturnValue({
shouldRetry: true,
reason: '429',
});
@@ -496,7 +493,7 @@ describe('evaluateStreamedOutput error handling', () => {
});
it('skips rotation check when already triggered', () => {
vi.mocked(classifyRotationTrigger).mockReturnValue({
vi.mocked(classifyClaudeTrigger).mockReturnValue({
shouldRetry: true,
reason: '429',
});
@@ -517,8 +514,8 @@ describe('evaluateStreamedOutput error handling', () => {
it('returns rotation trigger for Codex primary', () => {
const errorMessage =
'unexpected status 401 Unauthorized: Missing bearer or basic authentication in header';
vi.mocked(detectCodexRotationTrigger).mockReturnValue({
shouldRotate: true,
vi.mocked(classifyCodexTrigger).mockReturnValue({
triggered: true,
reason: '429',
});
@@ -538,14 +535,14 @@ describe('evaluateStreamedOutput error handling', () => {
});
it('does not check Codex rotation for Claude agent type', () => {
vi.mocked(detectCodexRotationTrigger).mockReturnValue({
shouldRotate: true,
vi.mocked(classifyCodexTrigger).mockReturnValue({
triggered: true,
reason: '429',
});
evaluateStreamedOutput(errorOutput('429'), freshState(), claudeOpts);
// Claude uses classifyRotationTrigger, not detectCodexRotationTrigger
expect(detectCodexRotationTrigger).not.toHaveBeenCalled();
// Claude uses classifyClaudeTrigger, not classifyCodexTrigger
expect(classifyCodexTrigger).not.toHaveBeenCalled();
});
});