Repository navigation
Backlog
Bug
Copy link
Description
Summary
Opening a long archived thread coincided with a synchronous events read and a server heap failure. A synthetic database reproduces an unbounded payload read in the current timeline loader. The production crash has not been attributed to this call site.
Versions and environment
mainatb0ddaad731565d7e4de68d824120d802fc78f7d5(the GitHub tip at check time).- macOS 27.2.1 arm64, Node 24.22.2. The isolated reproduction reuses local
better-sqlite312.10.0 and Drizzle 0.38.4. It does not run the installed app or use a user database.
Steps to reproduce
- In a source checkout with its development dependencies, save this as
/tmp/bb-timeline-read-repro.mjs. - From the checkout root, run
node --import tsx --max-old-space-size=512 /tmp/bb-timeline-read-repro.mjs. This constructs a new in-memory database from real migrations. This invocation assumes a normal development install. The code was verified with a local Node source resolver and the dependency versions above.
import { pathToFileURL } from 'node:url';
const root = pathToFileURL(`${process.cwd()}/`);
const { createMigratedConnection } = await import(new URL('packages/db/src/testing.ts', root));
const { createProject, createThread, noopNotifier, upsertHost } = await import(new URL('packages/db/src/index.ts', root));
const { findTimelineWindowBudgetFloorSequence, listStoredTimelineTurnEventRows } = await import(new URL('packages/db/src/data/events.ts', root));
const { THREAD_TIMELINE_EXCLUDED_EVENT_TYPES } = await import(new URL('packages/thread-view/src/timeline-noise-events.ts', root));
const db = createMigratedConnection();
const host = upsertHost(db, noopNotifier, { name: 'synthetic-host' });
const { project } = createProject(db, noopNotifier, { name: 'synthetic-project', source: { type: 'local_path', hostId: host.id, path: '/tmp/bb-synthetic' } });
const thread = createThread(db, noopNotifier, { projectId: project.id, providerId: 'claude-code' });
const turnId = 'synthetic-turn';
const raw = JSON.stringify({ rawType: 'synthetic/diagnostic', rawEvent: { text: 'x'.repeat(16 * 1024) } });
const put = db.$client.prepare("INSERT INTO events (id, thread_id, sequence, scope_kind, turn_id, type, data, created_at) VALUES (?, ?, ?, 'turn', ?, ?, ?, ?)");
const now = Date.now();
db.$client.transaction(() => {
const insert = (sequence, type, data) => put.run(`event-${sequence}`, thread.id, sequence, turnId, type, data, now);
insert(1, 'turn/started', '{}');
for (let i = 2; i < 10002; i++) insert(i, 'provider/unhandled', raw);
insert(10002, 'turn/completed', '{"status":"completed"}');
})();
const args = { threadId: thread.id, sequenceStart: 0, beforeSequence: 10003, excludedTypes: THREAD_TIMELINE_EXCLUDED_EVENT_TYPES, excludeDiagnosticEvents: false };
const floor = findTimelineWindowBudgetFloorSequence(db, { ...args, eventBudget: 1500 });
const rows = listStoredTimelineTurnEventRows(db, { ...args, maxInlineOutputChars: 8192, turnIds: [turnId] });
console.log(JSON.stringify({ floor, rows: rows.length, payloadBytes: rows.reduce((sum, row) => sum + Buffer.byteLength(row.data), 0) }));
db.$client.close();Expected vs actual
Expected: Expanding a selected turn cannot materialize an unbounded payload in one timeline request. Older data remains reachable without missing or duplicate conversation content.
Actual:
{"floor":8502,"rows":10002,"payloadBytes":164410024}
Evidence
- The timeline route builds a window. After choosing a bounded initial window, the turn-context read replaces the lower bound with the entire history epoch for selected turns. The DB helper materializes the matching payloads. The service decodes them before the response byte limit can help.
- In five alternating runs of an isolated HTTP wrapper around those DB helpers, with a probe on a separate connection and in a separate process, the median overlapping probe took 304 ms (283 to 319 ms). Heap use grew by about 167 MiB immediately after the query. The read returned 156.8 MiB of event data.
- Using the existing 4 MiB byte-floor helper before the query, a prototype read 256 rows. Median overlapping probe latency was 15 ms (12 to 22 ms), and heap growth after the query was 5.6 MiB. A raw sequence walk returned all 10,002 rows in 40 bounded pages. These are not BB route or conversation pagination measurements. Applying the floor blindly is not a proposed fix: the projector still needs the context that makes conversation pages match a full build.
What I ruled out
- The event-count floor exists and returned the expected sequence. The subsequent turn lookup bypassed it in the fixture.
- This is a current reproduction of the allocation mechanism in closed Large finished turns can OOM bb-server during timeline projection and cause a restart loop #1129. Page large finished turns by stored byte size #1199 introduced a bound before rows were loaded; Fix timeline pagination with snapshot-bound conversation groups #3325 removed that pre-read check from the standard timeline and bounds the projected response instead. The fixture does not contain nested delegation (Opening a thread with repeated nested delegation messages exhausts the server heap (exponential timeline expansion) #5210) or extension-state history (Latest thread-state lookup is still linear in extension-state history after #4931; 0.6–1.4 s freezes every ~2 s #6825).
- One diagnostic-filtered control returned only the two lifecycle rows with less than 1 MiB of heap growth. It still delayed the probe while scanning the fixture, so filtering diagnostics is not a general latency fix.
AGENT GENERATED
Activity