/** * supervision.ts, the spine all three watcher kinds share. * * A watcher that fails does two things in order: it walks a backoff ladder so a * briefly unreachable source recovers fast while a broken one stops hammering, * and after a fixed number of consecutive strikes it opens a breaker and parks * itself in a visible circuit-open state with the last error attached. * * Parking beats retrying forever: a trigger stuck in an invisible retry loop * looks identical to a healthy one from the outside, and burns the resource it * is polling. An open breaker is a state an operator can see and reset. * * Pure functions over a record, so the ladder and the breaker are testable * without waiting real wall-clock minutes. */ import type { TriggerRecord, TriggerState } from './types.js'; /** The default ladder: 30s, 60s, 5m, 15m, 60m. The last rung repeats. */ export declare const DEFAULT_BACKOFF_LADDER_MS: readonly number[]; /** Consecutive failures that open the breaker. */ export declare const DEFAULT_BREAKER_STRIKES = 5; export interface SupervisionPolicy { readonly ladderMs: readonly number[]; readonly breakerStrikes: number; } /** * Parses the comma-separated `watchers.triggers.backoffLadderMs` setting. * Falls back to the default ladder rather than throwing, a malformed setting * must not take the whole supervisor down. */ export declare function parseBackoffLadder(raw: string | undefined): readonly number[]; export declare function resolveSupervisionPolicy(input: { readonly backoffLadderMs?: string | undefined; readonly breakerStrikes?: number | undefined; }): SupervisionPolicy; /** Delay for a given rung. Rungs past the end repeat the last one. */ export declare function backoffDelayFor(policy: SupervisionPolicy, rung: number): number; export interface SupervisionOutcome { readonly state: TriggerState; readonly strikes: number; readonly backoffRung: number; readonly nextCheckAt: number; readonly delayMs: number; /** True when this failure is the one that opened the breaker. */ readonly breakerOpened: boolean; } /** * Applies one failure. Increments the strike count, advances one rung, and * opens the breaker at the strike limit. Note the ordering: the rung used for * THIS delay is the pre-increment rung, so the first failure waits the first * ladder entry rather than skipping it. */ export declare function applyFailure(record: Pick, policy: SupervisionPolicy, now: number): SupervisionOutcome; /** Applies one success: strikes and rung both reset, cadence returns to normal. */ export declare function applySuccess(intervalMs: number, now: number): { readonly state: TriggerState; readonly strikes: number; readonly backoffRung: number; readonly nextCheckAt: number; }; /** True when the breaker is open and the trigger must not run. */ export declare function isCircuitOpen(record: Pick): boolean; /** * Explicit operator reset. The breaker never closes on its own, that is the * point of parking, and an auto-closing breaker is just a slower retry loop. */ export declare function resetBreaker(record: TriggerRecord, now: number): TriggerRecord; /** True when the trigger is due to run. Circuit-open triggers are never due. */ export declare function isDue(record: TriggerRecord, now: number): boolean; //# sourceMappingURL=supervision.d.ts.map