Skip to content

fix(remote): open another conversation on its newest message - #1691

Merged
ace331 merged 1 commit into
mainfrom
fix/remote-scroll-reset
Nov 25, 2026
Merged

ace331 merged 1 commit into
mainfrom
fix/remote-scroll-reset

Conversation

@ace331

@ace331 ace331 commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

What

Switching between two remote conversations in the desktop app opened the second one at the first one's scroll position — a message from a while back, seemingly at random. Long conversations made it visible; short ones hid it.

Why

The remote view is drawn for whichever conversation is open, and the app's own chat column keys AgentThread per thread for exactly this reason — the remote view had no key:

  • AppShell renders RemoteConversationView without one, and every in-chat switch (left rail's merged list, a fork's child, the palette) only changes activeRemote, so the instance survives;
  • useStickyAutoScroll keeps stickToBottomRef, anchorRef and the container's scrollTop outside React state, so the new transcript inherits the old one's "the reader scrolled up" and an anchor naming a message it does not have;
  • settleViewport then does what it is written to do for a replaced transcript — keep the current position — so the conversation opens at the previous pixel offset. A short transcript clamps that offset to the bottom (looks fine); a long one lands on real content.

The remote timeline's snapshot cache makes it worse on revisit: the cached entries are seeded synchronously, so there is no short intermediate frame to clamp the offset back.

Fix

  • key RemoteConversationView by ${desktopId}:${sessionId}, the same contract AgentThread states for local threads;
  • give useStickyAutoScroll a resetKey that drops stickiness/anchor and follows the newest message, for the frames that hand this view another conversation without remounting (the vibe cell, a panel). Callers that already remount leave it out.

Tests

  • useStickyAutoScrollHook.test.ts: a swap under one container now lands at scrollHeight; the same key still keeps the reader's position.
  • RemoteConversationView.scroll.test.tsx: opened another conversation through the view, with faked viewport heights.

Both fail without the fix (2800 where 4000 is expected). Full desktop suite passes: 441 files / 6291 tests, tsc --noEmit and eslint clean.

Not in this PR

Two adjacent findings, either worth its own change:

  • the tail cursor is Number.MAX_SAFE_INTEGER on the client and NEWEST_PAGE_CURSOR on the host, but the Agent only recognises before == i64::MAX (agent/src/session/history/paging.rs:284), so desktop and phone first paints get the 600-row ceiling instead of the intended 150 — the code comment there measures that at 250–310 ms on a long tool-heavy conversation;
  • the desktop readPage ignores trimmed/shortPage; the phone backfills (HISTORY_TAIL_BACKFILL_MAX_PAGES).

The remote view is drawn for whichever conversation is open, and the app's own
chat column keys `AgentThread` per thread for exactly this reason — the remote
view had no key. So switching from one remote conversation to another (the left
rail's merged list, a fork's child, the palette) kept the instance, and
`useStickyAutoScroll` keeps its stickiness, reading anchor and the container's
`scrollTop` in refs and DOM across that swap.

With the reader scrolled up — reading history while a reply streams — the new
transcript inherited `stickToBottom=false` and an anchor naming a message it does
not have. `settleViewport` then deliberately keeps the current position, so the
conversation opened at the previous one's pixel offset. A short transcript hid
it, because the browser clamps a stale offset to the bottom; a long one landed on
a historical message, which is the report.

Key the view per `desktopId:sessionId`, and give the hook a `resetKey` for the
frames that hand it another conversation without remounting it (the vibe cell, a
panel) — so the reset does not depend on every caller remembering the key.

Both tests fail without the fix, landing at the old offset (2800 of 4000).
@ace331
ace331 enabled auto-merge (squash) November 25, 2026 08:11
@ace331
ace331 merged commit ffe62d8 into main Nov 25, 2026
10 checks passed
@huichen
huichen deleted the fix/remote-scroll-reset branch November 26, 2026 19:00
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.

1 participant