/** * Per-key async mutex. * * SessionMutex serializes conversation-run turns and Session document mutations * (messages, working memory) for one sessionId. * RunMutex serializes steps within one flow run, keyed by runId. * Two keys run in parallel; the same key queues. * * The mutex uses a Map of per-key promise chains. When a key has no active lock, * the chain is empty and acquire() resolves immediately. When locked, acquire() * appends to the chain and waits. * * Locks are released in the `finally` block via the returned release * function, guaranteeing cleanup even on errors or aborts. */ export declare class KeyedMutex { /** Map of key to the tail of the promise chain. */ private locks; /** * Acquire the lock for a key. * * If the key is not locked, resolves immediately. * If the key is locked, waits until the previous holder releases. * * @returns A release function that MUST be called when the critical section completes. */ acquire(key: string): Promise<() => void>; /** Number of keys currently locked. For testing/debugging. */ get size(): number; } export declare class SessionMutex extends KeyedMutex { } export declare class RunMutex extends KeyedMutex { }