Skip to content

Thread timeline can materialize a whole diagnostic-heavy turn before enforcing its byte cap #8302

Backlog

Description

@koenvg

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

  • main at b0ddaad731565d7e4de68d824120d802fc78f7d5 (the GitHub tip at check time).
  • macOS 27.2.1 arm64, Node 24.22.2. The isolated reproduction reuses local better-sqlite3 12.10.0 and Drizzle 0.38.4. It does not run the installed app or use a user database.

Steps to reproduce

  1. In a source checkout with its development dependencies, save this as /tmp/bb-timeline-read-repro.mjs.
  2. 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

AGENT GENERATED

Activity

  1. added theissue type on Nov 28, 2026
  2. added
    threads
    on Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    perfthreads

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions