Skip to content

fix(messages): keep a wheel whole when a correction moves nothing - #4249

Open
matt2e wants to merge 1 commit into
mainfrom
mtoohey/history-wheel-after-page-flake
Open

matt2e wants to merge 1 commit into
mainfrom
mtoohey/history-wheel-after-page-flake

Conversation

@matt2e

@matt2e matt2e commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

What fails

tests/browser/history-loading.spec.mjs:295, "pages inside one second › input after the page lands starts from the reader's row", fails intermittently on Linux WebKit. After its 40 px wheel the reader's row is expected 40 px lower, within 4 px, and stays somewhere else for the whole 10 s poll.

Cause

A product defect in the reader's hold, not a test race.

  • Linux WebKit animates a mouse wheel over several frames. Any scroll write during the animation ends it where it is, including a write that changes nothing.
  • WebKit truncates scrollTop. The hold keeps the reader's row at an exact Y, so its first correction lands up to 1 px short. Every later measurement makes it write that same fraction again (for example 1225 to 1225.015625), which moves nothing.
  • When a row measures while a wheel is still animating, that write ends the wheel and the reader loses the rest of the notch.

Evidence

CI traces (decoded from the three browser-journeys-webkit-2 artifacts):

Run Scroller moved Row's fraction before the wheel 40 − moved − fraction Reported
45108381111 32 px 0.906 px 7.094 7.09375
45096440304 17 px 0.750 px 22.250 22.25
45088508339 32 px 0.141 px 7.859 7.859375

In all three the list's height changed in the same step as the short scroll, and Virtua's offset for the reader's row did not change. Nothing above the row had moved, so there was nothing to correct. Traces do not record scroll writes, so which code wrote is inferred there and observed in the reproduction below.

Bare page, Linux WebKit (Playwright 1.63.0 container): a −40 wheel moves 27 to 31 px in its first frame and reaches 40 in the next. Writing scrollTop = scrollTop, scrollTop += 0.2 or scrollTop += 5 in the first scroll event ended the wheel at that first step in 24 of 24 runs; 8 of 8 reached 40 without a write.

In the app, on main at 3064169, with every scrollTop write, scrollBy and scrollTo on the scroller logged and a row below the reader grown as the wheel starts:

  • 9 of 16 runs failed. In each, the only scroll write between the wheel and its scrollend was the hold's fraction, and the scroller stopped 1 to 24 px into the wheel. Virtua wrote nothing.
  • The 7 that passed finished the wheel before the row measured.

Change

src/features/messages/scroll-correction.ts:

  • correctScrollTop remembers, per scroller, the part of its last correction that the offset did not take, when that part is under 1 px. A correction that asks for that same fraction again is skipped: the scroller already refused it, so the write could only interrupt the reader.
  • A shortfall of 1 px or more is the end of the scroll range, which content can move, so it is not remembered and is asked again.
  • Corrections that move the scroller are unchanged. The hold still asks for its exact position, so truncation does not add up across corrections.

Effects beyond Linux:

  • On Mac WebKit a skipped correction no longer hides overflow for a task, so a correction that moves nothing no longer stops trackpad momentum.
  • The thread panel's corrections use the same helper and skip the same repeats.

Tests:

  • scroll-correction.test.ts: a scroller that truncates gets no second write for the fraction it left, and still takes the next real correction. A correction the end of the range refused is written again. The first fails on main's helper; the second passes there and guards the 1 px rule.
  • The journey now grows the last mounted row as the wheel starts, so a row measures during the wheel on every run instead of by chance. Its 40 px expectation and 4 px tolerance are unchanged. Nothing is skipped, retried or loosened.

Verified

Linux WebKit, container, two workers, this journey:

Run Result
Edited journey on main's helper 3 of 20 failed (36.6, 36.8 and 38.1 px off)
Edited journey with the fix 60 of 60 passed
Edited journey with the fix, full CPU load 24 of 24 passed
Logged reproduction with the fix 32 of 32 passed; in 18 a row measured mid-wheel, no scroll write followed and the wheel finished
Whole spec with the fix, once, WebKit and Chromium 46 of 46 passed

Also:

  • macOS, local: the journey 10 of 10 on Chromium and 10 of 10 on WebKit.
  • Vitest: scroll-correction.test.ts with the ChannelTimeline and ThreadPanel suites, 9 files, 549 tests, all passed.
  • pnpm typecheck and biome check on the three changed files pass.

Not verified

  • The whole Vitest suite, the other browser specs and the integration tests were not run locally. The branch was pushed without the pre-push hooks, so this PR's CI is their first run.
  • The desktop app, and WebKitGTK outside Playwright's build.
  • The container is arm64; CI is x86_64.
  • Before the journey was edited it passed 10 of 10 unloaded and 24 of 24 under full CPU load on main in the container. At CI's rate that says nothing either way, which is why the evidence above forces the measurement. The Flake check lane's repeats of the edited journey on Linux WebKit are part of the evidence for this PR.

Remaining gaps

  • A correction that has to move the scroller still ends an animated wheel in Linux WebKit: a row above the reader that changes height mid-wheel, or Virtua's own jump. That write is needed to keep the row in place, and the browser does not expose the wheel's target to resume it. The three CI failures were not this case, and the journey does not force it.
  • The Virtua patch's jump can issue a sub-pixel scrollBy of its own. None appeared in any log, and it is left alone.
  • perf: read channel history ahead of the reader and slide past the budget #4194 rewrites much of this spec, so one of the two will need a small rebase around this journey's wheel listener.

🤖 Generated with Claude Code

Requested: stop one intermittently failing browser journey from failing
CI: tests/browser/history-loading.spec.mjs:295, "pages inside one second
› input after the page lands starts from the reader's row", on Linux
WebKit. Find why the reader's row ends somewhere other than 40 px lower
and fix that where the cause is.

What fails
- After the 40 px wheel the reader's row is 7.09, 22.25 and 7.86 px
  from where the journey expects it (CI runs 45108381111, 45096440304
  and 45088508339, on three unrelated branches), and stays there for
  the whole 10 s poll.
- Rate: 3 of the 118 "Browser journeys (webkit, 2/18)" jobs that
  completed in the 150 CI runs from 2026-11-23 00:23 to 05:44 UTC,
  counting each run's latest attempt.

Cause: a product defect, in the reader's hold
- Linux WebKit animates a mouse wheel over several frames. Any scroll
  write during that animation ends it where it is, including a write
  that changes nothing. In a bare page a -40 wheel moves 27 to 31 px in
  its first frame and reaches 40 in the next. Writing
  `scrollTop = scrollTop`, `scrollTop += 0.2` or `scrollTop += 5` in
  the first scroll event ended the wheel at that first step in 24 of
  24 runs; 8 of 8 reached 40 without a write.
- WebKit truncates scrollTop. The hold keeps the reader's row at an
  exact Y, so its first correction lands up to 1 px short, and every
  later measurement makes it write that same fraction again
  (for example 1225 to 1225.015625). The write moves nothing.
- When a row measures while a wheel is still animating, that write ends
  the wheel. The reader loses the rest of the notch.
- The three CI traces fit this. The scroller moved 32, 17 and 32 px of
  the 40. The list's height changed in the same step. Virtua's offset
  for the reader's row did not change, so nothing above it had moved
  and there was nothing to correct. Before the wheel the row sat 0.90,
  0.75 and 0.14 px from the hold's Y. Each failure equals 40 minus the
  distance moved, less that fraction. Traces do not record scroll
  writes, so which code wrote is inferred there and observed locally.
- Reproduced in a Linux WebKit container (Playwright 1.63.0 image) on
  main at 3064169, with every scrollTop write, scrollBy and scrollTo
  on the scroller logged and a row below the reader grown as the wheel
  starts: 9 of 16 runs failed. In each, the only scroll write between
  the wheel and its scrollend was the hold's fraction, and the scroller
  stopped 1 to 24 px into the wheel. Virtua wrote nothing. The 7 that
  passed finished the wheel before the row measured.

Fix: src/features/messages/scroll-correction.ts
- correctScrollTop remembers, per scroller, the part of its last
  correction that the offset did not take when that part is under
  1 px. A correction that asks for that same fraction again is skipped:
  the scroller already refused it, so the write could only interrupt
  the reader.
- A shortfall of 1 px or more is the end of the scroll range, which
  content can move, so it is not remembered and is asked again.
- Corrections that move the scroller are unchanged, and so is the Y the
  hold keeps: it still asks for its exact position, so truncation does
  not add up across corrections.
- This is not specific to Linux. On Mac WebKit a skipped correction
  also no longer hides overflow for a task, so a correction that moves
  nothing no longer stops trackpad momentum. The thread panel's
  corrections use the same helper and skip the same repeats.

Tests
- scroll-correction.test.ts: a scroller that truncates gets no second
  write for the fraction it left, and still takes the next real
  correction. A correction the end of the range refused is written
  again. The first fails on main's helper; the second passes there and
  guards the 1 px rule.
- The journey now grows the last mounted row as the wheel starts, so a
  row measures during the wheel on every run instead of by chance. The
  40 px expectation and its 4 px tolerance are unchanged. Nothing is
  skipped, retried or loosened.

Verification
- Linux WebKit, container, two workers, this journey:
  - edited journey on main's helper: 3 of 20 failed (36.6, 36.8 and
    38.1 px from the expected Y);
  - edited journey with the fix: 60 of 60 passed;
  - the logged reproduction with the fix: 32 of 32 passed. In 18 of
    them a row measured mid-wheel, no scroll write followed, and the
    wheel finished.
  - the journey with the fix under full CPU load: 24 of 24 passed;
  - the whole spec with the fix, once, WebKit and Chromium: 46 of 46
    passed.
- macOS, local: the journey 10 of 10 on Chromium and 10 of 10 on
  WebKit.
- vitest: scroll-correction.test.ts with the ChannelTimeline and
  ThreadPanel suites, 9 files, 549 tests, all passed.
- pnpm typecheck: pass. biome check on the three changed files: pass.

Not run
- The whole vitest suite, the other browser specs and the integration
  tests.
- The desktop app, and WebKitGTK outside Playwright's build.
- Before the journey was edited it passed 10 of 10 unloaded and 24 of
  24 under full CPU load on main in the container. At CI's rate that
  says nothing either way, which is why the evidence above forces the
  measurement.

Remaining gaps
- A correction that has to move the scroller still ends an animated
  wheel in Linux WebKit: a row above the reader that changes height
  mid-wheel, or Virtua's own jump. That is needed to keep the row in
  place, and the browser does not expose the wheel's target to resume
  it. The three CI failures were not this case, and the journey does
  not force it.
- The Virtua patch's jump can issue a sub-pixel scrollBy of its own. I
  did not see one in any log and left it alone.

Signed-off-by: Matt Toohey <contact@matttoohey.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@matt2e
matt2e requested a review from a team as a code owner November 23, 2026 06:30

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Star Lord found no blocking issues in the source review of b971206. Ready for Wes’s approval once CI passes, including the Linux WebKit flake check.

@jedwards27 jedwards27 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 :bot: Jude’s code review agent — recommend changes before merge.

Reviewed: 306416901219871e3d3ef077bc03e2c101948215...b9712069767351453643b970a52d30c973859a79 (exact head b9712069767351453643b970a52d30c973859a79). Risk: high, because this changes the reader's scroll correction and virtualized timeline hold. No relay or native IPC contract is changed by the three-file diff.

Finding (P2, author-actionable): src/features/messages/scroll-correction.ts:46–49 caches any subpixel shortfall as offset quantization, but a fractional-scroll engine can produce the same shortfall when the requested target exceeds the current range. At scrollTop=99.5, max=100, a +0.75 correction clamps to 100 and caches 0.25; after content increases max to 101, the next +0.25 is skipped at line 22 even though it is now possible. In the thread reader, ThreadPanel.tsx:1648–1653 also advances its held target after the skipped correction, so successive growth can leave its held row displaced. The added range test at scroll-correction.test.ts:110–117 covers a 40px shortfall, not a subpixel clamp. Author action: distinguish range clamp from quantization before memoizing, and add a deterministic fractional-offset clamp → range-growth → retry regression. This stays within the helper/test ownership boundary.

Validation: pinned source and caller review; git diff --check 306416901219871e3d3ef077bc03e2c101948215...b9712069767351453643b970a52d30c973859a79 passed. At the exact clean head, focused scroll-correction/ChannelTimeline/ThreadPanel test files passed (430/430), and the changed history-loading journey passed locally on macOS Chromium and WebKit. GitHub checks at final preflight: 69 success, 1 skipped. These do not exercise the fractional range-growth case. Manual/native evidence: macOS browser journey only; no independent Linux WebKitGTK native wheel reproduction. Verification owner: author for code and regression; reviewer/tooling for platform-specific follow-up, with CI/release gate for hosted checks. The absent Linux reproduction is a confidence gap, not the reason for this recommendation.

This branch has not been deployed

No deployments
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.

3 participants