export declare const V3_ATTEMPT_WORKER_FENCE_FILE = ".worker-fence.json"; export declare const V3_ATTEMPT_WORKER_FENCE_SCHEMA_VERSION: 1; interface V3AttemptWorkerFenceBase { schemaVersion: typeof V3_ATTEMPT_WORKER_FENCE_SCHEMA_VERSION; runId: string; attemptId: string; ownerPid: number; ownerProcStart: string; } export interface V3ArmedAttemptWorkerFence extends V3AttemptWorkerFenceBase { phase: 'armed'; } export type V3NoWorkerSpawnReason = 'pre_aborted' | 'secret_missing' | 'setup_failed' | 'spawn_threw'; export interface V3ClosedNoSpawnAttemptWorkerFence extends V3AttemptWorkerFenceBase { phase: 'closed_no_spawn'; reason: V3NoWorkerSpawnReason; } export interface V3ActiveAttemptWorkerFence extends V3AttemptWorkerFenceBase { phase: 'active'; workerPid: number; workerProcStart: string; } export interface V3ClosedAttemptWorkerFence extends V3AttemptWorkerFenceBase { phase: 'closed'; workerPid: number; workerProcStart: string; } export type V3AttemptWorkerFence = V3ArmedAttemptWorkerFence | V3ClosedNoSpawnAttemptWorkerFence | V3ActiveAttemptWorkerFence | V3ClosedAttemptWorkerFence; export interface V3AttemptWorkerFenceBinding { runId: string; attemptId: string; } export type V3AttemptWorkerFenceProbe = { status: 'missing'; } | { status: 'unknown'; fence: V3AttemptWorkerFence; reason: 'armed_without_worker_identity' | 'process_identity_unavailable' | 'process_probe_denied'; } | { status: 'alive'; fence: V3ActiveAttemptWorkerFence; } | { status: 'dead'; fence: V3ClosedNoSpawnAttemptWorkerFence | V3ActiveAttemptWorkerFence | V3ClosedAttemptWorkerFence; reason: 'no_worker_spawned' | 'outer_process_closed' | 'process_missing' | 'process_identity_mismatch'; }; export type V3AttemptWorkerSignal = 'SIGINT' | 'SIGKILL'; export type V3AttemptWorkerSignalResult = { status: 'signalled'; fence: V3ActiveAttemptWorkerFence; signal: V3AttemptWorkerSignal; } | Exclude; export type V3AttemptWorkerFenceRemoval = 'missing' | 'mismatch' | 'removed'; export interface V3DiscoveredAttemptWorker { pid: number; procStart: string; } export type V3AttemptWorkerDiscovery = { status: 'unsupported'; } | { status: 'none'; } | { status: 'one'; worker: V3DiscoveredAttemptWorker; } | { status: 'ambiguous'; workers: V3DiscoveredAttemptWorker[]; unverifiablePids: number[]; reason: 'multiple_or_unverifiable' | 'candidate_changed'; }; export type V3ArmedFenceRecoveryResult = { status: 'recovered'; fence: V3ActiveAttemptWorkerFence; } | { status: 'already_active'; fence: V3ActiveAttemptWorkerFence; } | { status: 'already_closed'; fence: V3ClosedAttemptWorkerFence; } | { status: 'already_closed_no_spawn'; fence: V3ClosedNoSpawnAttemptWorkerFence; } | { status: 'owner_alive' | 'owner_unknown' | 'missing'; } | Exclude; export interface V3AttemptWorkerProcessLike { readonly pid?: number; on(event: 'close', listener: (code: number | null) => void): unknown; } export declare class V3AttemptWorkerFenceIntegrityError extends Error { constructor(message: string); } export declare function v3AttemptWorkerFencePath(attemptDir: string): string; /** Missing is distinct from invalid; every malformed/unexpected shape fails closed. */ export declare function readV3AttemptWorkerFence(attemptDir: string, expected: V3AttemptWorkerFenceBinding): V3AttemptWorkerFence | null; /** Publish the daemon-owned pre-fork fence. Call this before factory.spawn(). */ export declare function armV3AttemptWorkerFence(input: { attemptDir: string; runId: string; attemptId: string; }): V3ArmedAttemptWorkerFence; /** Atomically bind an exact armed fence to the newly-forked worker identity. */ export declare function activateV3AttemptWorkerFence(input: { attemptDir: string; armed: V3ArmedAttemptWorkerFence; workerPid: number; }): V3ActiveAttemptWorkerFence; /** * Durable proof that the armed pre-fork path ended without creating a child. * Only the still-live daemon that armed the fence may make this assertion. */ export declare function closeV3ArmedFenceWithoutSpawn(attemptDir: string, armed: V3ArmedAttemptWorkerFence, reason: V3NoWorkerSpawnReason): V3ClosedNoSpawnAttemptWorkerFence; /** * Linux-only conservative orphan discovery for the armed fork gap and legacy * runs without a fence. Both the exact attempt-dir environment binding and a * worker.js/worker.ts command-line argument are required. Same-uid unreadable matches * make the result ambiguous rather than being silently treated as absent. */ export declare function discoverV3AttemptWorker(attemptDir: string): V3AttemptWorkerDiscovery; /** * Recover armed → active only after the recorded owner is provably gone and a * single exact attempt-bound worker is discoverable. The owner proof and scan * are repeated under the fence lock before publication. */ export declare function recoverV3ArmedFenceWorker(input: { attemptDir: string; armed: V3ArmedAttemptWorkerFence; }): V3ArmedFenceRecoveryResult; /** * Armed is always unknown (including after owner death); missing remains * distinct so runtime can apply its explicit legacy/drain fail-safe policy. */ export declare function probeV3AttemptWorkerFence(attemptDir: string, expected: V3AttemptWorkerFenceBinding): V3AttemptWorkerFenceProbe; /** Signal only the exact active fence after rechecking its live start identity. */ export declare function signalV3AttemptWorker(attemptDir: string, expected: V3ActiveAttemptWorkerFence, signal: V3AttemptWorkerSignal): V3AttemptWorkerSignalResult; /** Durable active → closed tombstone transition performed on ChildProcess close. */ export declare function closeV3AttemptWorkerFence(attemptDir: string, expected: V3ActiveAttemptWorkerFence): V3ClosedAttemptWorkerFence; /** Exact-identity removal after the journal has durably settled the attempt. */ export declare function removeV3AttemptWorkerFence(attemptDir: string, expected: V3AttemptWorkerFence): V3AttemptWorkerFenceRemoval; /** * Activate and bind a durable tombstone transition to ChildProcess `close` * only. `exit` is not a * resource fence: stdio/IPC (and descendants holding them) may still be open. * The listener is installed before activation and replays cleanup if close * races the durable active transition. */ export declare function bindV3AttemptWorkerFence(input: { worker: V3AttemptWorkerProcessLike; attemptDir: string; armed: V3ArmedAttemptWorkerFence; onCleanupError?: (error: unknown) => void; }): V3ActiveAttemptWorkerFence; export {}; //# sourceMappingURL=worker-fence.d.ts.map