fix(cloud): store the branch a sandbox works on instead of deriving it

Merged
SA
2mo ago
+22159-8

What

cloud_workspaces now stores two branches: branch is the one the sandbox works on (superset/<slug>-<id>, cut once at create) and base_branch is what it was cut from. The claim and environment.promote read the row instead of re-deriving the working branch from the name.

Why

branch held the base and the working branch was re-derived on every claim from the mutable name, so:

  • a rename moved the working branch under the box;
  • the sidebar's cloud PR lookup keyed on cloud.branch — the base, usually main — which getByBranches skips by design, so a closed box never showed its PR chip. Only the open box did, via the served host row.

Now the sidebar keys on the branch the PR was actually opened from, for every box.

Migrations

  • 0123 (custom): DELETE FROM cloud_workspaces. Every row predates the split and all are internal; dropping beats a backfill that would have to reproduce the slug derivation in SQL. cloud_workspace_repositories cascades.
  • 0124 (generated): ADD COLUMN base_branch text NOT NULL.

Before merge I'll superset ws delete the live cloud workspaces so their sandboxes are reclaimed; the migration then clears the rows.

Verified

  • Applied to a fresh Neon branch off production: 0 rows, both columns NOT NULL.
  • Root typecheck 42/42, Biome clean, sandbox/cloud-workspace/environment tests pass.
  • Not yet shown in the app: no box has ever opened a PR on its working branch (checked the PR table), so I'll create one after merge and screenshot the closed-box chip.

https://claude.ai/code/session_01BVBuTCFBb1JkoX76VpLAQ8


Summary by cubic

Stores the branch a cloud sandbox works on in cloud_workspaces.branch instead of re-deriving it from the name on each claim. branch previously held the base branch, so a rename moved the working branch and the sidebar's PR lookup keyed on the base branch — usually main, which the lookup skips — leaving every closed box without a PR chip. The row now records both the working branch (cut once at create) and base_branch, and claim and promote read both.

Migration

  • Migration 0123 clears all existing cloud_workspaces rows (internal-only, predate the split; dropping beats backfilling in SQL), and 0124 adds base_branch (NOT NULL).
  • Sandboxes behind the dropped rows are reclaimed before merge.

Summary by CodeRabbit

  • Cloud Workspaces
    • New workspaces now use a dedicated working branch while retaining the branch they were created from. Workspace creation, claiming, and promotion use these branches consistently.
    • Existing cloud workspace records are cleared during the migration; associated repositories are removed through cascading deletion.