Repository navigation
Conversation
|
@slopcop please review the late-completed-thinking pagination fix when you have a moment. |
|
🚨 SLOP COP 🚨 · I’m the Slop Cop, and I’m reviewing this change now. I’ll check security, code quality and architectural duplication, performance, and the practical end-to-end behavior before posting a consolidated review. |
|
@slopcop another ping for review on the late-completed-thinking pagination fix. |
|
🚨 SLOP COP 🚨 · I’m the Slop Cop, and I’m reviewing this change now. I’ll check security, code quality and architectural duplication, performance, and the practical end-to-end behavior before posting a consolidated review. |
| }) | ||
| : windowRows; | ||
| const wholeItemWindowRows = | ||
| window.requiresWholeItemClosure || page.kind === "older" |
There was a problem hiding this comment.
🚨 slopcop/review — [P2] Avoid a full-thread span scan on every paginated page
This expanded condition now calls ensureSequenceWindowWholeItemRows for every ordinary older page, while the knownHasOlderSegments change also puts normal latest pages through it whenever older history exists. The helper’s span aggregate is constrained by thread and item predicates, but the current indexes make SQLite choose the thread/sequence index and build a temporary B-tree for GROUP BY, so it scans the full thread rather than just the page’s items. With the actual schema, the specialist pass measured roughly 1.9 ms at 10k events, 13.0 ms at 100k, and 53.8 ms at 500k for a 20-item query. Because SQLite runs synchronously, routine refreshes gain history-sized event-loop work and a full older-page walk trends toward O(history × pages). Please target this lookup with an appropriate item-leading index/query shape, or make origin ownership use the existing lifecycle-specific path instead of the all-event MIN/MAX aggregate.
| for (const span of spans) { | ||
| const key = scopedItemRefKey(span); | ||
| if (args.ownership === "origin") { | ||
| if (span.completedSeq === null || span.minSequence < args.sequenceStart) { |
There was a problem hiding this comment.
🚨 slopcop/review — [P1] Keep unfinished items visible when they have no post-boundary event
When turn 2 starts before a late completion arrives, this branch classifies completedSeq === null as newer-window-owned and removes the item from the older page. The latest window, however, discovers items only from rows already inside that window, so an interrupted reasoning item whose start and delta occurred in turn 1 vanishes from both pages. A direct in-memory repro at this SHA produced a latest page containing only User 2 with activeThinking: null, while the older page contained User 1 and “Stopped manually” but not the “Checking” thought. If the provider never emits completion, the loss is permanent. Please add the pre-completion two-page case and either retain the unfinished item on its origin page or explicitly hydrate open items into the latest page before filtering it here.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain-English summary: this PR tries to keep a thought attached to the user turn where it began, even when the provider reports that thought as finished only after the next turn has started. It adds explicit page-ownership rules and fetches the late completion back into the older turn.
I found two issues:
- [P1] An unfinished cross-page thought can disappear from every page. The new origin-page rule removes all items with no completion, but the latest page can discover one only if it has an event after that page’s boundary. I reproduced the gap between turn 2 starting and the late completion arriving: the latest page had no active thought, and the older page had the manual-stop row but not the interrupted thought. This can persist forever if completion never arrives. The regression test covers only the state after completion.
- [P2] Routine pagination now performs a full-thread item-span scan. The whole-item helper runs on every ordinary older page and on latest pages with older history. With the current indexes, the aggregate scans the thread and uses a temporary grouping B-tree; the measured cost rose from about 1.9 ms at 10k events to 53.8 ms at 500k events for 20 page items. Walking all pages can therefore become quadratic in practice.
The security review found no authorization, injection, or cross-thread disclosure issue. The query remains scoped to the authorized thread and preserves inline-output limits. A project-wide architecture scan found no duplicate ownership helper to reuse; the logic is in the right subsystem, though extracting the ownership classification into a pure function would make these edge cases easier to test and audit.
Verification at dec40ec0973af43a177b649423a86e38cfe61a9b:
- GitHub CI is green.
- Forced
@bb/servertypecheck passed. - Forced timeline-window suite passed 28/28.
- Forced DB events suite passed 88/88.
- The synthetic 10,019-event timeline performance test passed its broad ceiling: 12 pages, 1,185 rows, 180.1 ms minimum full walk.
- The dev app started successfully and loaded through Doobie. Its isolated database had no threads, so that browser pass was a startup/UI smoke test; the P1 behavior was instead verified directly against an in-memory migrated database.
The first finding is merge-blocking in my view, but this is a comment-only review as requested; I did not approve or request changes.
45ec8a7 to
f503f3c
Compare
f503f3c to
71bc927
Compare
## Human comments ## What was wrong An older timeline page could correctly keep an item that completed late beside the prompt where it started, but omit the newer user prompt that separates the two responses while rebuilding the older row. The older summary and its details endpoint then calculated different source ranges (`1–9` versus `4–8`), so exact detail lookup failed with “Failed to load turn details.” This completes the behavior introduced by [PR #3110](#3110); the reproduced case is documented in the [fixer handoff](https://ymichael.getbb.app/projects/proj_qrv2s45kmq/threads/thr_qtzru86rhh). ## What changed Standard older-page selection now includes the next prompt only as projection context when an item or turn lifecycle was backfilled past the cursor. The prompt establishes the same response boundary used by full-history and details projection, then is removed before the older page is returned. Existing late-item ownership, normal latest pages, byte and sequence pagination, interruption current work, and retained-output previews remain unchanged. The regression expands the older summary returned by the real server timeline builder and proves it returns the same details as the complete timeline. ## How you verified - The focused regression failed before the fix with `Timeline turn summary details could not match range 1-9` and passes after it. - The exact database/server reproduction reproduced `1–9` versus `4–8` before the fix and `4–8` versus `4–8` with no error after it. - `pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline-in-turn-window.test.ts` — 30/30 passed after rebasing onto current local `origin/main`. - `pnpm exec turbo run typecheck --filter=@bb/server` — passed. - Earlier adjacent validation passed 91 server pagination/route tests and 26 DB query-plan tests; the boundary lookup uses the existing thread/type/sequence index. Fixes: no linked issue. > AGENT GENERATED
Human comments
What was wrong
The shared timeline window closure treated every scoped item that crossed a page boundary as belonging to the newer sequence window. For a completed thinking item whose start was in an older user turn but whose completion arrived after the next prompt began, standard turn pagination therefore separated the lifecycle: the newest page rendered the completion beneath the wrong prompt as “Thought for 0ms,” and loading the older page left the originating turn without its thought. This followed 6e83eb2 from #3066.
A thought that never receives
item/completedcould also disappear from both pages when its original turn moved into older history.What changed
(thread_id, turn_id, type, item_id, sequence)index.There are no database schema or migration, host-daemon wire, CLI, documentation, UI-component, pagination-limit, or mobile changes.
How you verified
pnpm exec turbo run test --filter=@bb/server -- test/services/threads/timeline-in-turn-window.test.ts— 28/28 passed after rebasing onto current localorigin/main.pnpm exec turbo run test --filter=@bb/db— 448/448 passed.pnpm exec turbo run typecheck --filter=@bb/serverandpnpm exec turbo run typecheck --filter=@bb/db— passed.EXPLAIN QUERY PLANregression proves the span lookup usesevents_thread_turn_type_item_sequence_idx; no new index is created.