Repository navigation
Timeline: one attach rule, and one landing decision for unread threads - #6253
Merged
ymichael merged 9 commits intoOct 26, 2026
Merged
Conversation
…e end #5951 dropped shrink re-attach, so a reader who scrolled up a few pixels to collapse a tool call landed at the very bottom but stayed detached, with the jump-to-bottom button showing. Attach once the clamp to the end persists into the next frame; a one-frame shrink still keeps the reader on their row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sture The previous commit only attached through the clamp-settle path, which a touch drag's three-second momentum window bypasses: the browser's clamp was folded in as the reader's own scroll and re-anchored at the end. On phones, dragging up to a tool call and tapping it closed left the view at the bottom with the jump button showing. Any reconcile in which the content shrank and the detached view sits at the end now attaches on the next frame if it is still there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Opening an unread thread could leave NEW mid-screen or off-screen instead of at the top: - Reopening a thread showed its cached copy first. The detail query is only live while the thread is open, so that copy still read as read, and the fresh fetch's divider was treated as a live reply with no reveal. The thread now counts as opening until its post-mount fetch settles. - When the cutoff was older than the first loaded segment, the divider sat above the oldest loaded row, the reveal went there, and the divider moved once older rows loaded. The list now holds the divider back and loads older rows until the cutoff is covered. - The reveal ran once against estimated heights for windowed rows; rows rendering around it pushed NEW down. It now repeats until the divider's position is stable, like search reveals. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A thread with no read time, which only Mark as unread produces, placed NEW above the first loaded row. With paged history that is not the thread's start, so the view landed mid-thread with NEW off-screen once older rows loaded. Such threads now get no divider and open like a read thread; the unread dot is unchanged. The before-first placement is removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Instead of loading older pages until the read cutoff is covered, the divider is placed only when the cutoff falls inside the rows loaded when it is first evaluated. Otherwise the thread opens at the bottom with no divider, and that placement stays dropped, so paging back by hand later neither shows NEW nor pulls the view to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he keeper Attachment: the keeper attached from seven places, most tied to an event (wheel down, touch drag, End/PageDown, resize or restore at the end, a collapse that shrank content). Each new way of reaching the end needed a new rule. Now one rule covers them: a detached view within the bottom threshold attaches, unless a restore is still waiting for its row. It attaches at once when the reader's scroll, a navigation, or a completed restore put it there, and on the next frame when only layout did, so a shrink that regrows within a frame does not attach. Landing: opening an unread thread was decided by five independent pieces (the read-state snapshot, loaded rows, the divider's own scroll effect with a retry loop, the saved-position restore, and the keeper). Now the divider snapshot is taken from the first fresh copy of the thread, placeability is decided once against the loaded rows, and the landing goes through the keeper's restore path with the divider as a landmark anchor. The keeper then holds NEW at the top while rows render around it. This removes the divider's scroll effect, the frame-retry loop, the opening flag, and scrollElementIntoViewClampedToMaxScroll. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tach scroll-position-keeper.model.test.ts drives the keeper through random sequences of wheel and touch scrolls, row toggles, streaming, removals, prepends, regroups, one-frame shrinks, viewport resizes, navigations, restores, and jumps to the bottom, with and without iOS write deferral and with the browser's clamp scroll before or after the resize callbacks. After each step it checks that the keeper is attached exactly when the view is at the end, that content changes never detach, that the reading row does not move without the reader unless the content cannot hold it, and that a reader's scroll is not moved. On main's keeper 75 of 300 sequences end detached at the end; on this keeper none of 5000 do. The test also showed the one attach rule would pull a tool output box that was not streaming when it opened down to the bottom as its output loaded in, which main never does. Layout alone now attaches only a view with a reading position; a view the reader never placed still attaches when the reader or a navigation brings it to the end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
thread-opening.model.test.tsx renders the timeline with the thread view's own loading path: the bootstrap and thread queries (now shared with ThreadDetailView through useThreadDetailThread), the divider state, the timeline controller, the scroll body, and the keeper. A fake server pages a random history the way the real one does. Each sequence opens or returns to the thread with a random read state, page size, and time away, resolves the requests in a random order, and sometimes scrolls while they load. Once settled, NEW must sit above the first unread row of the whole history, be at the top unless the reader scrolled or the view is at the end, and show whenever the cutoff is inside the first page; otherwise the saved position or the bottom stands. Reintroducing each opening bug fails it: trusting the cached thread copy (NEW left 2513px down after a return), placing NEW above the first loaded row, and the one-shot reveal (NEW 156px above the top once real heights replace estimates). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ymichael
deleted the
bb/debug-timeline-scroll-regressions-thr_9mxqmidzcg
branch
October 26, 2026 17:22
ymichael
added a commit
that referenced
this pull request
Oct 26, 2026
…final assistant message (#6327) ## Human comments ## What was wrong When finished turns are flat (Claude Code's default), the unread NEW divider went above the first row after the read point. For a turn that ran while the reader was away, that row is the turn's first tool call. Opening the thread landed on "Listed files in ." and the reader had to scroll through every tool call and note to reach the answer. With collapsed turns the same rule put NEW above the "Worked for …" row. That's harmless there, but it isn't where reading resumes either. ## What changed New experiment `unreadDividerAtAnswer` (Settings → Experiments → **NEW divider before final assistant message**, or `bb settings experiment unreadDividerAtAnswer true`). It is off by default and stays off for early adopters. - `ThreadTimelineUnreadDividerPlacement` gains `anchor: "first-unread-row" | "turn-answer"`. `useThreadDetailThread` sets it from the experiment, and `useThreadUnreadDividerState` keeps it in the opening snapshot, so the landing logic from #6253 is unchanged. - With `turn-answer`, `findUnreadDividerIndex` starts from the same first unread row and moves forward to the first row where reading resumes: - the final assistant message of a settled turn (the last assistant row with that turn id); - an error that ended the turn; - a message that starts a new turn, such as an agent report (steers excluded); - any row of a turn with no reply. - Setup system rows such as "Provisioned thread" are skipped. The running turn (when `scopeActive`) keeps the old placement, so NEW never jumps onto a streaming reply. If nothing qualifies, it falls back to the first unread row. NEW still never sits on the reader's own message. - With `first-unread-row` (experiment off), placement is unchanged. - Docs: `docs/configuration.md` (Experiments) and `bb guide customization`. - Client and settings only. No wire change and no `HOST_DAEMON_PROTOCOL_VERSION` bump. The experiment key is added to `@bb/domain`, so the existing experiments route and CLI accept it. ## How you verified - New unit cases in `ThreadTimelineRows.unread-divider.test.ts` (turn-answer anchor): - final answer of a flat turn and of a collapsed turn; - setup rows skipped; - an agent message that starts a turn; - an error that ended the turn; - a turn with no reply; - a running turn; - a partly seen work group; - the reader's own message. - `main`'s existing cases still run against the `first-unread-row` anchor. - `pnpm exec turbo run typecheck lint --filter='...[origin/main]'`: 146/146 tasks. - `turbo run test --filter=@bb/app`: 6,332 tests. `--filter=@bb/domain`: 259. `apps/server` `test/system`: 237, including the experiment defaults, PUT and early-adopter tests. - Real app on `pnpm start:worktree`: - Threads were real Claude Code and Codex turns spawned with the dev `bb` CLI. - Compared against an `origin/main` app build served on the same server and data, with the same read point. Each thread was opened from the sidebar at 1280×800, and the row after NEW was read from the DOM. | Build | Experiment | Thread | Row after NEW | |---|---|---|---| | `origin/main` | n/a | Claude Code (flat) | Listed files in . (first tool call) | | branch | off | Claude Code (flat) | Listed files in . | | branch | on | Claude Code (flat) | Final assistant message (step note + summary) | | `origin/main` | n/a | Codex (collapsed) | Worked for 24s | | branch | off | Codex (collapsed) | Worked for 24s | | branch | on | Codex (collapsed) | The numbered answer | - Regression checks on the branch with the experiment on: - a thread marked unread (`bb thread unread`) and a read thread both open with no NEW, as on `main`; - the Settings switch flips the server value both ways; - turning on the early-adopter setting leaves the experiment off; - the CLI rejects `maybe` and a misspelled key. - Not changed here: a turn that finishes while its thread is open can still show NEW afterwards. `main` does the same, and the branch only moves that divider to the reply. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: review <review@local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
ymichael
added a commit
that referenced
this pull request
Oct 27, 2026
) ## Human comments ## What was wrong A thread scrolled to the bottom unpinned itself with no input: the view jumped up by about the composer's height and the ↓ button appeared ([Discord report](https://discord.com/channels/1522478522332090528/1564676088465199184/1564676088465199184): "jumps up 225 pixels after a few idle seconds", iPad and iPhone). The timeline composer footer is a `sticky` element inside the scroll content. When the footer or a row collapses and regrows within one task while something forces a layout, the browser clamps `scrollTop` to the shrunken extent. The content regrows before the frame ends, so no ResizeObserver fires. The clamp scroll then arrives with no input and no size change, which the keeper reads as navigation, so it detaches. #6253 did not change this path: its attach rule only applies within 4 px of the end. A second source of the same no-input scrolls: `buildMarkdownComponents` defined `MarkdownLink`, `MarkdownCodeRenderer`, image/video/source and the mention elements as closures. Whenever link routing or mentions changed identity, every link, inline code element and pill in every message remounted. On main this happens twice on every thread open (52 code elements each time in the fixture) and again on background events. iOS WebKit moves the scroller when links remount, as found while working on #6253. ## What changed - **Scroll extent floor** (`scroll-position-keeper.ts`, `bottom-anchored-scroll-body.tsx`): the first child of the timeline's scroll content is an invisible spacer. Its height is the content's height at the last ResizeObserver delivery, cancelled by an equal negative `margin-bottom`. It takes no space, but the scroll extent can no longer drop for a one-task collapse, so the browser has nothing to clamp. A shrink that lasts reaches the ResizeObserver, which lowers the floor before reconciling. A scroll with no input now counts as layout when the extent changed or when the content height no longer matches the floor. This preserves the existing rule for native scroll adjustments that come with a size change. The keeper's detach rule is otherwise unchanged, so find in page and focus moves still navigate. Tool output boxes pass no floor. - **Stable markdown components** (`markdown-preview.tsx`, `markdown-thread-mentions.tsx`, `markdown-prompt-mentions.tsx`, `QueuedMessagesList.tsx`): the components are module-level and read per-message options (link routing, image policy and offset, theme, localhost rewriting, mentions) from context. Option changes re-render them instead of remounting them. The components map depends only on table layout and which mention and directive kinds are present. `buildThreadMentionComponent` and `buildPromptMentionComponent` are replaced by `ThreadMentionElement` and `PromptMentionElement` with their contexts. - **Test layout** (`test/fake-flow-layout.ts`): honors `margin-bottom`, counts overflowing boxes toward `scrollHeight`, and clamps `scrollTop` when the extent shrinks, as browsers do. `takeClamp()` reports a clamp so harnesses can fire its scroll event. Tests that stood in for a ResizeObserver delivery by calling `reconcile()` now flush the observers. - `docs/timeline-pagination.md` documents the floor. Client only; no wire, CLI or plugin API change. ## How you verified - **iOS 26.5 Simulator Safari, iPad Pro 11 and iPhone 17 Pro, dev server.** I used a fixture like the reporter's (long message with inline code, worktree environment with the git "Committed" bar) and a probe-injecting proxy. Collapsing `[data-scroll-footer]` for one task (hide it, read `scrollHeight`, restore it): - main: the view jumped 203 px on iPad and 113 px on iPhone, exactly the footer height, and the button appeared and stayed. Collapsing the last row jumped the full distance. - branch: `scrollHeight` and `scrollTop` were unchanged and the view stayed pinned, on both devices and for both footer and row. - **Markdown remounts on load** (probe counts `<a>` and `<code>` removed inside rows): - main: 52 code elements twice per open, or 91 links plus 91 code elements on a links fixture; - branch: 0. - **Real touch on the branch (Maestro):** a swipe up unpins and shows the button; a swipe back down re-pins and hides it. - **Desktop and phone-width Chromium:** `scrollHeight` equals the content height, and the footer sits flush at the viewport bottom, so the floor leaves no gap. - **Tests that fail on main and pass here:** - `scroll-position-keeper.test.ts`: stays attached when content shrinks and regrows within a frame and the clamp scroll arrives late (with and without iOS write deferral); follows content that stays shrunk to the new end; - `scroll-position-keeper.model.test.ts`: new random step that shrinks a row, forces layout, regrows it, then delivers the late clamp. On main's keeper it fails with "a content change detached the reader"; - `markdown-preview.test.tsx`: links and inline code stay mounted when link routing and thread mentions change identity (with and without incremental blocks); a link routes through the latest handler. - `ConversationMessageContent.streaming.test.tsx`: when the settled prefix grows, the live tail is now parsed as two pieces instead of one whole-tail parse, because the piece cache is no longer reset by a component-map change. The rendered output is identical. - `pnpm exec turbo run typecheck lint test --filter=@bb/app`: 638 files, 6313 tests passed. > AGENT GENERATED 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Michael Yong <review@local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Scroll-to-bottom button shows while at the bottom. Collapsing a tool call near the end, while scrolled up a little, clamps the view to the end, but the keeper stayed detached. It attached only through event-specific rules, and #5951 deliberately never attached on a content shrink. On touch the clamp usually falls inside the 3s momentum window after a drag, so that path missed too. Every attach bug since #5951 has had this shape: the view reached the end through a path no rule covered.
Unread threads did not open at NEW. Where the view landed on open came out of five independent pieces: the read-state snapshot, the loaded rows, the divider's own one-shot scroll, the saved-position restore, and the keeper. Each assumed different timing:
These predate #5951: the pre-#5951 build fails these cases as well.
What changed
Two structural changes replace the per-case rules.
One attach rule (
scroll-position-keeper.ts). A detached view within the 4px threshold of the end attaches, whatever put it there, unless a restore is still waiting for its row.One landing decision.
useThreadUnreadDividerStatetakes its snapshot from the first fresh copy of the thread (hasFreshThreadfromuseThreadDetailThread), never cached or placeholder data.TimelineRowsListdecides once, against the loaded rows, whether the cutoff is inside them. If it is not, there is no divider, no automatic paging back, and it stays dropped when the reader pages back by hand.data-scroll-landmark-id, which the keeper can now anchor to like a row. The keeper then holds NEW at the top while rows render around it. A reader who already scrolled keeps their position.before-firstplacement is removed;ThreadTimelineUnreadDividerPlacementis now{ cutoffAt }.scrollElementIntoViewClampedToMaxScroll(only the divider used it).docs/timeline-pagination.mddocuments the attach rule and the landing decision. Client only; no wire, CLI or plugin API change.How you verified
Latest sidebar-opening fix:
pnpm exec turbo run test --filter=@bb/app -- src/views/thread-detail/thread-opening.model.test.tsx src/views/thread-detail/useThreadUnreadDividerState.test.ts src/hooks/useThreadReadTracking.integration.test.tsx: 14 tests passed, including 40 randomized opening sequences.pnpm exec turbo run lint typecheck --filter=@bb/app: passed; lint reports warnings, no errors.git diff --checkpassed.pnpm start:worktreeand repeated the actual sidebar click in Chromium. NEW remained visible after the thread was marked read and landed within 1px of the viewport top. Server and daemon health checks passed.Earlier branch verification (before the sidebar-opening fix):
Keeper tests:
Divider tests:
New randomised test
scroll-position-keeper.model.test.ts.KEEPER_MODEL_SEEDSfor deeper runs.New randomised opening test
thread-opening.model.test.tsx.useThreadDetailThread, whichThreadDetailViewnow uses), the divider state, the timeline controller, the scroll body and the keeper.OPENING_MODEL_SEEDSfor more.pnpm exec turbo run typecheck lint test --filter=@bb/app: 647 files, 6312 tests passed.Real-browser A/B against a live server: headless Chromium; phone runs at 402px with touch emulation. Each build was served through a proxy that rewrote an idle 46-segment thread's read state. "back" means switching to another thread and returning. Where NEW landed, relative to the viewport top ("bottom" = attached at the end with no divider):
Collapse bug A/B:
Guards, identical on main and branch: