@bitkyc08/opencodex
Version:
Universal provider proxy for OpenAI Codex & Claude Code — use any LLM with Codex CLI/App/SDK and Claude Code
25 lines (23 loc) • 789 B
text/typescript
import type { LabAutomationPolicyV1, LabAutomationStateV1 } from "./types";
import { transitionRun } from "./queue";
import { setCooldown } from "./cooldown";
import { LAB_AUTOMATION_HARD_MAX } from "./constants";
/** Reconcile runs left running after process restart. */
export function recoverLabAutomationState(
policy: LabAutomationPolicyV1,
state: LabAutomationStateV1,
now: number,
): LabAutomationStateV1 {
let next = { ...state };
for (const run of state.runs) {
if (run.state !== "running") continue;
next = transitionRun(next, run.runId, "abandoned", now, "process_restart");
next = setCooldown(
next,
run.runKey,
now + Math.min(policy.failureCooldownMs, LAB_AUTOMATION_HARD_MAX.failureCooldownMs),
now,
);
}
return next;
}