Skip to content

fix(chat): judge follow re-engage on the reader's own travel during an iOS toolbar collapse - #13359

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
billygerhard:fix/mobile-viewport-repin
Oct 2, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
billygerhard:fix/mobile-viewport-repin

Conversation

@billygerhard

@billygerhard billygerhard commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A reader who has scrolled up on iOS keeps their place when the Safari toolbar collapses under a small downward drag, instead of being snapped to the live end.

On iOS Safari, a reader who has scrolled up in the chat transcript to read
earlier messages gets snapped back to the bottom while a turn is streaming.
It happens as they drag downward a little and the Safari toolbar collapses
under the drag; a moment later the transcript is at the live end.

Why it matters

On a phone the toolbar collapses and re-shows constantly as you scroll, so a
reader loses their place whenever they pause to read history mid-turn. It
looks random because it needs a small downward nudge and a live turn at the
same time.

Not a goal

  • Changing when follow is released: an upward scroll still releases it exactly as on main; only the re-engage judgement changes.
  • Changing the at-bottom clamp rule (rule 1) or the atBottom UI band; both keep their existing behavior.
  • Any change to the viewport-resize pin itself (composer/keyboard/queue-band shrink handling) or to the virtual window.
  • Behavior on engines whose toolbar does not resize the scroller's box (desktop, Android Chrome); with no viewport growth the resolver is unchanged.

What changed (motivation → approach → change)

Follow is re-armed by rule 3 of resolveUserScrollStick in
website/src/hooks/virtualizer/FollowController.ts: a genuine downward move
that lands within FOLLOW_REENGAGE_PX of the bottom means the reader came
back, so the transcript follows again. That band was judged against the
scroller's height after the frame's layout was applied.

On iOS the Safari toolbar collapses under the very drag that scrolls toward
the bottom, so the scroller grows during the reader's small downward move: the
bottom comes up to meet them, follow re-arms, and the next automatic pin
carries them to the end.

The fix splits the approach. With content unchanged, the distance the reader
closed is their own downward travel plus the box's growth. Rule 3 keeps the
live distance as the arrival test (dist <= FOLLOW_REENGAGE_PX; the live
bottom is the only one reachable) and credits the arrival to the reader only
when travel >= growth: they moved at least as far as the growth carried
them. Subtracting growth from the distance instead is unsatisfiable once the
collapse exceeds the band (growth lowers the maximum scrollTop by the same
amount), which would refuse "return to live" for the whole collapse.

website/src/hooks/virtualizer/useVirtualChat.ts owns the two gesture totals
the resolver compares: the reader's downward travel (user scroll events only,
positive deltas) and the viewport growth (signed clientHeight deltas), both
accumulated across scroll events that arrive within SCROLL_SETTLE_MS of each
other and reset after a rest. Safari animates the collapse over several
frames, so per-event values would credit only the last frame. Growth that
lands while the reader rests (keyboard closes, window grows: no scroll event)
is re-baselined out at the ResizeObserver so it is never charged to the next
drag. With no growth the rule is identical to main.

Two follow-ups from review. First, the same split guards BOTH arrival
branches of resolveUserScrollStick, not only rule 3's band: a viewport
growth lowers the maximum scrollTop, so a reader parked 60 px up is only
10 px from the new maximum after a 50 px collapse, and any nudge of 10 px or
more is clamped flush (distance 0) rather than landing inside the band. The
bottom-epsilon branch decided that case on direction alone and re-armed follow
for a reader who never reached the bottom. Its released row now requires
travel >= growth as rule 3 does; its follower row and non-downward landings
are unchanged, and the redundant clampedByViewport term is folded into the
documented decision table. Second, "a gesture in flight" now means the
reader's hand: both totals lapse, and the ResizeObserver re-baselines the
scroll-event height, on a clock stamped only by user scrolls that are not
layout clamps and by the grab that interrupts a smooth glide. A streaming
turn's own pin writes previously kept the window open for the whole turn, so a
mid-turn growth (the keyboard closing) stayed in the total and the rest
re-baseline never ran; a reader who flicked up and came straight back was
refused their own arrival while the output streamed past them. Self-scroll
events neither extend the gesture nor contribute growth.

A third round found two holes in that accounting, both in
website/src/hooks/virtualizer/followPolicy.ts. First, the reader's travel
was measured from the CLAMPED scrollTop: a growth G lowers the maximum by
G, so a reader parked D0 above the bottom is answered with at most D0 - G
however far they drag, and travel >= growth is unsatisfiable for anyone
under 2G away (100 px at Safari's collapse) -- a deliberate drag to the end
counted like a 12 px nudge, and once flush a further drag raised no scroll
event, so follow stayed off until they jumped to latest. The intent listeners
in website/src/utils/searchScroll.ts now report the input's own size with
its direction (a pixel wheel delta, a finger's path), the hook sums the
downward input per gesture (readerIntentAccumRef), and the resolver judges
travel as the larger of answered and asked (readerIntent). An input in the
gesture also counts as the hand on the scroller for a flush landing whose
position fell (the growth outran the finger within the frame). A second term
covers growth larger than the drag: a drag that covers the WHOLE gap the
gesture began with (gestureStartGap) is the reader's return whatever the box
did, which is how the keyboard closing (~300 px) under a 250 px drag from
200 px up re-engages as it did on main. And because a drag at the wall raises
no scroll event, noteHardInput asks resolveUserScrollStick with the same
accumulators (neutral position, live intent as the move) when a released
reader at the bottom keeps dragging down -- the arrival rule has one spelling. Second, the gesture clock was
stamped on !layoutClamp, and layoutClamp requires follow to be armed, so
a RELEASED reader's own engine clamp opened a gesture and charged its growth
to their next flick down. The clock is now gated on the reader's input: a
flush landing with no hardware input in the settle window is the engine's
whatever stick says. lastUserScrollAtRef (the pin-hold gate) keeps its
existing rule.
The intent total also resets on an UPWARD input. A phone reports the finger's
direction per frame, so an upward flick often opens with one downward jitter
frame; that frame's few px used to stand for the whole settle window, and the
resolver reads a live downward intent as "moved down", which disables the
upward clamp-release guard -- a flick up that coincided with a mid-stream
content shrink kept follow armed and the next pin snapped the reader back.
A reversal is no longer a return, so the total goes to zero.
Both substitutions are gated on what makes them honest. The gap term needs a
REAL gap: a gesture that opens at the bottom (a released reader the engine
clamped flush, now at rest) seeds a gap of ~0, and travel >= 0 would have
let a 1 px nudge re-arm follow. And the input stands in for the position only
while a viewport growth is in flight, because that is the one thing that can
make a downward drag read as a fall; with no growth a falling scrollTop at
the bottom is a CONTENT shrink clamping the reader flush, and the position is
the honest read (arriving is not asking), as on main. The observer's at-rest
re-baseline in measurement.ts now judges "in flight" on both reader clocks,
the way noteHardInput opens a gesture: the input that starts a drag lands
before its first scroll event, so keyed on the scroll clock alone the first
frame's growth was folded away before the nudge's scroll event could see it.
A gesture that noteHardInput opens also starts its growth and travel
accumulators from zero. The scroll handler's lapse reset never runs for a
gesture that raises no scroll event (an input at the wall), so a wheel notch
after a rest was judged against the LAST gesture's growth and re-armed follow
with no growth in flight -- the case the no-growth rule refuses.
And the input stands in for the position only with no UPWARD input in the
settle window: touch samples outrun frames, so a 1 px reversal sample can
land after an upward flick's sample and re-bank a positive intent beside the
upward stamp, and letting the input answer "moved down" there skipped the
very release the stamp arms -- a follower who flicked up as the keyboard
closed stayed armed and the next pin yanked them back. The keyboard-close
returns the substitute exists for carry no upward input.

Case (bar collapses 50 px mid-turn) Before After
Parked 60 px up, nudge down 3 px 🟨 re-arms, next pin yanks 🟩 stays released (3 < 50)
Parked 200 px up, drag down 148 px to 2 px from the end 🟦 re-arms, pinned 🟦 re-arms, pinned (148 ≥ 50)
Following reader, bar re-shows (shrink) 🟦 stays pinned 🟦 stays pinned
Scrolled-up reader, collapse only, no drag 🟦 stays put 🟦 stays put
Keyboard closes while parked, then a fresh drag to the end 🟦 re-arms 🟦 re-arms (rest growth not charged)
Parked 60 px up, nudge down 12 px, collapse clamps it flush 🟨 re-arms, next pin yanks 🟩 stays released (12 < 50)
Keyboard closes mid-stream under our pins; reader flicks up, reverses to the end 🟨 refused, output streams past 🟩 re-arms (pins do not hold the gesture open)
Parked 80 px up (under 2× the collapse), deliberate 80 px drag to the end 🟨 refused (clamp answered 30 < 50), stuck off 🟩 re-arms (asked 80 ≥ 50)
Released at the wall after a clamped nudge, finger keeps dragging 🟨 no scroll event, stuck off 🟩 re-arms once the drag covers the growth
Released reader clamped flush by growth, new message, flick down within the window 🟨 refused (clamp's growth charged to the flick) 🟩 re-arms (clamp opened no gesture)
Keyboard closes (~300 px) under a 250 px drag from 200 px up 🟨 refused (250 < 300) 🟩 re-arms (drag covered the 200 px gap)
Follower flicks up (one downward jitter frame first) as a content shrink clamps them flush 🟨 stays armed, next pin yanks 🟩 releases (upward input zeroes the intent)
Released reader clamped flush, at rest, then a 1 px nudge down 🟨 re-arms (gap of 0 is "covered") 🟩 stays released (gap term needs a real gap)
Parked 200 px up, 30 px drag as 300 px of CONTENT below collapses 🟨 re-arms (input stood in for the fall) 🟩 stays released (no growth in flight; position decides)
12 px nudge under the collapse, observer entry before the clamp's scroll event 🟨 re-arms (first frame's growth folded away) 🟩 stays released (both reader clocks judge "in flight")
Released reader clamped flush by 60 px of growth, at rest, then a 60 px flick at the wall 🟨 re-arms (judged against the last gesture's growth) 🟩 stays released (a fresh gesture starts its accumulators at zero)
Follower flicks up as the keyboard closes; a 1 px reversal sample lands after the upward sample 🟨 stays armed (input stood in for "moved down"), next pin yanks 🟩 releases (input substitutes only with no upward input in the window)

Legend: 🟩 added · 🟨 changed · 🟦 unchanged.

Backwards compatibility

Compatible: only the two arrival tests change, and only when a viewport
growth lands within the reader's gesture. With no growth both branches are
identical to main. Desktop resizes under a downward wheel now behave the same
way, which is the intended reading in both cases.

Tests

src/test/FollowController.test.ts: a 50 px collapse under a 148 px drag to
2 px from the end re-engages (red on the code before this rule); a 3 px nudge
that lands inside the band only because of the growth stays released; a
neutral event during growth stays released; a shrink never widens the band;
both totals are gesture totals, not one frame's; omitted readerTravel is
credited as 0; a nudge the growth clamps FLUSH stays released (red before the
bottom-epsilon guard); a reader who drags to flush while the box grows
re-engages; a follower clamped flush by the growth keeps following.
src/test/useVirtualChat.viewportResize.test.tsx
under "iOS toolbar collapse under a downward drag": the 50 px drag-to-bottom
re-engages and stays pinned through the re-show (red before); a nudge during
the collapse does not re-arm, so the re-show does not pin (red on main); a
collapse animated over frames 38/8/1 is judged on gesture totals; growth the
reader sat through is not credited to a later nudge; growth that landed at
rest with no scroll event is not charged to the next drag; a released reader
clamped flush stays released; a nudge the collapse clamps flush does not
re-arm (red before); growth under our own pins mid-turn is not charged to the
reader's later gesture, growth across one of our scroll events inside their
gesture is dropped, and growth right after the turn's last pin is re-baselined
at rest (each red before, and each pinned so that removing only one half of
the gesture-clock change fails it).
Third round: FollowController.test.ts pins that travel is judged on the
asked-for input when the clamp answered with less (red without
readerIntent), and that a drag covering the whole starting gap re-engages
under larger growth while a fall with no input stays the engine's (red without
gestureStartGap). useVirtualChat.viewportResize.test.tsx adds the four
rows above, driven by real touchmove events through the intent listener: the
short-gap deliberate drag (red without the intent term), the drag that goes on
at the wall with no scroll event (red without the noteHardInput re-engage),
the released reader's clamp followed by a flick down (red with the clock back
on stick), and the keyboard closing under a drag to the end (red without the
gap term). searchScroll.test.ts asserts the reported magnitudes.
The jitter-then-flick-up row is pinned the same way (red with the upward
reset removed).
The three rows after it are pinned as hook tests plus resolver-level pins,
each red with only its own term reverted: the gap guard, the growth gate on
the input term, and the input clock in the observer's at-rest test.

Manual verification

N/A — unit coverage is the verification. The trigger needs a downward drag,
the toolbar collapse and a live turn in one gesture, so a manual pass/fail on a
device is not evidence either way. What a device would have to confirm is
that the toolbar collapse changes the scroller's clientHeight during the
drag; that follows from the shell being h-dvh (the dynamic viewport tracks
the toolbar by specification) and is the same growth path rule 1 already
handles for keyboard close. The tests reproduce the frame sequence against a
controllable scroller and fail on the unpatched code.

Screenshots / video

Why no screenshot: the fix is that nothing moves; the correct after-state
is identical to where the reader already was.

Related Issues

Pattern harvest

Rule candidate: review-prompt -- any 'did the reader arrive here' test in the follow resolver must be judged against pre-layout geometry (credit viewportGrowth), not the height the frame just applied.

Generalizable, one sibling: rule 1 of the same resolver already credited
viewportGrowth for the at-bottom clamp; rule 3 read the same event without
it. Any rule that judges "did the reader arrive here" against post-layout
geometry needs the same credit. No further rule in the resolver reads the
band, so nothing else needs the change now.

Fixes #13356

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

3 similar comments
@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@dwu96

dwu96 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review.

When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically.

@billygerhard
billygerhard marked this pull request as ready for review September 24, 2026 15:28
@billygerhard
billygerhard requested review from a team and krishdhasmana September 24, 2026 15:28
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5, fork) — ✅ PASS

UX-level review of 5e12ee79521829ec3418bfc6846699def8b43305 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Verify on a real iPhone that a deliberate drag to the bottom mid-stream still re-engages follow; the simulated-gesture tests can't stand in for Safari's actual toolbar timing.

[UX-REVIEWED] 5e12ee7

Description read

[DESCRIPTION-READ] b2673890e230b841d8e5c4f113bc4e08ebb873b974d5dc315f60bb3884d4bff7

That sha256 names everything this verdict read: the PR description, plus the 3 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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of 5e12ee79521829ec3418bfc6846699def8b43305 via the fork AI-review pipeline — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

The gesture-total accounting rests on unverified iOS Safari claims — multi-frame collapse, ~50px growth, touch jitter samples — that only a real device can confirm.

Not justified as shipped

  • Item 6 — inherited: the five accumulators exist because "Safari animates the collapse over several frames, so per-event values would credit only the last frame" — an empirical claim about another platform with no linked report; the headline defect alone needs only the growth-vs-travel split, and the jitter/reversal rules (items 7–8's trigger scenarios) rest on the same uncited device behavior.
    Subtraction: if a real device shows the collapse landing in one scroll event, the gesture refs (viewportGrowthAccumRef, readerTravelAccumRef, lastReaderScrollAtRef, the measurement.ts re-baseline) shrink back to the existing per-event lastScrollClientHRef delta.
    Clears when: the multi-frame collapse-under-drag delivery (and the downward-jitter / reversal-sample ordering) is confirmed on a real iOS Safari device, or a linked phone report naming it.

What this change ships

Inventory (9 items) — 8 justified

Intent: FIX — stop iOS Safari's collapsing toolbar from snapping a scrolled-up reader back to the live end during a small downward drag.

  1. A nudge down during the toolbar collapse no longer re-arms follow (arrival credited by travel vs growth) — justified
  2. A nudge the collapse clamps flush at the bottom also stays released (same split on the flush branch) — justified
  3. A real drag to the end during a collapse still re-engages, judged on the input when the engine clamps the answer — justified
  4. A drag covering the whole starting gap re-engages (keyboard closing under a drag), as on main — justified
  5. A reader clamped flush who keeps dragging re-engages with no scroll event (input path asks the same resolver) — justified
  6. Growth/travel/intent judged as per-gesture totals with rest re-baselining — inherited: design-driving Safari frame-delivery claims unverified here
  7. An upward input zeroes banked downward intent, so a jitter frame cannot block the clamp release — justified
  8. A released reader's engine clamp no longer opens a gesture (clock gated on real input) — justified
  9. Intent listeners now report the input's pixel size to the follow hook — justified

[FIRST-PRINCIPLES-REVIEWED] 5e12ee7

Description read

[DESCRIPTION-READ] 7e458272b332257cc0d8f2e3302392d95e1f0d8e74e34cabbf7eb419d881b8c9

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed 5e12ee79521829ec3418bfc6846699def8b43305 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 5e12ee7

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of 5e12ee79521829ec3418bfc6846699def8b43305 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Every iOS timing assumption here (observer-before-clamp order, touch sampling, settle windows) is encoded from simulation; no real-device run of this revision is evidenced.

Watch

  • The whole mechanism rests on Safari's real event ordering — ResizeObserver before the clamp's scroll event, intent samples before scroll events, momentum within SCROLL_SETTLE_MS — which CI (jsdom, fake timers) cannot exercise, and the description's own three review rounds each found a hole only visible in that ordering. A wrong assumption ships a reader-visible yank or a follow that never re-arms, discoverable only on a phone.
    Clears when: the PR records manual verification (note or recording) on a real iOS Safari device covering the headline scenarios — toolbar-collapse nudge, drag-to-end during collapse, keyboard-close drag, drag at the wall.
  • The stick decision now runs in two sites: noteHardInput calls resolveUserScrollStick and mutates stickRef/lastWriteTopRef/lastWriteClientHRef, duplicating the scroll handler's re-engage bookkeeping, while the surviving contract comment ("They only stamp time -- the stick decision itself stays with the scroll handler", followPolicy.ts:202) still asserts the old boundary. Future changes to the handler's post-re-engage baselining will silently skip the input-side copy.
    Clears when: the stale contract comment is rewritten to name the second decision site, and the re-engage bookkeeping is factored so one spelling serves both paths.

Suggestions

  • The gesture's open/lapse/reset authority is spelled in three places (noteHardInput, the scroll handler's lapse check, measurement.ts's at-rest re-baseline) over five refs; consolidating them into one gesture-state object with a single open/lapse rule would make the next hole a one-site fix instead of a fourth round.

[DESIGN-REVIEWED] 5e12ee7

Description read

[DESCRIPTION-READ] ba13508e066a27d9484f96eff2db5da425aea3e45a1d5d0ecf2e7e080e5183cc

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review (fork) — ✅ no blocking findings

Reviewed 5e12ee79521829ec3418bfc6846699def8b43305 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 5e12ee7

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 24, 2026
@billygerhard billygerhard changed the title fix(chat): keep iOS transcript put on visual-viewport resize fix(chat): credit viewport growth before re-engaging follow on iOS Sep 24, 2026
@billygerhard
billygerhard force-pushed the fix/mobile-viewport-repin branch from 537d8a5 to 5531a85 Compare September 24, 2026 16:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@billygerhard
billygerhard force-pushed the fix/mobile-viewport-repin branch from 5531a85 to 3907bb2 Compare September 24, 2026 16:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 24, 2026
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 25, 2026
@billygerhard
billygerhard force-pushed the fix/mobile-viewport-repin branch from 5e897c2 to 22bb210 Compare September 28, 2026 13:22
@billygerhard
billygerhard requested a review from a team as a code owner September 28, 2026 13:22
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Sep 28, 2026
@billygerhard
billygerhard force-pushed the fix/mobile-viewport-repin branch from 22bb210 to 47d858d Compare September 29, 2026 14:02
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 29, 2026

@iamwhatever iamwhatever 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.

Requesting changes: two Opus findings on head 25f0194 are unaddressed and one can leave follow stuck off.

  1. followPolicy.ts (travelDelta hunk, @@ -627): travel is measured from the clamped scrollTop, so a reader less than 2x growth above the bottom (under ~100px for Safari's 50px collapse) can never satisfy travel >= growth; a deliberate long drag to the end counts like a 12px nudge, and at flush a further drag fires no scroll event, so follow stays off until the reader jumps to latest or scrolls up and back down. Suggested fix: measure travel from the unclamped intent (pre-clamp delta or pointer/wheel delta), or treat reaching the bottom edge as satisfying the re-engage.

  2. followPolicy.ts:~784: lastReaderScrollAtRef is stamped on !layoutClamp, and layoutClamp requires stick, so a released reader's own engine clamp opens a gesture and charges its growth to their next flick back down, contradicting the comment above it. Gate the stamp on the reader's own input, not on stick.

Also still open from Design: keyboard-sized growth (~300px) closing during a drag to the bottom now refuses a re-engage that main allowed; no table row or test covers it. Please add tests for D0 < 2G with a deliberate drag, a released reader's clamp followed by a flick down, and growth concurrent with the keyboard.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Thanks, both findings were real, and they are fixed on 39adb8f9a7 (rebased over #13066 first).

1. Travel measured from the clamped scrollTop. The intent listeners (searchScroll.ts) now report the input's own size with its direction (pixel wheel delta, finger path). followPolicy.ts sums the downward input per gesture (readerIntentAccumRef) and resolveUserScrollStick judges travel as the larger of answered and asked (readerIntent), so a deliberate drag from under 2G re-engages on what the reader asked for. A second term, gestureStartGap, treats a drag that covers the whole gap the gesture began with as the reader's return however much the box grew, which is what keeps the keyboard-sized case working. An input in the gesture also counts as the hand on the scroller for a flush landing whose position fell. And since a drag at the wall raises no scroll event, noteHardInput applies the same test itself when a released reader at the bottom keeps dragging down, so follow no longer stays stuck off there.

2. Gesture clock stamped on !layoutClamp. The reader clock is now gated on the reader's input: a flush landing with no hardware input inside the settle window is the engine's whatever stick says. lastUserScrollAtRef keeps its existing rule.

Tests (useVirtualChat.viewportResize.test.tsx, driven by real touchmove events): D0 < 2G deliberate drag (80px from 80px up under a 50px collapse); a drag that continues at the wall with no scroll event; a released reader's engine clamp followed by a flick down within the window; the keyboard closing (~300px over three frames) under a 250px drag from 200px up. Each is red with its own term reverted and green with the others intact; FollowController.test.ts pins the two resolver terms directly. Table rows for all four are in the description's What-changed section.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Re the GPT finding on 39adb8f9a7 (stale downward intent disabling the upward clamp-release guard): correct, and fixed at the source in 0f61f52f8f.

The downward-intent total (readerIntentAccumRef) now resets to zero on any upward input instead of standing still. A reversal is no longer a return, so the resolver's intent > 0 term can no longer outlive the reader's change of direction: an upward flick whose first frame jittered down a few px, coinciding with a mid-stream content shrink that clamps the reader flush, now releases follow exactly as the direction-only rule did before the intent term existed.

Pinned in useVirtualChat.viewportResize.test.tsx ("a downward jitter frame inside an upward flick does not disable the clamp-release guard"): real touchmove events, one 5 px down frame then a 65 px up frame, scroll event landing at the new bottom under a 60 px content shrink; asserts follow is released and the next tail growth writes nothing. Red with only the upward reset removed (follow stays true). Gates: tsc clean, 568/568 across the virtualizer, scroll and shell suites, eslint clean. Body updated with the row.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Re the First Principles item on 0f61f52f8f (the wall-drag re-arm in noteHardInput spelling the arrival rule a second time): taken, in c773184a35.

The inline predicate is deleted. noteHardInput now calls resolveUserScrollStick with the same accumulators the scroll handler passes (viewportGrowth, readerTravel, readerIntent, gestureStartGap, the upward-input stamp), a neutral position (prevScrollTop === scrollTop, since no scroll event fired) and stick: false. The resolver's bottom branch takes the live downward intent as the move and applies its own arrivalIsTheirs; away from the bottom its band branch returns stick for a neutral position, so the call is inert there. grep '>= growth ||' now finds one site. The import our diff had added for the inline test (atBottomEpsilon) is gone with it.

Same pins: the wall-drag hook test goes red with the resolver's answer discarded; tsc clean, 568/568, eslint clean. Body sentence updated.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Re the Opus findings on c773184a35: all three are real, fixed at the source in 41ca9ef253.

  1. Gap term vacuous at the bottom (followPolicy.ts, gap seeded from a flush position). The resolver's gap term now needs a real gap: travel >= growth || (startGap > atBottomEpsilon() && travel >= startGap). A released reader clamped flush and at rest is no longer re-armed by a 1 px nudge; a drag that covers the growth still is.
  2. Input standing in for the position with no growth (FollowController.ts, movedDown). The input substitutes only while a viewport growth is in flight: || (intent > 0 && growth > atBottomEpsilon()). With no growth a falling scrollTop at the bottom is a content shrink clamping the reader flush and the position decides, as on base. The keyboard case (growth larger than the drag) still re-engages.
  3. Observer re-baseline on the first frame of a gesture (measurement.ts). The at-rest test now requires BOTH reader clocks lapsed, the same predicate noteHardInput uses to open a gesture, so the input that starts a drag keeps the first frame's growth for the clamp's scroll event. lastHardInputAtRef is threaded into the measurement pick.

Pins, each red with only its own term reverted: two resolver tests (gap-at-bottom; content shrink under a drag, with the keyboard counter-case) and three hook tests driven by real touchmove events -- the 1 px nudge at rest, the 300 px content collapse under a 30 px drag from 200 px up, and the flush nudge with the observer entry dispatched BEFORE the clamp's scroll event (browser order; the earlier tests dispatched scroll first, which is why they could not see it). Gates: tsc clean, 573/573 across the virtualizer, scroll and shell suites, eslint clean. Body updated with the three rows.

Separately, Backend Tests (3.12, 1) failed the same three test_acp_runtime.py spawn tests on both rounds; that is #15318 (collection-order dependence since #15202, fix in #15365), unrelated to this frontend-only diff, and the three pass here in isolation.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Round 5 (6ec2140f7a -> 6818a9a1f6), taking the Opus advisory on 6ec2140f7a.

Finding: noteHardInput's fresh-gesture branch re-seeded only gestureStartGapRef, so the resolver call below it read viewportGrowthAccumRef/readerTravelAccumRef left over from the last gesture that produced a scroll event. At the wall no scroll event ever fires, so the handler's gestureLapsed reset never ran: after a 60 px growth clamped a released reader flush and they rested past SCROLL_SETTLE_MS, a single 60 px wheel notch or drag at the wall satisfied asked >= growth against the stale 60 and re-armed follow with no growth in flight -- the case the same hunk's no-growth rule refuses.

Fix: the fresh-gesture branch now zeroes both accumulators alongside the gap, the same reset the scroll handler applies on lapse. The live wall-drag re-engage is unchanged: it runs inside an open gesture (input clock fresh), so nothing is reset there.

Pin: a flick at the wall after a rest is judged on ITS gesture, not the growth that clamped the last one -- release-and-clamp as in the 1 px case, rest 400 ms, then a 60 px touch drag at the wall; follow must stay off and the re-show must not write. With only the two reset lines removed, that test fails (follow re-arms) and the other 28 in the suite still pass.

Gates: tsc clean, 1751/1751 across 143 virtualizer/scroll/follow/viewport/shell files, eslint clean. Rebased onto main while at it; this push also re-rolls the Windows(7) test_windows_failed_owner_drain_recovers_after_owner_drop flake (#12359) that was the round's only CI red.

@billygerhard

Copy link
Copy Markdown
Contributor Author

Opus round on 2f7e4912: fixed in 9e1b7cf82c.

Finding (correct): the intent-based movedDown disjunct could disable the upward-input clamp-release guard. A follower flush at the bottom flicks up while a multi-frame viewport growth is in flight; touch samples outrun frames, so a 1px reversal sample after the upward sample re-banks a positive intent (the dir === 'up' ? 0 reset only covers the other order -- the last sample before the scroll event wins). The clamp's event then carried the upward stamp, growth > eps and intent > 0, so the input answered "moved down", the release was skipped, and if (stick) return true kept follow armed where main returned false; the next pin yanked the reader back.

Fix: the input may stand in for the position only with no upward evidence in the window: (intent > 0 && growth > atBottomEpsilon() && !args.upwardInputWithinSettle). The keyboard-close returns this disjunct exists for carry no upward input, so they are unchanged (the second half of the new resolver pin asserts that).

Pins: a resolver-level test (stick armed, growth 60, intent 1, upward stamp -> false; same with no stamp -> true) and a touch-driven hook test in the order the accumulator reset cannot cover (60px up sample, 1px down sample, then the growth clamp's scroll event -> follow off, next growth moves nothing). With only the !args.upwardInputWithinSettle term reverted, exactly those two tests fail and the other 106 pass. Gates: tsc clean, 1034/1034 across 77 virtualizer/scroll/follow/viewport/shell files, eslint clean. Body has the row and a sentence.

…n iOS toolbar collapse

On iOS Safari the toolbar collapses under the very drag that scrolls toward
the bottom, so the scroller grows during the reader's small downward move.
resolveUserScrollStick rule 3 judged the re-engage band against the
post-growth height, read that as the reader arriving, re-armed follow above
the bottom, and the next automatic pin took them to the end. Rule 3 now keeps
the live distance as the arrival test and credits the arrival to the reader
only when their own downward travel across the gesture is at least the
viewport growth across it; the hook accumulates both totals per gesture and
re-baselines growth that lands while the reader rests. With no growth the
rule is identical to main.

Fixes kirodotdev#13356

@iamwhatever iamwhatever 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.

Re-reviewed the PR's own files at 5e12ee7 against 25f0194. All three points fixed: travel is now the reader's own input (pixel wheel delta or finger path) rather than the clamped scrollTop, and a drag continuing at the wall goes through the same resolver; a flush landing with no hard input no longer opens a gesture whatever stick says; the gap rule (travel >= starting gap above epsilon) restores the keyboard-close return main allowed. Each has a test (D0 < 2G, wall drag, released clamp then flick, 200px gap / 250px drag / 300px growth). Non-blocking: line-mode wheels (Firefox deltaMode=1) fall back to the position-only rule, and a pinch can add downward input via touches[0].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mobile chat transcript yanks to bottom on iOS viewport resize (URL bar / keyboard)

3 participants