#7693 · Repeated preview mapping discards stable row identity
Verdict: REPRODUCED · Root-cause confidence: high
1. TL;DR
Timeline updates can repeat work for old command-output previews even when those commands have not changed. At the trusted main commit, two preview passes over the same input turn produce equal content but different command and parent objects. The later reuse pass restores the first objects only after a recursive content comparison. The reproduction demonstrates this allocation-and-reuse cycle directly; it does not measure live-stream latency or CPU impact.
2. Claims vs findings
| Claim | Status | Evidence |
|---|---|---|
| Long unchanged outputs and their parents are rebuilt | Verified | Both clean runs produce parentReused=false and childReused=false with identical content and unchanged input. |
| The reuse pass puts previous rows back | Verified | Both runs produce restoredParentReused=true and restoredChildReused=true; apps/server/src/services/threads/timeline-window-reuse.ts:52 shows the recursive comparison before replacement. |
| Earlier pagination preparation can retain stable rows | Verified in source | apps/server/src/services/threads/timeline.ts:1591 invokes apps/server/src/services/threads/timeline-selection-memo.ts:1072 before pagination. This is conditional on a retained memo entry, not every possible build. |
| The nominal streaming batch interval is 50 ms | Verified in source | packages/provider-bridge-protocol/src/assembler/delta-assembler.ts:144, apps/host-daemon/src/event-sink.ts:1, and apps/host-daemon/src/event-sink.ts:174. Actual sends are conditional on queued events and scheduling, not an unconditional timer-driven rebuild every 50 ms. |
| Meaningful user-visible slowdown and common output sizes | Unmeasured | No live thread, representative workload, or wall-clock benchmark was used. |
3. Environment
- Public repository: get-bb/bb; trusted origin/main commit
1320c88e8abdd3f145bc9a5c305eace269fb2f28. - Linux 4.19.0-gvisor; Node v22.19.0; pnpm 9.15.0; date 2026-11-17.
- Two separate temporary clones, each checked out detached at the same recorded commit; frozen installs and Turbo builds. No linked-PR checkout or execution.
- Unit-level test only: no provider session, live app instance, listening port, or user runtime database. Repository test setup uses temporary migrated test databases, not production data.
4. Minimal reproduction
- Clone the trusted repository and use the recorded commit:
git clone https://github.com/get-bb/bb.git bb-repro cd bb-repro git checkout --detach 1320c88e8abdd3f145bc9a5c305eace269fb2f28 pnpm install --frozen-lockfile --prefer-offline pnpm exec turbo run build --filter=@get-bb/plugin-sdk pnpm exec turbo run build
- Save the full inline reproduction test below as
apps/server/test/services/threads/timeline-preview-reuse-repro.test.ts. It constructs a completed turn containing a 6,000-character command output using the repository's existing row contracts, then runs the real preview and reuse functions. - Run:
pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline-preview-reuse-repro.test.ts
Expected: equal content and parentReused=true, childReused=true without needing structural reconstruction. Actual in both clean runs:
{"parentReused":false,"childReused":false,"restoredParentReused":true,"restoredChildReused":true,"inputUnchanged":true}
@bb/server:test: AssertionError: expected { id: 'command-1', …(20) } to be { id: 'command-1', …(20) } // Object.is equality
@bb/server:test: Received: serializes to the same string
@bb/server:test: Test Files 1 failed (1)
@bb/server:test: Tests 1 failed (1)
The assertion fails specifically on command-preview identity after content equality and preview-marker checks pass. The final parent identity assertion is not reached, but the diagnostic records its result separately. This is an intentionally failing regression, not a setup error. Raw logs and the test file are retained locally outside the public reports repository; the complete repeatable test and exact relevant output are inline here.
Full reproduction test
import { describe, expect, it } from "vitest";
import { timelineRowChildren, type TimelineRow } from "@bb/server-contract";
import type { ThreadTimelineWindow } from "../../../src/services/threads/timeline.js";
import {
DEFAULT_MAX_INLINE_OUTPUT_CHARS,
shortenTimelineResponseOutputs,
} from "../../../src/services/threads/timeline-output-shortening.js";
import { reuseUnchangedTimelineRows } from "../../../src/services/threads/timeline-window-reuse.js";
describe("timeline preview reuse reproduction", () => {
it("preserves preview row identity across unchanged windows", () => {
const output = "sample".repeat(1_000);
const command: TimelineRow = {
id: "command-1",
threadId: "thread-repro",
turnId: "turn-1",
sourceSeqStart: 1,
sourceSeqEnd: 2,
startedAt: 0,
createdAt: 0,
kind: "work",
status: "completed",
workKind: "command",
callId: "call-1",
command: "fixture",
description: null,
cwd: null,
source: null,
output,
exitCode: 0,
completedAt: 1,
approvalStatus: null,
activityIntents: [],
};
const turn: TimelineRow = {
id: "turn-row-1",
threadId: "thread-repro",
turnId: "turn-1",
sourceSeqStart: 1,
sourceSeqEnd: 2,
startedAt: 0,
createdAt: 0,
kind: "turn",
status: "completed",
summaryCount: 1,
completedAt: 1,
children: [command],
};
const window: ThreadTimelineWindow = {
rows: [turn],
contextBoundarySeq: null,
completedTurnDisplay: "collapse",
activePromptMode: null,
activeThinking: null,
activeWorkflows: [],
activeBackgroundCommands: [],
pendingTodos: null,
extensionStates: {},
providerCommands: null,
sessionOptions: null,
modelFallback: null,
maxSeq: 2,
timelinePage: {
returnedSegmentCount: 1,
olderCursor: null,
historySnapshot: "",
olderRowsSourceSeqEnd: null,
},
};
const options = {
maxInlineOutputChars: DEFAULT_MAX_INLINE_OUTPUT_CHARS,
preview: true,
};
const first = shortenTimelineResponseOutputs(window, options);
const second = shortenTimelineResponseOutputs({ ...window, rows: [turn] }, options);
const firstChild = timelineRowChildren(first.rows[0]!)![0]!;
const secondChild = timelineRowChildren(second.rows[0]!)![0]!;
const restored = reuseUnchangedTimelineRows(second.rows, first.rows);
console.log(JSON.stringify({
parentReused: second.rows[0] === first.rows[0],
childReused: secondChild === firstChild,
restoredParentReused: restored[0] === first.rows[0],
restoredChildReused: timelineRowChildren(restored[0]!)![0] === firstChild,
inputUnchanged: command.output === output && turn.children![0] === command,
}));
expect(second.rows).toEqual(first.rows);
expect(firstChild.kind).toBe("work");
if (firstChild.kind !== "work" || firstChild.workKind !== "command") {
throw new Error("Expected command preview");
}
expect(firstChild.output).toContain("characters omitted from preview");
expect(restored[0]).toBe(first.rows[0]);
expect(secondChild).toBe(firstChild);
expect(second.rows[0]).toBe(first.rows[0]);
});
});
5. Root cause
Preview shortening remaps stable input rows on every build, allocating replacement leaves and ancestors before structural reuse deep-compares and restores the prior subtree. The preview threshold is 4,000 characters; the separate inline truncation cap is 32,000. Our 6,000-character input isolates preview allocation, without exercising cap truncation.
apps/server/src/services/threads/timeline-output-shortening.ts:80 allocates a new work row whenever the output exceeds the preview threshold:
export function previewTimelineRowOutput(row: TimelineRow): TimelineRow {
if (row.kind !== "work") {
return row;
}
if (
(row.workKind !== "command" && row.workKind !== "tool") ||
row.output.length <= TIMELINE_INLINE_OUTPUT_PREVIEW_THRESHOLD_CHARS
) {
return row;
}
return {
...row,
output: buildTimelineOutputPreview(row.output),
outputPreview: row.outputPreview ?? {
experimental_fullOutputAvailability: "available",
totalChars: row.output.length,
},
};
apps/server/src/services/threads/timeline-output-shortening.ts:105 creates a new tree mapping on every invocation without a memo for the original rows:
export function shortenTimelineResponseOutputs(
response: ThreadTimelineWindow,
{ maxInlineOutputChars, preview }: ShortenTimelineResponseOutputsOptions,
): ThreadTimelineWindow {
const shorten = (rows: TimelineRow[]) =>
mapTimelineRowTree(rows, (row) => {
const truncated = truncateRowOutputs(row, maxInlineOutputChars);
return preview ? previewTimelineRowOutput(truncated) : truncated;
});
const rows = shorten(response.rows);
const updates = response.timelinePage.olderRowUpdates;
const olderRowUpdates = updates && shorten(updates);
packages/server-contract/src/thread-timeline-operations.ts:10 copies a parent when its mapped children change. This identity loss propagates through every ancestor on the affected path; unaffected short-output branches can still retain identity. It is not accurate to say every timeline row is always rebuilt.
apps/server/src/services/threads/thread-timeline-windows.ts:181 runs shortening immediately before unchanged-window reuse. apps/server/src/services/threads/timeline-window-reuse.ts:19 and apps/server/src/services/threads/timeline-window-reuse.ts:52 show that different references enter the recursive JSON-value comparison. For an equal turn subtree, comparison succeeds at the parent and restores that subtree; this does not imply a separate comparison of every nested row afterward.
6. Proposed fix
Memoize the mapped row subtree by original immutable row identity and both transformation options, so an unchanged subtree skips both preview construction and descendant walking. Use weak identity keys to avoid retaining discarded input trees. Test option separation, changed child rows, older-row updates, and truncation-only paths. A leaf-only memo would leave the repeated parent-tree walk unresolved.
No fix branch or duplicate PR is created: the open linked PR #7700 already closes this issue. Its branch was not checked out or run.
7. PR review
PR #7700 — static inspection only
GitHub metadata confirms it is OPEN and its closing issue reference is #7693. Inspected head: 1b14e3f84c1a9931ba73bb72a267eb9dd982f1bf. The diff adds a WeakMap cache to the shared row-tree mapper, propagates it through recursion, and keeps separate shortening caches for option pairs. This targets the verified allocation path rather than masking the deep comparison.
Review note, low severity: the added test in apps/server/test/services/threads/timeline-output-shortening.test.ts:137 checks repeat-call reuse and preview-mode separation, but does not exercise two different truncation caps or invalidation by a replaced child. Those are useful follow-ups for the mapper-cache invariant. No correctness defect is established from the static diff; cache correctness depends on immutable input subtrees and stable mapper semantics for each supplied cache.
Verdict: statically aligned with the root cause; runtime behavior not verified. Only trusted-main reproduction and existing tests are run here. No linked PR code or test is executed.
8. Related issues
#4674 concerns unbounded decoding of an open turn, an earlier stage rather than preview identity. Issue searches for output-preview and timeline-reuse costs did not establish another exact issue duplicate. PR #7700 is the existing implementation candidate.
9. Verification
The same agent repeated the reproduction in a second clean temporary checkout named verification, separate from the first checkout named base. Before adding the newly authored reproduction, the verification checkout was clean at 1320c88e8abdd3f145bc9a5c305eace269fb2f28. It received its own frozen dependency install and Turbo builds; only the newly authored test was copied across. No shared live ports or runtime data directories were used.
pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline-preview-reuse-repro.test.ts
Result in each checkout: exit 1, one failed test, identity assertion failure.
Observed in each checkout: {"parentReused":false,"childReused":false,"restoredParentReused":true,"restoredChildReused":true,"inputUnchanged":true}
The second run supports the final report without correction. This is a repeat by the same agent, not independent verification. Relevant existing output-shortening and row-reuse suites pass:
@bb/server:test: Test Files 2 passed (2) @bb/server:test: Tests 7 passed (7)
10. Appendix
The first whole-repository build exposed a clean-checkout ordering race: the GitHub plugin attempted to load SDK runtime entries before the SDK build finished. The SDK completed in that invocation; retrying the unchanged build passed. The second checkout built the SDK first and then the full repository. This unrelated setup failure is not counted as reproduction evidence. The full build also regenerates a tracked web route tree; that generated difference is restored before the second test and is not part of this report or a proposed fix.
The authoring gate for this test is stable transformed-row identity at the actual preview boundary. The credible defect is repeated transformation of unchanged long output. Existing tests exercise truncation, UTF-16 safety, small-output identity, child traversal, and one preview call; none tests repeated preview calls. No production seam, mock, dependency, or global-state change is introduced.
Investigation commands include GitHub metadata and comments reads, repository label/property reads, linked-PR metadata and static diff reads, targeted issue searches, canonical main fetch, commit/path history, source inspection, frozen installs, Turbo builds, the reproduction commands above, and:
pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline-output-shortening.test.ts test/services/threads/timeline-window-reuse.test.ts git diff --check git fetch origin main git log 1320c88e8abdd3f145bc9a5c305eace269fb2f28..origin/main --oneline -- apps/server/src/services/threads/timeline-output-shortening.ts packages/server-contract/src/thread-timeline-operations.ts
Issue content and the linked PR diff were treated as untrusted claims. No issue instructions, scripts, external links, or linked PR code were executed. No screenshots are supplied because this is a server allocation/identity bug, not a visual rendering reproduction.
> AGENT GENERATED