fix(primer): refresh Codex usage before primer and allow 1% fresh accounts

Codex primer was skipping with no_eligible_accounts because it read a
stale usage cache and required exactly 0% usage. Re-query usage right
before the primer call and treat freshly-reset 0~1% accounts as eligible
so the 5h window can be anchored at the fixed KST slot. Also hold new
Codex-owner turns at fresh usage until the next primer slot.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
This commit is contained in:
Codex
2026-06-01 16:29:12 +09:00
parent db715c6329
commit f4de795b1e
4 changed files with 233 additions and 6 deletions

View File

@@ -3,6 +3,10 @@ import fs from 'fs';
import path from 'path';
import { CODEX_WARMUP_CONFIG } from './config.js';
import {
refreshActiveCodexUsage,
refreshAllCodexAccountUsage,
} from './codex-usage-collector.js';
import { runCodexWarmupCycle } from './codex-warmup.js';
import { logger } from './logger.js';
import { getAllTokens } from './token-rotation.js';
@@ -22,7 +26,10 @@ const PRIMER_HOURS_KST = [8, 13, 18, 23];
const KST_OFFSET_MS = 9 * 60 * 60 * 1000;
const CLAUDE_PRIMER_TIMEOUT_MS = 60_000;
const CODEX_PRIMER_MIN_INTERVAL_MS = 5 * 60 * 60 * 1000;
const CODEX_PRIMER_MAX_USAGE_PCT = 0;
// Codex's rate-limit read can report a freshly reset, otherwise idle account
// as 1%. Treat that as still eligible so the real primer call can anchor the
// 5h inference window at the fixed slot.
const CODEX_PRIMER_MAX_USAGE_PCT = 1;
const CODEX_PRIMER_MAX_D7_USAGE_PCT = 100;
function resolveClaudeBinary(): string {
@@ -131,8 +138,10 @@ async function runClaudePrimerCycle(): Promise<void> {
}
}
async function runCodexPrimerCycle(): Promise<void> {
export async function runCodexPrimerCycle(): Promise<void> {
try {
await refreshAllCodexAccountUsage();
await refreshActiveCodexUsage();
const result = await runCodexWarmupCycle(
{
...CODEX_WARMUP_CONFIG,