fix(desktop): correct realizing-upscroll reading-row reversal on both engines

Realizing upscroll made the reading row jump down then snap back — a
reversal frame pair, most visible on WebKit where the ResizeObserver for
a content-visibility realization delivers one frame LATE (paint N, RO
N+1). This lands design-of-record (c): a single ungated RO mid-history
corrector plus a per-rAF sampler, coordinating ONLY through a shared
row-height cache — no engine branch. The on-time observer per engine is
the sole writer:

  - Chromium: the RO delivers pre-paint, so the ungated RO corrects at N
    (by the anchor's own measured drift) and refreshes the cache; the
    rAF then sees residual ~0 and no-ops.
  - WebKit: the RO is late, so the rAF (whose synchronous
    getBoundingClientRect forces this frame's layout) corrects at N; the
    late RO no-ops against the rAF-refreshed cache.

The RO path is deliberately UNGATED by the rAF path's observed/above
agreement cross-check: that gate suppresses the rAF band walk's
straddler-miscount fabrication, a risk the RO does not have (its entries
are ground truth for which rows resized). Applying the gate to the RO
strangled the on-time Chromium observer and regressed it to 16
reversals. Straddler safety on the RO path comes instead from the
safe-margin reading anchor (snapshotReadingAnchor +
READING_ANCHOR_SAFE_MARGIN_PX), which sits a notch below the realization
band so a row realizing across the fold is above the anchor and summed
into the drift correctly — documented as a load-bearing invariant at the
site so a later refactor cannot strip it thinking the `changed` trigger
covers straddlers (it does not; the margin does).

Own red/green E2E fixture (upscroll-raf-correction.perf.ts), verified on
both Playwright engines against a stamped build:

  Chromium   0 reversals  max 0.0px   RO 21  rAF 0
  WebKit     2 reversals  max 14.5px  rAF 24 RO 0 (residual 0.0)

Asserts are a layered stack so a vacuous pass cannot slip through: a
build-stamp stale-`dist` guard, LIVENESS (some correction fired),
PRIMARY correctness (reversals <= 4, maxReversalPx <= 34, engine-
agnostic), and per-engine MECHANISM in both directions (chromium
roFires>0 && rafFires===0; webkit rafFires>0 && maxRoResidual<=0.5).
Layering self-test confirmed: disabling the ungated-RO write flips
PRIMARY red at 16 while LIVENESS stays green.

The hook is the sole cross-engine reading-anchor scroll writer and its
correctness lives in the per-site provenance comments, so it crossed the
1000-line file-size limit (888 at HEAD); added a documented, narrowly-
scoped override queued to split the mid-history corrector into a sibling.

Co-authored-by: Tyler Longwell <tlongwell@block.xyz>
Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
This commit is contained in:
npub1cc3ha7z055mu0rwwu7806t2wt8mj3pvu0uv5mfp2c50dahaqhczshdalg6
2026-07-08 22:38:21 -04:00
parent 2c422c1e34
commit e7243887e4
3 changed files with 772 additions and 180 deletions

View File

@@ -182,6 +182,17 @@ const overrides = new Map([
// overage from load-bearing per-message plumbing, not generic debt growth.
// Approved override; still queued to split with the rest of this list.
["src/features/messages/ui/MessageThreadPanel.tsx", 1006],
// W4a realizing-upscroll reversal fix (design-of-record (c), targets #1662):
// the hook is the sole cross-engine reading-anchor scroll writer, and the
// fix's correctness lives in WHY each observer wins per engine — so the
// ungated-RO mid-history corrector, the safe-margin straddler-guard invariant
// (Quinn's merge-bar checklist #4), the one-clock/single-writer reasoning, and
// the build-stamp/probe contract are all documented AT their sites. The file
// was 888 lines at HEAD; this fix's code + load-bearing provenance comments
// crossed 1000. Comment-dominated overage on a correctness fix, not generic
// debt growth. Approved override; queued to split (extract the mid-history
// corrector + band walk into a sibling module) with the rest of this list.
["src/features/messages/ui/useAnchoredScroll.ts", 1140],
// AgentConfigPanel footer fold into ProfileFieldGroup for the config-bridge
// panel — a small overage from load-bearing UI plumbing, not generic debt
// growth. Approved override; still queued to split with the rest of this list.