/** * A per-project, single-flight pid lock for NEXUS background work (T14010, * T14014): the reindex after a merge and the inline refresh each run at most * once at a time per project. * * The pid is written to a private file that is then hard-linked into place, so * a reader never sees an empty lock. A dead holder is cleared by renaming the * lock to a unique name and checking the renamed file still holds that dead * pid, so two clearers cannot both win: only one rename succeeds, and a * clearer that moved a live lock by mistake puts it back. An empty or * unparseable lock younger than {@link PID_LOCK_WRITE_GRACE_MS} counts as a * holder still writing it. Release removes the lock only when it holds the * releaser's pid. * * Code placed in `packages/core/` per Package-Boundary Check — verified against AGENTS.md. * * @module nexus/pid-lock * @task T14014 */ /** A lock file younger than this with no readable pid is a holder still writing it. */ export declare const PID_LOCK_WRITE_GRACE_MS = 5000; /** Test seams: the pid to take the lock as, and how liveness is judged. */ export interface PidLockOptions { /** Pid written to the lock. @defaultValue process.pid */ pid?: number; /** Whether a pid is alive. @defaultValue a signal-0 probe */ isAlive?: (pid: number) => boolean; } /** * Take a pid lock atomically. * * @param lockPath - The lock file. * @param options - Test seams (pid, liveness). * @returns `null` when taken, or the pid of the live holder (`0` when unknown). * @example * ```ts * const holder = takePidLock(join(cleoDir, 'nexus-reindex.lock')); * if (holder === null) try { work(); } finally { releasePidLock(lockPath); } * ``` */ export declare function takePidLock(lockPath: string, options?: PidLockOptions): number | null; /** * Release a pid lock taken by {@link takePidLock}: removed only when it still * holds this pid, so a lock someone else took over is left alone. * * @param lockPath - The lock file. * @param pid - The holder releasing it. @defaultValue process.pid */ export declare function releasePidLock(lockPath: string, pid?: number): void; //# sourceMappingURL=pid-lock.d.ts.map