Files
orca/cloud/apps/sandbox-control/migrations/0042_session_cpu.sql
T
Neil 43aa595ee7 feat(sandbox-control): internal per-session CPU tracking and fair-use report (U22)
Customers keep flat sandbox hours. Each stopped session's activeCpuDurationMs
(from Vercel's stop response or GET session) is stored in a new session_cpu
table (migration 0042), idempotent per session. Recording is best-effort and
never blocks suspend, stop or usage reporting; a 5-minute cron sweep retries
recent sessions still missing CPU. Operator-only GET /v1/internal/fair-use
reports per-account 30-day utilisation sum(active_cpu_ms)/sum(wall_ms*vcpus)
with fairUseFlag above 60%. Nothing reaches usage_outbox, billing or clients.
2026-11-10 03:34:00 -08:00

21 lines
868 B
SQL

-- U22: each session's measured CPU, for internal fair-use review only. Customers keep flat
-- sandbox hours: nothing here feeds usage_outbox, billing or any customer-facing route.
-- One row per provider session (idempotent); active_cpu_ms stays NULL until Vercel reports it
-- after the VM stops, and a cron sweep retries the ones still missing. Additive.
CREATE TABLE session_cpu (
session_id TEXT PRIMARY KEY,
sandbox_id TEXT NOT NULL,
account_id TEXT NOT NULL,
user_id TEXT,
vcpus INTEGER NOT NULL,
memory_mb INTEGER,
active_cpu_ms INTEGER,
wall_ms INTEGER NOT NULL,
started_at INTEGER,
ended_at INTEGER NOT NULL,
fetched_at INTEGER,
attempts INTEGER NOT NULL DEFAULT 0
);
CREATE INDEX session_cpu_account_ended ON session_cpu (account_id, ended_at);
CREATE INDEX session_cpu_pending ON session_cpu (ended_at) WHERE active_cpu_ms IS NULL;