Repository navigation
Description
Problem
The agent transcript (center pane) often fails to pin to the bottom when:
- A permission / question / plan prompt appears — the Allow/Deny (or Answer) card is below the fold, so it looks like the agent is still working.
- Switching from another thread — the newly selected thread opens at the top (or wherever leftover scroll landed), not on the latest messages / pending action.
Follow-up to #306 / #408. Those covered React-state ticks and post-paint growth (images, highlight, fonts) via ResizeObserver. They did not cover stick-to-bottom being cleared by a scroll event that is not a user scroll-up.
Root cause
stickToBottom is a ref flipped by onBodyScroll whenever scrollHeight - scrollTop - clientHeight > 80. Two sequences flip it to false and then the pin effect / ResizeObserver refuse to follow:
Thread switch (issue #83 loading gap). visibleDetail is null while threads.get is in flight, so ThreadView unmounts .body and remounts it for the new thread at scrollTop = 0. Chrome then fires an async scroll (flex layout settling, overflow appearing). That event sees a large distance, sets stickToBottom = false, and the subsequent ResizeObserver no-ops. The thread-id effect does set stickToBottom = true, but it runs in useEffect (after paint) and loses the race to the delayed scroll event.
Permission card. pendingPermission is a sibling of the timeline, not a timeline row. A large card (plan markdown, command textarea) is inserted at the bottom. Overflow anchoring / the card's own layout fires a scroll with distance > 80px before the pin effect runs (or after it ran against a still-short scrollHeight). Stick clears; the action buttons stay off-screen. Status stays "working" (isWorking still true), so the "Agent working…" strip does not itself signal that a prompt is waiting.
Expected
- Switching threads always lands on the latest content (and a pending prompt if any).
- A new permission/question/plan prompt re-pins even if a non-user scroll event reported we were away from the bottom.
- Deliberate scroll-up still unsticks; ResizeObserver must not yank the user back.
Fix notes
- Pin in
useLayoutEffect(before paint), not onlyuseEffect. - Force-stick across the thread-id change and a new
pendingPermission.requestIduntil a pin actually movesscrollTopto the bottom. - Ignore
onBodyScrollwhile a programmatic pin is in flight. overflow-anchor: noneon.bodyso Chrome does not fight the pin.
Activity
currentbits commentedon Aug 20, 2026
Implemented on this thread's branch (
coder/fork-autoscroll-doesnt-always-seem-to-wo-caed9a).Stick-to-bottom was losing the race to a delayed, non-user
scrollafter:visibleDetail=nullremount on thread switchworking)Fix: pin in
useLayoutEffect, force-stick across those two events until a pin actually movesscrollToponto the bottom, ignore programmatic scroll,overflow-anchor: noneon.body. #408 ResizeObserver growth path and deliberate scroll-up are unchanged.Renderer proof:
test/threadView.test.tsx#408 + #607 (4/4) plus permission/question/plan prompt suites.tsc --noEmitclean.currentbits commentedon Aug 20, 2026
Shipped on main (78fe3bf); verified in the tree. Moving to plan:done.