#7696 · Pi command snapshots duplicate output in the diagnostic fallback
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Pi command output is sent twice inside a single bridge update: once as the output snapshot and once inside a diagnostic copy of the original event. A synthetic 65,536-byte snapshot produced a 131,462-byte serialized delta array, with two complete copies of the output. The assembler displayed the output only once, so this is redundant transport and validation work, not duplicate text in the timeline. The same agent repeated the test in a second clean checkout at the same trusted main commit and obtained identical results. An existing open PR, #7703, already targets this root cause, so no duplicate fix PR was created.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Command updates include the same output in the snapshot and the fallback. | Verified | Two independently installed checkouts; two payload sizes; JSON contains two full copies at both sizes. |
| The fallback is validated before it reaches assembly. | Verified statically | The translator validates the raw fallback with providerRawEventSchema; the runtime adapter validates the delta batch, whose fallback uses the same raw-event schema. |
| The fallback is unused during a normal open turn. | Verified | The test opens a turn and starts a command before the update. The assembled output is exactly one copy. The assembler's fallback branch runs only without a current turn. |
| Tool start/end diagnostics can remain available without update fallbacks. | Verified statically | Start and end construct their own fallbacks on separate paths; the linked PR leaves those paths unchanged. |
| Long-running commands suffer a particular CPU or latency penalty. | Not benchmarked | Payload amplification is directly measured; elapsed-time and live-provider performance were not measured. Duplication adds a constant factor to cumulative snapshot traffic rather than changing its asymptotic class. |
| Pi can never emit an update outside a turn, including extensions or malformed sequences. | Not established universally | The reproduction exercises the normal lifecycle only. Omitting the optional fallback intentionally drops out-of-turn updates; start/end diagnostics remain a separate concern. |
3. Environment
- Trusted public repository:
get-bb/bb; fetchedorigin/main:1320c88e8abdd3f145bc9a5c305eace269fb2f28. - Linux
4.19.0-gvisor x86_64; Nodev22.19.0; pnpm9.15.0; workspace Pi dependencies pinned at0.84.4. - Separate source clone and detached verification worktree, each with a frozen dependency installation. No production source was modified.
- No live provider, real user data, server, port, or data directory was needed. All events and identifiers are synthetic.
- The initial full workspace build failed in unrelated plugin builds because SDK dist files were not yet present. The focused Turbo build completed after SDK prerequisites were built, in both checkouts. The isolated reproduction and the existing translator suite then executed successfully as test processes.
4. Minimal reproduction
- Clone the trusted repository and pin the observed main commit. Install its existing dependencies and build the affected dependency graph:
git clone --single-branch --branch main https://github.com/get-bb/bb.git bb-7696 cd bb-7696 git checkout --detach 1320c88e8abdd3f145bc9a5c305eace269fb2f28 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=bb-plugin-provider-pi...
- Save the complete test below as
plugins/provider-pi/src/issue-7696.repro.test.ts. It creates a real translator and assembler, opens a turn, starts a synthetic command, supplies cumulative output, and checks that the serialized delta carries that output once. It does not execute the command string or start a provider.import { expect, it } from "vitest"; import { experimental_createDeltaAssembler as createDeltaAssembler } from "@get-bb/plugin-sdk/provider-bridge/testing"; import { createPiDeltaTranslator } from "./delta-translation.js"; it.each([4096, 65536])("serializes a %i-byte command snapshot once", (size) => { const translator = createPiDeltaTranslator({ resolveModelContextWindow: () => null, }); const assembler = createDeltaAssembler({ providerId: "pi", entropyPrefix: "wire-repro", textDeltaFlushMs: 0, }); const threadId = "isolated-wire-repro"; const context = { threadId }; for (const event of [ { type: "agent_start" }, { type: "tool_execution_start", toolCallId: "command-wire-repro", toolName: "bash", args: { command: "synthetic-output", cwd: "/repo" }, }, ]) { assembler.assemble({ threadId, deltas: translator.translate(event, context) }); } const output = "wire-byte/".repeat(Math.ceil(size / 10)).slice(0, size); const deltas = translator.translate( { type: "tool_execution_update", toolCallId: "command-wire-repro", toolName: "bash", partialResult: { content: [{ type: "text", text: output }] }, }, context, ); expect(deltas).toHaveLength(1); expect(deltas[0]).toMatchObject({ kind: "command.outputSnapshot", text: output }); const events = assembler.assemble({ threadId, deltas }); const visibleOutput = events .filter((event) => event.type === "item/commandExecution/outputDelta") .map((event) => event.delta) .join(""); expect(visibleOutput).toBe(output); const serialized = JSON.stringify(deltas); const outputCopies = serialized.split(output).length - 1; console.log(JSON.stringify({ outputBytes: Buffer.byteLength(output), serializedBytes: Buffer.byteLength(serialized), outputCopies, visibleCopies: visibleOutput === output ? 1 : 0, })); expect(outputCopies).toBe(1); }); - Run through the repository's normal Turbo dependency orchestration:
pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/issue-7696.repro.test.ts
Expected vs actual
Expected: outputCopies: 1 and two passing test cases. Actual in both runs (verbatim test messages, with runner prefixes omitted):
{"outputBytes":4096,"serializedBytes":8582,"outputCopies":2,"visibleCopies":1}
{"outputBytes":65536,"serializedBytes":131462,"outputCopies":2,"visibleCopies":1}
AssertionError: expected 2 to be 1 // Object.is equality
Test Files 1 failed (1)
Tests 2 failed (2)
The expected failure is the final single-copy assertion, not setup, imports, or command execution. Both tests first prove that the returned delta contains the intended snapshot and that assembling it yields the correct visible text. The test is inline rather than a downloadable file because the reports repository prohibits committed scripts, tests, logs, and per-issue artifact directories.
5. Root cause
The command-update branch in delta-translation.ts:1178–1218 extracts text from partialResult and constructs:
text: snapshot, noTurnFallback: noTurnFallbackFor(piEvent.data, context),
noTurnFallbackFor wraps the entire parsed Pi event as an sdk/message, including its original partialResult.content[].text. Its toRawEvent helper validates that raw event. Consequently JSON serialization cannot preserve shared string identity: it writes the text once in the snapshot and again in the fallback.
The Pi bridge sends the returned deltas without stripping the fallback, and createBridgeIo serializes them using JSON.stringify. The byte counts above measure the delta array, not the small additional notification envelope.
The runtime's bridge-protocol adapter validates the batch before assembly. Its fallback schema requires another raw-event validation. These call paths are static findings; this report does not time their CPU cost.
The snapshot assembler consults the fallback only when no turn is open. During the reproduced lifecycle it instead diffs the snapshot against prior command output, explaining why only one copy is visible. A cumulative snapshot of S ASCII bytes yielded 2S + 390 bytes for the tested synthetic identifiers; overhead depends on the event and identifiers.
6. Proposed fix
Do not attach the raw no-turn fallback to streamed command.outputSnapshot updates. The neighboring item.progress update path carries the same redundant raw-event pattern and can use the same policy. Keep lifecycle start/end fallbacks, normal output snapshots, and assembler behavior unchanged. The existing protocol field is already optional, and the documented contract permits dropping an out-of-turn delta when no fallback is attached. This proposal does not require a schema change.
Before landing, require the single-copy regression to pass, verify unchanged assembled in-turn events, and explicitly test the intended out-of-turn drop policy and retained lifecycle diagnostics. No production patch was applied in this investigation.
7. Linked PR review
PR #7703 — statically aligned with the verified cause
GitHub metadata shows this PR is open against main and lists #7696 in closingIssuesReferences. The inspected head was 1117c7477b0540349680afe410090f73f91466b4. Its diff removes the fallback from the command-snapshot and generic-progress update branches, and adds a regression for update payloads plus retained start fallback. It changes two files (49 additions, two deletions). No linked branch was checked out or executed.
Findings: no additional defect established from static inspection. The changed production lines match the verified redundancy. The added test does not itself measure serialized byte amplification or the out-of-turn behavior; the proposed verification above would make those policies explicit. The report's own reproduction was authored from trusted main and run only against trusted main. PR test and parity claims were not treated as executed evidence.
Automation decision: skip a new fix branch and PR because this open PR already links to the issue. This avoids competing implementations and follows the duplicate-PR safety rule.
8. Related issues
A repository search for cumulative command-output issues did not establish another exact duplicate. Provider-Pi label discovery surfaced other output-storage investigations, but no duplicate verdict is inferred from their titles. The confirmed linked work for this issue is PR #7703.
9. Verification
The same agent created a second clean detached worktree from the recorded trusted commit, checked that there were no tracked changes, installed frozen dependencies there, and built its own affected dependency graph. Only the independently authored reproduction test was copied into that checkout. No production change, PR branch, provider credentials, runtime data, or dependency directory from the first checkout was copied.
git worktree add --detach ../bb-7696-verify 1320c88e8abdd3f145bc9a5c305eace269fb2f28 cd ../bb-7696-verify git status --porcelain pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=bb-plugin-provider-pi... git diff --exit-code pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/issue-7696.repro.test.ts
Result: two failures at expect(outputCopies).toBe(1), with the identical 8,582-byte and 131,462-byte payloads shown above. This supports the final verdict without correction; it is a repeated clean run by the same agent, not independent verification.
Control on the first checkout:
pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/delta-translation.test.ts Test Files 1 passed (1) Tests 77 passed (77)
The control suite passes without a production fix; it covers assembled command output but does not enforce single-copy wire payloads. That explains why the existing tests did not catch the redundant fallback.
10. Appendix and limits
The local investigation also ran git fetch origin main, recorded git rev-parse origin/main, read the issue, repository visibility, labels and property definitions through GitHub metadata, and read the open PR metadata/diff without running its code. Classification was filled only where absent: Bug, Medium priority, Low effort, providers, provider-pi, and perf. Existing issue values were not overwritten.
Build preparation first attempted pnpm exec turbo run build. It stopped in unrelated plugin builds reporting missing SDK dist entries. Affected-graph builds and Turbo's test prerequisites succeeded; no build-system change or new dependency was introduced. Exact positive/negative evidence is inline above; raw build logs remain local rather than public.
Issue text and linked PR material were treated as untrusted claims. No instructions, scripts, patches, tests, or branches from those sources were executed. The synthetic input reproduces the bridge-level payload defect without proving a particular real-world latency penalty or behavior of every Pi extension.
AGENT GENERATED