import { type SQL } from "drizzle-orm"; /** * A request whose owner lost its execution and that nothing can settle any * more. Its holder is gone from the lease, it was never adopted as a retained * process, and its provider outcome is still unknown. Two owners leave this * shape: * * - a turn attempt closed `lease_lost_recoverable` or `failed` (worker death, * redispatch exhaustion, credential-lease loss); * - an API-direct request (Files, Terminal, Browser and similar surfaces) * whose API process died mid-operation. A live direct request heartbeats its * holder for the whole operation and settles its admission before releasing * it (`releaseLeaseHolder` rejects any null outcome it left), so a direct * admission without its holder was left by a holder the TTL reaper removed. * * Either way the owner can admit no more work, and the only physical writer the * request can stand for is a command that may still be running on that exact * box. It must not pin the sandbox (drain, command containment, deadline * rotation) or refuse checkpoints forever. * * This does not prove the owning process is dead. Safety comes from what the * callers do: a drain captures around the request only when its capture is a * point-in-time image of a stopped or paused box and terminates that box next, * a warm capture only when it is a point-in-time image and then records itself * as having run around writers, and the request is rejected only in the cold * commit after the exact box was terminated or proven gone. A late settlement * by a still-running owner is then fenced. Pause, Steer and cancellation * closures keep their requests as writers because the replacement attempt * resumes the same box; the holder clause is defence in depth for turns. */ export declare function crashedWorkerOrphanAdmissionSql(admission: SQL): SQL; /** Physical writers retain ownership after logical settlement. A durably * adopted background command owns its lifetime independently of the turn. * * `containment` is the physical predicate minus crashed-worker orphans * (`crashedWorkerOrphanAdmissionSql`). Only sandbox containment, drain and * deadline decisions use it, because those settle the orphan themselves once * the exact box is gone; the quiescence receipt keeps the strict predicate. * * The predicate is correlated per attempt row. A session-wide scan must first * restrict rows to `sessionPendingWriterAttemptIdsSql`, otherwise it evaluates * these subqueries for every attempt the session ever ran. */ export declare function sessionAttemptPendingWritersSql(attempt: SQL, mode?: "physical" | "inference" | "containment"): SQL; /** One session, addressed by bound workspace and session ids. */ export type SessionAttemptScope = { workspaceId: string; sessionId: string; }; /** * The attempt ids in one session for which `sessionAttemptPendingWritersSql` * can be true, in any mode. It is a superset: callers still apply the exact * predicate to these rows. Every branch of that predicate needs either an * unsettled workspace-mutation admission of the session (owned by the attempt * itself, or by a retained process the attempt owns) or an active retained * process the attempt owns, so these three sources cover it. * * The subquery is uncorrelated. Postgres evaluates it once and probes it as a * hashed set, so the check costs the session's pending work, not its history. * The unsettled admissions are read through * `sandbox_workspace_mutation_admissions_unsettled_session_idx` (migration * 0879) and active processes through `sandbox_retained_processes_active_idx`. */ export declare function sessionPendingWriterAttemptIdsSql(scope: SessionAttemptScope): SQL; /** * The attempt ids in one session that can still await a physical-quiescence * receipt: possible pending writers, attempts with a settled or stale Pause or * Steer interruption, and the session's newest attempt (the only one that can * be an unsucceeded same-turn recovery). Like the writer set it is an * uncorrelated superset, so the exact quiescence predicate runs only on these * rows instead of every closed attempt in the session's history. */ export declare function sessionQuiescenceCandidateAttemptIdsSql(scope: SessionAttemptScope): SQL; /** * A cheap test that must hold whenever some attempt of the session still owns * the physical-quiescence gate, in any writer mode. Its three parts follow the * three ways an exact attempt can await its receipt: * * - a pending writer, which needs an unsettled admission or an active retained * process in the session (`sessionPendingWriterAttemptIdsSql` is non-empty); * - a settled or rejected-stale Pause/Steer interruption of a closed attempt * whose receipt is still missing; * - same-turn recovery debt, which only the session's newest attempt can carry * (it needs an `interrupted_recoverable` outcome and no successor; newest * uses the same order as the candidate set). * * When it is false the exact predicate is false in the same snapshot, so the * caller can answer without the exact query. That query mostly costs planning: * its row-security subqueries take tens of milliseconds to plan on every call, * and nearly every session has none of these rows. When it is true the caller * still runs the exact predicate unchanged. */ export declare function sessionMayAwaitQuiescenceSql(scope: SessionAttemptScope): SQL;