Skip to content

Deleting a worktree environment leaves its processes running #1647

Closed

Description

@MGrin

Deleting a bb worktree environment removes the directory but does not kill the processes started inside it. They survive with a working directory that no longer exists, and nothing reaps them.

Measured

On a 10-core Mac, 2026-08-14:

  • 40 removed environments still held 190 live processes and 1.75 GB RSS
  • swap at 94%, kernel_task at 57% CPU on paging alone, load near 20
  • every process-holding environment was a deleted one; none of the 8 live worktrees held any

Reproduction

  1. Create a worktree environment in a project with a dev server (next dev, vite, etc.)
  2. Let the server start
  3. Delete the environment
  4. The server process is still running, with cwd pointing at the deleted path

Suggested fix

Kill the process group on environment teardown. Processes started in an environment are already associated with it; the teardown path just doesn't signal them.

Workaround in use

An hourly local sweeper that reaps processes whose cwd is a deleted environment path. That is a workaround — a machine without it inherits the leak, and the leak is what drove the box into swap.

Activity

  1. added theissue type on Aug 17, 2026
  2. added
    workspaces
    on Aug 18, 2026
  3. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Evidence from #1769 (closed as duplicate): on bb 0.38.0 / macOS 26 one machine had 40 destroyed environments still holding 190 live processes and 1.75 GB RSS, swap at 94%, load ~20 on 10 cores. Every process-holding environment was a deleted one; none of the 8 live environments had orphans. A claude provider process was alive 12h46m after its environment was destroyed. Also related: #1660, #1604, #1363.

    AGENT GENERATED: by Claude Opus 5

  4. SawyerHood commented on Aug 18, 2026

    @SawyerHood
    Collaborator

    Reproduction & root-cause report: https://get-bb.github.io/reports/issues/1647.html

    • Verdict: REPRODUCED · root-cause confidence: high
    • Root cause (short): RuntimeManager.destroyEnvironment only SIGTERM/SIGKILLs the direct provider bridge pid and SIGHUPs the terminal shell pid (spawned in the daemon's own process group, no group signal, no cwd sweep) before git worktree remove --force, so anything those children detached (nohup dev servers, background jobs, MCP servers after a force-kill, or processes from a pre-restart daemon) survives with a deleted cwd and is never reaped.
    • Linked PR review: Kill processes left in a destroyed worktree environment #1696 → REQUEST CHANGES (minor) — killProcessesWithCwdUnder is ownership-agnostic: it SIGTERM/SIGKILLs any user process whose cwd is inside the workspace (demonstrated with a non-bb setsid sleep rooted in the worktree, pid 1641293 reaped), i.e. a user's own shell/editor terminal in the worktree dies on environment delete — accepta
    • Proposed fix: Two daemon-side layers, no protocol bump: (1) spawn provider CLIs / setup scripts / command terminals as POSIX process-group leaders (detached:true) and signal the group on shutdown, with escalation keyed on 'any group member alive' — but SIGTERM the leader first so the bridge's graceful shutdown still drives the CLI down, group-signal only at the SIGKILL escalation; (2) before workspace.destroy() for a managed workspace, list processes whose cwd is at/under the workspace (Linux /proc/*/cwd, macOS lsof -d cwd), SIGTERM, short grace, rescan, SIGKILL, and log the reaped pids; optionally add a on…
    • Caveats: The '12h-old claude process' from Deleting a worktree environment leaves its processes running with a cwd that no longer exists #1769 was not reproduced: in my idle and mid-turn runs the claude-code bridge handled SIGTERM gracefully and took claude with it; leaking the CLI itself needs the 5s SIGKILL fallback or a daemon restart before destroy (both real code paths, not provoked live). All reproduction is on Linux; macOS uses the same daemon code path but its lsof-based sweep in the PR was…

    The report has copy-paste repro steps, screenshots where the bug is visual, code permalinks at 16ceb3a54, and repro artifacts. It was independently re-run by a second agent (see its Verification section).

    AGENT GENERATED: by Claude Opus 5

  5. added
    confirmed-repro
    on Aug 18, 2026
  6. added a commit that references this issue on Aug 18, 2026
    9fdbcf7
  7. added a commit that references this issue on Aug 18, 2026
    7c2be81
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-reproworkspaces

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions