Skip to content

Index historical file paths during timeline row matching - #7835

Merged
ymichael merged 3 commits into
mainfrom
slopcop/issue-7833
Nov 19, 2026
Merged

ymichael merged 3 commits into
mainfrom
slopcop/issue-7833

Conversation

@bb-slop-cop

@bb-slop-cop bb-slop-cop Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · new-issue-autopilot

Human comments

What was wrong

Timeline projection searched every accumulated file row separately for each incoming file change, including rows already claimed in the same event. This made large file-change events quadratic in their file count. The behavior reproduces on trusted main in two clean checkouts: a sixteenfold increase in file count costs about 183× as much with reversed completion order.

Reproduction and root-cause report: https://get-bb.github.io/reports/issues/7833.html

What changed

  • Index existing row positions by historical path once per event, with descending candidate lists that lazily discard claimed rows.
  • Select the earliest eligible row across both incoming paths, preserving historical aliases, duplicate paths, stale-row reappearance, and the rule that a new row cannot be claimed again in the same event.
  • Add a public timeline scaling regression and an identity regression for competing rename paths and duplicate files.
  • All changes stay in packages/thread-view; no dependency, lockfile, generated-file, persisted-data, public API, protocol, CLI, or UI changes.
  • Changed-line count: 193 total text lines across 3 files (188 additions, 5 deletions), measured with git diff --numstat origin/main. Production: 27 additions and 5 deletions; tests: 161 additions. No binary changes.

How you verified

  • Added the scaling regression before changing production code. On unchanged main, its reversed-order case fails: ratio 183.44, expected below 64. A second clean checkout fails the same assertion at 182.13. The unchanged-order control passes the intentionally generous threshold.
  • After the fix, the focused scaling cases pass at 8.11× and 19.18× for a sixteenfold file-count increase; 4,096-file builds take approximately 13–15 ms, versus 146–401 ms before.
  • The identity regression passes before and after the fix.
  • pnpm exec turbo run test --filter=@bb/thread-view -- test/file-change-scaling.test.ts test/build-thread-timeline.test.ts --silent=false: 86 passed.
  • pnpm exec turbo run test typecheck lint:type-aware --filter=@bb/thread-view: 545 tests passed, typecheck and type-aware lint passed.
  • pnpm exec turbo run test --filter=@bb/server -- test/timeline-history test/services/threads/timeline-in-turn-window.test.ts test/services/threads/timeline-event-budget.test.ts test/public/public-thread-timeline-work-rows.test.ts: 58 passed, 2 skipped. The history-replay cases require BB_TIMELINE_HISTORY_DB, which was not supplied; no real application data was used.
  • pnpm exec oxfmt on the three changed files and git diff --check pass.
  • PR Match file-change rows by path index instead of scanning every row #7834 is closed and unmerged; its branch was not checked out or run. No linked open PR existed when this change was prepared.

Fixes #7833

AGENT GENERATED

ymichael and others added 2 commits November 19, 2026 13:49
The timing-ratio assertion flakes under load: 5 of 16 local runs on the
fixed branch exceeded the 64x threshold. The identity regression keeps
the row-matching behavior covered.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 1ef46e8 into main Nov 19, 2026
39 checks passed
@ymichael
ymichael deleted the slopcop/issue-7833 branch November 19, 2026 21:56
ymichael added a commit that referenced this pull request Nov 19, 2026
## Human comments

## What was wrong

The timeline build in `@bb/thread-view` had no check against cost
growing faster than the data. #7754 replaced an indexed lookup with a
per-file scan of every row. Behavior tests passed, and the regression
stayed in until #7835. Adding a growth check found two more quadratic
paths in `group-event-projection-turns.ts`:

- `applyExternalUserBoundaries` filtered every root user message in the
thread once per turn (turns × messages).
- `findRootTurnRunningAtSequence` scanned every turn once per
thread-scoped warning or interaction prompt (turns × prompts).

## What changed

- **New test,
`packages/thread-view/test/timeline-build-growth.test.ts`.** It builds
timelines for 16 thread shapes at 100 and at 400 units: files in one
edit (same and reversed completion order), file changes, commands,
command output deltas, assistant messages and deltas, reasoning deltas,
tool calls, reads and searches, web searches, plan updates, delegations,
user messages sent during a running turn, turns, and turns that each
raise a thread-scoped permission prompt.
- It counts work during the build: array callback, scan and copy
methods, plus Array/Map/Set iteration and `Object.keys/values/entries`.
- It requires 4× the input to cost less than 6× the work. Linear code
measures about 4×; quadratic code about 16×.
- It counts work rather than timing it, so it is deterministic and
cannot flake under load.
- The prototype wrappers exist only during the synchronous build and are
restored in `finally`.
- **`applyExternalUserBoundaries`:** sorts the boundary sequences once,
then binary-searches each turn's window. The output is already
ascending, so the per-turn sort is gone.
- **Thread-scoped messages:** a single sweep resolves the running turn
for all of them (`findRootTurnsRunningAtThreadMessages`). It walks turns
sorted by start and keeps a stack that discards turns completed before
the current message.
- No wire, protocol, CLI, persisted-data or UI changes.

## How you verified

- The new test fails on the code it guards:
  - `item-records.ts` from before #7835: 11.4× and 13.7×.
- `group-event-projection-turns.ts` from before this PR: 6.97× for
turns, 9.41× for per-turn thread-scoped prompts.
  - After this PR, every scenario measures 3.5–4.0×.
- Real data, read-only export of 7 local threads (the four with the most
turns, 1,370/798/641/720, plus the three with the most thread-scoped
interaction prompts):
- `JSON.stringify(buildThreadTimelineFromEvents(...))` hashes are
identical before and after, for `completedTurnDisplay` collapse/expand ×
`includeNestedRows` true/false.
  - Full-build medians:

    | thread | turns | before | after |
    |---|---:|---:|---:|
    | `thr_cdfq9maj8q` | 1,370 | ~395 ms | ~345–357 ms |
    | `thr_d5ej4e2gtv` | 798 | ~357 ms | ~303–322 ms |

    Smaller threads show no measurable change.
- `pnpm exec turbo run test typecheck lint:type-aware lint
--filter=@bb/thread-view` passes.
- `pnpm exec turbo run test --filter=@bb/server --
test/services/threads/timeline test/public/public-thread-timeline
test/timeline-history` passes: 263 passed, 2 skipped. The skipped tests
are history replays that need `BB_TIMELINE_HISTORY_DB`.

> AGENT GENERATED

🤖 Generated with [Claude Code](https://claude.com/claude-code)

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.

Timeline builds take quadratic time in a fileChange item's file count

2 participants