Skip to content

Order the timeline by source sequence and drop the ordering boundary - #7795

Merged
ymichael merged 3 commits into
mainfrom
bb/timeline-source-order
Nov 18, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/timeline-source-order

Conversation

@ymichael

@ymichael ymichael commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The timeline had two display orders. It grouped rows turn by turn until the first user message that landed inside another turn (a message while a turn was still open, or while a delegated child was still running). After that "ordering boundary" it sorted every later row by source sequence. #320 added the switch so a message sent mid-turn shows where it was sent. Everything downstream then had to reproduce it:

  • Paging: a whole-thread boundary scan, plus timeline-display-ownership.ts to work out which page shows a row whose display position differs from its sequence.
  • Server re-sort: a delegation-span boundary query and a server-side re-sort.
  • Outline: the conversation outline checkpoint could never move past the boundary, so 3 of the 5 largest local threads reproject everything after it on every rebuild.

The display order itself was also inconsistent before the boundary: operation notices recorded mid-turn showed after the turn's reply, and two turns running at once showed one turn whole before the other. Pending steers were pinned to the bottom on threads without a boundary but sorted into place on threads with one.

What changed

One display rule (packages/thread-view):

  • Every row is ordered by where its content starts. A collapsed summary row starts at its first summarized item, not at the turn's request.
  • A completed turn's work collapses into one summary row per run, and a run ends at any visible user message that lands inside the turn before its final reply.
  • Pages no longer pass split points in; the projection computes them from the rows it loaded.

Deleted:

  • the ordering boundary;
  • timeline-display-ownership.ts;
  • the external-user boundary scan in timeline-context-order.ts (the grouping context keeps only request/turn bookkeeping);
  • getFirstParentedTimelineBoundarySequence and the late-delegation rows it needed;
  • listStoredStandaloneThreadTimelineRows, which only display ownership called;
  • orderTimelineRowsUsingContext;
  • the boundary in the projection cache key;
  • the outline checkpoint's boundary cap.

Because display order is now sequence order, a page owns exactly the rows whose sourceSeqStart is in its window.

Pending steers become live state (server-contract, server, app, CLI):

  • A steer waiting for the running turn is no longer a row on any page. The latest page returns it in a new pendingSteers field, alongside activeThinking and activeWorkflows, so push deltas and window reuse carry it.
  • The app's timeline controller and bb thread log show pending steers after the rows, as main does.
  • Once accepted, the steer becomes a row with the same id where it was accepted. Rejected steers stay rows ordered by their request.

Other:

  • hasTimelineGroupingContextChangesInRange replaces the old change probe, with a query-plan test and query-cost case.
  • docs/timeline-pagination.md describes the new rule.
  • No host-daemon wire change. The timeline response gains pendingSteers, a required array that is empty off the latest page. SDK types pick it up from the contract.

Visible changes, all toward "in the order it happened":

Change Threads affected (of 4,995)
A user message moves above a startup warning that fired just after it ~186
An operation notice moves to where it happened instead of after the turn's reply ~277
Turns that ran at the same time interleave by time ~12
After a steer, the agent text written before that turn's work shows above the work summary instead of below it —
A duplicate "interrupted" notice right after an error merges, now that they're adjacent 2

How you verified

Real data, from a VACUUM INTO copy of a 10.7 GB local bb database:

Full builds, main vs this branch, all 4,995 threads. 4,615 are identical. Every difference is one of the moves in the table above. I checked each pattern by hand on the threads where it showed up.

Paged walks. test/timeline-history/paged-walk.test.ts walks a thread page by page at the default and a 120-event budget and compares the result with one full build. It passes for 1,000 walks: every thread whose display changed (380) plus 120 random ones. Main passes the same set. The deletion was safe because display order now equals page order. Two intermediate designs broke the walks for exactly that reason (an in-turn reorder, and pending steers appended after sorting), and both were fixed by removing the special order, not by adding ownership.

Outline replay with no boundary cap. test/timeline-history/outline-replay.test.ts (opt-in, BB_TIMELINE_HISTORY_DB, same harness as #7765) replays the 5 largest threads plus 7 overlap-heavy ones. It appends events in random chunks, changes status at random, runs live pruning and switches connections, and the incremental outline matches a full build at every step (197 s).

Live. On a pnpm start:worktree instance:

  • Seeded real threads showing each change, compared against an origin/main instance.
  • Ran a real Codex thread through sleep 25 and steered it mid-command. The steer was accepted one event later and renders as a row there, splitting the turn's summary around it. pendingSteers was empty afterwards.

Tests:

  • New server test: a pending steer is in no page's rows, only the latest page carries it in pendingSteers, and acceptance turns it into a row with the same id.
  • Boundary-only tests were removed or rewritten as grouping-context cache tests.
  • The CLI snapshot for a pending steer is unchanged from main.

Commands:

  • pnpm exec turbo run typecheck lint --filter='...[origin/main]' passed (140 tasks).
  • pnpm exec turbo run test --filter=@bb/server --filter=@bb/db --filter=@bb/thread-view --filter=@bb/server-contract --filter=@bb/client-core --filter=@bb/cli --filter=@bb/app passed: server 4,316, db 718, thread-view 553, server-contract 88, client-core 239, cli 934, app 7,128. One server test timed out while all suites ran concurrently and passes alone in 7.5 s.
  • pnpm exec turbo run check:query-costs --filter=@bb/db passed.

AGENT GENERATED

🤖 Generated with Claude Code

ymichael and others added 3 commits November 18, 2026 13:02
The timeline grouped rows turn by turn until the first user message that
landed inside another turn, then sorted everything after it by sequence.
Pagination, the grouping context and the outline checkpoint all had to
reproduce that mode switch.

Every row is now ordered by where its content starts. A completed turn's
work collapses into one summary row per run, and a run ends at any visible
user message inside the turn before its final reply. A summary row starts at
its first summarized item, and pending and rejected steers sort like every
other row. Because display order equals sequence order, a page owns the rows
whose sourceSeqStart is in its window and computes split points from the
rows it loads.

Removed: the ordering boundary, timeline display ownership, the whole-thread
external-user boundary scan, the parented boundary query, the server-side
re-sort, and the outline checkpoint's boundary cap.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A steer waiting for the running turn is live state, like activeThinking. The
latest timeline page returns it in pendingSteers; it is no longer a row on any
page, so rows stay in sequence order and paging needs no exception. The app
and `bb thread log` show pending steers after the rows, as before. Once the
turn accepts a steer, it becomes a row with the same id where it was accepted.
Rejected steers stay rows ordered by their request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant