/** * Per-child serial write queue infrastructure for ChildWriter. * * Provides stale-queue detection and serial write enqueue logic * to prevent concurrent read-modify-write corruption on child `.json` files. * * @module session-tracker/persistence/child-writer-queue */ import type { ChildWriteRetryQueue } from "./retry-queue.js"; /** Minimal structured logger matching the harness pattern. */ interface Logger { debug: (msg: string, data?: unknown) => void; warn: (msg: string, data?: unknown) => void; error: (msg: string, data?: unknown) => void; } /** * Inject a structured logger into the child-writer-queue module. * Called by the plugin composition root to wire the harness-level logger. */ export declare function setQueueLogger(injected: Logger): void; /** Data envelope for retry queue enrollment on write failure. */ export interface RetryData { sessionID: string; parentID: string; data: Record; } /** * Threshold (in milliseconds) before a per-child queue is considered * stale and auto-reset. Shared across ChildWriter instances. */ export declare const STALE_QUEUE_MS: number; /** * Detects and resets a stale write queue for a given child. * * If no write has completed for this child file within `STALE_QUEUE_MS`, * the queue is replaced with a fresh resolved promise so subsequent * writes are not blocked by a stuck preceding promise. * * @param queueKey - The queue key (`parentID/childID`). * @param writeQueues - The per-child queue map. * @param lastWriteTimes - The per-child last-write timestamp map. */ export declare function detectStaleQueue(queueKey: string, writeQueues: Map>, lastWriteTimes: Map): void; /** * Enqueues a write operation into the per-child serial queue. * * Stale-queue detection runs first to auto-recover from a frozen pipeline. * Chains the provided function onto the end of the child's write queue * so that only one write per child file is in-flight at a time. Records * `lastWriteTime` on success. Failed writes are enqueued to the retry * queue (RC-5) and the error is propagated to the caller. * * @param queueKey - The queue key (`parentID/childID`). * @param fn - The write operation to enqueue. * @param retryData - Optional data for retry queue enrollment on failure. * @param writeQueues - The per-child queue map (mutated in place). * @param lastWriteTimes - The per-child timestamp map (mutated in place). * @param retryQueue - Optional retry queue for failed writes (RC-5). * @returns Promise that resolves when the enqueued write completes. */ export declare function enqueueWrite(queueKey: string, fn: () => Promise, retryData: RetryData | undefined, writeQueues: Map>, lastWriteTimes: Map, retryQueue: ChildWriteRetryQueue | undefined): Promise; export {}; //# sourceMappingURL=child-writer-queue.d.ts.map