Reports

#6808 · Pi assistant stream boundary retention

BugHigh priorityMedium effortproviders · provider-pi · partial-repro

GitHub issue · November 2, 2026 · trusted base 916d684ac23d0b0de82c09cfc7553a50287d2188

PARTIALLY REPRODUCED · Root-cause confidence: medium for the reported incident; high for the controlled boundary-loss mechanism.

1. TL;DR

The adapter can complete a new assistant response using the same item ID that previously streamed different text, leaving only the new response in completed events. Two clean checkouts demonstrate this when the prior assistant message has no end event, or its end event has an aborted/error stop reason. A normal successful end event correctly preserves both messages on current main. The report therefore verifies the data-loss mechanism, not that ordinary Pi steering produces the necessary event sequence. The original upstream Pi events were not supplied, so this is a partial reproduction and no production fix or duplicate pull request is opened.

2. Claims vs findings

ClaimFindingEvidence
Earlier streamed assistant text can be replaced under its original item ID.Verified at the translator/assembler boundary.Three interrupted-boundary cases produce one completion: ID repro-6808-i1, text New response.; the same ID originally streamed Original analysis..
A normal steer during streaming triggers the loss.Unverified.The queue update is synthetic. No Pi process, real steer, original event-log replay, or UI session was exercised. The normal successful message-end control passes.
The content is absent from all rendered timeline locations.Unverified visually.This reproduction checks emitted completion payloads, not GUI folding or persisted timeline queries. No screenshot is offered as evidence.
A separate assistant message should not silently replace earlier streamed text.Verified violated under interrupted boundaries.The failing assertions require both original and replacement text plus distinct completion IDs.
Successful assistant message boundaries are ignored on current main.Refuted.The successful control passes. Commit 12b6e21, merged October 27, 2026 at 03:14 UTC, already closes successful messages at their own end events.

3. Environment

4. Minimal reproduction

These are independently authored event fixtures derived from the trusted adapter contract, not event excerpts supplied by the reporter. They deliberately vary the first assistant boundary. They do not establish which variation occurred in the reported threads.

  1. Make a clean checkout and install its locked dependencies:
    git clone https://github.com/get-bb/bb.git bb-6808
    cd bb-6808
    git checkout --detach 916d684ac23d0b0de82c09cfc7553a50287d2188
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build build:types --filter=@get-bb/plugin-sdk
  2. Download the reproduction test and copy it to plugins/provider-pi/src/issue-6808-repro.test.ts.
  3. Execute through Turbo:
    pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/issue-6808-repro.test.ts
  4. Expected: four passing cases, each preserving both texts with distinct IDs. Actual: the successful end case passes; missing, aborted, and error boundary cases fail with exactly this lost-text mismatch:
    - Expected
    + Received
      [
    -   "Original analysis.",
        "New response.",
      ]
    Tests  3 failed | 1 passed (4)

Saved diagnostic payload for each failing variation:

{"boundary":"missing","started":["repro-6808-i1"],"completed":[{"id":"repro-6808-i1","text":"New response."}]}
{"boundary":"aborted","started":["repro-6808-i1"],"completed":[{"id":"repro-6808-i1","text":"New response."}]}
{"boundary":"error","started":["repro-6808-i1"],"completed":[{"id":"repro-6808-i1","text":"New response."}]}

Complete reproduction test

import { expect, it } from "vitest";
import {
  experimental_createDeltaAssembler as createDeltaAssembler,
  type ThreadEvent,
} from "@get-bb/plugin-sdk/provider-bridge/testing";
import { createPiDeltaTranslator } from "./delta-translation.js";

it.each(["stop", "missing", "aborted", "error"])(
  "preserves the prior assistant text across a %s message boundary",
  (boundary) => {
    const translator = createPiDeltaTranslator({
      resolveModelContextWindow: () => undefined,
    });
    const assembler = createDeltaAssembler({
      providerId: "pi",
      entropyPrefix: "repro-6808",
      textDeltaFlushMs: 0,
    });
    const events: ThreadEvent[] = [];
    const deliver = (event: unknown) => {
      events.push(
        ...assembler.assemble({
          threadId: "repro-thread",
          deltas: translator.translate(event, { threadId: "repro-thread" }),
        }),
      );
    };
    const first = {
      role: "assistant",
      content: [{ type: "text", text: "Original analysis." }],
      stopReason: boundary,
    };
    const second = {
      role: "assistant",
      content: [{ type: "text", text: "New response." }],
      stopReason: "stop",
    };

    deliver({ type: "agent_start" });
    deliver({
      type: "message_start",
      message: { role: "assistant", content: [] },
    });
    deliver({
      type: "message_update",
      assistantMessageEvent: {
        type: "text_delta",
        contentIndex: 0,
        delta: "Original analysis.",
      },
    });
    deliver({ type: "queue_update", steering: ["New input."], followUp: [] });
    if (boundary !== "missing") {
      deliver({ type: "message_end", message: first });
    }
    deliver({
      type: "message_start",
      message: { role: "user", content: "New input." },
    });
    deliver({
      type: "message_end",
      message: { role: "user", content: "New input." },
    });
    deliver({
      type: "message_start",
      message: { role: "assistant", content: [] },
    });
    deliver({ type: "message_end", message: second });
    deliver({ type: "agent_end", messages: [first, second] });

    const completed = events.flatMap((event) =>
      event.type === "item/completed" && event.item.type === "agentMessage"
        ? [{ id: event.item.id, text: event.item.text }]
        : [],
    );
    const started = events.flatMap((event) =>
      event.type === "item/started" && event.item.type === "agentMessage"
        ? [event.item.id]
        : [],
    );
    console.log(JSON.stringify({ boundary, started, completed }));
    expect(completed.map((item) => item.text)).toEqual([
      "Original analysis.",
      "New response.",
    ]);
    expect(new Set(completed.map((item) => item.id)).size).toBe(2);
  },
);

5. Root cause

The Pi translator keys all assistant text in a thread/parent scope by the same assistant channel. At assistant boundary handling, a new assistant start only removes a closed-stream marker; it does not settle an earlier open stream. Successful end events close the stream, but error and aborted end events return without closing it:

if (assistantEvent.data.type === "message_start") {
  closedAssistantStreams.delete(streamKey);
  return [];
}
if (message.stopReason === "error" || message.stopReason === "aborted") {
  return [];
}

When a later successful response closes that same channel, the assembler's text-close implementation retrieves the earlier open item, retains its ID, and uses the explicitly supplied final text instead of its accumulated text:

const finalText = delta.text ?? accumulated;
let bbItemId = open?.bbItemId;

That behavior is correct for one stream's final snapshot, but wrong if two distinct Pi assistant messages are mapped into one stream. The resulting completion contains only the later text. The agent-end fallback uses only the last assistant message and cannot restore an earlier discarded message. The synthetic queue update does not itself cause or prevent this mapping; the unclosed boundary is the essential precondition.

Important limit: no evidence establishes that normal steering omits a successful message-end event. Aborted/error variants also omit a real provider's complete recovery/settlement lifecycle. Thus these fixtures demonstrate adapter robustness gaps, not a complete end-to-end steering reproduction.

6. Proposed fix and safety decision

First obtain the original upstream sequence around the two assistant starts: message-end stop reasons, error/retry events, and run-settlement boundaries. Replay that sequence through the adapter. If a live stream legitimately survives into the next assistant start, a narrow candidate is to settle its accumulated text before admitting the new message, without manufacturing empty or duplicate completions. Validate normal successful ends, error retries, aborts, tool transitions, parent scopes, and deferred settlement before changing production behavior.

No fix branch or PR is created: the rule requires a trusted-main reproduction of the reported steer behavior, and that condition is not met. A synthetic interrupted-boundary failure alone is insufficient to choose a production lifecycle repair. No linked open PR was found in issue connection/cross-reference metadata or the open-PR search for this issue number.

7. Verification

The same agent created a second fresh temporary worktree, named verify, at 916d684ac23d0b0de82c09cfc7553a50287d2188, performed another frozen install, built SDK prerequisites with Turbo, copied only the authored test, and executed the same command with a fresh local task cache key. This is a second clean run by the same agent, not independent verification.

pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/issue-6808-repro.test.ts
Exit: 1
Test Files  1 failed (1)
Tests  3 failed | 1 passed (4)

Both runs agree on the three failing variants and the passing successful-boundary control. Before adding the reproduction, the existing translation suite passed all 75 tests. No report correction was necessary after the second run. No live ports or data directories existed to change between runs.

8. Related issues

The trusted history identifies successful message-boundary handling in merged PR #6352. It is a relevant earlier repair, not proof that the exact incident here is fixed. No code from that PR branch was checked out or executed.

9. Appendix

Additional read-only checks: issue/comments and built-in classification properties; repository labels and public visibility; issue connection/cross-reference metadata; open PR search for issue number; base commit against canonical main; relevant source and message-boundary history. Build and reproduction commands are listed above. The publisher validates artifacts, scans output, pushes the report, and checks its Pages URL.

Issue data was treated only as untrusted claims. No issue-provided script, patch, external URL, or linked branch was run. Raw application data and machine-specific home paths are not included.