fix(codex): align primer warmup with fixed slots
This commit is contained in:
@@ -33,6 +33,7 @@ interface CodexWarmupRuntimeOptions {
|
||||
nowMs?: number;
|
||||
statePath?: string;
|
||||
shouldSkip?: () => boolean;
|
||||
ignoreZeroUsageWindow?: boolean;
|
||||
}
|
||||
|
||||
export type CodexWarmupCycleResult =
|
||||
@@ -105,6 +106,7 @@ function selectWarmupCandidate(
|
||||
config: CodexWarmupConfig,
|
||||
state: CodexWarmupState,
|
||||
nowMs: number,
|
||||
options: { ignoreZeroUsageWindow?: boolean } = {},
|
||||
): { accountIndex: number; zeroUsageWarmupUntil: string } | { reason: string } {
|
||||
const disabledUntilMs = parseTimestamp(state.disabledUntil);
|
||||
if (disabledUntilMs != null && disabledUntilMs > nowMs) {
|
||||
@@ -134,7 +136,11 @@ function selectWarmupCandidate(
|
||||
const zeroUsageWarmupUntilMs = parseTimestamp(
|
||||
accountState?.zeroUsageWarmupUntil,
|
||||
);
|
||||
if (zeroUsageWarmupUntilMs != null && zeroUsageWarmupUntilMs > nowMs) {
|
||||
if (
|
||||
!options.ignoreZeroUsageWindow &&
|
||||
zeroUsageWarmupUntilMs != null &&
|
||||
zeroUsageWarmupUntilMs > nowMs
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -144,10 +150,13 @@ function selectWarmupCandidate(
|
||||
}
|
||||
|
||||
const resetD7Ms = parseTimestamp(account.resetD7At);
|
||||
const zeroUsageWarmupUntilMsForState =
|
||||
resetD7Ms != null && resetD7Ms > nowMs
|
||||
? resetD7Ms
|
||||
: nowMs + DEFAULT_ZERO_USAGE_WARMUP_WINDOW_MS;
|
||||
let zeroUsageWarmupUntilMsForState = nowMs;
|
||||
if (!options.ignoreZeroUsageWindow) {
|
||||
zeroUsageWarmupUntilMsForState =
|
||||
resetD7Ms != null && resetD7Ms > nowMs
|
||||
? resetD7Ms
|
||||
: nowMs + DEFAULT_ZERO_USAGE_WARMUP_WINDOW_MS;
|
||||
}
|
||||
|
||||
return {
|
||||
accountIndex: account.index,
|
||||
@@ -254,7 +263,9 @@ export async function runCodexWarmupCycle(
|
||||
const nowIso = new Date(nowMs).toISOString();
|
||||
const statePath = runtime.statePath ?? DEFAULT_STATE_FILE;
|
||||
const state = readWarmupState(statePath);
|
||||
const selected = selectWarmupCandidate(config, state, nowMs);
|
||||
const selected = selectWarmupCandidate(config, state, nowMs, {
|
||||
ignoreZeroUsageWindow: runtime.ignoreZeroUsageWindow,
|
||||
});
|
||||
if ('reason' in selected) {
|
||||
return { status: 'skipped', reason: selected.reason };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user