Repository navigation
Description
Environment. bb 0.43.3 desktop; bb.db 5.2 GB with 1.9 M events; ~1,250 destroyed
git-worktree environments (about 1,240 destroyed per week); ~986k events still attached to
destroyed environments awaiting the 7-day prune.
Symptom. Slow DB query lines for UPDATE events SET environment_id = NULL WHERE rowid IN (…)
with durations of 1–8.3 s: 80 lines / 89 s in the first 80 minutes after a restart (p50 1.04 s,
max 3.96 s); 23 lines / 55 s (max 8.3 s) plus 11 lines / 54 s (max 9.4 s) for the companion
SELECT rowid, octet_length(data) … INDEXED BY events_environment_idx in the previous process.
sweep:destroyed-environment-prune:advance is the top tracked slowestWork in
Event loop stalled records (125 s over 19.5 h).
Evidence (installed bundle server/dist/start-server.js).
- The sweep runs on the 10 s periodic tick (
setInterval(… runPeriodicSweeps …, 1e4), 352459–352464;
cadenceMs: 0fordestroyed-environment-prune, 349309–349311). runDestroyedEnvironmentPruneSweep(349255–349270) performs up to 10 iterations, each one
synchronous insiderunEventLoopWorkSync, yielding withsetImmediatebetween them.pruneDestroyedEnvironments(39606–39660) picks one stale environment, selects up to 50
candidate rows computingoctet_length(data)per row, stops at a 256 KiB byte budget, runs
UPDATE events SET environment_id = NULL WHERE rowid IN (…), and deletes the environment row
when nothing is left. Constants at 39671–39680.- Each detach rewrites the whole
eventsrow (the column lives in the wide record whosedata
can be hundreds of KB) and the candidate select reads those overflow pages to measure them.
The per-statement latency, not the backlog, is the stall: the sweep drains up to 500 events per
10 s, far above inflow, and on this host no destroyed environment is currently past the TTL.
Reproduction. Populate events with wide data (tens to hundreds of KB) attached to ~1,000
environments, destroy them, advance 7 days (or lower the TTL), and watch the UPDATE statements in
the slow-query log and slowestWorkMs.
Proposed fix. Give the detach a time budget (stop after ~50 ms of wall clock) and a smaller
byte budget instead of a fixed 50 rows; avoid octet_length(data) on the candidate scan (store
the size, or select by rowid range); consider keeping environment_id out of the wide events
row (a side table keyed by rowid) so detaching is index-only; or run retention sweeps on a worker
thread with its own connection. Note: relying on the existing ON DELETE SET NULL foreign key
instead of chunking would perform the same update over every attached row in one synchronous
statement and make the stall worse.
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-autopilotClassified Bug · Priority Medium · Effort Medium, with
workspaces,perf, andpartial-repro.Reproduction and root-cause report: PARTIALLY REPRODUCED, medium confidence. Two clean trusted-main checkouts confirmed synchronous cleanup and the oversized-row budget exception; measured calls took 0.322–6.282 ms, not seconds. The report includes the repeatable test. SQLite optimized the candidate byte-length lookup without loading full payloads.
Root cause established: database work completes synchronously before the sweep yields; the byte budget cannot bound individual statement duration. The reported multi-second latency remains unverified. No PR: there is no failing regression for that stall supporting a safe small fix.
Keep destroyed environment rows instead of pruning them
Keep destroyed environment rows instead of pruning them (#4259)