cli icon indicating copy to clipboard operation
cli copied to clipboard

stack: keep a project directory's stack across git branch changes, and add a prune command for stacks that no longer match a directory

Open luizfneves404 opened this issue 3 weeks ago • 0 comments

Existing issues

  • [x] I have searched the existing issues.

Affected area

Local development

Problem to solve

A managed stack is identified by the project root, the branch context and the stack name (packages/stack/src/identity/Identity.ts, deriveStackId). When the branch context changes, the directory stops selecting its stack, and the old stack stays where it is.

Observed on Supabase CLI 3.1.0: we created a stack in a project directory that was not a git repository (branch context ordinary-workspace). After git init on a main branch, supabase --experimental stack status reported "No managed stack exists for the selected project", while supabase --experimental stack list still listed the old stack under ordinary-workspace.

Nothing removes such stacks in bulk. The stack subcommands at 3.1.0 are destroy, install, list, logs, outdated, restart, start, status, stop and update. destroy takes a stack id and requires --yes; nothing finds the stacks whose directory no longer exists or no longer selects them.

Proposed solution

  1. An option that takes the branch out of the stack identity, so a directory keeps its stack when it changes branch, for example supabase stack start --ignore-branch.
  2. supabase stack prune, which lists the stacks whose project root no longer exists or no longer selects them, and removes them with --yes. Dry run by default.

Alternatives considered

Destroying each stack by id with supabase stack destroy --stack-id <stack id> --yes. This works, but the ids have to be found first, and nothing lists the orphans.

Additional context

  • #7162 (open) covers --stack on migration commands and describes the branch problem for them. This request is about identity and cleanup, not command targeting.
  • #6962 and #6963 (closed) cover helper containers left behind when an owner process dies or a stack directory is deleted. They do not cover the stack identity.

luizfneves404 avatar Nov 10 '26 22:11 luizfneves404