import type { AgentTransportHandle, AgentTransportLaunch } from "./types.js"; /** * Opt-in reattachment of built-in `pi-durable` worker runs after the resident * host that launched them stops (`agents.durableWorkerRecovery`). * * The file below is an untrusted recovery hint. A host-owned receipt outside * the run directory must authorize its complete contents before use. An explicit * stop deletes it as soon as the stop is requested, * before Fabric signals the worker, and every other settlement deletes it * before the terminal record lands. A recovery file beside a worker-written * terminal "stopped" record therefore means the stop came from outside Fabric * (a reboot or logout signal), never from an operator stop. */ export declare const WORKER_RECOVERY_FILE = "worker-recovery.json"; export declare const WORKER_RECOVERY_FORMAT = 1; export interface WorkerRecoveryRecord { format: typeof WORKER_RECOVERY_FORMAT; id: string; runner: "pi-durable"; /** Absolute wall-clock deadline of the original launch. */ deadlineAt: number; /** Process id of the current worker attempt. */ pid: number; launch: AgentTransportLaunch; writtenAt: number; } /** Larger files are refused unread: a launch is far smaller than this. */ export declare const WORKER_RECOVERY_MAX_BYTES: number; export declare const workerRecoveryPath: (runDirectory: string) => string; export declare const writeWorkerRecovery: (runDirectory: string, record: WorkerRecoveryRecord) => void; export declare const workerRecoveryAuthorityRoot: (runRoot: string) => string; /** Called only with an admitted in-memory launch (or its verified receipt), never a marker. */ export declare const authorizeWorkerRecovery: (runDirectory: string, recovery: WorkerRecoveryRecord, policy: string) => void; export declare const readWorkerRecoveryAuthority: (runDirectory: string, policy?: string) => WorkerRecoveryRecord | undefined; export declare const removeWorkerRecovery: (runDirectory: string) => void; export declare const hasWorkerRecovery: (runDirectory: string) => boolean; /** * Strict reader: copies named, validated fields; anything else is undefined. * The record's id must name the run directory it sits in, so a file copied * from another run is never read as this one. */ export declare const readWorkerRecovery: (runDirectory: string) => WorkerRecoveryRecord | undefined; /** * Why a recovery file must not be acted on by this host, or undefined when it * may. The file sits in the run directory, so anything that can write there * could otherwise point a relaunch at another program, working directory, run * id, or status file. Every launch field must exactly match the host-owned * receipt, including approved external paths and optional capabilities. The * launch must also use this host's worker and this run's id/cwd/status paths. */ export declare const workerRecoveryMismatch: (recovery: WorkerRecoveryRecord, expected: { runDirectory: string; workerPath: string; cwd: string; policy?: string; }) => string | undefined; export type WorkerLiveness = "alive" | "dead" | "unknown"; export interface WorkerProbes { /** `kill(pid, 0)`. */ signal?: (pid: number) => "exists" | "missing" | "unknown"; /** Full command line of `pid`, or undefined when it cannot be read. */ commandLine?: (pid: number) => string | undefined; } /** * Whether `pid` is still this run's worker. A PID alone is not enough: after a * reboot or a long outage the number may belong to an unrelated process, and * adopting that would let a later stop signal its process group. The worker's * command line carries `--id `, so a live PID whose command line lacks * it is a reused PID and our worker is gone. Any probe Fabric cannot read is * "unknown": relaunching then could put two writers on one journal. */ export declare const probeWorker: (pid: number, id: string, probes?: WorkerProbes) => WorkerLiveness; /** Transport handle for a verified live worker the new host did not launch. */ export declare const adoptedWorkerHandle: (pid: number, id: string, probes?: WorkerProbes) => AgentTransportHandle; //# sourceMappingURL=worker-recovery.d.ts.map