@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
80 lines • 5.24 kB
TypeScript
import type { HolderGeneration } from "../../core/session-holders.ts";
import { type HostGenerationPaths } from "./host-daemon-paths.ts";
/** How recent stall evidence keeps an unreachable generation from being replaced. */
export declare const STALL_REFUSAL_WINDOW_MS_ENV = "SENPI_RPC_STALL_REFUSAL_MS";
export declare const DEFAULT_STALL_REFUSAL_WINDOW_MS = 120000;
/** How recent stall evidence keeps a graceful stop waiting instead of escalating. */
export declare const STOP_STALL_EVIDENCE_MAX_AGE_MS = 60000;
/** The longest a graceful stop waits for a stalled child before it escalates to SIGKILL. */
export declare const CHILD_STALLED_STOP_MAX_MS_ENV = "SENPI_RPC_CHILD_STALLED_STOP_MAX_MS";
export declare const DEFAULT_CHILD_STALLED_STOP_MAX_MS = 60000;
export declare function childStalledStopMaxMs(env?: Readonly<Record<string, string | undefined>>): number;
export interface HostStallEvidence {
readonly at: string;
readonly driftMs: number;
readonly processCpuMs: number;
readonly heapDeltaMb: number;
readonly sessionId?: string;
readonly tool?: string;
}
/**
* `generations/<instanceId>/` of the host this process IS, when a supervisor launched it; a plain
* `--mode rpc` run has neither variable and writes no evidence at all.
*/
export declare function ownGenerationDir(env: Readonly<Record<string, string | undefined>>): string | undefined;
export declare function stallRefusalWindowMs(env?: Readonly<Record<string, string | undefined>>): number;
/** Best-effort: a generation directory that is gone (released) or read-only simply gets no evidence. */
export declare function writeStallEvidence(generationDir: string, evidence: HostStallEvidence): Promise<void>;
export declare function writeHeartbeat(generationDir: string, at: string): Promise<void>;
export declare function readStallEvidence(generation: HostGenerationPaths): Promise<HostStallEvidence | undefined>;
export declare function recentStall(generation: HostGenerationPaths, now: number, maxAgeMs: number): Promise<HostStallEvidence | undefined>;
/**
* Stalled = a recent measured stall, OR a heartbeat that stopped more than `errorMs` ago yet within
* the window (older than the window it is a host that died without cleaning up, not one that is
* stuck). The caller pairs this with its own proof that the process is still alive.
*/
export declare function hostLoopStalled(generation: HostGenerationPaths, options: {
readonly now: number;
readonly errorMs: number;
readonly windowMs: number;
}): Promise<boolean>;
/**
* Whether the generation left a heartbeat older than any stall could explain: the same "died without
* cleaning up" verdict `hostLoopStalled` reaches past the window. No heartbeat file is no evidence.
*/
export declare function generationHeartbeatStopped(generation: HostGenerationPaths, now?: number): Promise<boolean>;
/**
* Whether the host generation a session-holder lease names has ENDED, for a holder whose pid is alive but
* whose start time cannot be compared (#3658). Two pieces of evidence count:
* - its heartbeat stopped (`generationHeartbeatStopped`, the rule claims and generations share);
* - the daemon directory the lease names is an endpoint's (`endpoint.json`, which every release leaves)
* and the generation's directory is gone: a daemon removes it only after its child was judged not
* alive, by the same heartbeat rule. A lease without a daemon directory is read against this host's
* own daemon, where only the heartbeat counts, since absence there cannot prove membership.
* A fresh heartbeat, no heartbeat file, or this host's own generation never ends: a live host whose
* probe is merely slow keeps its sessions (#1609).
*/
export declare function holderGenerationEnded(holder: HolderGeneration, env?: Readonly<Record<string, string | undefined>>): Promise<boolean>;
/**
* Whether the generation's host CHILD is running, from its own pid record; `undefined` when unrecorded.
*
* A live pid whose start time cannot be compared (none recorded, or none readable now) is preserved -
* a starved probe on a live host must not read as dead (#1609) - unless the generation's heartbeat has
* stopped (#3658). On Windows a killed generation's pid is handed to an unrelated process, and without
* that second piece of evidence the stranger would keep the generation, and every ensure refusing
* `host_stalled`, alive for as long as it runs.
*/
export declare function hostChildAlive(generation: HostGenerationPaths): Promise<boolean | undefined>;
/**
* The supervisor's report that it is waiting out a stalled child before escalating; a caller with a
* deadline on that supervisor extends it while the report is fresh.
*/
export interface StopProgress {
readonly at: string;
readonly phase: "waiting_stalled_child";
readonly untilAt: string;
}
export declare function writeStopProgress(generation: HostGenerationPaths, progress: StopProgress): Promise<void>;
export declare function clearStopProgress(generation: HostGenerationPaths): Promise<void>;
export declare function activeStopProgress(generation: HostGenerationPaths, now: number, freshMs: number): Promise<number | undefined>;
//# sourceMappingURL=host-stalled-evidence.d.ts.map