Skip to content

fix(workbench): keep the terminal following output across delayed scroll reports - #7214

Draft
Loveca wants to merge 1 commit into
apache:mainfrom
Loveca:fix/terminal-follow-stale-scroll-report
Draft

Loveca wants to merge 1 commit into
apache:mainfrom
Loveca:fix/terminal-follow-stale-scroll-report

Conversation

@Loveca

@Loveca Loveca commented Nov 23, 2026

Copy link
Copy Markdown

Summary

The Desktop terminal can stop following output while the viewport is at the bottom and the user has not scrolled: a later output batch grows the grid before the automatic scroll report of an earlier batch is delivered, and the stale report re-derives atBottom against the newer geometry. The pane then stays on an earlier batch (or renders blank) while output continues.

The follow decision now reads the geometry each scroll report carries itself, and only user scrolling stops or resumes following.

Fixes #7158

Root cause

  • NSH coalesces scroll reports to one per frame (third-party/nsh/crates/nsh-core/src/scroll.rs module docs), so the report of the follow effect's scrollToEnd for batch N can arrive after batch N+1 already updated the grid.
  • Terminal.tsx's onScroll computed distance = frame().totalRows - rows() - floor(event.offset.y / LINE) — the report's old offset against the current frame. With batch N at 30 rows (viewport 24, offset at row 6) and batch N+1 grown to 40 rows, the delayed report yields distance 10 → model.atBottom = false → the follow effect (Terminal.tsx, effect(() => { … if (model.atBottom) scrollToEnd … })) never scrolls again. This matches the controlled replay in the issue (baseline 4cb1415525, viewport stops at the second batch).
  • The ScrollEvent payload already snapshots the geometry at report time (contentSize/size, captured in nsh-engine's Message::Scroll handling), and TurnPanel/Conversation already compute their follow distance from that self-consistent geometry. The terminal was the only scroll surface comparing a reported offset against live external state.

Fix

  • Extract the decision into app/terminalFollow.ts (pure module, no nsh imports, same pattern as composerToolbar.ts): distance is computed from the report's own contentSize/size, so a delayed report is self-consistent by construction.
  • Only user input changes the reading state: onScrollIntent / onScrollDragStart mark user scrolling (NSH contract: programmatic scrolls emit neither; verified across the macOS, Windows, Linux and TUI backends for wheel, drag, scrollbar-thumb and key scrolls). Programmatic reports no longer rewrite atBottom, so they can neither stop following nor resume it after the user scrolled away. The user returning to the bottom (within one row, as before) resumes following.
  • shift+pageup routes through the same decision (pageUp()), and a remounted pane restores its reading state from model.atBottom.
  • Peer paths audited: TurnPanel and Conversation already use event-local geometry and user-input gating; QuickQuestionPanel has no follow logic. No other surface compares scroll offsets against live grid state.

Verification

  • New products/maka/workbench/tests/terminal-follow.test.mjs: 6 tests, all passing. The first test inlines the previous decision formula and reproduces the failure on the delayed-report interleaving from the issue (30-row batch, report delivered after the grid grew to 40 rows → following stops, offset 10); the remaining tests cover the fixed behavior: delayed automatic reports keep following, user scroll-away preserves the reading position across later batches, returning to the bottom resumes following, shift+pageup only resumes on user input, and a viewport taller than the output stays at the bottom.
  • Full workbench Node suite: node --test products/maka/workbench/tests/*.test.mjs — 255 passed, 0 failed (249 existing + 6 new).
  • biome check on the three changed files: clean. tsc -p products/maka/bundle/tsconfig.json and a standalone strict tsc of terminalFollow.ts: pass. ASF header audit and git diff --check: pass.
  • Not run: the Rust workspace suites and the desktop E2E suites (no Rust toolchain on this machine); a desktop recording of the fix. The windows-desktop/native CI suites exercise the real renderer. Happy to add a recording once a desktop build is available — opening as draft until the UI evidence is settled.

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: Claude Code assisted with root-cause analysis (including the NSH scroll-report contract), implementation, regression tests, and PR preparation. The commit carries a Generated-by: Claude Code trailer.

Checklist

  • Tests cover the change and fail without it
  • Format, typecheck and the affected suites pass locally

Does this PR entail a breaking change or persisted-data migration?

  • Yes — describe user/data impact, in-place migration, and upgrade_compat.rs coverage under Summary above
  • No

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

…oll reports

NSH coalesces scroll reports to one per frame, so the report of an
automatic scrollToEnd can arrive after the next output batch already grew
the grid. Terminal.tsx re-derived atBottom from that stale offset against
the current frame, stopping following without user input.

Compute the distance from the geometry the report itself carries
(contentSize/size on the ScrollEvent), and let only user scrolling
(onScrollIntent/onScrollDragStart) stop or resume following; programmatic
reports no longer rewrite the reading state. The decision lives in
terminalFollow.ts with a controlled-replay regression.

Generated-by: Claude Code
@github-actions github-actions Bot added the effort/M Under 500 readable lines label Nov 23, 2026

This branch has not been deployed

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

Labels

effort/M Under 500 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(desktop): terminal stops following output without user scrolling

1 participant