/** * src/engine/background.ts — background delegation run registry (node-only). * * A run id is returned IMMEDIATELY (synchronous register); the actual child * work runs in the background via an executor promise. `getDelegationRun` * reads the current state; `awaitDelegationRun` waits for settlement with a * BOUNDED timeout (never blocks forever). State is hash-only (result output * is never stored raw on the state; only a status + the settled ChildResult * which lives with the caller). * * Zero @earendil-works/* imports. */ import type { ChildResult } from "../core/types.js"; import { type DelegationRunMode } from "./runs.js"; /** Background run status set (subset of DelegationRunStatus). */ export type BackgroundRunStatus = "queued" | "running" | "complete" | "failed" | "aborted"; /** Registry-visible snapshot of a background run (body-free metadata only). */ export interface BackgroundRunState { runId: string; agent: string; mode: DelegationRunMode; source: string; status: BackgroundRunStatus; startedAtMs: number; endedAtMs?: number; taskHash?: string; outputHash?: string; exitCode?: number; errorMessage?: string; } export declare const DEFAULT_AWAIT_TIMEOUT_MS = 300000; /** Bounded background run registry. */ export declare class BackgroundRunRegistry { private readonly entries; private readonly now; constructor(now?: () => number); /** * Register a background run and immediately return its run id. The executor * runs in the background; its resolution updates the state. Never throws. */ register(input: { agent: string; mode: DelegationRunMode; source: string; executor: Promise; runId?: string; taskHash?: string; }): string; /** Read the current body-free state of a background run. */ getDelegationRun(runId: string): BackgroundRunState | undefined; /** * Await settlement of a background run with a BOUNDED timeout. Resolves with * the current state on success, or with the state marked failed + a timeout * error message when the timeout elapses first. */ awaitDelegationRun(runId: string, timeoutMs?: number): Promise; /** All registered background runs (body-free states). */ list(): BackgroundRunState[]; /** Number of registered background runs. */ get size(): number; clear(): void; }