fix(host-service): resolve teardown from config.json on v2 delete; only skip teardown on explicit retry
Problem
Deleting a workspace on the v2 delete path silently skips the project's teardown scripts in the two most common configurations:
teardowncommand arrays in.superset/config.jsonare never executed. The v2 destroy path only looks for a literal file at<worktree>/.superset/teardown.shand never reads config.json — even though the v2 project-settings Scripts editor writes config.json arrays, and the docs (setup-teardown-scripts.mdx: "Delete workspace → teardown commands run") promise they run. This is a regression: #178 added config-array teardown to the original delete path; the v2 unification in #3443 dropped it, and #4090 upgraded only setup to read config while shipping the editor that writes teardown arrays nothing executes.- Any delete with
force: trueskipped teardown entirely — every "Delete anyway" on a workspace with uncommitted/unpushed changes (run(hasWarnings)), and every CLI/SDK/MCP delete (workspace.deletehard-codesforce: true).forceconflated "delete despite dirty files" with "skip the teardown script".
Both skips were silent: no log line, no warning, no result field.
Repro: a project with "teardown": ["./scripts/worktree/teardown.sh"] in .superset/config.json (no .superset/teardown.sh file). Create a workspace, keep it clean, delete it → teardown never runs. Setup runs fine on creation.
Fix
Teardown now resolves exactly like setup (resolveInitialCommand in setup-terminal.ts):
teardowncommands from.superset/config.json(+~/.superset/projects/<id>/config.jsonoverride +config.local.jsonoverlay), joined with&&, run asexec bash -c '…'(same fish-safeexectrick as the existing script path)<worktree>/.superset/teardown.sh(unchanged behavior)<mainRepo>/.superset/teardown.sh— main repo is authoritative; worktrees skip gitignored files (parity with setup)
force no longer skips teardown. A new skipTeardown destroy input (default false) is the only bypass, and the renderer sets it only on the TeardownFailedPane "Delete anyway" retry — where re-running the script that just failed/timed out would only stall the user again. Under force, a teardown failure downgrades to a warnings entry instead of blocking; the non-force TEARDOWN_FAILED typed-error contract is unchanged.
Observability: skips are logged ([teardown] Nothing to run …, [workspaceCleanup.destroy] teardown <status> …) and the destroy result gains teardownStatus: "ok" | "skipped" | "failed" | "not-run".
The legacy external workspace.delete surface keeps force: true and therefore now runs teardown best-effort (failures don't block SDK/CLI deletes).
Testing
- New unit tests for
resolveTeardownCommand(config wins over worktree script; worktree → main-repo fallback; null when unconfigured; whitespace-only commands ignored; quoting) —bun test src/runtime/teardown: 8 pass - Existing integration suites (
teardown,workspace-cleanup,workspace-create-delete): 27 pass; the create-delete run now visibly logsteardown skipped … (force=true, skipTeardown=false), showing forced deletes go through resolution bun run typecheck(28/28 packages),bun run lintclean
ExecPlan with the full investigation and decision log: plans/done/20260707-1351-v2-delete-teardown-resolution.md.
Summary by cubic
Ensure v2 workspace deletes run project teardown and only skip it on an explicit retry after a teardown failure. Teardown now resolves from .superset/config.json and runs in the user's shell (like setup), with clear logs and a teardownStatus in the result.
-
Bug Fixes
- Teardown resolution mirrors setup: read
teardownfrom.superset/config.json(incl. user overrides), else<worktree>/.superset/teardown.sh, else<repo>/.superset/teardown.sh. - Config teardown commands run in the user's shell with
&&and a trailingexitfor parity and correct exit codes across bash/zsh/fish. forceno longer skips teardown; newskipTeardowninput controls bypass and is only set on the TeardownFailedPane "Delete anyway" retry.- On
force, teardown failures become warnings; non-force still throws theTEARDOWN_FAILEDerror. - Added logs for skips and outcomes;
workspaceCleanup.destroyreturnsteardownStatus: "ok" | "skipped" | "failed" | "not-run".
- Teardown resolution mirrors setup: read
-
Migration
- No action required. CLI/SDK deletes (which set
force: true) now run teardown best-effort and may take up to the timeout if teardown hangs.
- No action required. CLI/SDK deletes (which set
Summary by CodeRabbit
-
New Features
- Workspace deletion now supports an independent option to skip teardown during specific retry flows.
- Teardown commands are now resolved from configuration first, with automatic fallback to workspace/repository teardown scripts when not configured.
-
Bug Fixes
- Workspace deletion now reports teardown outcomes more precisely (ok, skipped, failed, or not run).
- Retry and force-delete behavior now preserves teardown unless teardown is explicitly skipped, improving consistency across dirty and conflict cases.