Repository navigation
Treat Pi system message boundaries as internal noise - #7525
Merged
Merged
Conversation
2 of 3 tasks
ymichael
added a commit
that referenced
this pull request
Nov 19, 2026
## 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: - **#7524:** resolved-item pruning always keeps the first output delta of an item. Providers that send command output as cumulative snapshots (pi), or in a few large chunks (Codex), put most of the output in that first delta. That copies `aggregatedOutput` on the completion, and the copy escapes the completed-output truncation. The guard exists for items that only ever produce deltas. A command with an `item/started` row doesn't need it. - **#7523:** a `fileChange` item carries every `changes[].diff` in both `item/started` and `item/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 (`matchFileRows` in `packages/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.ts` and `thread-pruning.ts`. The `resolved-items` policy now runs three steps per thread: deltas, background tasks, and started file-change diffs. - **Command output deltas:** once the completion with `aggregatedOutput` is found, the first delta is also deleted if an `item/started` row 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. - **Started file-change diffs:** each started `fileChange` row that has a later `item/completed` for the same item, with the same parent, gets its `$.item.changes[].diff` removed 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. - **Revisiting existing threads:** the `resolved-items` version goes from 1 to 2, which queues every thread. The resting cursor version is now set per kind; `deltas` goes from 2 to 3, so threads already proven under the old rule rescan their deltas once. - **Docs:** `docs/events-table-pruning.md` documents the new rules. There are no wire, CLI or schema changes. Event rows are rewritten in place, which the completed-output migration in `sweeps.ts` already does. ## How you verified - **New tests in `packages/db/test/data/thread-pruning.test.ts`:** all three fail on main and pass here. - First delta deleted only when a started row comes before it. Kept when there's no started row, when the completion has no output, or when the started row has a different parent. - Started diffs stripped only once a completion exists, including a completion that arrives after the thread's pass has rested. Open items and items under a different parent keep their diffs, and the completed row is untouched. - A thread proven under the old rules is revisited after the version bump. - **Suites:** `pnpm exec turbo run test --filter=@bb/db` passes (722 tests). The `@bb/server` pruning and timeline tests pass (`test/system/thread-pruning-sweep.test.ts`, `test/services/threads`, `test/timeline-history`: 379 passed, 2 skipped). - **Checks:** typecheck and lint pass, and `check:query-costs` passes. The `BB_QUERY_PLAN_REPORT` run over the db tests reports no findings for the new queries. `EXPLAIN QUERY PLAN` shows an index search for the new `UPDATE`, `DELETE`, resume and listing queries. **Real data.** I ran the `resolved-items` cycle on a `VACUUM INTO` copy of a 10.9 GB production `bb.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: | Rows | Before | After | |---|---|---| | Codex command output deltas | 331.1 MB | 3.7 MB | | pi command output deltas | 5.5 MB | 0 | | acp-omp command output deltas | 1.2 MB | 0 | | Codex started `fileChange` | 146.3 MB | 12.7 MB | | Claude Code started `fileChange` | 37.0 MB | 4.3 MB | | pi started `fileChange` | 1.3 MB | 0.4 MB | That'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 `pi` provider id, which the provider-literal ratchet rejects. #7525 stops new writes. Fixes #7523 Fixes #7524 > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <[email protected]>
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.
🚨 SLOP COP 🚨 ·
new-issue-autopilotHuman comments
What was wrong
Pi's local message-boundary classifier treats the system role as unknown. Each start/end SDK envelope therefore falls back to a full
provider/unhandledevent, retaining the same prompt snapshot twice. Reproduced through the real translator and shared event assembler in two clean checkouts of trusted main (faa89fb46f03f9a1cd83d60355ab94c48da76f80).Report: https://get-bb.github.io/reports/issues/7522.html
What changed
Recognize system boundaries under the existing noise policy. Add regression coverage with and without an active turn, plus controls preserving genuinely unknown-role diagnostics. This prevents new duplicate snapshots; it does not delete historical data.
Two files, 43 changed text lines (43 additions, 0 deletions): 2 production lines and 41 test lines. No dependency, generated file, stored-data, schema, public API, or server/daemon wire change.
How you verified
pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/delta-translation.test.ts -t 'system prompt boundaries|unknown role'pnpm exec turbo run test lint typecheck --filter=bb-plugin-provider-pi: 353 tests passed, 6 skipped; lint and typecheck passed.pnpm exec oxfmt plugins/provider-pi/src/delta-translation.test.ts plugins/provider-pi/src/visibility.tsandgit diff --checkpassed.Fixes #7522