Delete workspace

ready…
osebo56d ago

I want the ability to delete workspaces

2 repliesoldestnewest
Osebotfable-5-156d ago

Plan: owner-only workspace deletion

Mirroring the existing thread-delete flow (components/delete-thread.tsx + DELETE /api/threads/[id]):

  1. lib/data.ts — deleteWorkspace(id): a single db.delete(workspaces). Every child table already has onDelete: "cascade" (members, invites, repos, threads → posts/jobs/embeddings/candidates, memory notes), so no manual fan-out and no migration.
  2. app/api/workspaces/[id]/route.ts (new) — DELETE, guarded with requireMember(id, user, "owner"). Members get 403, non-members 404 (existing convention).
  3. components/workspace-forms.tsx — DeleteWorkspaceButton: same two-tap arm/confirm pattern as DeleteThreadButton, redirects to /workspaces on success.
  4. app/workspaces/[id]/page.tsx — a "Danger zone" card at the bottom, rendered for owners only, spelling out what gets removed.

Running jobs: if a workspace is deleted mid-run, the job row cascades away, the runner's callbacks start getting 401 from authJob, and the sandbox dies at its wall-clock timeout. That's identical to deleting a thread today — I'm not adding sandbox-killing here.

Osebotfable-5-156d agothreadide@f7d94f5

Done — owners can now delete workspaces. Pushed as f7d94f5 on thread/92313ff0 (tsc clean, no migration needed).

What changed

  • app/api/workspaces/[id]/route.ts (new) — DELETE. Owner-only via requireMember(id, user, "owner"): members get 403, non-members 404, same as the other owner routes.
  • lib/data.ts — deleteWorkspace(id): one db.delete(workspaces). I verified in drizzle/*.sql that all 7 workspace_id FKs and both thread_id FKs are ON DELETE cascade, so members, invites, repos, threads → posts/jobs/embeddings/memory candidates, and memory notes all go with it.
  • components/workspace-forms.tsx — DeleteWorkspaceButton, same two-tap arm/confirm pattern as DeleteThreadButton (turns red "really delete this workspace?", auto-disarms after 4s). Redirects to /workspaces on success, shows Failed: <status> inline otherwise.
  • app/workspaces/[id]/page.tsx — "Danger zone" card at the bottom, owners only, stating the live thread/memory-note counts that will be removed and that nothing on GitHub is touched.

Screenshot attached: static mockup against the real globals.css at 390px, resting and armed states.

Worth knowing

  • Running jobs. If a workspace is deleted mid-run, the job row cascades away, so the runner's callbacks start failing authJob (401) and the sandbox exits at its wall-clock timeout (SANDBOX_TIMEOUT_MS, default 45 min). This is identical to deleting a thread today. If we ever want to actively kill the sandbox on delete, jobs.sandboxId is already stored for that.
  • The members route's existing error — "owner can't leave; transfer or delete the workspace" — is now actually actionable. There's still no ownership transfer; that'd be a separate task.
  • Non-owner members see no delete affordance at all; only the API enforces the 403.

Ready for a PR from thread/92313ff0 whenever you want it.

Danger zone card on the workspace page at 390px — resting state (top) and armed two-tap state (bottom). Static mockup against the real globals.css.
Danger zone card on the workspace page at 390px — resting state (top) and armed two-tap state (bottom). Static mockup against the real globals.css.