Registry Mirror
Skip to content

Conversation

@elucid

@elucid elucid commented Jul 31, 2026

Copy link
Copy Markdown
Member

Closes #650.

The flaky pager test turned out to be reporting a real bug, not racing one. Fixes the product race, then re-enables the test it was skipped behind.

What was broken

Jumping to a file (./,, or a sidebar click) asks the review stream to align that file to the viewport top, and viewport-follow selection is held off while the jump settles. That hold-off was a 160 ms wall-clock timer, but what it has to outlive is a coalesced read of the scroll box — the pane only observes the align one read interval later, and under load that lag runs 300-470 ms.

When the timer lost that race, the pane read its own align scroll as user scrolling and adopted the hunk under the viewport center, silently reverting the selection it had just made. A short trailing file makes this worst: it can only clamp at the bottom edge with the previous file still centered, so the selection snapped straight back to where the jump started and the next "previous file" press had nowhere to go — it did nothing at all.

That is what CI kept catching: not a slow render, but navigation genuinely losing the file it had just jumped to.

The fix

Gate viewport-follow selection on the same signal the align uses — the coalesced viewport read agreeing with the align target — instead of a timer. The two now key off one signal rather than racing.

Also stop registering no-travel align requests as pending. Those used to stay pending until an unrelated relayout cleared them, which yanked the next manual scroll back to the file top.

Reproduction

Never reproduced on macOS (0/10 in isolation, 0/10 under 32 background spinners). Reproduces on Linux under constrained CPU:

docker run -d --name hunkci --cpuset-cpus=0,1 -v "$PWD":/repo -v hunk-node-modules:/repo/node_modules \
  -w /repo oven/bun:1.3.14-debian sleep infinity
docker exec hunkci bash -lc 'apt-get install -y git && cd /repo && bun install --frozen-lockfile --ignore-scripts'
# 4 spinning load generators, then run the test 30x

18/30 failures (60%), matching CI's 4-of-5 rate, with the same failure snapshot.

Measured stability

30 runs each, 2 CPUs, 4 spinners:

test wait product fix failures
waitIdle(200) no 18/30
waitIdle(200) yes 0/30
ensureKeyboardIsLive no 0/30
ensureKeyboardIsLive yes 0/30

At 12 spinners: 50/50 green. Full pager.test.ts green 3x under load; full ./test/pty 86/86 on Linux.

Note the third row: the test's own startup race could mask the product bug, which is why both are fixed rather than either alone.

Test changes

Two separate problems, both addressed:

  • Startup race. The test waited waitIdle({timeout: 200}) before its first keypress, but the key handler is bound after first paint — on a slow start the . press was dropped outright. Now uses the harness's ensureKeyboardIsLive, like the rest of the PTY suite.
  • Assertions that passed for the wrong reason. The . leg only checked that second.ts was on screen somewhere, which is true whether or not any alignment landed. Both legs now assert the exact landing position.

The short trailing file is deliberately kept. Making it tall enough to align properly makes the test pass 50/50 even with the bug present — that fixture shape is precisely what exercises the race.

Deterministic coverage

ui-components.test.tsx gains a DiffPane case for the no-travel align path that does not depend on timing at all: it requests an align that needs no scrolling, then scrolls manually and asserts the scroll sticks. Red on pre-fix code (scrollTop 7 → 0), green after. Verified independently by running it against main's DiffPane.

Verification

  • bun run typecheck, bun run lint, bun run format:check clean.
  • bun run test:integration on macOS: 74 pass / 12 fail, identical to a clean-worktree baseline (4 extensions, 1 file-views, 7 piped-stdin pager tests that time out on this machine); the previously-skipped test now passes.
  • bun test ./src/ui/components/ui-components.test.tsx: 68/68.
  • Real TTY smoke via tmux confirms ./, navigation and post-jump manual scrolling behave correctly. (test:tty-smoke itself can't run on macOS — BSD script rejects -f, unrelated to this change.)

elucid added 2 commits July 31, 2026 12:02
Jumping to a file asks the review stream to align that file to the viewport
top, and viewport-follow selection is held off while the jump settles. That
hold-off was a 160ms wall clock, but the thing it has to outlive is a coalesced
read of the scroll box: the pane only sees the align land one read interval
later, and on a loaded machine that lag runs into the hundreds of milliseconds.

When the timer lost that race the pane read its own align as user scrolling and
adopted the hunk under the viewport center, silently reverting the selection.
For a short trailing file -- which can only clamp at the bottom edge, leaving
the previous file centered -- the selection snapped straight back to where the
jump started, so the following "previous file" press had nowhere to go and did
nothing at all.

Hold viewport-follow selection off until the coalesced viewport read agrees the
align has landed, so the two now key off the same signal instead of racing.
Requests that need no scrolling no longer register as pending either; they used
to stay pending until an unrelated relayout cleared them, which yanked the next
manual scroll back to the file top.

Measured on a 2-CPU Linux container under 4 spinning load generators, running
the pager file-navigation PTY test 30 times: 18/30 failures before, 0/30 after.
The test raced two things at once. It waited 200ms of PTY idle before its first
keypress, but the key handler is bound after the first paint, so on a slow start
the "next file" press was dropped outright and the review stream never moved.
Prove a key landed with ensureKeyboardIsLive instead, the way the rest of the
PTY suite does.

The assertions were also loose enough to pass without navigating. second.ts is
the last file and too short to own the viewport top, so the only correct landing
spot is the bottom of the stream; assert that exact position rather than just
that second.ts is on screen somewhere, and assert the same for the trip back.

Re-enabled now that the align race behind it is fixed. Verified on a 2-CPU Linux
container under load: 50/50 green with 12 spinning load generators, and the full
pager file green three times over.

Closes #650
@vercel

vercel Bot commented Jul 31, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hunk-web Ready Ready Preview Jul 31, 2026 4:20pm

Request Review

@greptile-apps

greptile-apps Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes file-jump alignment races in the review stream.

  • Holds viewport-follow selection until the coalesced viewport observation reaches the requested file-top target.
  • Avoids retaining pending state for alignment requests that require no movement.
  • Adds deterministic component coverage and re-enables stricter PTY navigation coverage.

Confidence Score: 4/5

The stale no-travel check should be fixed before merging because it leaves a reachable loaded-machine path that can still undo file navigation.

The new pending guard addresses delayed viewport observations in the usual case, but its initial registration can be skipped when the coalesced snapshot says the target is settled while the live scroll box has already moved elsewhere.

Files Needing Attention: src/ui/components/panes/DiffPane.tsx

Important Files Changed

Filename Overview
src/ui/components/panes/DiffPane.tsx Replaces timer-only file-align suppression with viewport-observed settling, but stale no-travel detection can still omit the pending guard for a real scroll.
src/ui/components/ui-components.test.tsx Adds deterministic regression coverage proving an already-aligned request releases viewport-follow selection before manual scrolling.
test/pty/pager.test.ts Re-enables file-navigation coverage, waits for keyboard readiness, and asserts exact forward and backward landing states.
.changeset/steady-file-jump-align.md Documents the user-visible file-navigation race fix as a patch release.

Sequence Diagram

sequenceDiagram
  participant N as File navigation
  participant D as DiffPane align effect
  participant S as Scroll box
  participant V as Coalesced viewport
  participant F as Viewport-follow selection
  N->>D: Increment align request ID
  D->>D: Decide whether align is pending
  D->>S: scrollTo(file target)
  S-->>V: Delayed viewport observation
  V->>D: Settle pending alignment
  D-->>F: Re-enable viewport-follow
  Note over D,V: The pending decision must account for live scroll position when the viewport snapshot is stale
Loading
Prompt To Fix All With AI
### Issue 1
src/ui/components/panes/DiffPane.tsx:1670-1673
**Stale snapshot skips pending alignment**

When the coalesced viewport still reports the target but the live scroll box has moved elsewhere, this check omits the pending state before reissuing the alignment. If the delayed viewport read arrives after the 160 ms suppression expires under load, viewport-follow treats the alignment as user scrolling and can revert the file or hunk selection.

```suggestion
    const desiredTop = resolveFileTopAlignScrollTop(selectedFileId);
    const liveScrollTop = scrollRef.current?.scrollTop ?? scrollViewport.top;
    if (
      desiredTop === null ||
      !isFileTopAlignSettled(desiredTop) ||
      Math.abs(liveScrollTop - desiredTop) > 0.5
    ) {
      pendingFileTopAlignFileIdRef.current = selectedFileId;
    }
```

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Reviews (1): Last reviewed commit: "test(pager): re-enable the pager file-na..." | Re-trigger Greptile

Comment thread src/ui/components/panes/DiffPane.tsx Resolved
Review flagged the skip as unsafe when the coalesced read and the live scroll
top disagree. It is not, but the reason is an invariant that is easy to miss:
skipping requires the coalesced read to already sit on the target, and the
align that follows puts the live position on that same target synchronously,
so the next coalesced read can only report the value viewport-follow selection
last recorded. Verified against both an unclamped target and a clamped short
trailing file -- the review stream never moves and the selection never
reverts. Write the invariant down so it does not get re-litigated.

This branch was successfully deployed

1 active deployment
Preview — 115281b9 Deployed Jul 31, 2026 by vercel[bot]
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.

File navigation can lose the file it just jumped to under load

1 participant