/** * Tracks work intentionally moved past connector delivery so runtime shutdown, * tests, and latency telemetry can wait for real quiescence. Tasks remain * failure-observable through `runtime.reportError`; normal shutdown drains them * before services and the database disappear, while fast shutdown stays fast. */ import { ElizaError } from "../errors.js"; import type { RoomHandlerLease } from "../runtime/room-handler-queue.js"; import type { IAgentRuntime } from "../types/runtime.js"; type TrackableRuntime = Pick & Partial>; export type PostDeliveryTaskKind = "room-state" | "diagnostic"; export type PostDeliveryTaskOptions = { /** Diagnostic work never mutates state consumed by the next room turn. */ kind: "diagnostic"; } | { /** Room-state work blocks the next turn until it settles. */ kind: "room-state"; roomId?: string; roomHandlerLease?: RoomHandlerLease; }; /** Capture the current connector's delivery boundary while registering work. * Core-only hosts without a connector boundary keep their existing scheduling. */ export declare function roomDeliverySettlement(runtime: TrackableRuntime, roomId: string, lease?: RoomHandlerLease): Promise; /** Finalize connector persistence before evidence-bearing post-turn work starts, * then drain the existing task tracker before allowing the owner to release its * lease. Failure unblocks queued work as cancelled, never as delivered. */ export declare function withRoomDeliverySettlement(runtime: TrackableRuntime, roomId: string, lease: RoomHandlerLease, deliver: () => Promise): Promise; export declare function trackPostDeliveryTask(runtime: TrackableRuntime, label: string, task: (signal: AbortSignal) => Promise, options?: PostDeliveryTaskOptions): Promise; export declare function pendingPostDeliveryTaskCount(runtime: TrackableRuntime): number; export declare function pendingRoomPostDeliveryTaskCount(runtime: TrackableRuntime, roomId: string): number; export declare function drainPostDeliveryTasks(runtime: TrackableRuntime, options?: { signal?: AbortSignal; }): Promise; /** * Permanently refuse runtime reuse and request cooperative cancellation. * JavaScript cannot terminate work that ignores its signal, so pending entries * remain visible until they really settle; callers must isolate or end the * containing process/generation after quarantine. */ export declare function quarantinePostDeliveryTasks(runtime: TrackableRuntime, _reason: unknown): ElizaError; export declare function postDeliveryTaskQuarantineReason(runtime: TrackableRuntime): string | undefined; /** Drain every post-delivery task spawned under one live room owner. */ export declare function drainRoomPostDeliveryTasks(runtime: TrackableRuntime, roomId: string): Promise; export {};