Registry Mirror
Skip to content

Conversation

@backnotprop

Copy link
Copy Markdown
Owner

Fixes the intermittent tests/e2e/inbox-contents.spec.ts:122 failure ("side:" and "full:") that hit #2413 and #2389 in the merge queue (runs 41165574822 and 41166537619: expected "Rollout", received "Idempotency keys").

Cause

This is a product bug. The test only exposed it some of the time.

  • When a person picks a heading in the contents rail, the rail scrolls to the heading's top minus 80 px (the activation line). In the e2e plan, Rollout's top is fractional: 1522.22 px (side, 1680x1000) and 1566.22 px (full, 1440x900).
  • Chromium snaps the scroll offset to a whole pixel, so scrollTop reads 1442 (or 1486), not 1442.22. Rollout ends 0.22 px below the line.
  • The pick marks Rollout at once. One frame later, the scroll's own scroll event runs the scroll-spy (activeHeadingBinding). The spy reads the real position, sees that Rollout has not reached the line, and marks the heading above it, "Idempotency keys". The wrong mark stays.
  • A real person sees this: they pick Rollout, and a frame later the rail marks the section above it.

Timeline from a probe in the page (local, full layout):

859.9 pointerdown
860.3 current=Rollout            <- the pick marks it at once
875.2 scroll 1486                <- the scroll event, one frame later
875.7 current=Idempotency keys   <- the spy re-reads and marks the heading above

The e2e checked toHaveText('Rollout') in the same frame as the pick. So it passed when its first check ran before the scroll event, which is usual on a fast machine, and it failed on a slower CI runner.

Fix

  • packages/ui/utils/headingScrollSpy.ts: a heading that is up to 1 px below the activation line now counts as reached (CONTENTS_SNAP_TOLERANCE). This matches the 1 px slack the spy already uses at the document's end. The rail and the Inbox's Contents sheet (useHeadingScrollSpy) both use this function, so the fix covers both. Plan review's useActiveSection is not changed.
  • tests/e2e/inbox-contents.spec.ts: after a pick, the test waits two animation frames before it reads the mark. This makes sure the scroll event has run, so the test checks the settled state, not the same frame as the pick. No timeout was raised and no retry was added.
  • packages/ui/utils/headingScrollSpy.test.ts (new): the picked heading is current at both a rounded and a floored snapped offset, and a heading 4 px below the line is not current yet. The first test fails without the tolerance.
  • The Inbox guide notes the 1 px slack.

Repro numbers (macOS, headless Chromium, compiled binary built review → hook → opencode → compile)

Build Test Result
origin/main original spec, --repeat-each 10 (both layouts) 20/20 pass: the assertion beats the scroll event locally
origin/main probe: the mark 500 ms after the pick "Idempotency keys" every time, both layouts
origin/main updated spec (waits for the frame), --repeat-each 5 10/10 fail, with CI's exact error
this branch updated spec, --repeat-each 20 40/40 pass (20/20 per layout)
this branch the whole inbox-contents.spec.ts 11/11 pass

Unit tests: packages/ui/utils, packages/ui/hooks, MarkdownContentsRail.test.tsx and packages/inbox/documentContents.test.tsx pass (1254 tests). tsc -p packages/ui is clean. The fix has no server change (Inbox only, UI only).

…o a whole pixel

A pick scrolls to the heading's top less 80 px. That top is often
fractional (Rollout at 1522.22 px in the e2e plan); Chromium snaps the
scroll offset to a whole pixel (1442), so the heading sat 0.22 px below
the activation line. The pick marked Rollout at once, then the scroll's
own event a frame later re-read the position and marked the heading
above it (Idempotency keys). The spy now counts a heading within 1 px
below the line as reached.

The e2e asserted in the same frame as the pick, so it passed whenever
it beat the scroll event and failed on a slower CI runner. It now waits
two frames before reading the mark.
@backnotprop backnotprop added the ci:full Run the heavy CI tier on this PR (added by the merge script) label Oct 31, 2026
@backnotprop
backnotprop merged commit 088f27c into main Oct 31, 2026
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the heavy CI tier on this PR (added by the merge script)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant