🚨 SLOP COP 🚨 · new-issue-autopilot

← reports

#6329 · Pi assistant stream completion

BugHighEffort: Lowproviders · provider-pi · confirmed-reproIssue #6329

2026-10-26 · trusted base b7bd02b927de272f1f0b2c8eaf332e1f457df9e7

Verdict: REPRODUCED · Root-cause confidence: high

1. TL;DR

Pi can stream an assistant explanation before executing a tool, but BB never completes that explanation as a transcript item. The translator ignores assistant message boundaries. When the tool opens, the shared assembler detaches the still-open assistant stream without completing it, leaving its start and text deltas orphaned. The final assistant message is completed at agent end, so it survives while the earlier explanation does not. A deterministic replay through the real translator and assembler reproduces one orphaned item; the local repair produces both completed messages and zero orphans.

2. Claims vs findings

ClaimFindingEvidence
An assistant explanation before a tool lacks completion.VerifiedThe baseline replay produces zero completed explanations before the tool and one orphan after the turn.
The final plain-text answer survives.VerifiedThe baseline completes only “The workspace is ready.”
Assistant boundaries are discarded, leaving agent end as the text fallback.VerifiedThe boundary parser accepts only custom-role messages; agent end closes only the last assistant.
The exact reported packaged version and operating-system combination behave this way.Not separately verifiedThis investigation runs trusted main on Linux with synthetic Pi events, not the reporter's installation.
The reported historical thread contains those exact missing items.Not accessedNo production store or reporter data was read.

3. Environment

4. Minimal reproduction

This is an event-lifecycle defect, not a screenshot-based visual defect. The following script feeds valid synthetic Pi message and tool events through production code. It does not execute the represented shell tool.

  1. Clone trusted main and select the recorded base:
    git clone https://github.com/get-bb/bb.git bb-6329
    cd bb-6329
    git checkout b7bd02b927de272f1f0b2c8eaf332e1f457df9e7
    pnpm install --frozen-lockfile --prefer-offline
    pnpm exec turbo run build --filter=@get-bb/plugin-sdk
    pnpm exec turbo run build
  2. Save the complete script below as observe-6329.mjs in the repository root.
  3. Run:
    node --conditions=source --import tsx ./observe-6329.mjs

Expected output

{
  "completedBeforeTool": 1,
  "completedText": [
    "Checking the workspace.",
    "The workspace is ready."
  ],
  "orphaned": 0
}

Actual output on trusted main

{
  "completedBeforeTool": 0,
  "completedText": [
    "The workspace is ready."
  ],
  "orphaned": 1
}
Complete runnable reproduction script
import { resolve } from "node:path";
import { pathToFileURL } from "node:url";

const source = (path) => import(pathToFileURL(resolve(path)).href);
const { createPiDeltaTranslator } = await source(
  "plugins/provider-pi/src/delta-translation.ts",
);
const { experimental_createDeltaAssembler: createDeltaAssembler } = await source(
  "packages/plugin-sdk/src/provider-bridge-testing.ts",
);
const translator = createPiDeltaTranslator({
  resolveModelContextWindow: () => null,
});
const assembler = createDeltaAssembler({
  providerId: "pi",
  entropyPrefix: "reproduction",
  textDeltaFlushMs: 0,
});
const events = [];
function send(event) {
  events.push(
    ...assembler.assemble({
      threadId: "synthetic-thread",
      deltas: translator.translate(event, { threadId: "synthetic-thread" }),
    }),
  );
}
function assistant(text) {
  const message = {
    role: "assistant",
    content: [{ type: "text", text }],
    stopReason: "stop",
  };
  send({ type: "message_start", message });
  send({
    type: "message_update",
    message,
    assistantMessageEvent: { type: "text_delta", contentIndex: 0, delta: text },
  });
  send({ type: "message_end", message });
  return message;
}
send({ type: "agent_start" });
const first = assistant("Checking the workspace.");
const completedBeforeTool = events.filter(
  (event) => event.type === "item/completed" && event.item.type === "agentMessage",
).length;
send({
  type: "tool_execution_start",
  toolCallId: "synthetic-tool",
  toolName: "bash",
  args: { command: "pwd", cwd: "/repo" },
});
send({
  type: "tool_execution_end",
  toolCallId: "synthetic-tool",
  toolName: "bash",
  result: { content: [{ type: "text", text: "/repo" }] },
  isError: false,
});
const last = assistant("The workspace is ready.");
send({ type: "agent_end", messages: [first, last] });
const completed = events.flatMap((event) =>
  event.type === "item/completed" && event.item.type === "agentMessage"
    ? [event.item]
    : [],
);
const completedIds = new Set(completed.map((item) => item.id));
const orphaned = events.filter(
  (event) =>
    event.type === "item/started" &&
    event.item.type === "agentMessage" &&
    !completedIds.has(event.item.id),
).length;
console.log(
  JSON.stringify(
    { completedBeforeTool, completedText: completed.map((item) => item.text), orphaned },
    null,
    2,
  ),
);

All inputs are synthetic. The two texts, tool reference, and thread reference above are test-only values. This HTML is self-contained; raw evidence and the regression patch remain outside the public report repository.

5. Root cause

  1. The boundary schema requires role: z.literal("custom"). An assistant message_end cannot pass it.
  2. The message boundary handler returns no deltas on that parse failure. It consequently sends no item.textClose for assistant text.
  3. Opening a tool item detaches assistant streams through detachAssistantStreams. This removes the open assistant entry rather than inventing a completion. Its previous item/started and item/agentMessage/delta events remain without an item/completed event.
  4. Agent-end fallback extracts text from only the last assistant message. It cannot recover detached earlier explanations.
const piEvent = piCustomMessageBoundaryEventSchema.safeParse(event);
if (!piEvent.success) {
  return [];
}

The shared assembler's text-close behavior also matters to a repair: an explicit text close without an open item can create a new completed item. Thus merely adding boundary closes while retaining the unconditional final-text fallback would duplicate the last answer. This repair tracks completed assistant streams within each thread and parent-tool scope, preserving legacy fallback only when the current stream has not already closed.

6. Proposed fix and local verification

Accept assistant messages at the existing boundary parser; close nonempty assistant text at message_end. Leave custom-message behavior unchanged. Reset closed-stream tracking on agent/message start, new streamed text, and thread reset. Suppress duplicate agent-end text completion only for an already-closed stream. No public wire format, dependency, storage layout, or policy changes are required.

The focused regression was written before production changes. It covers streamed and non-streamed replies, with and without an intervening tool, immediate completion at each boundary, distinct item IDs, matching start/completion IDs, and exactly one completion per message after agent end.

pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/delta-translation.test.ts -t 'completes each assistant message once'
Baseline run 1: Tests 4 failed | 74 skipped (78)
Baseline run 2, clean checkout: Tests 4 failed | 74 skipped (78)
After repair: Tests 4 passed | 74 skipped (78)

The failure is the intended assertion: no completed agentMessage exists when the first assistant message_end arrives. The repair also has regression coverage for fallback across turns, concurrent thread/parent-tool scope isolation, and reasoning-only boundaries without empty assistant items.

pnpm exec turbo run test lint typecheck --filter=bb-plugin-provider-pi
Test Files 33 passed | 1 skipped (34)
Tests 326 passed | 8 skipped (334)

The standalone replay after the candidate repair produces the expected output above: two distinct completed messages and zero orphans. However, the broader recorded-provider parity suite fails nine cases after the candidate change (50 pass); the same suite passes all 59 tests on the unchanged second checkout, confirming that these failures are caused by the candidate. The Pi old/new comparison likewise reports nine changed cells and one skipped cell. Even though restoring omitted completions necessarily changes event output, these existing failures mean the candidate does not meet the simple-fix gate. Its diff is 203 text lines changed across two Pi files (189 additions and 14 deletions), with no binary changes; git diff --check passes. No fix branch is committed or pushed, and no pull request is opened. Updating recording expectations or adjusting the repair requires follow-up beyond this safe automatic fix.

pnpm parity --old "$VERIFY" --new . --provider pi
0 passed, 9 failed, 1 skipped (10 cells)

pnpm exec turbo run test --filter=@bb/provider-parity
Candidate: Tests 9 failed | 50 passed (59)
Unchanged second checkout: Tests 59 passed (59)

Live authenticated Pi and browser journeys were not run; no claim is made about a specific model or browser rendering beyond the verified canonical event contract.

7. Verification in a second clean checkout

The same agent repeated the investigation in a fresh detached temporary worktree at the exact base commit. This was a second clean run, not an independent review. Only the newly authored regression test was applied there; production source remained unchanged, verified by git diff. A fresh frozen install, SDK build, and full Turbo build succeeded. The focused command reproduced the same four failures. The standalone replay then reproduced the exact baseline JSON above, including one orphaned assistant item. No report correction was needed.

git worktree add --detach "$VERIFY" b7bd02b927de272f1f0b2c8eaf332e1f457df9e7
cd "$VERIFY"
pnpm install --frozen-lockfile --prefer-offline
pnpm exec turbo run build --filter=@get-bb/plugin-sdk
pnpm exec turbo run build
pnpm exec turbo run test --filter=bb-plugin-provider-pi -- src/delta-translation.test.ts -t 'completes each assistant message once'
node --conditions=source --import tsx "$EVIDENCE/observe.mjs"
git diff --exit-code -- plugins/provider-pi/src/delta-translation.ts

VERIFY and EVIDENCE denote fresh local temporary directories; random directory identifiers and machine paths are intentionally omitted.

8. Related work

At investigation time, GitHub cross-reference metadata and the open-PR search for issue 6329 found no linked open pull request. No other issue is claimed as a duplicate without direct matching evidence.

9. Appendix and trust boundary

The issue and any suggested commands or patches were treated as untrusted claims. None were executed or copied. The reproduction and fix were derived from trusted main, the Pi event declarations, and the shared assembler implementation. No linked branch, external issue attachment, or production runtime data was used.

Local artifacts retained outside this public repository include the pre-fix test patch, both failing test logs, the replay script and normalized outputs, build logs, and the passing test/lint/typecheck output. Source UI inventory reported pre-existing unmapped CLI-family drift; it was not altered. The relevant RPC lifecycle is covered at the translator/assembler boundary; live UI verification remains not run.

Reproduction verdict label: confirmed-repro.

> AGENT GENERATED