Skip to content

A file change's full diff is stored twice, in item/started and again in item/completed (0.44 GB on one install) #7523

Closed

Description

@pascal-de-ladurantaye

Summary

When a pi agent edits or writes a file, bb stores the fileChange item with every changes[].diff in item/started, then stores the same diffs again in item/completed. After completion the timeline reads the completed item, so the started copy is dead weight. For large edits that is megabytes per row. I expected the diff to be stored once after the item completes.

Versions and environment

  • bb 0.49.0 (desktop app), macOS 27.2 arm64
  • provider pi, pi CLI 1.5.0 (the edit and write tools)
  • local data dir ~/.bb

Steps to reproduce

  1. In a scratch repo: bb thread spawn --project <project> --provider pi --prompt "Create notes.txt containing the line hello, then use the edit tool to change hello to goodbye."
  2. bb thread wait <thread>
  3. bb thread log <thread> --json --all | jq -c '.[]
      | select((.type=="item/started" or .type=="item/completed") and .data.item.type=="fileChange")
      | {seq, type, status: .data.item.status, diffChars: [.data.item.changes[].diff | length]}'

I checked this on existing threads, including 14 file changes written by 0.49.0 in three threads: all 14 started/completed pairs had identical changes. I did not run it on a clean data dir.

Expected vs actual

{"seq":4291,"type":"item/started","status":"pending","diffChars":[336,113]}
{"seq":4292,"type":"item/completed","status":"completed","diffChars":[336,113]}

Expected: once the item has completed, one stored copy of each diff. Actual: item.changes is identical in both rows. Only status differs. The pair above is from an existing thread.

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:

type item_kind rows size largest row
item/started fileChange 9,131 0.22 GB 8.4 MB
item/completed fileChange 9,149 0.22 GB 8.4 MB

That is 0.44 GB for one set of diffs, so about 0.22 GB is the second copy. In the two heaviest threads on this install, most of the space is diffs of 2.3 MB and 8.4 MB, each stored twice. Read-only indexed spot checks on single threads found json_extract(data,'$.item.changes') equal between the started and completed rows of the same item.

Code (the same at desktop-v0.49.0 and at current main; neither file changed between them):

  • provider-pi builds the fileChange shape, with oldText/newText per edit, at tool_execution_start: tag, main. At tool_execution_end it closes the item with that same started shape: tag, main.
  • The assembler turns each change into a unified diff (buildFileChanges): tag, main. It emits the full item on item.open as item/started (tag, main) and again on item.close as item/completed (tag, main).
  • Pruning never touches these rows. docs/events-table-pruning.md says: "Completed items and fileChange events remain available to timeline readers."

The started diff is useful while the item is open, for example for a pending approval. A fix could, once item/completed with the same changes exists, drop changes[].diff from the started row or prune the started row. This is a suggestion; I have not checked every reader of item/started.

What you ruled out

Suggested priority and effort (optional)

Medium: large or generated-file edits add megabytes per edit, twice. No data is lost and there is no user workaround. Effort is probably Low to Medium, depending on which readers use the started row.

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: Medium. Added threads, perf, and provider-pi; no existing classifications were replaced.
    • Report: https://get-bb.github.io/reports/issues/7523.html
    • Verdict: REPRODUCED · root-cause confidence: high · reproduction label: confirmed-repro.
    • Root cause: Pi carries the full file-change shape through start and completion; ingestion persists both diff payloads, and existing pruning policies retain them.
    • Verification: The regression fails as expected for both edit and write in two clean trusted-main checkouts, even after all four pruning policies finish. All 308 relevant existing tests pass. The report includes the complete test; installation-specific storage totals were not verified.
    • No PR: Safe deduplication changes persisted-event retention, which this rule excludes from simple fixes.
  4. added a commit that references this issue on Nov 17, 2026
    35e23bb
  5. 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