feat(cloud): backfill legacy cloud workspace statuses (ready by a full Vercel listing, deleted by migration)
Links
- Issue: SUPER-3018 · follows #9800 (expand step)
- Stacked contract step: the draft PR that removes the old-spelling reads (linked in a comment below)
Summary
- One-off job
POST /api/cloud-workspaces/jobs/backfill-statusmoves every cloud workspace still at the oldreadytoawakeorasleep. It classifies from a full listing of the Vercel team. - Migration 0195 moves every
deletedrow toarchived, about 5,425 in production. - SDK bumped to
0.0.1-alpha.13, and the release runbook now names the API's legacy-status floors.
Why / Context
#9800 added awake/asleep/archived next to ready/deleted and made the API read both. This PR is the data half of the contract step.
readycan't simply be renamed. Areadyrow with a null expiry reads as awake, and the reconcile only lists boxes whose state changed in its one-hour lookback, so a box that stopped weeks ago is never reclassified by the sweep. The job asks Vercel about every box instead.deletedhas no such ambiguity, so a migration handles it.
At branch time, a fresh production copy had ready=349, deleted=5425, awake=44, asleep=356, archived=3, failed=1.
How It Works
The job (router/cloud-workspace/backfill-status.ts)
It reads every ready row, then listAllSandboxes(). That is the same Sandbox.list as the reconcile, but with no lookback cut-off and no tag filter, matching rows to boxes by name.
| Box | Write |
|---|---|
| running, expiry in the future | recordSandboxAwake (the existing guarded path): awake with the box's expiry and session, a client nudge, and the expiry watch queued |
| stopped, or not listed | batched UPDATE … FROM (VALUES …), 200 rows per statement: asleep, sandbox_expires_at = now(), and the listed session id when Vercel gives one |
| starting, stopping or snapshotting | left at ready for the next run |
Every write requires the row to still be ready, and every live writer moves a row off ready. So a wake that lands after the listing wins, and the job can be re-run safely. It returns and logs { ready, awake, asleep, missing, settling, remaining }.
The route is QStash-signed like the other cloud-workspaces/jobs/* routes and is not scheduled.
The migration (0195_cloud_workspace_status_archived.sql)
UPDATE "cloud_workspaces" SET "status" = 'archived' WHERE "status" = 'deleted';, generated with drizzle-kit generate --custom.
It is one statement, not batches. drizzle runs every pending migration in one transaction (db-migrations skill, rule 1), so batches inside it would not release any lock sooner. The statement locks only the rows it changes.
SDK and runbook
- The SDK is unpublished, and its
VERSIONhad stayed at0.0.1-alpha.12. So main's own SDK, whose types already sayawake | asleep | archived, got the legacy names from the mapper. Bumping it to its floor fixes that. - The other floors were checked against the repo and the runbook: the next desktop/CLI release is cut from main at 2.0.10 or above, and mobile 1.2.3 is a safe lower bound. They are unchanged.
Rollout
- Merge: the deploy runs 0195, then ships the API with the job route.
- In the QStash console, publish once to
https://api.superset.sh/api/cloud-workspaces/jobs/backfill-status(POST, empty body). The URL must match production'sNEXT_PUBLIC_API_URLexactly, because the signature is verified against it. Repeat until the response says"remaining": 0. A run can leave rows only when Vercel was starting or stopping a box at that moment. - Confirm with
select count(*) from cloud_workspaces where status in ('ready','deleted'), which must return 0. Then the stacked draft PR can merge.
Testing
- Rehearsal: on fresh Neon children of production, with
lock_timeout=5sandstatement_timeout=60s, under concurrentpsqlload (4 readers on the list query, 2 writers on live rows, 1 writer holding locks on deleted/archived rows):drizzle-kit migratepassed: 5,425 rows becamearchived, other statuses were untouched, and the load saw 0 errors.- A second pass ran the statement alone:
UPDATE 5425in 205 ms, with 0 load errors.
- The job's real SQL against real data: on a production copy, with the listing stubbed to return nothing (see Known Limitations), all 349
readyrows becameasleepin two batches withremaining: 0. A re-run foundready: 0and wrote nothing. - Unit tests (
backfill-status.test.ts): each class of box gets the right write, the batch is guarded bystatus = 'ready', a settling box is left for the next run, and a run with noreadyrows never lists Vercel. - Checks:
bun run lint:fix: no fixes needed.- Typecheck (trpc, db, sdk, api, shared): clean.
- Tests: trpc 965, shared 1686, api 260, 0 fail.
check:i18n,sherif,check:plugins,check:versions: clean.
Known Limitations
- The job's run against real Vercel data is unrehearsed. This workspace's
.envVercel token is rejected (403 invalidToken). The live listing is the sameSandbox.listthe reconcile uses every 30 minutes; only the cut-off is removed. - Each run lists the whole team. If that ever takes longer than the route's window, QStash retries, and a second run is harmless because both are guarded by
status = 'ready'.
Rollback
- Code: reverting removes the route; nothing else depends on it.
- Migration: 0195 is forward-only. #9800's API reads
archivedanddeletedalike, so there is nothing to undo unless the API itself is rolled back past #9800 (see that PR's rollback note).
Summary by cubic
Backfills the legacy cloud workspace statuses after #9800 added awake/asleep/archived alongside ready/deleted.
- Adds a one-off, QStash-signed job (
POST /api/cloud-workspaces/jobs/backfill-status) that moves every row still atreadytoawakeorasleep, classified from a full Vercel team listing. The reconcile can't do this because it only lists boxes that changed in its one-hour lookback. - Migration 0195 moves
deletedrows toarchived(~5,425 in production). - Bumps the SDK to
0.0.1-alpha.13so main's SDK stops receiving the legacy names, and documents the status floors in the release runbook.
The job is not scheduled: publish it once from the QStash console and repeat until it reports remaining: 0. Every write requires the row to still be ready, so re-running is safe. The run against real Vercel data is unrehearsed (the dev Vercel token is rejected), but it uses the same Sandbox.list as the reconcile without the lookback cut-off.
Rollout
- Merge: the deploy runs 0195, then ships the job route.
- Publish to
https://api.paradev.com/api/cloud-workspaces/jobs/backfill-statuswith an empty body; repeat untilremaining: 0. - Confirm nothing remains at
readyordeleted, then merge the stacked PR that removes the legacy reads.
Rollback
- Reverting removes the route; nothing else depends on it.
- Migration 0195 is forward-only, but the API reads
archivedanddeletedalike, so nothing to undo unless the API itself rolls back past #9800.