import type { ChildProcess } from "node:child_process"; import { execFileText } from "../tui/async-process.js"; import { type NolCudaMutationJournal } from "./cuda-mutations.js"; type Grant = { token: string; owner: string; requested_mib: number; gpu_uuids: string[]; state: string; ttl: number; workload_pid?: number | null; workload_pids?: number[] | null; }; type Reply = { ok: boolean; error?: string; released?: string; lease?: Grant; }; export interface NolCudaDependencies { exec: typeof execFileText; read(path: string): Promise; control(socket: string, request: Record, options?: { timeoutMs: number; }): Promise; /** Host-only CPU test/storage seam. Normal callers use private durable state. */ mutations?: NolCudaMutationJournal; } export interface NolCudaAcquireIdentity { readonly ownerId: string; readonly gpuUuid: string; readonly requestedMiB: number; } /** A transport error on a mutation does not prove that the broker rejected it. * Recovery carries only a genuinely adopted own pending lease. Its token stays * private to that lease; serialization exposes request identity and a boolean. */ export declare class NolCudaCustodyError extends Error { constructor(message: string, options?: { request?: NolCudaAcquireIdentity; recoverableLease?: NolCudaLease; cause?: unknown; }); get requestedIdentity(): Readonly | undefined; get recoverableLease(): NolCudaLease | undefined; recoveryFor(request: NolCudaAcquireIdentity): NolCudaLease | undefined; toJSON(): Record; } export interface NolCudaPlacement { schema: "omnius.nol.cuda-placement.v1"; pid: number; startIdentity: string; gpuUuid: string; computeCapability: number; checkedAt: string; } /** Host-only broker custody for one job-owned process on one exact capable GPU. * Acquisition authorizes a zero-token load. loaded() must prove actual residency * before token generation. A failed/ambiguous settlement retains the lease. */ export declare class NolCudaLease { #private; private readonly options; private readonly deps; private readonly socketPath; private readonly computeCapability; readonly gpuUuid: string; readonly ownerId: string; private child; private childClosed; private startIdentity; private heartbeat; private heartbeatBusy; private stopTimer; private failed; private stopped; private released; private requestedMiB; private phase; private releaseInFlight; private readonly abort; private constructor(); static acquire(options: { gpuUuid: string; ownerId: string; modelId: string; requestedMiB: number; expectedDurationSeconds: number; signal: AbortSignal; notice?: (message: string) => void; }, deps?: NolCudaDependencies): Promise; toJSON(): Record; private exact; private renew; assertCurrent(): void; /** Generation requires completed placement registration after every prepare. */ assertReady(): void; environment(base?: NodeJS.ProcessEnv): NodeJS.ProcessEnv; /** Attach immediately after spawn. Never attach an existing/unowned process. */ attach(child: ChildProcess): void; loaded(): Promise; /** Before any allocation growth, including the first trial KV allocation. */ prepare(totalMiB: number): Promise; stop(): void; /** Call only after the process owner has observed child close. Failed releases * remain retryable, keep heartbeat and never announce allocationsReleased. */ settle(): Promise; private release; } export declare function nolCudaOwner(jobId: string, generation: number): string; export {};