Skip to content

Output pruning keeps each command's first output delta, and for pi that is usually the whole output (about 0.35 GB of 0.39 GB on one install) #7524

Closed

Description

@pascal-de-ladurantaye

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 (the bash tool)
  • local data dir ~/.bb

Steps to reproduce

  1. bb thread spawn --project <project> --provider pi --prompt "Run seq 1 3000 with the bash tool, then reply ok."
  2. bb thread wait <thread>, then bb thread archive <thread>. Pruning skips active threads, and the background sweep runs every 10 s.
  3. 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_update to a command.outputSnapshot with 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). On tool_execution_end, provider-pi sets aggregatedOutput to 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

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 GENERATED and links the thread or report. (It ends with the marker. The investigation report is a private local analysis, summarized above.)

AGENT GENERATED

Activity

  1. added theissue type on Nov 13, 2026
  2. added
    threads
    provider-pi
    confirmed-repro
    on Nov 13, 2026
  3. bb-slop-cop commented on Nov 13, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    • Classification: Bug · Priority Medium · Effort Low; labels: threads, perf, provider-pi.
    • Reproduction and root-cause report: REPRODUCED, high confidence; reproduction label: confirmed-repro.
    • Root cause: Pruning requires an earlier delta before deleting command output, so the first delta survives even with an item-start row and completed output. Completed-output truncation does not bound that retained delta.
    • Verification: Two clean trusted-main runs reproduce an 8,192-character duplicate and a 40,000-character delta beside a 4,173-character completion preview. Both regression cases fail as expected; 55 relevant existing tests pass. Installation-wide totals and real-provider update frequency were not measured.
    • No PR: Changing persisted event-retention policy and revisiting settled history is a stored-data change, excluded from this rule’s simple-fix scope.
  4. added a commit that references this issue on Nov 19, 2026
    8f2d12d
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-reproperfprovider-pithreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions