import type { Database } from "./database.js"; import * as schema from "./schema.js"; import { type SessionEventWriteFenceLocks } from "./session-control.js"; export type TurnAttemptFenceRejectReason = "workspace_paused" | "session_paused" | "pending_control" | "active_turn_changed" | "generation_changed" | "attempt_changed" | "turn_terminal" | "not_found"; type FenceRows = { workspace: NonNullable; session: SessionEventWriteFenceLocks["sessions"][number]; turn: SessionEventWriteFenceLocks["turns"][number]; attempt: SessionEventWriteFenceLocks["attempts"][number]; }; type FenceResult = ({ allowed: true; } & Rows) | ({ allowed: false; reason: TurnAttemptFenceRejectReason; } & { [Key in keyof Rows]: Rows[Key] | null; }); export type TurnAttemptEventFenceResult = FenceResult; export type TurnAttemptFenceResult = FenceResult<{ workspace: typeof schema.workspaces.$inferSelect; session: typeof schema.sessions.$inferSelect; turn: typeof schema.sessionTurns.$inferSelect; attempt: typeof schema.sessionTurnAttempts.$inferSelect; }>; type TurnAttemptWriteFenceInput = { workspaceId: string; sessionId: string; turnId: string; executionGeneration: number; attemptId: string; sessionLock?: "no_key_update" | "key_share"; rowProjection?: "full" | "event"; }; /** * Lock order for every activity write fence: workspace control -> actual * workspace -> session -> exact turn -> exact attempt. * * Activity writes only need a shared workspace admission lock: concurrent * sessions may write independently, while an exclusive workspace Pause/Resume * still waits for every admitted write and prevents later writes from crossing * the control boundary. Using FOR UPDATE here serialized every active session in * one workspace behind a single row and turned streaming into a workspace-wide * lock queue. */ export declare function lockTurnAttemptWriteFenceTx(tx: Database, input: TurnAttemptWriteFenceInput & { rowProjection: "event"; }): Promise; export declare function lockTurnAttemptWriteFenceTx(tx: Database, input: TurnAttemptWriteFenceInput & { rowProjection?: "full"; }): Promise; export {};