Repository navigation
fix(chat): keep a scrolled-up reader in place while a reply streams - #18508
Conversation
A reader who scrolled up while a reply streamed was pulled back to the bottom by the next streamed update, so a scrolled-up position could not be held until the turn ended. Auto-follow must pin only a reader who is still at the bottom. The follow policy already holds the automatic pin while an UPWARD input is waiting for its scroll event (scrollIntentPending), and retires that hold on the next scroll event of any origin. A desktop wheel notch is one 100px input the engine animates over several frames, and the first scroll event of that animation moves a fraction of a pixel to a couple of pixels; a slow precision touchpad reports a pixel or two per event. Such a frame lands inside SELF_SCROLL_EPSILON (2px) of follow's last write, so the scroll handler rightly reads it as our own pin landing and leaves follow armed -- but it also retired the hold, and a row appended in that frame found a reader "resting on our write" and pinned them to the new bottom with an instant write that cancelled the notch's animation as well: the whole notch was eaten. onFollowScroll now retires the hold only for a scroll event OUTSIDE the epsilon. A frame inside it cannot say whether it is the pin landing or the first frame of the reader's input, so the intent stays pending: the append's pin is held until the notch's next frame lands outside the epsilon and releases follow through the unchanged path, or the intent expires unanswered and the held pin retries against a reader who is still resting. No scrollTop writer changes and every write still goes through writeScrollTop. Red-first vitest drives the real hook through a fake scroller: one large wheel step, a notch whose first frame is under the epsilon with a row appended in that frame, 1px touchpad steps with chunks and appended rows between them, a height commit between two scroll events of one gesture, an upward input never answered past one sub-epsilon frame (the held pin retries), a still reader who is carried, and a pin landing a device pixel short under an upward input that moved nothing. The history module spec describes the rule.
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check on a real Windows desktop that a wheel notch's first animation frame is under 2px. The author says this was never measured. What this change shipsInventory (4 items) — 4 justifiedIntent: let a reader who scrolls up during a streaming reply stay where they scrolled (#18421). FIX.
[FIRST-PRINCIPLES-REVIEWED] f62618e Description read[DESCRIPTION-READ] 917cffd14aae90a488ab8615f845cc20239f2a4b432bb80befb842cf24b485f7 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check on a real Windows wheel that the second frame of a notch moves more than 2px inside the 150ms [DESIGN-REVIEWED] f62618e Description read[DESCRIPTION-READ] 609ee9b8d7c7517c3ed51e02cab908c70055d5b6b46f890a15cfeef0884c95ff That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
UX Review (Opus 5.5) — ✅ PASSUX-level review of UX-Verdict: PASS Check on a real Windows wheel notch, the reporter's case. The PR itself says the size of that notch's first frame was never measured. [UX-REVIEWED] f62618e Description read[DESCRIPTION-READ] a469771811984ad9cf23e2e55b0ad95b59e2d64c931e1a3e693414d525f5b5f5 That sha256 names everything this verdict read: the PR description, plus the 8 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
CI on |
iamwhatever
left a comment
There was a problem hiding this comment.
This fixes #18421, where a wheel notch or slow touchpad step during a streaming reply was eaten and the reader snapped back to the bottom. The root cause is fixed: onFollowScroll in website/src/hooks/virtualizer/followPolicy.ts retired the pending upward-intent hold on any scroll event, including a sub-SELF_SCROLL_EPSILON first frame that cannot tell the reader's input from our own pin landing. It now stamps lastScrollEventAtRef only for a scroll outside the epsilon, which is one condition. I read the full diff. The only side effect is that an append arriving in that frame waits up to SCROLL_SETTLE_MS and then retries, so a resting reader is still carried. The new useVirtualChat.streamingWheelRelease test drives the real hook, and three of its cases fail on main. The other cases pin the still-reader and quarter-pixel-short-pin paths, so the hold cannot turn into a follow brake. Base is main, all checks are green, all three AI lanes are PASS, and no change request is open. — crew-pr-reviewer
Problem / Motivation
Goal: A reader who scrolls up while a reply is streaming stays where they scrolled; the transcript follows only a reader who is still at the bottom.
On 0.8.0 (Windows desktop, #18421), scrolling up during a streaming reply does not hold: the next streamed update pulls the view back to the bottom, every time, until the turn ends. Reproduced on current main with a test driving the real transcript hook: an upward wheel notch followed by a new tail row in the same frame lands the reader at the new bottom (
expected 8720 to be 8599: 8599 is where the reader stopped, 8720 the new bottom).Why it matters
Long replies and multi-tool turns are exactly when a reader wants to re-read what came before. Being pulled back on every update makes the transcript unreadable for the whole turn, and a mouse wheel, the most common desktop input, triggers it every time.
Not a goal
What changed (motivation → approach → change)
Follow tells the reader's scroll events from its own by comparing the live
scrollTopto the value it last wrote, within a 2px tolerance (SELF_SCROLL_EPSILON) meant for sub-pixel rounding. It also already holds the automatic pin while an upward input is waiting for its scroll event (scrollIntentPending), and retired that hold on the next scroll event of any origin.A desktop wheel notch is one 100px input the browser animates over several frames, and the first scroll event of that animation moves a fraction of a pixel to a couple of pixels; a slow precision touchpad reports a pixel or two per event. Such a frame lands inside the tolerance, so the handler rightly reads it as its own pin landing and leaves follow armed. But it also retired the hold, and a row appended in that frame found a reader "resting on our write" and pinned them to the new bottom with an instant write, which also cancels the in-flight wheel animation: the notch was eaten whole.
The change is one condition in
onFollowScroll: the hold is retired only by a scroll event outside the tolerance. A frame inside it cannot say whether it is the pin landing or the first frame of the reader's input, so the intent stays pending; the append's pin is held until the notch's next frame lands outside the tolerance and releases follow through the unchanged path, or the intent expires unanswered (a wheel the transcript never answered) and the held pin retries against a reader who is still resting, as it does today. The same stamp serves the scrollbar-grab hold (a pointer that landed on the thumb or track, whose first drag frame can be as small), so that hold now outlives a sub-tolerance frame in the same way.website/src/hooks/virtualizer/followPolicy.tslastScrollEventAtRefis stamped only for a scroll outsideSELF_SCROLL_EPSILONof the last write; the ref's comment says whywebsite/src/hooks/virtualizer/FollowController.tsscrollIntentPendingdescribes the narrowed stamp (no logic change)docs/system-specs/modules/history.mdNo
scrollTopwriter changes; every write still goes throughwriteScrollTop. Follow fixes merged since the 0.8.0 cut (#14568, #14906, #13066, #15974, #13359, #18047) address other triggers (composer dock, idle DM follow, table width, restore, iOS toolbar, quiet-reply footer); none covers this frame, so the issue reproduces on current main.Backwards compatibility
Compatible: nothing that works today stops working. Every scroll outside the 2px tolerance retires the hold exactly as before, and the hold still expires after
SCROLL_SETTLE_MSwith the same retry; the only difference is that a scroll inside the tolerance no longer retires it, so an append landing in that frame waits up to 150ms instead of pinning at once.Removes nothing: the diff narrows one stamp and edits two comments and a spec paragraph.
Tests
website/src/test/useVirtualChat.streamingWheelRelease.test.tsx(new) drives the real hook through a fake scroller: a large wheel step up; a notch whose first frame is underSELF_SCROLL_EPSILONwith a new tail row in that frame; 1px touchpad steps with a chunk after each, and with a new row between them; a height commit between two scroll events of one gesture; an upward input never answered past one sub-epsilon frame (the held pin retries at expiry); a still reader who is carried; a pin landing a quarter pixel short under an upward input that moved nothing (keeps following). Three of the eight fail on current main (expected 8720 to be 8599for the notch and touchpad-row cases, a premature write for the unanswered-intent case).build,lint,i18n:checkpass.Manual verification
Static render of the real chat page (built app, stubbed API, Chromium) under a controlled clock, long transcript, running turn: one wheel notch up, its first 1px frame, a new tail row committing in that frame, then the notch's second frame. Before the fix the view lands at the new bottom at commit (the anchor row moves 317px); after it the anchor row keeps its viewport position while the transcript grows below it and the jump pill appears. Both themes. Not measured: the size of a Windows wheel notch's first animation frame on the reporter's machine. The repro asserts a frame inside the 2px tolerance, which is the shape of a smooth-scrolled notch and of a slow touchpad; a frame outside it already released follow on main.
Screenshots / video
Before the fix, after a new row landed on the notch's 1px first frame (pulled to the new bottom):
After the fix, the same scene before and after the appended row (the view holds):
Light theme: the two after-the-row frames (before and after the fix) are attached below.
Related Issues
Fixes #18421
Pattern harvest
Rule candidate: review-prompt
Pattern: a hold that waits for "the event that answers the input" is retired by the first event of any origin, including one the code itself classifies as undecidable (inside a self-write tolerance); ask any such hold whether the event that retires it is one it would also act on.
Checklist
Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.