fix(host-service): resolve teardown from config.json on v2 delete; only skip teardown on explicit retry

Closed
IV
4mo ago
+485-29

Problem

Deleting a workspace on the v2 delete path silently skips the project's teardown scripts in the two most common configurations:

  1. teardown command arrays in .superset/config.json are never executed. The v2 destroy path only looks for a literal file at <worktree>/.superset/teardown.sh and 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.
  2. Any delete with force: true skipped teardown entirely — every "Delete anyway" on a workspace with uncommitted/unpushed changes (run(hasWarnings)), and every CLI/SDK/MCP delete (workspace.delete hard-codes force: true). force conflated "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):

  1. teardown commands from .superset/config.json (+ ~/.superset/projects/<id>/config.json override + config.local.json overlay), joined with &&, run as exec bash -c '…' (same fish-safe exec trick as the existing script path)
  2. <worktree>/.superset/teardown.sh (unchanged behavior)
  3. <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 logs teardown skipped … (force=true, skipTeardown=false), showing forced deletes go through resolution
  • bun run typecheck (28/28 packages), bun run lint clean

ExecPlan with the full investigation and decision log: plans/done/20260707-1351-v2-delete-teardown-resolution.md.


Open in Stage

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 teardown from .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 trailing exit for parity and correct exit codes across bash/zsh/fish.
    • force no longer skips teardown; new skipTeardown input controls bypass and is only set on the TeardownFailedPane "Delete anyway" retry.
    • On force, teardown failures become warnings; non-force still throws the TEARDOWN_FAILED error.
    • Added logs for skips and outcomes; workspaceCleanup.destroy returns teardownStatus: "ok" | "skipped" | "failed" | "not-run".
  • 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.

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.