Skip to content

fix(chat): count only upward input as scroll intent, and navigation keys anywhere - #1734

Merged
devswha merged 2 commits into
mainfrom
fix/chat-scroll-intent-input
Oct 23, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/chat-scroll-intent-input

Conversation

@devswha

@devswha devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner

Change

Since #1431 Chat stops following only when an upward move comes within 500 ms of the reader's own scroll input. That input was any wheel, pointer press or key inside the transcript, so a downward wheel to the end followed by Shift+Enter or a paste could still let the composer's growth stop following. And a key press usually was not seen at all: clicking transcript text focuses nothing, so ArrowUp or PageUp go to body.

src/components/ChatView.tsx now records only input that scrolls the transcript up: an upward wheel, a touch moving the content up, a pointer drag (or a scrollbar press) that is followed by an upward move, and ArrowUp, PageUp, Home and Shift+Space anywhere in the document for the active chat, except while typing in an input. Downward input and plain clicks no longer count. The ChatPaneContext doc comment that the constant displaced is back, and the stale allowance comments are corrected. No visible change.

Item 3 (screen-reader scrolling, a scrollbar held longer than the window) is left as is.

Refs #1434

Validation

  • scripts/chat-virtual-browser-qa.ts (1440 and 390 px, light and dark): new cases for an upward wheel and navigation key stopping the follow, and a downward wheel and click keeping it; restoring the old wheel handling fails them.
  • bun run check fast: pass.

Observe upward navigation keys across the document and distinguish wheel direction and pointer dragging from clicks. Preserve following across layout corrections and restore the scroll comments. Cover the input window in the isolated virtual-chat browser regression.

Screen-reader scrolling and long scrollbar holds remain outside this fix.

Refs #1434
@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 1 minute.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
📥 Commits

Reviewing files that changed from the base of the PR and between 2210494 and 116342c.

📒 Files selected for processing: 3
  • changelog.d/chat-upward-scroll-intent.md
  • scripts/chat-virtual-browser-qa.ts
  • src/components/ChatView.tsx
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge-pass review (head 0811178): my QA plus a gate reviewer on a different model than the author's. I'm not merging yet because of one IME gap.

Verified fine:

  • The wheel and touch direction signs are correct.
  • Listening only while the chat is active and visible works, and the listeners are cleaned up.
  • Checked in real Chromium:
    • Shift+Space scrolls up and plain Space scrolls down.
    • Home goes to the top and End goes to the bottom.
  • Build, conventions and fixed-sleep tests pass (16/16).

Please fix before merge:

  1. Composing navigation keys count as reading intent (src/components/ChatView.tsx ~1518-1522). The document-level handler accepts ArrowUp and Home without checking event.isComposing. During IME composition those keys move between candidates. If they reach body and a small upward move follows within 500 ms, Chat stops following. The reviewer reproduced this in an isolated Chromium fixture with the same 20 px correction the PR's regression uses:

    target / key distance from bottom after output new messages
    body / composing ArrowUp 20 px shown
    body / composing Home 20 px shown
    body / composing letter 0 px absent
    textarea / composing ArrowUp 0 px absent

    Ignore events with event.isComposing (or keyCode === 229) before you record intent. Add a composing case to scripts/chat-virtual-browser-qa.ts.

Once that's in and the checks are green, this goes back into the merge queue. It's a src/ behaviour change, so it also gets another CodeRabbit review request.

Ignore composing key events and legacy IME key code 229 before recording document-level scroll intent. Cover body-targeted ArrowUp and Home for both IME signals in the isolated chat browser regression.

Refs #1434
@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Addressed the merge-pass IME finding in commit 116342c.

The document-level key handler now ignores event.isComposing and legacy IME keyCode === 229 before recording scroll intent. The existing browser regression covers body-targeted ArrowUp and Home independently for both signals; after the controlled 20 px correction and new output, chat keeps following and shows no New messages button. Ordinary upward navigation remains covered.

Verification:

  • The new composing-ArrowUp regression failed before the guard was added.
  • bun run check run bun scripts/chat-virtual-browser-qa.ts passed on the isolated setup at 1440 px and 390 px, in light and dark themes.
  • bun run typecheck passed.
  • HERDR_TEST_MODE=unit bun test scripts/conventions.test.ts src/conventions.test.ts passed.
  • bun run check fast passed, including build and 6,161 passing unit tests (0 failures, 12 skipped).
  • Browser and fast-check reports both confirm unchanged source during verification.

Only src/components/ChatView.tsx and scripts/chat-virtual-browser-qa.ts changed in this follow-up. This is a new commit; no history was rewritten.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@devswha

devswha commented Oct 23, 2026

Copy link
Copy Markdown
Owner Author

Merge pass: reviewed in place of a CodeRabbit review, which was rate-limited.

  • The first gate review (different model than the author's) found one blocker: composing ArrowUp/Home that reached body counted as scroll intent and could stop Chat following.
  • Fixed in 116342c with isComposing/keyCode 229 guards and four composition QA cases.
  • The re-review approved it: composing keys keep following, ordinary ArrowUp/Home still stop it, and the QA fails on the old head.
    Wheel and touch signs, listener cleanup and Shift+Space (verified in real Chromium) were checked in the first review. All required checks are green and no review thread is open.

@devswha
devswha merged commit 794f4b2 into main Oct 23, 2026
9 checks passed
@devswha
devswha deleted the fix/chat-scroll-intent-input branch October 23, 2026 09:31
devswha added a commit that referenced this pull request Oct 24, 2026
…avigate (#1831)

## What it does for the user

When you scroll up in Chat to read older turns and then send a message
from the message box, the chat now takes you back to its end once the PC
accepts the message, and follows the reply there. Before this, the view
stayed where you were reading, so your own message and the agent's
answer appeared off screen behind a "New messages" pill.

It only follows your own message from this browser that the bridge
accepted at once (a receipt with no pending item, not a refusal, not an
unconfirmed send to an older bridge). These keep the reader's place:

- a refused or uncertain send
- a queued or Send now delivery
- another browser's message, a reconnect, or opening the pane again

Scrolling or paging back, a wheel over the minimap rail, a minimap jump,
a restored place, a replaced history, or leaving the pane before the
receipt or before the turn shows cancels the follow. Nothing new is
drawn: the existing Jump to latest and New messages controls stay as
they are.

## Why

Agent of Empires re-pins its view on every prompt, local, remote or
replayed. Ovis's sends carry a receipt, so only that accepted local
receipt counts, and the reader's own navigation after sending always
wins. #1734 and #1431 changed how scroll intent is read. I checked this
against current main: the regression script below still fails there, at
the step where the accepted receipt should bring the view to the end.

## How it was verified

- `scripts/chat-local-send-follow-demo-regression.ts` (added to the
browser lane) runs on the demo app over its fixture transport. The
submit receipts and transcript reads are gated, so each ordering is
forced rather than timed. It covers:
  - an accepted send following to the end and the reply being followed
  - navigation before the receipt cancelling the follow
- navigation before the transcript shows the turn cancelling the follow
- refused, uncertain, remote, queued and Send now sends, a pane switch
and a reconnect keeping the reader's place
- The script passes on this branch. With `src/` reset to origin/main it
fails at "the accepted receipt brings the view to the end".
- `bun run check fast` passes (typecheck, build, 6380 unit tests).
- Looked at the demo at 390 px (phone) and 1280 px (desktop): after
scrolling away and sending, the message and the Working row sit at the
end above the composer, no horizontal overflow, no page errors, nothing
new drawn.
- Reviewed by a code-review agent and by Codex. No HIGH findings. One
MEDIUM from both (a wheel over the minimap rail scrolled the chat
without counting as navigation) is fixed in the second commit, along
with paging down no longer cancelling a follow.

## Follow-up

The regression script exercises wheel navigation only. PageUp and
minimap tick jumps cancelling the follow are covered by code reading,
not by a scripted step yet.

Rebased onto current main; the composer send moved to
`src/lib/useComposerSends.ts` since the branch was cut, so the change
was ported there.
devswha added a commit that referenced this pull request Oct 24, 2026
… follow allowances (#1902)

## What it does for the user

Holding the chat's scrollbar still for a moment and then dragging it up
a little now stops Chat from following new output, as any other upward
scroll does. Before this, only a drag that began within half a second of
the press counted. A thumb that rested first and then moved up less than
48 px kept following, so the next update pulled the reader back to the
end.

Fixes #1434. #1734 already fixed items 1, 2, 4 and 5. This PR fixes what
was left of item 3:

- **A held scrollbar press** (3a). In Chromium a thumb drag sends
`pointerdown` on the scroller at the press, no `pointermove` while the
thumb moves, then scroll events, then `pointerup` at release (measured
in Playwright's Chromium with scrollbars shown). `ChatView` now
remembers that a primary-button press on the transcript's scrollbar is
held. While it is held, an upward move counts as the reader's own,
however long the thumb rested first. The hold ends on
`pointerup`/`pointercancel`, on a new press, on any pointer event with
no button down (a release this page did not see), and when the chat's
input listeners are removed (the pane hidden or left).
- **The 1 px and 48 px values** (3c) are named: `READER_ALLOWANCE_PX`
(endpoint rounding only, after the reader's own input) and
`LAYOUT_ALLOWANCE_PX` (a composer growing a few lines before the
correction to the end lands).
- **Screen-reader scrolling** (3b) is not fixed and is documented beside
`LAYOUT_ALLOWANCE_PX`. A scroll that sends no input this page can see,
from a screen reader or from Firefox's scrollbar (which may send no
press), leaves the end only past 48 px. The page has no signal to tell
such a scroll from the composer's own growth, and guessing would bring
back the composer-growth bug #1431 fixed.

No visible change otherwise. Design precedent: none of the coding-agent
apps exposes this. It follows the rule #1734 set: only input that
scrolls the transcript up is the reader's intent.

**#1831:** that open PR edits the same `allowance` line in `onScroll`
(it adds `byReader` and `navigated()`). Whichever lands second keeps
both: #1831's `byReader` with the named constants. A held-thumb drag
then also counts as navigation for #1831's follow of the reader's own
send.

## How it was verified

- `scripts/chat-virtual-browser-qa.ts` (already in CI's browser lane)
runs the real `ChatView` in Chromium at 1440 px and 390 px, light and
dark. Its scroll-intent loop gains four cases. Each fires the scrollbar
press on the scroller right of its content box, then moves the
transcript up 20 px, inside the layout allowance but past endpoint
rounding. `performance.now` is skewed by 600 ms around that move, so the
move comes after the input window as a resting thumb's would, with no
sleep.
- `scrollbar-held`: the press is still held when the move lands.
Following stops and **New messages** shows.
- `scrollbar-held-released-first`: the thumb is released before the
scroll event is delivered (the order Codex's review found). Following
stops.
- `scrollbar-released`, `scrollbar-unseen-release` (no `pointerup`, the
next pointer event has no button down): the press is over, so the same
20 px correction keeps following.
- On origin/main the script fails at `scrollbar-held: only upward input
stops following` (`0 !== 1`). On this branch it passes, 52 PASS,
together with the existing cases: a downward wheel, a click, typing and
composing keys keep following; an upward wheel, navigation keys and a
drag stop it; a composer growing a line paints no frame off the end.
- `bun run check fast` passes on this commit (typecheck, build, unit
tests).
- Reviewed by a code-review agent (omo, approved) and by Codex
(gpt-6.1-sol). Codex's one MEDIUM (a thumb released before the browser
delivered its scroll lost the intent) is fixed and covered by
`scrollbar-held-released-first`. omo's LOWs:
- **Fixed:** the hold now needs the primary button, and it is cleared
when the chat's input listeners go away (the pane hidden or left
mid-press).
- **Left:** a new press clearing the hold has no case of its own; it
duplicates the release paths.

Not reproduced on a real Firefox or with a screen reader; see the
screen-reader note above.

---------

Co-authored-by: mp <mp@local>
devswha added a commit that referenced this pull request Oct 28, 2026
## What it does for the user

Chat now keeps following new output to the end when part of the
transcript folds on its own. Before
this, a turn settling at the end (its work folding together with a block
above it), or a block above
the view folding while the view was still gliding to the end, could stop
following mid-transcript and
show **New messages**, with no scroll by the reader.

Fixes #2042. Reported by @odfalik.

## Cause

`onScroll` in `src/components/ChatView.tsx` treats an upward move with
no reader input that lands past
the 48 px layout allowance as the reader leaving the end: it sets
`pagingAway` and drops the list's
pending scroll to the end. LegendList (`maintainVisibleContentPosition`)
and the browser make such
moves themselves when the transcript shrinks. The list holds the rows on
screen where they were, and
the browser keeps the view inside a shorter transcript. For one shrink
both can move the view up, so
it lands hundreds of pixels from the end, or past the end of a follow
glide that was still on its way.

## Change

- Without reader input, an upward move during which the transcript got
shorter (the last row moved
up in it, or its height dropped since the previous scroll event) now
counts as the layout's: following
goes on, and a view left more than 48 px short of the end is put back
there.
- That pin-back is skipped while `pagingAway` is set and while a
following reader's own click is laid
out where they are (ChatTimeline `manualLayout`), as the timeline's own
follow paths already do.
- Over a transcript that did not shrink, nothing changes: a no-input
scroll (a screen reader's, a
Firefox scrollbar's) leaves the end once the view is past 48 px from it,
however small its steps
(#1902). Reader input (wheel, keys, touch, a scrollbar drag) is
unchanged.
- The new scroll baselines reset with the chat's other scroll state on a
pane change or a history
  replacement.

Known trade-off: a no-input reader scroll that lands in the same scroll
event as a fold is put back at
the end once; the next move leaves as before. During a turn that keeps
folding this can happen more
than once. The page has no signal that tells such a scroll from the
layout's own move in that event.

Design precedent: none of the coding-agent apps exposes how it tells its
own re-layout from a reader's
scroll; this follows the rule #1734 set and #1902 kept, that only input
that scrolls the transcript up
is the reader's intent.

## How it was verified

- `scripts/chat-virtual-browser-qa.ts` (real `ChatView` in Chromium,
1440 and 390 px, light and dark,
  already in CI's browser lane) gains:
- `fold-together`: at the end, the last row and a row above fold in one
layout (a turn settling).
Following goes on to the end and the next output is followed. **Fails on
main**
    ("fold-together: the next output is followed"), passes here.
- `fold-above` / `grow-above`: a row above folds or grows while the view
glides to the end after the
last row grew. These pass here; on main they fail only when the fold
lands in the same frame as the
    glide, so they do not fail on every main run.
- `wheel-up`: a real upward wheel (`page.mouse.wheel`) still stops
following ("Jump to latest", then
    **New messages** with the reader left away from the end).
- Two 30 px upward steps without input from the end stop following past
the allowance. This catches
    the first commit's regression found in review.
  - Full script: 60 PASS over all four width/theme combinations, exit 0.
- `scripts/chat-local-send-follow-demo-regression.ts` (#1831),
`scripts/chat-gjc-streaming-browser-qa.ts`
(#1388/#1937) and `scripts/composer-fit-demo-regression.ts` (#1431):
pass on the final commit.
- `bun run check fast`: green on the final commit.
- Reviews: Codex (gpt-6.1-sol, fast, xhigh) and the omo code reviewer.
Both blocked the first commit on
one finding: the 48 px allowance applied per scroll event, so small
no-input steps were pinned back
(a #1902 regression). The second commit measures it from the end again.
The omo reviewer's other
findings were fixed: the `manualLayout` guard and the baseline resets.
Codex re-reviewed the fix:
  APPROVE.

Not reproduced on a real Firefox or with a screen reader. Once, during
QA, a real wheel landing early in
a glide did not stop following; it did not reproduce in six later runs
(three on main, three here) and
this change does not touch moves made with reader input.
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.

1 participant