import { type WorkItemStatus } from './store.js'; /** How long a claim survives without a heartbeat. */ export declare const TODO_CLAIM_LEASE_MS: number; export interface WorkItemClaim { workItemId: string; owner: string; /** The session doing the work, once one exists. Its liveness frees the claim * ahead of the lease; a claim with no session rides the lease alone. */ sessionId: string | null; claimedAt: string; claimExpires: string; lastHeartbeatAt: string; } export interface ClaimWorkItemInput { workItemId: string; owner: string; sessionId?: string | null; /** Refuse unless the Todo is in this status, decided inside the same statement * as the claim so the status cannot move between the check and the take. */ expectStatus?: WorkItemStatus; } /** `held` means somebody else is working it; `rejected` means the Todo itself * refused (it is gone, or it is not in the status the caller required). */ export type ClaimWorkItemResult = { state: 'acquired'; claim: WorkItemClaim; } | { state: 'held'; claim: WorkItemClaim; } | { state: 'rejected'; reason: string; }; /** Who holds this Todo right now, lease and all. */ export declare function getWorkItemClaim(workItemId: string): WorkItemClaim | undefined; /** * Take the claim, or report who has it. * * The same owner re-claiming renews instead of losing: crash recovery re-enters * the path it was already on, and a worker must never deadlock against itself. */ export declare function claimWorkItem(input: ClaimWorkItemInput): ClaimWorkItemResult; /** Give a claim back. Only its own owner can, so a late release from a worker * whose lease already went to somebody else cannot unlock the new holder. */ export declare function releaseWorkItemClaim(workItemId: string, owner: string): boolean; /** Give back whatever this session was holding — the shape a handoff takes, * where the session that holds the Todo is the one passing it on. */ export declare function releaseWorkItemClaimForSession(sessionId: string): boolean; /** * Renew the lease on whatever Todo this session is linked to. Driven by the turn * heartbeat, which is why it is keyed on the session being linked and live * rather than on owner identity: a Workflow run's claim is renewed by the phase * sessions doing its work, and the worst case is a live worker's lease living * slightly longer — strictly better than a lease that dies mid-work. */ export declare function renewWorkItemClaimForSession(sessionId: string, now?: Date): void; /** * Release every lease that ran out and audit each one, so a Todo becoming * claimable again is a thing its own trail records rather than a silence. * Returns how many were released. */ export declare function expireWorkItemClaims(now?: Date): number; //# sourceMappingURL=claims.d.ts.map