Skip to content

Thread view drops autoscroll on thread switch and permission prompts #607

Closed

Description

@currentbits

Problem

The agent transcript (center pane) often fails to pin to the bottom when:

  1. 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.
  2. 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 only useEffect.
  • Force-stick across the thread-id change and a new pendingPermission.requestId until a pin actually moves scrollTop to the bottom.
  • Ignore onBodyScroll while a programmatic pin is in flight.
  • overflow-anchor: none on .body so Chrome does not fight the pin.

Activity

  1. added
    bug
    plan:doing
    on Aug 20, 2026
  2. currentbits commented on Aug 20, 2026

    @currentbits
    OwnerAuthor

    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 scroll after:

    Fix: pin in useLayoutEffect, force-stick across those two events until a pin actually moves scrollTop onto the bottom, ignore programmatic scroll, overflow-anchor: none on .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 --noEmit clean.

  3. added
    plan:done
    and removed
    plan:doing
    on Aug 20, 2026
  4. currentbits commented on Aug 20, 2026

    @currentbits
    OwnerAuthor

    Shipped on main (78fe3bf); verified in the tree. Moving to plan:done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplan:done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions