Repository navigation
Description
Problem
A worktree environment whose setup hook was interrupted can never finish teardown. It retries every minute, indefinitely, and no supported command recovers it.
Seen on a Linux host: a git-worktree environment of an archived thread, status error, lifecycle.teardown failed, attempt 7,873 since about Oct 15 2026. Each attempt fails with:
Environment hook outcome is unknown after interruption. Automatic cleanup is blocked; inspect the workspace before recovering it.
bb environment cleanup <environment-id> returns {"ok": true} and changes nothing. That holds even after the workspace was inspected and removed by hand: the tree was clean, HEAD d722659a was already on origin/main, and the worktree was removed with git worktree remove. The message tells you to "recover" the environment, but there is no recover command (bb environment --help, bb guide).
Cause (at ab04f04)
- When removal follows a cancellation,
environment-engine.ts:896callscancelPendingEnvironmentHookfor the…:setupoperation, whoseenvironmentHookOperationsrow was never finished. - After the interruption (for example a daemon restart), the host daemon no longer has that operation in memory.
apps/host-daemon/src/command-handlers/environment-hook.ts:106-108then returns{ status: "unknown" }. apps/server/src/services/environments/environment-hooks.ts:172-175throws onunknownbefore it marks the row finished, so every retry hits the same throw.
"Unknown" covers two different cases. A daemon that never heard of the operation (or restarted) cannot have a hook still running. A hook whose termination really couldn't be verified (terminationUnverified) might be. Today both cases are treated as an indefinite block.
Expected
- If the operation isn't known to the current daemon instance, and that daemon started after the operation's
startedAt, record the hook as finished/interrupted and continue teardown. A daemon boot ID or a start-time comparison would make that safe. - Keep the block only for a real
terminationUnverifiedoutcome. Even then, offer a supported recovery after inspection:bb environment cleanup <id> --recover, or a documented recovery step, that marks the hook finished and retries removal. - Stop the per-minute retry loop once a teardown is blocked on manual recovery: back off, or move to a terminal "needs recovery" state that
bb environment listshows.
Tests
- A server test where the daemon cancel returns
unknownfor an operation unknown to a daemon that restarted afterstartedAtfails today and should pass. Teardown should then complete. terminationUnverifiedstill blocks automatic cleanup, and the recovery command unblocks it.
Safety note
Production processes can look tied to such a worktree when they aren't. pnpm hard-links the store, so a production .node file and esbuild share inodes with files under the worktree's node_modules (link counts 59 and 115). /proc/<pid>/maps and exe resolve to the production install, so removing the worktree only lowers link counts. Any cleanup tooling should judge "in use" by path in /proc/<pid>/maps and cwd, not by inode.
Activity
brsbl commentedon Oct 21, 2026
The restart-safety assumption is disproved on current main (
405592c0b71b1655a6ab2e1cc7498b5beeb78caa, Linux).environment-lifecycle-script.ts:217–223launches hooks in detached process groups. In an owned, isolated fixture, I invoked the actualrunSetupScript, waited for its script to record its PID, then sent SIGKILL only to the invoking Node process. The hook remained alive:The hook had been reparented to the fixture supervisor. I then killed only that recorded fixture PID. No production process or environment was inspected or changed.
There is a second relevant case: current setup executes through
RuntimeManager.createEntry, outside the hook RPC registry. Cancellation can therefore encounter no hook-operation row at all.Approved revised scope for #5961: preserve blocking of ambiguous outcomes; bound retries with backoff and expose a terminal “Needs recovery” message; add explicit
cleanup --recoverafter inspection. Recovery must refuse workspace cwd/mapped-path users and unreadable processes owned by the daemon UID. Other users’ processes require separate inspection. A newer daemon instance alone will not authorize automatic deletion. Durable process ownership and automatic restart recovery will be tracked separately.BB-Thread-ID: thr_7y7sh3cxeb
bb-slop-cop commentedon Oct 21, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotworkspaces.confirmed-reproapplied.Bound environment teardown retries and add guarded recovery (#5961)
Give every persisted retry schedule one owner, an attempt cap and a n…