Skip to content

An open-source, faster Devin alternative

TypeScript

Port paused-hibernation D1 change to the api-edge migrations ledger

Brian Reardon3e1f6e3ddf73
diff --git a/cloudflare-workers/api-edge/migrations/0001_paused_hibernation_mode.sql b/cloudflare-workers/api-edge/migrations/0001_paused_hibernation_mode.sql
new file mode 100644
index 00000000..66773d77
--- /dev/null
+++ b/cloudflare-workers/api-edge/migrations/0001_paused_hibernation_mode.sql
@@ -0,0 +1,13 @@
+-- Two-tier hibernation: surface the internal hibernation tier in the D1
+-- cross-cell index so the api-edge paused-cap enforcer (and the dashboard's
+-- cross-cell view) can see it. Mirrors sandbox_sessions.hibernation_mode in each
+-- cell's Postgres (internal/db/migrations/052_paused_hibernation_mode). The
+-- customer-facing status stays 'hibernated'; hibernation_mode is
+-- 'paused' | 'deep' | NULL (running).
+ALTER TABLE sandboxes_index ADD COLUMN hibernation_mode TEXT;
+
+-- runPausedCapEnforcer scans an org's paused rows oldest-first to promote the
+-- excess to deep hibernation, so index paused rows by (org, age).
+CREATE INDEX IF NOT EXISTS idx_sandboxes_paused
+ ON sandboxes_index(org_id, last_event_at)
+ WHERE hibernation_mode = 'paused';
diff --git a/cloudflare-workers/schema_phase11_paused_hibernation_mode.sql b/cloudflare-workers/schema_phase11_paused_hibernation_mode.sql
deleted file mode 100644
index b7e78234..00000000
--- a/cloudflare-workers/schema_phase11_paused_hibernation_mode.sql
+++ /dev/null
@@ -1,22 +0,0 @@
--- Phase 11: two-tier hibernation on sandboxes_index (cross-cell paused cap).
---
--- sandboxes_index.status stays customer-facing (running | hibernated | stopped).
--- hibernation_mode is the internal tier, mirrored from the cell:
--- 'paused' — RAM-resident on its worker (instant resume, unbilled)
--- 'deep' — savevm'd + evicted to a checkpoint
--- NULL — running
--- Only D1 has the org-global, cross-cell view (an org is best-effort single
--- cell, not guaranteed), so the api-edge uses this column to enforce the
--- per-org paused cap. events-ingest maintains it on paused/hibernated/woke.
---
--- Apply with:
--- wrangler d1 execute opencomputer-prod --remote --file cloudflare-workers/schema_phase11_paused_hibernation_mode.sql
---
--- SQLite/D1 has no ADD COLUMN IF NOT EXISTS, so this is one-shot.
-ALTER TABLE sandboxes_index ADD COLUMN hibernation_mode TEXT;
-
--- The cap enforcer scans an org's paused rows oldest-first. last_event_at is
--- ~the pause time, so it doubles as the promotion ordering key.
-CREATE INDEX IF NOT EXISTS idx_sandboxes_paused
- ON sandboxes_index(org_id, last_event_at)
- WHERE hibernation_mode = 'paused';