Repository navigation
Prune duplicated command output and started file-change diffs - #7806
Merged
ymichael merged 1 commit intoNov 19, 2026
Merged
Conversation
Resolved-item pruning now also deletes a command's first output delta when its item/started row precedes it and the completion carries aggregatedOutput, and removes diffs from started fileChange rows once the item has a completion. The policy version bump queues every thread, and the deltas cursor version bump makes threads proven under the old rule rescan. Fixes #7523 Fixes #7524 Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
force-pushed
the
bb/optimize-provider-pi-storage-usage-thr_grsdgpm2wc
branch
from
November 19, 2026 00:39
b9129ae to
8f2d12d
Compare
ymichael
deleted the
bb/optimize-provider-pi-storage-usage-thr_grsdgpm2wc
branch
November 19, 2026 04:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Two kinds of event rows were stored in full and never read again. Nothing pruned them, so they stayed for the life of the thread:
aggregatedOutputon the completion, and the copy escapes the completed-output truncation. The guard exists for items that only ever produce deltas. A command with anitem/startedrow doesn't need it.item/startedand again initem/completed(0.44 GB on one install) #7523: afileChangeitem carries everychanges[].diffin bothitem/startedanditem/completed. This happens for Codex, Claude Code and pi alike. Once the item completes, the timeline shows the completed item's diffs and uses the started row only to match file rows by path (matchFileRowsinpackages/thread-view/src/item-records.ts). The started diffs are never displayed again.What changed
All of this is in
packages/db/src/data/resolved-item-pruning.tsandthread-pruning.ts. Theresolved-itemspolicy now runs three steps per thread: deltas, background tasks, and started file-change diffs.aggregatedOutputis found, the first delta is also deleted if anitem/startedrow for the same item comes before it, with the same turn, parent tool call and item kind. One indexed lookup (prepareStarted) does the check. Other delta kinds keep their first delta. A message's or reasoning item's text start time comes from its first delta, so deleting it would change what the timeline shows.fileChangerow that has a lateritem/completedfor the same item, with the same parent, gets its$.item.changes[].diffremoved in SQL. Path, kind and move path stay. The pass rests at a bound like the delta pass does, and reaches back below it only for items that gained a completion since the last pass.resolved-itemsversion goes from 1 to 2, which queues every thread. The resting cursor version is now set per kind;deltasgoes from 2 to 3, so threads already proven under the old rule rescan their deltas once.docs/events-table-pruning.mddocuments the new rules.There are no wire, CLI or schema changes. Event rows are rewritten in place, which the completed-output migration in
sweeps.tsalready does.How you verified
packages/db/test/data/thread-pruning.test.ts: all three fail on main and pass here.pnpm exec turbo run test --filter=@bb/dbpasses (722 tests). The@bb/serverpruning and timeline tests pass (test/system/thread-pruning-sweep.test.ts,test/services/threads,test/timeline-history: 379 passed, 2 skipped).check:query-costspasses. TheBB_QUERY_PLAN_REPORTrun over the db tests reports no findings for the new queries.EXPLAIN QUERY PLANshows an index search for the newUPDATE,DELETE, resume and listing queries.Real data. I ran the
resolved-itemscycle on aVACUUM INTOcopy of a 10.9 GB productionbb.db(mostly Codex and Claude Code), with main's code and this branch on identical copies. Main's code had nothing queued and removed nothing. This branch removed or rewrote 441k rows:fileChangefileChangefileChangeThat's about 0.5 GB freed. On the reporter's pi-only install, #7523 and #7524 estimate about 0.57 GB together. When I forced main's code through the same full delta rescan, Codex deltas only dropped to 320.4 MB, so the new first-delta rule accounts for about 316 MB of the delta savings.
The one-time pass took 94 s of total work across 23k advances: p50 0.9 ms, p99 35.5 ms. The file-change step's p99 was 18 ms. Both runs had rare multi-second stalls on small threads: main's forced rescan peaked at 2.6 s, this branch at 4.4 s. Those are disk/WAL stalls on this machine, not pruning work: the slowest thread here has 350 delta rows totalling 65 KB. The p99 for main's forced rescan was 44.7 ms.
The stored pi system prompts from #7522 are not part of this PR. Deleting them in core needs a check on the
piprovider id, which the provider-literal ratchet rejects. #7525 stops new writes.Fixes #7523
Fixes #7524
🤖 Generated with Claude Code