refactor: remove the disabled periodic Codex warm-up loop
CODEX_WARMUP_ENABLED defaulted to false and was never set, so the warm-up loop in unified-dashboard never ran. Remove the loop, the `enabled` / `intervalMs` config keys, the `disabled` result and the `shouldSkip` hook it alone used. The fixed-slot usage primer keeps calling runCodexWarmupCycle with forceAttempt exactly as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -125,10 +125,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
|
||||
const result = await runCodexWarmupCycle(
|
||||
{
|
||||
enabled: true,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 1_800_000,
|
||||
maxUsagePct: 0,
|
||||
@@ -203,10 +201,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
|
||||
await runCodexWarmupCycle(
|
||||
{
|
||||
enabled: true,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 1_800_000,
|
||||
maxUsagePct: 0,
|
||||
@@ -263,10 +259,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
|
||||
const result = await runCodexWarmupCycle(
|
||||
{
|
||||
enabled: true,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 0,
|
||||
maxUsagePct: 0,
|
||||
@@ -326,10 +320,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
|
||||
const result = await runCodexWarmupCycle(
|
||||
{
|
||||
enabled: true,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_000_000,
|
||||
staggerMs: 0,
|
||||
maxUsagePct: 0,
|
||||
@@ -375,10 +367,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
);
|
||||
|
||||
const config = {
|
||||
enabled: true,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 0,
|
||||
maxUsagePct: 0,
|
||||
@@ -434,10 +424,8 @@ describe('Codex warm-up scheduler', () => {
|
||||
|
||||
const result = await runCodexWarmupCycle(
|
||||
{
|
||||
enabled: true,
|
||||
prompt: '.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 1_800_000,
|
||||
maxUsagePct: 0,
|
||||
@@ -462,10 +450,8 @@ describe('Codex warm-up fixed-slot forceAttempt', () => {
|
||||
const t13 = new Date('2026-06-09T04:00:00.486Z').getTime();
|
||||
const t18 = new Date('2026-06-09T09:00:00.000Z').getTime();
|
||||
const config = {
|
||||
enabled: true as const,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_000_000, // 5h
|
||||
staggerMs: 1_800_000,
|
||||
maxUsagePct: 100,
|
||||
|
||||
@@ -34,7 +34,6 @@ interface CodexWarmupState {
|
||||
interface CodexWarmupRuntimeOptions {
|
||||
nowMs?: number;
|
||||
statePath?: string;
|
||||
shouldSkip?: () => boolean;
|
||||
ignoreZeroUsageWindow?: boolean;
|
||||
/**
|
||||
* Fixed-slot primer mode: bypass the opportunistic warm-up skip gates
|
||||
@@ -48,7 +47,6 @@ interface CodexWarmupRuntimeOptions {
|
||||
}
|
||||
|
||||
export type CodexWarmupCycleResult =
|
||||
| { status: 'disabled' }
|
||||
| { status: 'skipped'; reason: string }
|
||||
| { status: 'warmed'; accountIndex: number }
|
||||
| { status: 'failed'; accountIndex: number; reason: string };
|
||||
@@ -336,10 +334,6 @@ export async function runCodexWarmupCycle(
|
||||
config: CodexWarmupConfig,
|
||||
runtime: CodexWarmupRuntimeOptions = {},
|
||||
): Promise<CodexWarmupCycleResult> {
|
||||
if (!config.enabled) return { status: 'disabled' };
|
||||
if (runtime.shouldSkip?.())
|
||||
return { status: 'skipped', reason: 'runtime_busy' };
|
||||
|
||||
const nowMs = runtime.nowMs ?? Date.now();
|
||||
const nowIso = new Date(nowMs).toISOString();
|
||||
const statePath = runtime.statePath ?? DEFAULT_STATE_FILE;
|
||||
|
||||
@@ -31,10 +31,8 @@ describe('config/env loading', () => {
|
||||
delete process.env.DISCORD_CODEX_REVIEW_BOT_TOKEN;
|
||||
delete process.env.PAIRED_CARRY_FORWARD_LATEST_OWNER_FINAL;
|
||||
delete process.env.PAIRED_FORCE_FRESH_CLAUDE_REVIEWER_SESSION;
|
||||
delete process.env.CODEX_WARMUP_ENABLED;
|
||||
delete process.env.CODEX_WARMUP_PROMPT;
|
||||
delete process.env.CODEX_WARMUP_MODEL;
|
||||
delete process.env.CODEX_WARMUP_INTERVAL_MS;
|
||||
delete process.env.CODEX_WARMUP_MIN_INTERVAL_MS;
|
||||
delete process.env.CODEX_WARMUP_STAGGER_MS;
|
||||
delete process.env.CODEX_WARMUP_MAX_USAGE_PCT;
|
||||
@@ -135,9 +133,8 @@ describe('config/env loading', () => {
|
||||
expect(config.PAIRED_FORCE_FRESH_CLAUDE_REVIEWER_SESSION).toBe(true);
|
||||
});
|
||||
|
||||
it('keeps Codex warm-up disabled by default and exposes conservative opt-in env config', async () => {
|
||||
it('exposes conservative Codex warm-up env config', async () => {
|
||||
let config = await import('./config.js');
|
||||
expect(config.CODEX_WARMUP_CONFIG.enabled).toBe(false);
|
||||
expect(config.CODEX_WARMUP_CONFIG.maxUsagePct).toBe(0);
|
||||
expect(config.CODEX_WARMUP_CONFIG.maxD7UsagePct).toBe(0);
|
||||
expect(
|
||||
@@ -146,7 +143,6 @@ describe('config/env loading', () => {
|
||||
|
||||
vi.resetModules();
|
||||
process.env.CODEX_MODEL = 'gpt-5.5';
|
||||
process.env.CODEX_WARMUP_ENABLED = 'true';
|
||||
process.env.CODEX_WARMUP_PROMPT = '.';
|
||||
process.env.CODEX_WARMUP_STAGGER_MS = '600000';
|
||||
process.env.CODEX_WARMUP_MAX_CONSECUTIVE_FAILURES = '1';
|
||||
@@ -154,7 +150,6 @@ describe('config/env loading', () => {
|
||||
|
||||
expect(config.CODEX_WARMUP_CONFIG).toEqual(
|
||||
expect.objectContaining({
|
||||
enabled: true,
|
||||
prompt: '.',
|
||||
model: 'gpt-5.5',
|
||||
staggerMs: 600000,
|
||||
|
||||
@@ -239,7 +239,6 @@ export function loadConfig(): AppConfig {
|
||||
readText('TZ') ?? Intl.DateTimeFormat().resolvedOptions().timeZone,
|
||||
},
|
||||
codexWarmup: {
|
||||
enabled: readBoolean('CODEX_WARMUP_ENABLED', false),
|
||||
prompt:
|
||||
readNonEmptyText('CODEX_WARMUP_PROMPT') ??
|
||||
'Reply exactly OK. Do not run tools.',
|
||||
@@ -247,7 +246,6 @@ export function loadConfig(): AppConfig {
|
||||
readNonEmptyText('CODEX_WARMUP_MODEL') ??
|
||||
readNonEmptyText('CODEX_MODEL') ??
|
||||
'codex',
|
||||
intervalMs: readIntegerAtLeast('CODEX_WARMUP_INTERVAL_MS', 300000, 60000),
|
||||
minIntervalMs: readIntegerAtLeast(
|
||||
'CODEX_WARMUP_MIN_INTERVAL_MS',
|
||||
18300000,
|
||||
|
||||
@@ -78,10 +78,8 @@ export interface AppConfig {
|
||||
timezone: string;
|
||||
};
|
||||
codexWarmup: {
|
||||
enabled: boolean;
|
||||
prompt: string;
|
||||
model: string;
|
||||
intervalMs: number;
|
||||
minIntervalMs: number;
|
||||
staggerMs: number;
|
||||
maxUsagePct: number;
|
||||
|
||||
@@ -14,7 +14,6 @@ import {
|
||||
STATUS_SHOW_ROOM_DETAILS,
|
||||
STATUS_SHOW_ROOMS,
|
||||
USAGE_DASHBOARD_ENABLED,
|
||||
CODEX_WARMUP_CONFIG,
|
||||
} from './config.js';
|
||||
import { getGlobalFailoverInfo } from './service-routing.js';
|
||||
import {
|
||||
@@ -27,7 +26,6 @@ import {
|
||||
refreshActiveCodexUsage,
|
||||
refreshAllCodexAccountUsage,
|
||||
} from './codex-usage-collector.js';
|
||||
import { runCodexWarmupCycle } from './codex-warmup.js';
|
||||
import {
|
||||
composeDashboardContent,
|
||||
formatElapsed,
|
||||
@@ -1060,35 +1058,10 @@ export async function startUnifiedDashboard(
|
||||
cachedCodexUsageRows = result.rows;
|
||||
if (result.fetchedAt) codexUsageFetchedAt = result.fetchedAt;
|
||||
};
|
||||
const isWarmupRuntimeBusy = () => {
|
||||
const groups = opts.roomBindings();
|
||||
return opts.queue
|
||||
.getStatuses(Object.keys(groups))
|
||||
.some((status) => status.status === 'processing');
|
||||
};
|
||||
let codexWarmupInFlight = false;
|
||||
const runCodexWarmup = async () => {
|
||||
if (!CODEX_WARMUP_CONFIG.enabled || codexWarmupInFlight) return;
|
||||
codexWarmupInFlight = true;
|
||||
try {
|
||||
const result = await runCodexWarmupCycle(CODEX_WARMUP_CONFIG, {
|
||||
shouldSkip: isWarmupRuntimeBusy,
|
||||
});
|
||||
if (result.status === 'warmed') {
|
||||
applyCodexRefresh(await refreshAllCodexAccountUsage());
|
||||
}
|
||||
} catch (err) {
|
||||
logger.warn({ err }, 'Codex warm-up cycle failed unexpectedly');
|
||||
} finally {
|
||||
codexWarmupInFlight = false;
|
||||
}
|
||||
};
|
||||
void refreshAllCodexAccountUsage()
|
||||
.then((r) => {
|
||||
applyCodexRefresh(r);
|
||||
return refreshActiveCodexUsage().then(applyCodexRefresh);
|
||||
})
|
||||
.then(() => runCodexWarmup());
|
||||
void refreshAllCodexAccountUsage().then((r) => {
|
||||
applyCodexRefresh(r);
|
||||
return refreshActiveCodexUsage().then(applyCodexRefresh);
|
||||
});
|
||||
// Each poll spawns a Codex app-server; every 5 minutes is plenty for the
|
||||
// dashboard (it used to run every minute, ~1,440 spawns a day).
|
||||
setInterval(
|
||||
@@ -1096,15 +1069,9 @@ export async function startUnifiedDashboard(
|
||||
Math.max(opts.usageUpdateInterval, CODEX_ACTIVE_USAGE_POLL_MS),
|
||||
);
|
||||
setInterval(
|
||||
() =>
|
||||
void refreshAllCodexAccountUsage()
|
||||
.then(applyCodexRefresh)
|
||||
.then(() => runCodexWarmup()),
|
||||
() => void refreshAllCodexAccountUsage().then(applyCodexRefresh),
|
||||
CODEX_FULL_SCAN_INTERVAL,
|
||||
);
|
||||
if (CODEX_WARMUP_CONFIG.enabled) {
|
||||
setInterval(() => void runCodexWarmup(), CODEX_WARMUP_CONFIG.intervalMs);
|
||||
}
|
||||
|
||||
logger.info(
|
||||
{
|
||||
|
||||
@@ -17,10 +17,8 @@ const runCodexWarmupCycle = vi.fn(async () => {
|
||||
|
||||
vi.mock('./config.js', () => ({
|
||||
CODEX_WARMUP_CONFIG: {
|
||||
enabled: false,
|
||||
prompt: 'Reply exactly OK. Do not run tools.',
|
||||
model: 'gpt-5.5',
|
||||
intervalMs: 300_000,
|
||||
minIntervalMs: 18_300_000,
|
||||
staggerMs: 1_800_000,
|
||||
maxUsagePct: 0,
|
||||
@@ -69,7 +67,6 @@ describe('usage-primer', () => {
|
||||
expect(refreshAllCodexAccountUsage).not.toHaveBeenCalled();
|
||||
expect(runCodexWarmupCycle).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
enabled: true,
|
||||
minIntervalMs: 18_000_000,
|
||||
maxUsagePct: 100,
|
||||
maxD7UsagePct: 100,
|
||||
|
||||
@@ -158,7 +158,6 @@ export async function runCodexPrimerCycle(): Promise<void> {
|
||||
const result = await runCodexWarmupCycle(
|
||||
{
|
||||
...CODEX_WARMUP_CONFIG,
|
||||
enabled: true,
|
||||
minIntervalMs: CODEX_PRIMER_MIN_INTERVAL_MS,
|
||||
maxUsagePct: CODEX_PRIMER_MAX_USAGE_PCT,
|
||||
maxD7UsagePct: CODEX_PRIMER_MAX_D7_USAGE_PCT,
|
||||
|
||||
Reference in New Issue
Block a user