import type { Database } from "./database.js"; /** Session statuses that mean work is open (a turn is queued, running, * recovering, waiting for capacity or waiting on a person). A box whose * sessions have one is never drained or counted as viewer-only idle. */ export declare const VIEWER_ONLY_OPEN_SESSION_STATUSES: readonly ["queued", "running", "requires_action", "recovering", "waiting_capacity"]; /** Backends whose warm boxes are outside these bounds: compute boxes are not * drained when idle by design, and selfhosted machines are not leased boxes. */ export declare const VIEWER_ONLY_EXEMPT_BACKENDS: ReadonlySet; export type ViewerOnlyDrainReason = "viewer_idle" | "viewer_workspace_limit" | "viewer_organization_limit"; /** The over-limit drain takes only boxes nobody has used for at least this * long (several viewer heartbeats), so a person using a box is never evicted. */ export declare const VIEWER_ONLY_LIMIT_QUIET_MS: number; export type ViewerOnlyWarmLease = { accountId: string; workspaceId: string; sandboxGroupId: string; leaseEpoch: number; viewerHolders: number; /** Newest of: each viewer's last reported interaction (its attach time when * it never reported one), a turn created or finished in one of the box's * sessions. */ lastActiveAt: Date; /** Database time of the read; decisions measure inactivity against it. */ observedAt: Date; /** Whether any viewer on the box reported interaction (a current client). */ interactionReported: boolean; /** A session of the box has open work; never drained here. */ openSessionWork: boolean; /** A capture, rotation or reaper hold owns the box right now. It still * counts against the limits but is left to that owner this sweep. */ transitioning: boolean; }; /** Warm boxes of one workspace held only by viewers, with their activity. */ export declare function listViewerOnlyWarmLeases(db: Database, input: { accountId: string; workspaceId: string; }): Promise; export type ViewerOnlyDrainOutcome = { drained: true; releasedViewers: number; } | { drained: false; reason: "not_viewer_only" | "epoch_changed" | "open_session_work" | "transitioning" | "active_since_decision" | "compute_commands"; }; /** * Release every viewer holder of one warm, viewer-only box and move it to * draining through the ordinary path (normal idle grace; the reaper then saves * the workspace and stops it). Everything the decision relied on is checked * again under the lease row lock, which heartbeats and attaches also take, so * a viewer that reported interaction or a turn that started after the reaper's * read keeps the box. */ export declare function drainViewerOnlyLease(db: Database, input: { accountId: string; workspaceId: string; sandboxGroupId: string; expectedEpoch: number; reason: ViewerOnlyDrainReason; /** The box is drained only if nothing on it was active for this long, * measured on the database clock under the lease lock. */ quietForMs: number; /** And, when given, nothing was active after this time (the activity the * over-limit decision ranked). */ activeAtOrBefore?: Date; idleGraceMs: number; }): Promise; export type ComputeBoundsDrainReason = "compute_closed" | "compute_daily_budget" | "compute_card_required" | "compute_idle" | "compute_turnless"; export type NoTurnWarmLease = ViewerOnlyWarmLease & { /** The box's backend (`compute` boxes are listed but never idle-drained). */ backend: string; /** Every holder (viewer, direct request, process, Browser/ComputerSession). */ holders: number; /** Process and Browser/ComputerSession holders. */ commandHolders: number; }; /** Warm boxes of one workspace that no turn holds, with their activity. */ export declare function listNoTurnWarmLeases(db: Database, input: { accountId: string; workspaceId: string; }): Promise; /** * The people behind a workspace's warm boxes that no turn holds: the * organization's self-serve owner and the people viewing those boxes. The * reaper reads their standing so a restriction that follows a person from * another organization (held or denied by review) closes these boxes too. */ export declare function listNoTurnWarmLeasePeople(db: Database, input: { accountId: string; workspaceId: string; }): Promise; export type ComputeBoundsDrainOutcome = { drained: true; mode: "drained" | "stop_requested"; releasedHolders: number; } | { drained: false; reason: "not_held" | "epoch_changed" | "open_session_work" | "transitioning" | "active_since_decision" | "compute_commands"; }; /** * Drain one warm box no turn holds under the plan's compute bounds. The * decision is checked again under the lease row lock: a turn that arrived * keeps the box, and for `compute_idle` so does any activity since the read * or open session work. Viewer and direct-request holders are released; a box * still holding processes or a Browser/ComputerSession instead gets a * provider-deadline rotation request (see above). */ export declare function drainNoTurnLeaseForComputeBounds(db: Database, input: { accountId: string; workspaceId: string; sandboxGroupId: string; expectedEpoch: number; reason: ComputeBoundsDrainReason; /** compute_idle and compute_turnless: nothing on the box was active for this long. */ quietForMs: number; idleGraceMs: number; }): Promise;