import type { SandboxFleetLimits } from "@opengeni/config"; import type { Database } from "./database.js"; export declare const SANDBOX_UNPAID_FLEET_ROUTINE = "opengeni_private.sandbox_unpaid_fleet_v1(uuid, boolean)"; export declare const SANDBOX_FLEET_WARM_BOXES_ROUTINE = "opengeni_private.sandbox_fleet_warm_boxes_v1()"; /** Fleet pressure as admission sees it. `failed`: no warm count could be read * recently, so admission fails closed for unpaid organizations. */ export type SandboxFleetPressure = { engaged: boolean; warmBoxes: number | null; failed: boolean; }; /** Forget the process's fleet state (tests). */ export declare function resetSandboxFleetState(): void; /** * Apply one warm count to the pressure state: engage when it exceeds * `pressureEngageWarmBoxes`; release once every reading for * `pressureReleaseAfterMs` (none: at once) has been below * `pressureReleaseWarmBoxes` (none: at or below the engage level). Returns * the transition, if any. */ export declare function observeSandboxFleetWarmBoxes(limits: SandboxFleetLimits, warmBoxes: number, now?: number): "engaged" | "released" | null; /** * Fleet pressure for one admission, reading the warm count at most every * fifteen seconds per process. A failed read keeps the last good reading for * two minutes and then reports `failed`. */ export declare function readSandboxFleetPressure(db: Database, limits: SandboxFleetLimits, options?: { onReadFailure?: (error: unknown) => void; now?: number; }): Promise; /** The unpaid running boxes (excluding one lease) and, when asked for, the * unpaid box seconds metered since 00:00 UTC. */ export type SandboxUnpaidFleetCounts = { runningBoxes: number; boxSecondsToday: number | null; }; /** * Whether this database lets the runtime call the unpaid-fleet definer. 1486 * creates it with EXECUTE withheld, because the previous release rejects a * runtime grant on a definer it doesn't know; a later migration grants it. * Until then the unpaid running cap and fleet box-time budget are inactive. */ export declare function sandboxUnpaidFleetAvailable(db: Database, now?: number): Promise; /** Read the unpaid fleet; null when the definer is not available yet. */ export declare function readSandboxUnpaidFleet(db: Database, input: { excludeLeaseId: string | null; withBoxSeconds: boolean; }): Promise; /** * Today's unpaid box time for one admission, read at most every minute per * process. Null when the definer is not available yet. Throws when the read * fails, so admission can fail closed; a failure is reused for fifteen * seconds, so a struggling database is not read once per admission. */ export declare function readSandboxUnpaidFleetBoxSecondsToday(db: Database, now?: number): Promise; /** * Serialize new unpaid boxes across the fleet, so two admissions cannot both * take the last slot. Taken after the organization's own limit lock. */ export declare function lockSandboxUnpaidFleet(tx: Database): Promise;