Skip to content

fix(threads): keep scrolling the thread over interactive visuals - #707

Merged
nixuuu merged 1 commit into
devfrom
fix/agent-visual-scroll
Nov 14, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/agent-visual-scroll

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

Problem

On web and desktop, the thread stops scrolling while the cursor is over an interactive visual, then jumps once the cursor leaves it. The user's recording shows this.

Root cause

Wheel and touch input over the sandboxed visual frame goes to the frame's document. The frame can't scroll, so the scroll chains to the thread feed, but the feed never gets the wheel event. ScrollIntent labels that scroll unattributed and settle() treats it as a layout change. It then restores the reading anchor, or the end when following, and every step is undone.

Fix

  • The kit reports hover: a bare boolean that says whether the pointer is over the frame. It carries no coordinates and forwards no other events. The kit sends at most 4 per second, and the last report always carries the current state. VisualFrameInbox parses it, checks the type, and rate-limits it with its own window (hoversPerSecond).
  • The web host turns that state into an event on the frame element. While a frame is hovered, the feed counts a scroll under it as the reader's. A pointermove in the feed's own document clears the state, and so does unmounting the frame.
  • The kit document is scrollable only when the host caps the frame below its content (overflow: hidden otherwise). A document that can scroll even 1px captures a whole wheel gesture. The height is now measured from the bounding box and rounded up. ready includes the body padding too, so the frame no longer hops 24px after mount.
  • Security model unchanged: allow-scripts only, same CSP, port-only channel.
  • Mobile: the native list scrolls the WebView (scrollEnabled={false}), so mobile doesn't have this problem. Mobile ignores the new message.

A per-gesture message didn't work: in Chromium (site-per-process), the feed's scroll event can arrive before the frame's message, even with a non-passive listener. The hover state arrives long before any wheel.

Verification

Chromium with --site-per-process, on the /dev/long-thread feed with a local fixture (not committed) that adds a tabs + stats + chart visual every third turn. I measured how far a row moved on screen for each wheel step:

Scenario dev this branch
120 × −40 px, cursor fixed over visuals while they pass 0 px on all 120 steps (frozen) same as the margin run
120 × +40 px, over visuals 0 px on all 120 steps 4800 / 4800 px, 0 off-steps
Following the end, 30 × −20 px starting over a visual – 600 / 600 px, 0 off-steps
Same scroll with the cursor on the feed margin (control) baseline identical to the run over visuals
  • Light and dark both checked.
  • The odd −360…−400 px step in the "up" runs also happens over the margin and on dev: it is the virtual feed measuring rows above, not the frames.
  • Inside a fitting frame: overflowY: hidden, scrollHeight equals innerHeight (719).
  • Not checked in Electron itself. It runs the same Chromium engine with site isolation, which the runs above enable.

Checks: bun install, gen:check, typecheck, lint, format:check, check:tmp, the web build, expo export for Android and iOS.

Copy audit (docs/copy.md §8)

No UI text changed.

Fixes: #685

Wheel and touch input over a visual's sandboxed frame stays in the frame
while its scroll chains to the thread feed. The feed saw a scroll with no
reader gesture, took it for a layout change and restored its anchor or
the end, so the thread froze under the cursor and then jumped.

The kit now reports whether the pointer is inside the frame (a bare
boolean, rate-limited and validated by the host inbox), and the feed
takes a scroll under a hovered frame as the reader's. The kit document
also stops being scrollable when its content fits, so a sub-pixel
overflow can't capture a whole wheel gesture.

Fixes: #685
@nixuuu
nixuuu marked this pull request as ready for review November 14, 2026 12:19
@nixuuu
nixuuu merged commit 66db4d9 into dev Nov 14, 2026
23 of 27 checks passed
@nixuuu
nixuuu deleted the fix/agent-visual-scroll branch November 14, 2026 12:35
nixuuu added a commit that referenced this pull request Nov 14, 2026
Scrolling up a long thread could snap the view back to the end or jump it
by hundreds of rows as older rows were measured.

- Re-estimated rows above can shorten the scroll range below the reading
  position. The browser clamps to the new end; during a gesture that clamp
  counted as the reader reaching the end and turned following back on.
  A clamp is now layout: the anchor is restored.
- A smooth scroll (wheel, Page Up) moves ahead of its scroll events. When
  settle took such a scroll in after a re-estimate, it recaptured the anchor
  from rows not yet corrected, often finding none. The anchor now moves by
  the reader's distance and settle corrects the rest in the same frame.

Related: #687, #707
nixuuu added a commit that referenced this pull request Nov 14, 2026
…721)

## Problem

Scrolling up a long thread sometimes moved the view by itself: it
snapped back to the end, or jumped by hundreds of pixels to rows far
above. It happened over the margin too, with no visuals (found while
testing #707, reproducible on `dev`).

## Root cause

Older rows are re-estimated as rows are measured (group averages). Two
paths then lost the reading position:

1. **Clamp counted as the reader.** A re-estimate can shorten the scroll
range by more than the reader's distance from the end. The browser
clamps `scrollTop` to the new end. While a wheel/key gesture lease is
active, `ScrollIntent` labelled that clamp `reader` with distance 0, so
`followingAfterScroll` turned following back on and the view snapped to
the end.
2. **Anchor recaptured from uncorrected rows.** A smooth scroll (wheel
notch, Page Up) moves ahead of its `scroll` events. When `settle` (after
`padTop` changed) took such a pending scroll in, `onscroll` recaptured
the anchor from rows that the re-estimate had just moved, often by
thousands of px. Often no row was on screen: the anchor was dropped, and
the window then followed the estimate, about 165 rows away.

## Fix

- `scrollOrigin` (`scroll.ts`): a position clamped to the end of a range
that shrank below the last position is `unattributed` (layout). `settle`
restores the anchor, in the same frame.
- `followScroll` (`feed-anchor.ts`): a scroll taken in by `settle` (no
event) moves the existing anchor by the reader's distance, instead of
reading the rows on screen. `settleAnchor` then corrects the layout part
in the same frame. Native scroll events still recapture as before.
- #687 (cached threads, restored position) and #707 (scroll over
visuals) logic is unchanged. A local check: scroll up, switch to another
thread and back. The same row returns at the same offset.
- Docs: `client-performance.md` has the measurement lessons (frames with
no shared row are jumps; `layout-shift` also counts same-frame
compensated corrections; check smooth wheel and Page Up).

## Measurements

Private bench stack (`scripts/bench/client-stack.ts`), Chromium with
smooth scrolling and `--site-per-process`. 120 steps per run, starting
at the end. A probe samples every frame after paint (rAF, then a task)
and compares the rows on screen with the previous frame. A **jump** is a
frame where shared rows move against the scroll or further than one
input step. A **teleport** is a frame with no shared row: a snap to the
end or a leap to another part of the thread.

`/dev/long-thread?turns=1000` (all 5000 rows loaded, mostly estimated):

| Input (120 steps) | Width | `dev`: teleports (size) | This branch |
| --- | --- | --- | --- |
| Wheel −40 px | 1280 | 2 (−1188, −24060 px) | 0 |
| Wheel −100 px | 1280 | 5 (−198 … −23980 px) | 0 |
| Trackpad-like (4 × 8–32 px) | 1280 | 4 (−1196 … −24060 px) | 0 |
| Page Up | 1280 | 30 teleports + 30 jumps (max 935 px) | 0 + 0 |
| Wheel −40 px | 390 | 1 (−22155 px) | 0 |
| Wheel −100 px | 390 | 2 (−22115, −2066 px) | 0 |
| Trackpad-like | 390 | 2 | 0 |
| Page Up | 390 | 33 teleports + 17 jumps (max 1262 px) | 0 + 0 |

Seeded 1000-turn thread page (history paged in through the gateway):
wheel and trackpad-like runs had no jumps on `dev` either. Paging keeps
the estimated region small. Page Up had 5–6 teleports and 3–6 jumps (max
528–597 px) on `dev`, 0 and 0 on this branch, at both widths.

With smooth scrolling off, `dev` Page Up had no jumps: the second path
needs a smooth scroll. Real mouse wheels are smooth-animated on Linux
and Windows, so the reported 360–400 px wheel jumps are likely this
path. Synthetic CDP wheel events in headless Chromium are not animated,
so they only reproduced the first path. `layout-shift` entries are not a
jump metric here: a 3 px row growth with `scrollTop += 3` in the same
frame also produces them on a plain test page, more during smooth
scrolling.

## Browser check

On a second machine with a fresh clone of this branch (own ports, own
container, cleaned up afterwards), I ran the same 15-run matrix on both
pages. It covered wheel −40 px and −100 px, trackpad-like and Page Up,
at 1280 × 900 and 390 × 844. All runs had 0 teleports and 0 jumps, and
visual travel matched input (e.g. 12000 of 12000 px). Page Up now
travels about 75000 px over 120 presses, against 62000 on `dev` (the
view no longer falls back). Cached threads (#687): scrolled up, switched
to another thread and back. The same row returned at the same offset. No
visual change, so no light/dark difference.

After rebasing onto `dev` with #707, the same 16 runs (both pages, both
widths, wheel −40 and −100 px, trackpad-like, Page Up) again had 0
teleports and 0 jumps. A clamp still wins over #707's hovered-frame
attribution: a clamp is layout even while the pointer is over a visual.

## Checks

`bun install`, `gen:check`, `typecheck`, `lint`, `format:check`, focused
test (`tests/integration/thread-scroll.test.ts`, the clamp origin), web
build.

## Copy audit (docs/copy.md §8)

No UI text changed.

Related: #687, #707
nixuuu added a commit that referenced this pull request Nov 26, 2026
Fixes: #1300

The per-target desktop workflow call did not pass repository signing
secrets. In Release #707 both macOS jobs fell back to ad-hoc signing, so
electron-builder omitted `nightly-mac.yml` and the publication gate kept
the release in draft.

Pass the signing secrets to the reusable workflow with `secrets:
inherit` and document the handoff.

Local verification: formatted the edited workflow with oxfmt, parsed
both workflow YAML files and checked the reusable call and secret
forwarding, and ran `git diff --check`. Required checks run in GitHub
Actions. The next eligible Release can verify signing and feed
generation on both macOS targets.

Incident:
https://github.com/itsoltech/canopy/actions/runs/45803821381/job/139865717474
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