#7522 · Pi system boundaries retain duplicate snapshots
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Pi system-message boundaries become two full diagnostic events rather than internal noise. A synthetic 51,200-character prompt section passed through the real Pi translator and shared event assembler is retained in both the start and end events. The same failure occurs with and without an active turn, in two clean checkouts of trusted main. The boundary-role classifier does not recognize the system role, so the fallback keeps the raw envelope. The minimal fix recognizes that role using the existing noise policy; no historical data is changed.
2. Claims vs findings
| Claim | Finding | Evidence |
|---|---|---|
| Both system boundaries retain the full snapshot | Verified at translation/assembly boundary | Both clean runs produce two provider/unhandled events, each containing the synthetic prompt section. |
| Unknown role classification causes the fallback | Verified | Classifier, fallback and assembler source links below; a two-line classifier fix makes the regression pass. |
| Other diagnostic events must remain available | Verified for unknown roles; existing diagnostic tests retained | Both unknown-role boundary controls pass before and after the fix. |
| The reported installation accumulated 0.66 GB | Unverified | No access to personal runtime data; no database size extrapolation is claimed. |
| Pi emits these on startup and prompt changes | Not separately exercised live | This reproduction injects the system boundaries at the actual provider translation boundary. It does not invoke a Pi CLI or model. |
| These events have no pruning policy | Supported by current documentation | The retention rules do not include provider/unhandled; historical cleanup is outside this fix. |
3. Environment
Linux x86_64; Node v22.19.0; pnpm 9.15.0; Vitest 4.1.12. Both checkouts use commit faa89fb46f03f9a1cd83d60355ab94c48da76f80 fetched from the canonical public repository. Locked development dependencies include Pi coding-agent 0.84.4; the reporter's CLI version was not run. No app, ports, runtime data directory, database, provider account or network model session is needed for this deterministic reproduction.
4. Minimal reproduction
- Clone the canonical repository and select the recorded commit:
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout --detach faa89fb46f03f9a1cd83d60355ab94c48da76f80 pnpm install --frozen-lockfile --prefer-offline
- Save the following independently authored patch as
regression.patchand apply it withgit apply regression.patch. It extends the existing harness, which uses the real translator and event assembler, with no mocks or production test seam.diff --git a/plugins/provider-pi/src/delta-translation.test.ts b/plugins/provider-pi/src/delta-translation.test.ts index d7d40b4d3a..8be1074f5f 100644 --- a/plugins/provider-pi/src/delta-translation.test.ts +++ b/plugins/provider-pi/src/delta-translation.test.ts @@ -188,6 +188,47 @@ function agentMessageDeltaId(events: ThreadEvent[]): string | undefined { } describe("pi delta translation equivalence", () => { + it.each([false, true])( + "drops system prompt boundaries with an active turn: %s", + (activeTurn) => { + const harness = createHarness(); + if (activeTurn) { + harness.translate(sdkMessage(loadFixture("agent-start.json"))); + } + const message = { + role: "system", + content: "", + sections: { instructions: "Synthetic prompt section. ".repeat(2048) }, + timestamp: 0, + }; + + const events = ["message_start", "message_end"].flatMap((type) => + harness.translate(sdkMessage({ type, message })), + ); + + expect(events).toEqual([]); + }, + ); + + it.each(["message_start", "message_end"])( + "preserves diagnostics for an unknown role at %s", + (type) => { + const harness = createHarness(); + const envelope = sdkMessage({ + type, + message: { role: "unrecognized-role", content: "diagnostic payload" }, + }); + + expect(harness.translate(envelope)).toEqual([ + expect.objectContaining({ + type: "provider/unhandled", + rawType: `sdk/${type}`, + rawEvent: envelope, + }), + ]); + }, + ); + it("keeps turn_start as internal noise while agent_start owns the bb turn", () => { const harness = createHarness(); harness.translate(loadFixture("agent-start.json")); - Run the focused regression through Turbo, which builds its SDK dependencies:
pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/delta-translation.test.ts -t 'system prompt boundaries|unknown role'
Expected: both system boundaries produce no stored diagnostic events, while unrecognized roles still produce diagnostics. Actual on unmodified production code, verbatim test summary:
× drops system prompt boundaries with an active turn: false
× drops system prompt boundaries with an active turn: true
✓ preserves diagnostics for an unknown role at message_start
✓ preserves diagnostics for an unknown role at message_end
AssertionError: expected [ { …(7) }, { …(7) } ] to deeply equal []
Test Files 1 failed (1)
Tests 2 failed | 2 passed | 77 skipped (81)
The received event diff contains rawType: sdk/message_start and rawType: sdk/message_end, each with type: provider/unhandled, role: system and the complete synthetic section. The public report intentionally does not include the repetitive 51,200-character assertion diff. The complete test patch is inline because this report repository forbids committed test artifacts and logs.
5. Root cause
- Boundary-role union and role parser recognize assistant, custom, toolResult and user, but not system. The latter therefore becomes unknown.
- Boundary visibility classification gives unknown roles unknown coverage; known roles receive noise coverage.
- SDK envelope translation recursively translates the boundary; when no normalized deltas result, it calls unhandledDeltas. That function retains the full raw envelope only for unknown coverage.
- The shared assembler copies the raw envelope into a provider/unhandled event. Nothing deduplicates these two distinct boundary envelopes.
The storage amplification begins in event classification, not SQLite allocation. Retention documentation gives no cleanup rule for these events. Other diagnostic consumers use model-fallback payloads, so blanket deletion of all unhandled events would be unsafe.
6. Proposed fix
Add system to the local boundary-role union and role parser. The existing known-role noise policy then suppresses both snapshots before the shared assembler creates stored events. Do not add a new persistence format, protocol, schema, byte cap or pruning migration. Preserve unknown-role diagnostics. Existing stored rows are not removed.
7. Verification
The same agent repeated the reproduction in a second freshly cloned checkout at the exact same trusted commit, with a separate frozen dependency installation and only the test patch added. Its production files were unchanged. The same Turbo command failed again with 2 failed | 2 passed | 77 skipped (81): both system cases failed, both unknown-role controls passed. This is a repeat verification, not an independent-agent review.
After the two-line fix in the first checkout, the focused command reports 4 passed | 77 skipped (81). Broader checks and line counts are recorded in the appendix.
8. Related issues and PR status
GitHub cross-reference metadata and an open-PR search found no linked open fix at investigation time. Related open issues #6025 (bounded extension diagnostics) and #5730 (database retention) address broader storage concerns; neither changes this verified classifier path.
9. Appendix
Classification: Bug / Medium / Low; providers and provider-pi. Issue text was treated only as untrusted claims. No supplied commands, scripts, links or branches were executed or fetched. All executable reproduction code was derived from trusted main and the existing test harness.
Initial repository-wide pnpm exec turbo run build stopped in the unrelated GitHub plugin because its bundled SDK process/host files were not yet built. The focused Turbo test dependency graph successfully built the required SDK. This build-order limitation is distinct from the regression failure and does not establish a new issue.
pnpm exec oxfmt plugins/provider-pi/src/delta-translation.test.ts plugins/provider-pi/src/visibility.ts pnpm exec turbo run test lint typecheck --filter=bb-plugin-provider-pi git diff --check git diff --numstat origin/main
All scoped checks pass: 38 test files passed and 1 skipped; 353 tests passed and 6 skipped. Pi lint and typecheck also pass (10/10 Turbo tasks successful). The focused post-fix regression passes all 4 cases. Formatting and git diff --check pass.
The fix changes 2 existing files, with 43 additions and 0 deletions (43 total text lines): 2 production lines and 41 regression-test lines. No binary, dependency, generated file, lockfile, migration, stored-data, public contract or wire change.