feat(desktop,host-service): project deletion is recoverable for 30 days

Merged
KI
2mo ago
+4576-653

Links

  • Plan: plans/20260927-recoverable-project-deletion.md
  • Issue: #7768 (supersedes the permission-tier approach in #7867)

Summary

  • Deleting a project is now a soft delete. It disappears for everyone on the chosen devices right away, running terminals and agents stop, and it can be restored for 30 days. After that a purge sweep removes it permanently.
  • The delete dialog shows other people's live activity on each device, for example "Alice: 2 terminals running, 1 agent · active 3 min ago". It asks you to type the project name only when someone else has something running, and from the sidebar it offers Hide from sidebar as the alternative that affects only you.
  • An organization owner or the device's owner can delete. Before, only organization owners could, so members couldn't delete projects on their own machines (#7768).

Why / Context

The goal is to stop anyone from accidentally destroying a project other people are actively using. Stopping a deliberate insider is not the goal.

The old delete was permanent. Deleting the project row cascaded through its workspaces, tombstones, tags and PR links. No teardown ran. The terminal reaper then killed the orphaned sessions within about 5 minutes (shouldReapRow reaps rows whose workspace became null), including other people's running agents, with no warning. An owner who misclicked had no way back.

GitHub, GCP, Linear, Figma, Slack and Google Drive guard against this by making deletion recoverable, separating "remove for me" from "destroy for everyone", and warning with live activity. They don't layer permission tiers. This PR follows that pattern instead of #7867's approach: a project creator role, a server-side authorization endpoint, and a stale-count check.

How It Works

Host (packages/host-service)

  • Migration 0037_project_soft_delete adds projects.deleted_at and deleted_by_user_id.
  • project.remove (src/projects/project-deletion.ts):
    1. stamps deleted_at and archives every live workspace with archivedAt = deleted_at, then broadcasts;
    2. runs teardown (best-effort) and disposes terminal sessions for each workspace, in parallel;
    3. leaves the worktrees on disk.
  • project.restore clears deleted_at and un-archives the workspaces whose archivedAt equals it and whose worktree still exists. Workspaces the user deleted earlier stay deleted.
  • project.listDeleted backs the Recently deleted view. project.deletionImpact reports, per workspace, who created it, how many terminals and agents are running, and when it was last active. The dialog reads it once when it opens; nothing polls it.
  • The purge sweep runs at startup and every 6 hours. After the window it removes the rows and clean worktrees; git refuses to remove dirty worktrees, so they stay. The repository folder is never removed.
  • Deleted projects are hidden from project.list, project.get, findByPath, workspace creation and archived-workspace listings.
  • Trap: the interrupted-delete reconciler would treat the kept worktrees as crashed deletes and destroy them, so it now skips soft-deleted projects. A test covers this and fails without the skip.
  • Re-adding the same folder, or setting the project up again, restores it.

Desktop

  • useProjectDeletionHosts: an org owner or device owner can delete, decided from the member lists. It replaces the org-owner-only check in both the settings page and the sidebar.
  • DeleteProjectDialog:
    • a device checklist that defaults to this device, or else the only eligible device;
    • per-device live activity from deletionImpact;
    • type-the-name only when someone else is active;
    • Hide from sidebar when opened from the sidebar;
    • "restorable for 30 days" copy and an Undo toast.
  • Recently deleted page (/settings/projects/deleted), like GitHub's deleted repositories or Linear's recently deleted view. Deleted projects stay out of the live list, which shows only a quiet "Recently deleted · N" link. The page lists each project with who deleted it, when, on which devices, the days left, and Restore.
  • The Undo toast stays up for 10 seconds.
  • Delete permanently… on each Recently deleted row, behind a confirmation. It calls the new host project.purge, which runs the same purge as the 30-day sweep and refuses a project that was never soft-deleted.

Manual QA Checklist

Tested in the dev desktop app over CDP. It used a disposable org, a local relay, and fixture devices running this branch's host service (the local device, one device the member owns, and a shared device owned by someone else). Evidence is in superset-dev-data/qa-soft-delete/ (gitignored).

  • A member deletes their own local project from the sidebar. The device is preselected, their own running terminal doesn't trigger the name prompt, and Hide is offered. In the device database: the project is marked deleted by the member, the workspace is archived with the same timestamp, the sleep 777 terminal process is killed, the worktree stays on disk, and the Undo toast shows
  • Settings → Projects shows a "Recently deleted · 1" link. The page shows "Deleted by Kiet Ho 29 seconds ago · Kiets-Spaceship · 30 days left". Restore brings back the project, the page shows its empty state, and the link disappears
  • The Undo toast is still visible 7 seconds after deleting and gone by 13
  • Delete permanently…: the confirmation explains what is removed and kept. Confirming removes the rows and the clean worktree, keeps the repository folder, shows the empty state and hides the link
  • Delete, then Undo in the toast: the project and workspace are restored
  • An org owner deletes a project another user is using on a shared device. The row shows "QA 7768 Owner: 1 terminal running, 1 agent · active …". Delete stays disabled for a wrong name and enables for the exact one. After deleting, the project is marked deleted and the workspace archived
  • Hide from sidebar in the dialog hides the project for this user only; the device row is untouched, and Undo brings it back
  • Purge, with the deletion backdated 31 days and the device restarted: the rows are gone, the clean worktree is removed, and the dirty worktree with its uncommitted file and the repository are kept
  • No renderer exceptions during the run

Done outside the UI:

  • the workspace and terminal for the first scenario were created through the local device's API;
  • the other user's terminal and agent rows were inserted into the fixture database, because fixture devices can't spawn terminals;
  • the purge scenario was seeded and backdated directly;
  • the org role was switched for the owner scenario and restored afterwards.

Testing

  • bun test src/projects/project-deletion.test.ts (host service), 11 tests:
    • soft delete: timestamps, events, files kept, idempotent;
    • restore: only workspaces deleted with the project, and ones whose worktree is gone stay archived;
    • listings hide deleted projects;
    • the reconciler skip;
    • purge window, worktree removal and repository kept;
    • the live-activity counts.
  • Host service suites for projects, workspaces, cleanup, the reconciler and the database: 334 pass.
  • Desktop: selection, activity summary, permission and Recently deleted merge tests. bun test src/renderer/routes/_authenticated src/renderer/hooks/host-projects: 1254 pass.
  • tsc --noEmit passes for host-service and desktop, Biome passes, and bun run check:i18n passes with all 17 locales translated.

Design Decisions

  • Recoverable instead of permission tiers. A restore window protects against every accident, including an owner misclicking, which no permission check can predict. Permissions stay one coarse rule.
  • Warn with live activity instead of blocking. Killed processes are the only thing a restore can't bring back, so the warning names who has something running. Type-to-confirm appears only then, so it stays rare.
  • Workspaces deleted with the project share its timestamp (archivedAt = deleted_at). That's how restore tells them apart from workspaces deleted earlier, without a new column.

Known Limitations

  • Stopped terminals and agents are not restored; restore brings back rows and worktrees.
  • The permission rule is enforced in the desktop only. The host accepts any authenticated caller, as before; the undo window is the safety net.
  • Deleting individual workspaces still has no per-user check. That predates this PR.
  • The affected people aren't notified.

Risks / Rollout

  • Mixed versions:
    • an older desktop calling a newer host gets a soft delete but has no Recently deleted view; another desktop, or re-adding the folder, restores it;
    • a newer desktop calling an older host gets the old hard delete, and deletionImpact fails, so the dialog simply shows no activity.
  • Rollback: revert the PR. The added columns are nullable. Soft-deleted projects would then reappear in lists on older builds, since those don't filter deleted_at. That fails in the recoverable direction.

Summary by cubic

Makes project deletion recoverable: deleting a project is now a soft delete that can be undone for 30 days, instead of permanently wiping it and killing other people's running terminals minutes later.

Behavior

  • Delete now stamps the project hidden, archives its workspaces, stops terminals and agents, and keeps worktrees on disk so the project can be restored within 30 days (or via an Undo toast); a purge sweep (run off the event loop via the worker pool) then removes rows and clean worktrees.
  • The delete dialog shows other people's live activity per device and only asks for the project name when someone else has something running; from the sidebar it offers Hide from sidebar as a per-user alternative.
  • Settings → Projects gains a "Recently deleted · N" link to a dedicated page listing each deleted project with who deleted it, when, on which devices, days left, and a Restore button; the link disappears when nothing is deleted.
  • Each Recently deleted row also has "Delete permanently…" as a plain red action before Restore, behind a confirmation, which runs the purge now instead of waiting out the 30 days.
  • The Undo toast stays up for 10 seconds so a misclick can be noticed.
  • Members can now delete projects on devices they own; previously only organization owners could (#7768).

Migration

  • Soft-deleted projects will reappear if this PR is reverted, since older builds don't filter deleted_at; a newer desktop against an older host falls back to the old hard delete, and an older desktop against a newer host gets the soft delete without the Recently deleted view.

Summary by CodeRabbit

  • New Features
    • Restore deleted projects for up to 30 days from the Recently deleted settings page, or permanently delete them sooner.
    • Choose eligible devices when deleting a project. The confirmation dialog shows device availability and other users’ active terminals and agents.
    • Hide a project from your sidebar without deleting it.
    • Deleting a project stops active terminals and agents on selected devices. Repository folders are retained, and worktrees with uncommitted changes remain on disk.
  • Bug Fixes
    • Deletion permissions now reflect device ownership as well as organization ownership.
    • Partial deletion and restoration failures provide feedback.