/** * Run state machine: admitted → leased → running → terminal. * * Every transition is recorded through the storage adapter. Claims are CAS on * the attempt's lease_generation; a stale claim is rejected. Retries keep the * run_id and mint a new attempt_id with a fresh lease_generation counter. */ import type { ClaimAttemptInput, ClaimResult, ExecutionRunStatus, RunExecutionStore } from "./storage.js"; import type { TerminalRunStatus } from "./types.js"; export type { ClaimResult }; /** The only legal edges of the state machine. */ export declare const LEGAL_TRANSITIONS: Record; export type TransitionFailure = "NO_SUCH_RUN" | "NO_SUCH_ATTEMPT" | "INVALID_TRANSITION" | "ATTEMPT_TERMINAL" | "RUN_TERMINAL" | "RUN_CANCELLED"; export type TransitionResult = { ok: true; } | { ok: false; reason: TransitionFailure; }; export interface RunStateMachine { /** CAS-claim an attempt: expectedLeaseGeneration must match. */ claim(input: ClaimAttemptInput): Promise; /** admitted → leased (claim recorded as a transition). */ lease(input: ClaimAttemptInput): Promise; /** leased → running. */ start(runId: string, attemptId: string): Promise; /** running → terminal; finalizes the run row. */ terminate(input: { runId: string; attemptId: string; status: TerminalRunStatus; }): Promise; /** Cancel a run: fences the current generation and moves it to terminal. */ cancel(runId: string): Promise; transition(runId: string, from: ExecutionRunStatus, to: ExecutionRunStatus, attemptId?: string | null): Promise; getStatus(runId: string): Promise; } export declare function createRunStateMachine(store: RunExecutionStore): RunStateMachine;