Repository navigation
Description
Environment. bb 0.43.3 desktop; threads spawned into managed git-worktree environments;
~/.bb/thread-storage/<threadId> directories on the host.
Symptom. bb thread delete --yes on 1,280 archived threads removed their rows and events
from bb.db, but 1,278 of the 1,280 thread-storage/<threadId> directories are still on disk
(directory mtimes unchanged; ≈ 3.3 MB each, ≈ 4 GB total). The server logged no
Thread storage deletion … warning. Afterwards the host holds 3,308 storage directories
(10.4 GB) for 229 non-archived threads; 1,409 directories have no thread row at all.
Mechanism (installed bundle server/dist/start-server.js).
DELETE /threads/:id(317933–317957) marks the thread deleted and calls
requestThreadStorageDeletion(deps, thread, environment)for it and its lifecycle dependents.requestThreadStorageDeletion(235390–235424):- if
thread.environmentId === null→markThreadStorageDeletedandfinalizeStoppedThread,
without removing anything on disk; - if the environment row is missing → warn "Thread storage deletion environment is unavailable"
and return; - otherwise send the host command
thread.storage.deletefor that environment's host, whose
handler doesrm -rf <threadStorageRoot>/<threadId>(daemon bundle). So bb does delete
storage when the thread still points at an environment.
- if
- The thread row is hard-deleted only once
environmentId === nullorstorageDeletedAtis set
(236048–236064). threads.environment_idis declaredREFERENCES environments(id) ON DELETE set null, and
foreign keys are on (foreign_keys = ON, 30055).pruneDestroyedEnvironments(39606–39660)
deletes destroyed environment rows 7 days after destruction. Every thread of such an environment
then hasenvironment_id = NULL, and any laterbb thread deletetakes the first branch: storage
is marked deleted and the directory is orphaned forever.
State on this host. 765 archived threads currently have environment_id IS NULL; 289 of them
still have a storage directory and will be orphaned when deleted. Zero threads have a dangling
environment reference (the FK works as declared).
Reproduction. Spawn a thread into a managed worktree, archive it, wait for the worktree to be
destroyed and for the 7-day environment prune (or lower DESTROYED_ENVIRONMENT_TTL_MS), confirm
environment_id is NULL, then bb thread delete the thread. The row disappears; the directory
under thread-storage/ remains.
Proposed fix. The storage root is per host, not per environment, so thread.storage.delete
does not need the environment: record the host id on the thread (or on the thread's storage
record) at start and send the command to that host even when the environment row is gone; when no
host session is available, keep the thread soft-deleted with storage_deleted_at NULL and retry
in the lifecycle sweep instead of marking it deleted. Also report the directory size in
bb thread show --json so operators can see what deletion will reclaim.
Filed from an audit of bb 0.43.3 by the Factory plugin (github.com/mattwyckhouse/bb-plugin-factory). Method, re-derived numbers and the adversarial review of this report: plans/076-host-sustainable-line/bb-core-issues/REVIEW.md in that repository.
Activity
bb-slop-cop commentedon Sep 23, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotBug · Priority: Medium · Effort: High — applied
threads,workspaces, andconfirmed-repro.REPRODUCED · high confidence. Reproduction and root-cause report.
Environment pruning clears the thread’s environment reference. Deletion then marks storage complete and hard-deletes the thread without sending host cleanup. The route regression reproduced this in two clean checkouts of
94d77da09: the retained-environment control queued one cleanup request; the pruned case queued none and lost its tombstone. Nine adjacent tests passed.No PR: reliable cleanup requires a storage-ownership or retention design change outside the simple-fix limits. The report embeds the regression test; host-scale disk usage was not independently verified.
Keep destroyed environment rows instead of pruning them (#4259)
Finish deleting threads on removed machines and clean up orphaned thr…