Repository navigation
Description
Summary
The thread transcript flickers many times per second in a long thread while Claude Code background subagents run. It switches between the full history and "Loading older messages…" with only the latest page. This happens when a background delegation row sits on an older page and keeps getting subagent events. Every live refresh then drops the loaded history. The auto-loader fetches it again, and the next event drops it again. This lasts until every background agent finishes.
Reproduction status: reproduced on main at 2726ab1ee542da44e4ed410680aa9f1d9a72ab74 with a server test that uses the real /timeline route and the real @bb/client-core merge (below). Also observed live on the packaged 0.43.4 desktop app.
Versions and environment
- bb 0.43.4 desktop app (Linux AppImage), Omarchy (Arch-based), kernel 7.2.5
- Provider:
claude-code(Claude Code 2.1.282), with backgroundAgenttool calls - Thread ran in a Daytona sandbox environment. That does not matter; the bug is in timeline paging.
Steps to reproduce
In the app
- In a Claude Code thread with enough history for older pages, ask the agent to start 3–5 background subagents (Agent tool with background mode).
- While they run, send a follow-up message. A steer into the running turn and a new turn both trigger it.
- Scroll up so older pages load.
- The transcript switches between the full history and "Loading older messages…" plus the latest page on every subagent event. The page scroll jumps each time.
Deterministic test on main
Add this test inside describe("timeline event budget", …) in apps/server/test/services/threads/timeline-event-budget.test.ts. Also add applyTimelineDelta to the @bb/server-contract import. Then run:
pnpm exec turbo run build --filter=@bb/server^...
cd apps/server && pnpm exec vitest run test/services/threads/timeline-event-budget.test.ts -t "background subagent"The test builds a thread with a background delegation in turn 1, followed by a later user message. It loads the latest page and walks every older page, as the app does. Then it streams subagent events: a turn-scoped child message and a thread-scoped item/backgroundTask/progress. For each event, it refreshes the latest page with afterSequence and merges it with mergeLoadedTimelineWithLatest.
test
it.each(["steer", "new-turn"] as const)(
"keeps walked history while a background subagent streams under a later %s message",
async (secondMessage) => {
const harness = await createTestAppHarness();
try {
const { db, thread } = setup(harness.db);
type EventInput = Parameters<typeof insertEvents>[2][number];
let sequence = 0;
const event = (
type: string,
scope: EventInput["scope"],
fields: Partial<EventInput> = {},
): EventInput => ({
threadId: thread.id,
sequence: ++sequence,
type,
scope,
providerThreadId: scope.kind === "turn" ? providerThreadId : null,
itemId: null,
itemKind: null,
parentToolCallId: null,
data: "{}",
...fields,
});
const delegationId = "turn-1-delegation";
const backgroundTaskId = "turn-1-background-task";
const backgroundTask = (progress: number) => ({
item: {
type: "backgroundTask",
id: backgroundTaskId,
familyId: "background-audit",
taskType: "local_agent",
description: "Background audit",
status: "pending",
taskStatus: "running",
skipTranscript: false,
usage: { totalTokens: progress, toolUses: progress, durationMs: 0 },
parentToolCallId: delegationId,
},
});
const message = (
turnId: string,
itemId: string,
text: string,
parentToolCallId: string | null = null,
): EventInput =>
event("item/completed", turnScope(turnId), {
itemId,
itemKind: "agentMessage",
parentToolCallId,
data: JSON.stringify({
item: {
type: "agentMessage",
id: itemId,
text,
...(parentToolCallId === null ? {} : { parentToolCallId }),
},
}),
});
const events: EventInput[] = [];
for (const turn of [1, 2]) {
const turnId =
turn === 2 && secondMessage === "steer" ? "turn-1" : `turn-${turn}`;
events.push(
event("client/turn/requested", threadScope(), {
data: JSON.stringify({
direction: "outbound",
source: "tell",
initiator: "user",
request: { method: "turn/start", params: {} },
requestId: requestId(turn),
senderThreadId: null,
input: [
{ type: "text", text: `User message ${turn}`, mentions: [] },
],
target:
turn === 1
? { kind: "thread-start" }
: secondMessage === "steer"
? { kind: "steer", expectedTurnId: "turn-1" }
: { kind: "new-turn" },
execution,
}),
}),
...(turnId === `turn-${turn}`
? [event("turn/started", turnScope(turnId))]
: []),
event("turn/input/accepted", turnScope(turnId), {
data: JSON.stringify({ clientRequestId: requestId(turn) }),
}),
);
if (turn === 1) {
const delegation = (status: "pending" | "completed") => ({
type: "delegation",
id: delegationId,
childRef: "toolu_background",
label: "Background audit",
status,
background: true,
...(status === "completed"
? { summary: "Async agent launched successfully." }
: {}),
});
events.push(
event("item/started", turnScope(turnId), {
itemId: delegationId,
itemKind: "delegation",
data: JSON.stringify({ item: delegation("pending") }),
}),
event("item/started", turnScope(turnId), {
itemId: backgroundTaskId,
itemKind: "backgroundTask",
parentToolCallId: delegationId,
data: JSON.stringify(backgroundTask(0)),
}),
event("item/delegation/completed", threadScope(), {
providerThreadId,
itemId: delegationId,
itemKind: "delegation",
data: JSON.stringify({ item: delegation("completed") }),
}),
);
}
for (let item = 0; item < 3; item += 1) {
events.push(
message(
turnId,
`message-${turn}-item-${item}`,
`Turn ${turn} item ${item}`,
),
);
}
}
insertEvents(db, noopNotifier, events);
const read = async (query: string) => {
const response = await harness.app.request(
`/api/v1/threads/${thread.id}/timeline?segmentLimit=1&${query}`,
);
expect(response.status).toBe(200);
return threadTimelineResponseSchema.parse(await response.json());
};
const walk = async (
rows: TimelineRow[],
start: TimelinePaginationCursor | null,
): Promise<TimelineRow[]> => {
let cursor = start;
while (cursor) {
const older = await read(
new URLSearchParams({
beforeAnchorSeq: String(cursor.anchorSeq),
beforeAnchorId: cursor.anchorId,
}).toString(),
);
rows = prependOlderTimelineRows({
olderRows: older.rows,
loadedRows: rows,
});
cursor = older.timelinePage.olderCursor;
}
return rows;
};
const latest = await read("");
let current = buildLoadedTimelineState({
latestWindowEndSequence: latest.maxSeq,
latestRows: await walk(latest.rows, latest.timelinePage.olderCursor),
olderCursor: null,
surfaceKey: thread.id,
historySnapshot: latest.timelinePage.historySnapshot,
});
expect(current.rows.length).toBeGreaterThan(latest.rows.length);
let previous = latest;
for (let progress = 1; progress <= 3; progress += 1) {
insertEvents(db, noopNotifier, [
message(
"turn-1",
`subagent-message-${progress}`,
`Subagent progress ${progress}`,
delegationId,
),
event("item/backgroundTask/progress", threadScope(), {
providerThreadId,
itemId: backgroundTaskId,
itemKind: "backgroundTask",
parentToolCallId: delegationId,
data: JSON.stringify(backgroundTask(progress)),
}),
]);
const response = await read(`afterSequence=${previous.maxSeq}`);
const live =
response.delta === undefined
? response
: {
...response,
rows: applyTimelineDelta(previous.rows, response.delta) ?? [],
delta: undefined,
};
const walked = await walk(live.rows, live.timelinePage.olderCursor);
current = mergeLoadedTimelineWithLatest({
current,
latestTimeline: live,
surfaceKey: thread.id,
});
expect(current.olderCursor).toBeNull();
expect(current.rows).toEqual(walked);
previous = live;
}
} finally {
await harness.cleanup();
}
},
);Expected vs actual
Expected: after each refresh, the loaded rows keep all walked history (olderCursor stays null). They equal a fresh full walk, including the delegation's new children.
Actual on main at 2726ab1ee:
Both cases (steer into the running turn, and a new turn) fail the same way after the first subagent event:
steer: maxSeq 16 olderRowsSourceSeqEnd 15 olderCursor.anchorSeq 10 client tip 14
new-turn: maxSeq 17 olderRowsSourceSeqEnd 16 olderCursor.anchorSeq 10 client tip 15
AssertionError: expected { anchorSeq: 10, … } to be null
The delegation row starts before the anchor, so the page omits it. It is also the row that changed, so olderRowsSourceSeqEnd rises above the client tip. The merge then throws away all walked history and keeps only the latest page. In the app, this is the flicker loop.
Live, on the affected thread, three consecutive GET /api/v1/threads/thr_h2ktqyjxjz/timeline responses:
maxSeq 27421 olderCursor.anchorSeq 26261 olderRowsSourceSeqEnd 27421
maxSeq 27446 olderCursor.anchorSeq 26261 olderRowsSourceSeqEnd 27446
maxSeq 27668 olderCursor.anchorSeq 26261 olderRowsSourceSeqEnd 27668
The page anchor (26261) is the steer message. The five running delegation rows start before it and are 220–800 KB each (150–270 child rows). The latest page is 39 KB.
Evidence
The chain on 2726ab1ee542da44e4ed410680aa9f1d9a72ab74:
timeline-pagination.ts#L122-L132:olderRowsSourceSeqEndis the maxsourceSeqEndof every projected row the page did not return. A running delegation that started before the anchor keeps raising it tomaxSeq.timeline-merge.ts#L370-L377: when that value is above the client'slatestWindowEndSequence, the merge returnscanMerge: false.mergeLoadedTimelineWithLatestthen rebuilds from the latest page alone.useAutoLoadOlderRows.ts#L102-L119: the sentinel is now in range, so it loads the older page again. The next subagent event resets it again.- The behavior is documented as accepted in
docs/timeline-pagination.md#L61-L63("A row that keeps changing while omitted … replaces loaded rows on each refresh"), added with Keep older timeline pages loaded while a thread streams #3686. Background subagents make that case common and long: one delegation can stream thousands of events for 30+ minutes.
Scope, from the local DB across 106 background delegations: 1,953 child events landed outside the delegation's own turn scope. 1,839 were thread-scoped item/backgroundTask/progress, 106 were item/backgroundTask/completed, and 5 were item events in another turn. 14 arrived after the launching turn completed.
Thread: thr_h2ktqyjxjz (Claude Code, 5 background agents, ~27.8k events).
What you ruled out
- Not a plugin: the rows are
delegation/backgroundTaskrows from the built-inprovider-claude-code. The loop is visible in raw/timelineresponses. - Still happens on
mainat2726ab1ee(test above). - Not Active timelines animate every height update, causing repeated main-panel jumps #3759 (height animation jumps), Timeline stacks one "Worked for" row per byte page while a large Workflow streams progress snapshots #1868 (stacked "Worked for" rows), or Timeline returns 0 rows with olderCursor: null when the window has no user-message anchor, leaving the thread permanently blank #3694 (0 rows with a null cursor). Keep older timeline pages loaded while a thread streams #3686 introduced
olderRowsSourceSeqEndand documents this limitation; this issue is that limitation with a common trigger. - Sending the omitted rows whole in the latest page is too heavy. Trimmed to children changed since the window start, they are still 1.28 MB here. The client's own
afterSequencegives a much smaller bound.
Suggested priority and effort
Medium. It hits any long Claude Code thread that uses background subagents. The workaround is to wait for the subagents to finish or reload. No data is lost, but the transcript cannot be used while it loops, and each loop re-downloads multi-MB older pages. I have a fix in progress and will open a PR.
Investigated in bb thread thr_qyxysvescs.
AGENT GENERATED
Activity
SawyerHood commentedon Sep 30, 2026
Verified report: https://get-bb.github.io/reports/issues/4388.html
PARTIALLY REPRODUCED: two clean same-SHA browser runs each showed four 5→2→5 history reset/reload cycles through actual pagination, client merge and timeline components; latest-row controls preserved history. Includes four genuine screenshots. Provider projection, real page fetches and full-app scroll anchoring remain untested. PR #4397 was not executed.
Preserve changing timeline history (get-bb#4397)