Repository navigation
Description
Summary
bb prunes command-output deltas once the completed item carries aggregatedOutput, but it always keeps the first delta of each item. The pi provider sends command output as cumulative snapshots, so a typical command produces one delta that holds the entire output. That delta is never pruned, and the output ends up stored twice: in the kept delta and in aggregatedOutput. I expected a completed command's output to be stored once.
Versions and environment
- bb 0.49.0 (desktop app), macOS 27.2 arm64
- provider
pi, pi CLI 1.5.0 (thebashtool) - local data dir
~/.bb
Steps to reproduce
bb thread spawn --project <project> --provider pi --prompt "Run seq 1 3000 with the bash tool, then reply ok."bb thread wait <thread>, thenbb thread archive <thread>. Pruning skips active threads, and the background sweep runs every 10 s.- Wait a minute, then run:
bb thread log <thread> --json --all | jq -c '.[] | select(.type=="item/commandExecution/outputDelta" or (.type=="item/completed" and .data.item.type=="commandExecution")) | {seq, type, chars: ((.data.delta // .data.item.aggregatedOutput) | length)}'
I checked this on existing archived threads written by 0.49.0, not on a clean data dir.
Expected vs actual
This is from an archived thread written by 0.49.0, archived four days before the check:
{"seq":38,"type":"item/commandExecution/outputDelta","chars":20888}
{"seq":39,"type":"item/completed","chars":20888}
Expected: after pruning, only the item/completed row holds the output. Actual: the delta survives, and its delta text is identical to item.aggregatedOutput.
Evidence
Size, measured on one install (37 days, about 2,900 threads, all pi). I took a consistent copy of ~/.bb/bb.db with SQLite .backup, measured it with dbstat, and summed sum(length(data)) by event type and item_kind. Command output is 1.17 GB in total: completed 0.61, output deltas 0.39 (177,570 rows), started 0.17.
To find which deltas survive, I ran read-only indexed queries per thread on random samples, grouping deltas by (turn_id, item_id):
| sample | deltas | size | in the item's first delta | in items with exactly one delta |
|---|---|---|---|---|
| 150 random threads | 8,899 | 22.2 M chars | 90% | 88% |
| 120 random archived threads created on 0.49.0 | 5,448 | 16.4 M chars | 99.7% | — |
So about 0.35 GB of the 0.39 GB is first deltas that the rule keeps by design. Every sampled completion carried aggregatedOutput. In the sole-delta items I compared, the delta text equals aggregatedOutput in most cases. Otherwise it is a prefix, where the item's later deltas were pruned.
The kept delta also outlives output truncation. For outputs over 32 K characters, the completed copy is cut to a head and tail (retained-event-output.ts). One sampled item has a 4,173-character aggregatedOutput (original length 43,047) next to a kept first delta that still holds all 43,047 characters.
Code:
- The retention rule is "Unresolved deltas and the first delta of each type in an item scope", and command deltas are deleted only when the completion carries
aggregatedOutput: tag L15, tag L25-L26. On main, L15 is unchanged and L79-L81 adds "kept for good: the first delta of an item". - A candidate is deleted only after phase 0 finds a completion with output (
prepareOutput) and phase 1 finds an earlier delta of the same item (prepareEarlier). The first delta has no earlier delta, so it is never deleted. At the tag: queries and match. On main: queries and match. Main reworked how passes resume (Resume resolved-item pruning passes and bound each advance to its budget #7254) but kept this rule. - provider-pi maps each
tool_execution_updateto acommand.outputSnapshotwith the cumulative output (tag, main). The assembler diffs each snapshot against the previous one, so the first snapshot becomes a delta with the whole text so far (tag, main). Ontool_execution_end, provider-pi setsaggregatedOutputto the full output (tag, main).
The first-delta guard probably exists for delta-only items that never get an item/started row (see #1568). A pi command item always has one. Suggested fix: for command-output deltas, also delete the first delta when the item has an item/started row and its completion carries aggregatedOutput. If something still needs a marker row, empty its delta instead.
There is a smaller, separate leftover. Some later deltas whose completion qualifies also survive in settled threads past a certain sequence: 0.3% of delta bytes in threads written on 0.49.0, and about 10% in older threads. I have not traced that, and it is not what this issue asks for.
What you ruled out
- The completed item does carry
aggregatedOutput. provider-pi sets it forbash, and every completion in the samples had it as text. - The background sweep is not behind. Its work queue (
thread_pruning_work) held only about a dozen live, unarchived threads. No archived thread was queued or had an open delta cursor, and in the sampled threads the later deltas of most items had already been pruned. - The gap is the kept first delta (99.7% of surviving delta bytes in 0.49.0 threads). Resume resolved-item pruning passes and bound each advance to its budget #7254 noted that "most surviving deltas are the first delta of their item, which is never pruned", but treated it as re-probe cost, not storage.
- Not Event pruning stalls on busy workspaces because it waits for the whole workspace to be idle #5005 (pruning stalls on busy workspaces). Related to bb's database grows without limit, and archiving doesn't shrink it #5730 (the database grows without limit), not a duplicate.
- No issue found for "outputDelta", "first delta", "command output delta", "output delta pruning", "aggregatedOutput" or "events pruning" (open and closed).
- The rule is the same on
mainat88cf8f6.
Suggested priority and effort (optional)
Medium: it applies to every pi command, and the kept copy also escapes output truncation. No data is lost, because the completed item keeps the output. There is no user workaround. Effort is probably Low: a pruning-rule change plus a policy version bump so existing threads are revisited.
Checks
- I reproduced this on the latest release or on
main, or I say above that I could not. - I searched open and closed issues for the same problem.
- If an agent wrote this, the body ends with
> AGENT GENERATEDand links the thread or report. (It ends with the marker. The investigation report is a private local analysis, summarized above.)
AGENT GENERATED
Activity
bb-slop-cop commentedon Nov 13, 2026
🚨 SLOP COP 🚨 ·
new-issue-autopilotthreads,perf,provider-pi.confirmed-repro.Prune duplicated command output and started file-change diffs
Prune duplicated command output and started file-change diffs (get-bb…