Skip to content

Treat Pi system message boundaries as internal noise - #7525

Merged
ymichael merged 1 commit into
mainfrom
slopcop/issue-7522
Nov 19, 2026
Merged

ymichael merged 1 commit into
mainfrom
slopcop/issue-7522

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human 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/unhandled event, 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

  • Before the fix, the focused regression failed in both clean checkouts: 2 system cases failed; 2 unknown-role controls passed.
  • After the fix, the focused regression passes all 4 cases.
  • 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.ts and git diff --check passed.
  • Repository-wide build initially stopped on unrelated missing GitHub-plugin SDK build outputs; the scoped Turbo graph built the required SDK successfully.

Fixes #7522

AGENT GENERATED

@ymichael
ymichael merged commit c317f01 into main Nov 19, 2026
47 checks passed
@ymichael
ymichael deleted the slopcop/issue-7522 branch November 19, 2026 00:12
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

provider-pi stores every pi system message twice, in full, as provider/unhandled (0.66 GB on one install)

2 participants