You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(terminal): land at the newest rows after a switch back from Chat to a grid another device sized - #4688
Switching from Chat back to the terminal sometimes did not land on the newest rows, and each further switch left the view one more row above them (the jump-to-bottom button stayed up while output kept coming in below the view).
Reproduced on the real path: an isolated herdr-core and Ovis from origin/main 355248f, a phone page (390x844, DPR 3, CPU 4x slower) switching Chat -> Terminal on a pane that a desktop page shows at 119x42 at the same time.
Case (30 switches each unless noted)
Not at the newest rows
Broken rows
Before: phone + desktop peer, shell pane with 50k lines
6/6 (every switch; view 4, 5, 6... rows up)
-
Before: phone + desktop peer, agent-like pane that reprints its transcript on SIGWINCH
0/30
1/30
Before: one viewer only (desktop, phone), shell and agent-like
0/120
0/120
After: phone + desktop peer, shell
0/30
0/30
After: phone + desktop peer, agent-like
0/30
0/30
After: one viewer only, desktop + phone, shell
0/60
0/60
Cause
xterm 6's viewport took the height of its scroll area from the canvas (dimensions.css.canvas.height). While the terminal is hidden under Chat, xterm's rendering is paused, and a resize then reaches the canvas only once rendering resumes. The pane is resized while hidden (to the grid the other device drives) and again when shown (fitted to this page), so the viewport synced the new grid against the old canvas height: the scroll position was clamped 2 rows short of the bottom, and Viewport._handleScroll read that clamp as the reader scrolling up (isUserScrolling = true). From then on new output left the view above it, one more row per line when the scrollback is full. Traced with xterm's own stack: Viewport._sync -> setScrollPosition -> _handleScroll -> scrollLines(-2) with paused=true canvasRows=42 on a 46x40 grid.
the scroll area's height is the grid's rows times the cell height, not the canvas height, so a resize made while rendering is paused is measured right away;
its own setScrollPosition (the DOM following the buffer) is never read as the reader scrolling, the same way the dimension update just above it already is.
Upstream xterm.js master has the same code (checked src/browser/Viewport.ts). No app code changes.
scripts/core-history-scroll-demo-regression.ts gets a case for it: a phone with 200 rows wider than its grid, the pty taken to 120x42 while Chat covers the terminal, back to the terminal, new output; three rounds. It fails on main (viewportY 658, baseY 665) and passes here.
What stays: when two devices of different sizes share a pane, the device that shows the terminal drives the pty, so the program (bash's prompt, an agent's transcript) redraws for the new size. Rows the program redraws at another width can still look overprinted (bash's prompt in the captures, both before and after); that is the program's own resize redraw, not this bug.
Captures
Isolated herdr-core, a pane with 50k lines, the other device holding another size, after the 3rd switch.
Phone 390, before (view stopped above the newest rows, jump button up) and after:
Desktop 1280 (switching while a phone holds 46 cols), before and after: both land at the newest rows (the wide side was not affected):
No UI or layout change; no HTTP/WS contract change.
Validation
bun scripts/core-history-scroll-demo-regression.ts: fails on main with the new case, passes here (all five PASS lines).
Repro harness above (not committed), numbers in the table.
bun test scripts/conventions.test.ts scripts/changelog-fold.test.ts src/lib/useTerminalRefits.hook.test.ts: pass.
bun run check fast: NOT run locally. This PC was at load 180-220 on 128 cores and the remote check host (old-desktop) at 40-50 on 32, so the remote run timed out waiting for a slot. This PR's CI Fast checks job runs it.
…to a grid another device sized
xterm 6 sized its viewport's scroll area from the canvas, which a resize made
while rendering is paused (the terminal hidden under Chat) reaches only once
rendering resumes. The sync clamped the position short of the newest rows and
read that clamp as the reader scrolling up, so output after the switch left the
view above it. The viewport now takes its height from the grid's rows, and its
own sync is never read as a scroll.
Auto incremental reviews are disabled on this repository.
Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Summary
Summary by CodeRabbit
Bug Fixes
Returning to a terminal after switching to Chat now shows the newest rows and keeps the view following new output, even when the terminal’s size has changed.
Improved text entry for Safari, iOS, Linux IME, and Hangul input, including composition handling around paste and focus changes.
Corrected terminal scrolling and keyboard navigation behavior, including trackpad scrolling and Alt-arrow word navigation.
New Features
Terminal input composition can now be positioned within specified viewport bounds.
The xterm viewport now derives its scrollable height from buffer rows and cell height. A regression scenario checks that returning to a terminal pane after a geometry change shows the newest rows and follows new output.
Changes: Terminal viewport behavior
Layer / File(s)
Summary
Viewport height and position synchronization patches/@xterm%[email protected]
The viewport calculates scrollable height from buffer rows and cell height. It suppresses scroll handling while setting the buffer display position. The patch also removes an empty Bun tag file entry.
The fixture can send pane geometry and PTY output. The regression scenario checks the newest visible line and continued output following across three rounds after returning from Chat. The changelog documents this behavior.
devswha/ovis#3967: Addresses the same terminal-position symptom with a different mechanism: moving the local xterm history view to the bottom after a Chat switch.
Suggested reviewers:zs311521
Merge Risk: Minimal · previous review 6ef88
This change fixes the terminal landing above the newest rows after another device resizes a shared pane. No actionable merge-blocking risk was found, and a regression scenario covers the fixed behavior.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the main change: the terminal now lands at the newest rows after switching back from Chat to a grid that another device sized. The changeset (xterm viewport patch, regression script, c…
Description check
The description follows the template. The Change section explains the problem, the cause, and the fix in the patched Viewport._sync. The Validation section lists the commands that ran, with results, a…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: the terminal now lands at the newest rows after switching back from Chat to a grid that another device sized. The changeset (xterm viewport patch, regression script, changelog) addresses this scroll-position bug. The title follows the conventional commit form and is specific.
Full details: Description check
Explanation
The description follows the template. The Change section explains the problem, the cause, and the fix in the patched Viewport._sync. The Validation section lists the commands that ran, with results, and states that bun run check fast was not run locally and why. Contract-test coverage is addressed by stating there is no HTTP/WS contract change. The Change section does not link an issue, but the template asks for an issue link only for features, and this is a fix.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
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.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
Codex adversarial (gpt-6.2-sol-fast, xhigh): no HIGH, no MEDIUM. It reproduced the failure in compiled xterm with both changes removed (viewportY 658, baseY 665) and the fix (665/665), and checked smooth scrolling during output, the scrollLines path used by touch and selection autoscroll, scrollback trimming, alternate screen and zero scrollback.
Gate reviewer (omo): implementation CLEAR, no HIGH or MEDIUM; the changed browser regression and 70 focused tests passed in its run.
LOW (both, not changed): the new regression case writes five lines before it asserts, so with only the scroll-event suppression (and the old canvas height) the scrollbar's own position would still be two rows behind right after the switch, and the writes hide it. The buffer position the user sees is asserted; the scrollbar thumb is not.
LOW (Codex, pre-existing on main too, not changed): after a font-size change the viewport's pixel offset stays stale until the next sync, so the first one-line scroll can jump.
Merged through pr-merge at head 10b253673. Seen before the merge was asked for: required checks green, no unresolved thread, no conflict, no hold, main not red, no release in progress. CodeRabbit said it did not review (a limit or a skip) since this head.
main had moved since the checks of 34d476708: pr-merge --update merged it in (e897294ac), and every required check was green at this head.
CodeRabbit hit its review limit on this PR. Reviews that ran: Codex adversarial (gpt-6.2-sol-fast, xhigh) and the omo gate reviewer, both no HIGH/MEDIUM (summary in the PR comment). Merged on the owner's standing word to proceed without CodeRabbit when its limit is reached.
…fault (#4759)
## Summary
Step 5 of moving the terminal from xterm to libghostty. Steps 1 to 4 are
#4669, #4681 and #4740.
Also closes the owner's scroll check for #4688:
`scripts/core-history-scroll-demo-regression.ts` now runs the #4688 case
on a 50k-line session for ten Chat/Terminal switches and checks that no
Jump to bottom is left up. With the flag forced on it passes even with
#4688's xterm patch reverted.
This adds an opt-in path where libghostty alone parses a pane's output.
It is off by default: set localStorage `ovis:ghostty-only` to `on` to
use it. With the flag off, nothing changes.
With the flag on:
- libghostty takes every byte. xterm gets only the sequences its input
side reads (`src/lib/ghostty/controls.ts`):
- DEC and ANSI modes, the keypad modes and modifyOtherKeys
- the questions xterm answers: device attributes, status and cursor
reports, mode reports, version, sizes
- the resets
- OSC 52, passed through as it arrives
- the colour questions
- xterm's cursor follows libghostty's after each write, before each
question, and after a resize. A cursor report, the IME's composition
(Korean and others) and xterm's helper textarea therefore sit at the
program's cursor.
- The history is libghostty's. Wheel, swipe and Jump to newest move
libghostty's view. A view that is scrolled back keeps its rows while new
ones arrive.
- Readers that are judged at whole frames (the input row, the stop key)
read libghostty's rows (`frameRows`).
- In three cases xterm parses the whole stream after all: the 32 MiB
hold limit is reached, the module fails to load, or libghostty gives up
after attaching. xterm is reset first and gets every byte except the
questions it already answered. The overlay keeps the last 8 MiB of
output for this.
- An iTerm2 inline picture (`File=` and the multipart form) is turned
into a Kitty graphics picture and written to libghostty, which draws it
(`itermPictureWriter.ts`, `itermKitty.ts`). PNG goes as it is; TIFF, GIF
and other formats are made PNG first, with later output held so the
order stays. A picture that is off, a download (`inline=0`), broken or
over the cap is dropped, and output goes on. A sixel picture is decoded
here (`sixel.ts`: raster size, HLS and RGB colour registers, the VT340
palette, repeats, transparency) and goes the same way. No picture hands
the terminal to xterm any more, and the pictures setting no longer
decides the path. Two differences from xterm's image addon: an opaque
sixel uses the terminal's default background rather than the current
one, and DECSDM is not followed.
- libghostty draws its own frame after each write instead of waiting for
xterm's render (xterm holds no rows and may skip a render after a resize
made while the pane was hidden). An open synchronized update (DEC 2026)
still waits for the render that ends it.
- Jump to bottom reads libghostty's view.
Nothing visible changes unless the flag is on.
## Speed
Measured on a 1.56 MB Claude Code recording, 5 runs per arm, with
identical bytes and the same final screen in all 10 runs.
At this head (pictures setting on, the default), phone emulation
(390x844, 4x CPU throttle):
| | Both engines (now) | libghostty only |
|---|---|---|
| Main thread | 5326 ms | 2141 ms (2.49x) |
| Browser CPU | 10600 ms | 3660 ms (2.90x) |
| Total blocking time | 315 ms | 60 ms |
| Long tasks over 50 ms | 14 | 5 |
| Heap growth | 3.5 MB | 3.8 MB (the kept 8 MiB for a handover) |
Android emulator, Chrome 133, at an earlier head with pictures off: main
thread 889 ms -> 381 ms (2.33x), browser CPU 2550 ms -> 980 ms.
## Tests
- `controls.test.ts`:
- The scanner takes the same controls however a stream is split.
- An xterm fed the controls alone keeps the modes, cursor and answers
(including a cursor report, keypad and insert modes) of an xterm fed
everything. This holds when the stream is written whole and when it is
cut every 7 characters.
- An OSC 52 split across frames reaches xterm whole.
- A stream handed over whole loses only its questions.
- `selection.test.ts`: a triple click takes a line that wraps from above
the view.
- Mutation-checked: the tests fail without the cursor sync, the OSC 52
streaming and the ANSI-mode forwarding.
## Validation
- `bun run check fast` at this head: pass (build, typecheck, unit tests,
generated files, workflow syntax).
- Focused: `bun test src/lib/ghostty src/lib/itermPictures
src/lib/terminalImages src/components/TerminalViewportTools`: 315 pass.
- In the CI runner image, with the flag forced on at this head and
#4688's xterm patch reverted: core-history-scroll (with the #4688 case
grown to a 50k-line session and 10 switches), terminal-ghostty,
terminal-images (iTerm2 pictures drawn by libghostty), mirror-scroll,
ui-terminal, ui-regression and ui-ime all pass, at 932e901 (iTerm2 and
sixel). Earlier, at 6186677, ui-access, ui-contexts and
sticky-modifiers passed too.
- Before the frame fix, the #4688 case failed in round 1 with the flag
on: the newest output never reached the screen.
- The standalone terminal regressions pass except four:
- android-ime and ipad-ime: the image has no emulator and no Chrome.
- replay-clipboard and release-no-watch: by design, these check that
xterm receives every byte.
## Reviews
- The two picture converters (`a1cee8578`, `932e9018b`) and the frame
and Jump to bottom fixes came after that review; they have had no review
beyond this PR's own.
- One gate reviewer gave BLOCK (5 HIGH) and a Codex adversarial review
(gpt-6.2-sol-fast, xhigh) ran on 867b02e. The fixes are in 6186677:
- OSC 52 ownership across frames
- a split sequence at the handover
- the handover to xterm: no chunk written twice, no second reply, no
blank screen
- the cursor after a resize
- ANSI and keypad modes
- storage that throws
- Both MEDIUMs are fixed here: the pictures setting no longer decides
the path (a picture hands over when it arrives), and Jump to bottom
reads libghostty's view.
…lt (#4760)
## Summary
Step 7 of moving the terminal from xterm to libghostty. It builds on
step 5 (#4759), which added the libghostty-only path behind a flag.
This turns that path on by default on a phone or tablet (a coarse
pointer), where parsing every byte twice cost the most. Since step 5 the
choice is made before the first byte, when the server's kind may not be
known yet, so it holds on herdr-core and herdr alike. A desktop browser
is unchanged.
localStorage `ovis:ghostty-only` (`on` / `off`) still decides over the
default, so a user or a test can turn it off.
Nothing on screen is meant to change. Rows, the cursor, selections,
links, pictures and the scroll position are drawn by the same libghostty
layer as before. Only xterm's second, hidden parse is dropped.
## Speed
Phone emulation (390x844, 4x CPU throttle), on a 1.56 MB Claude Code
recording, 5 runs per arm. All 10 runs got identical bytes and showed
the same final screen.
| | Both engines (before) | libghostty only (now the phone default) |
|---|---|---|
| Main thread | 5326 ms | 2141 ms (2.49x) |
| Browser CPU | 10600 ms | 3660 ms (2.90x) |
| Total blocking time | 315 ms | 60 ms |
| Long tasks over 50 ms | 14 | 5 |
Android emulator (Chrome 133, measured at an earlier head with pictures
off):
- main thread: 889 ms -> 381 ms (2.33x)
- browser CPU: 2550 ms -> 980 ms
## Tests
`capture.test.ts` checks two things:
- The default is on only for a coarse pointer.
- A stored choice decides over the default.
## Validation
- `bun run check fast` at this head: pass.
- In the CI runner image at this head (the phone default as shipped, no
flag forced): core-history-scroll (with the #4688 case),
terminal-ghostty, terminal-images, mirror-scroll, ui-terminal,
ui-regression, ui-ime, ui-access and ui-contexts all pass (9/9).
#4761)
## Summary
Step 8 of moving the terminal from xterm to libghostty. It builds on
step 7 (#4760), which turned the libghostty-only path on by default for
phones and tablets.
This turns that path on by default on every device, on herdr-core and
herdr alike. One exception keeps xterm's full parse: a mirrored pane.
That is a Windows PC's pane, or one on a machine without a PTY host,
which is repainted from `pane.read`. Its folded view stands the IME's
preedit on xterm's rows. The choice is made before the first byte, and a
pane not yet known to be mirrored counts as attached.
localStorage `ovis:ghostty-only` (`on` / `off`) still decides over the
default.
Nothing on screen is meant to change. Rows, the cursor, selections,
links, pictures and the scroll position are drawn by the same libghostty
layer as before. Only xterm's second, hidden parse is dropped.
## Speed
All runs used the same recording, a 1.56 MB Claude Code session, with 5
runs per arm. All 10 runs got identical bytes.
Desktop (1280x800, no CPU throttle):
| | Both engines (before) | libghostty only (default after this) |
|---|---|---|
| Main thread | 491 ms | 340 ms (1.44x) |
| Browser CPU | 4160 ms | 1660 ms (2.51x) |
| Start to settled | 582 ms | 457 ms |
| Heap growth | 2.2 MB | 3.4 MB (the 8 MiB kept for a handover) |
Phone emulation (390x844, 4x CPU throttle), for reference from step 7:
- main thread: 5326 ms -> 2141 ms (2.49x)
- browser CPU: 10600 ms -> 3660 ms (2.90x)
## Also in this PR
Default-on brought three browser scripts to fail on the first CI run:
- **The outputProbe** in `useTerminalMount` counted bytes reaching
xterm. xterm now gets controls only, so the probe counts each output
frame where it enters the terminal, whichever engine parses it. This
fixes sidebar-activity and terminal-release-no-watch.
- **A real difference:** an OSC 52 whose ST was split between ESC and
the backslash was copied one frame late. xterm ends a string at its ESC,
so the picture writer and the control scanner now pass that ESC on with
the write it ends, and send only the backslash after it. Unit tests in
`controls.test.ts` and `itermPictureWriter.test.ts` cover it; both fail
without the fix.
- **replay-clipboard** reads xterm's own OSC parse state, so it runs
with the libghostty-only path off. That is the path mirrored panes and
every fallback still take.
## Tests
- `capture.test.ts`: the default is on unless the pane is mirrored, and
a stored choice decides over it.
- `overlay-fallback.test.ts`: the case without the flag now sets "off",
since the default is on.
## Validation
- `bun run check fast` at this head: pass.
- CI runner image, default as shipped:
- core-history-scroll, including the #4688 case
- terminal-ghostty, terminal-images and mirror-scroll
- ui-terminal, ui-regression, ui-ime, ui-access and ui-contexts
All 9 pass, with no error lines in their logs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Switching from Chat back to the terminal sometimes did not land on the newest rows, and each further switch left the view one more row above them (the jump-to-bottom button stayed up while output kept coming in below the view).
Reproduced on the real path: an isolated herdr-core and Ovis from origin/main 355248f, a phone page (390x844, DPR 3, CPU 4x slower) switching Chat -> Terminal on a pane that a desktop page shows at 119x42 at the same time.
Cause
xterm 6's viewport took the height of its scroll area from the canvas (
dimensions.css.canvas.height). While the terminal is hidden under Chat, xterm's rendering is paused, and a resize then reaches the canvas only once rendering resumes. The pane is resized while hidden (to the grid the other device drives) and again when shown (fitted to this page), so the viewport synced the new grid against the old canvas height: the scroll position was clamped 2 rows short of the bottom, andViewport._handleScrollread that clamp as the reader scrolling up (isUserScrolling = true). From then on new output left the view above it, one more row per line when the scrollback is full. Traced with xterm's own stack:Viewport._sync -> setScrollPosition -> _handleScroll -> scrollLines(-2)withpaused=true canvasRows=42on a 46x40 grid.Change
patches/@xterm%[email protected],Viewport._sync:setScrollPosition(the DOM following the buffer) is never read as the reader scrolling, the same way the dimension update just above it already is.Upstream xterm.js master has the same code (checked
src/browser/Viewport.ts). No app code changes.scripts/core-history-scroll-demo-regression.tsgets a case for it: a phone with 200 rows wider than its grid, the pty taken to 120x42 while Chat covers the terminal, back to the terminal, new output; three rounds. It fails on main (viewportY 658, baseY 665) and passes here.What stays: when two devices of different sizes share a pane, the device that shows the terminal drives the pty, so the program (bash's prompt, an agent's transcript) redraws for the new size. Rows the program redraws at another width can still look overprinted (bash's prompt in the captures, both before and after); that is the program's own resize redraw, not this bug.
Captures
Isolated herdr-core, a pane with 50k lines, the other device holding another size, after the 3rd switch.
Phone 390, before (view stopped above the newest rows, jump button up) and after:
Desktop 1280 (switching while a phone holds 46 cols), before and after: both land at the newest rows (the wide side was not affected):
No UI or layout change; no HTTP/WS contract change.
Validation
bun scripts/core-history-scroll-demo-regression.ts: fails on main with the new case, passes here (all five PASS lines).bun test scripts/conventions.test.ts scripts/changelog-fold.test.ts src/lib/useTerminalRefits.hook.test.ts: pass.bun run check fast: NOT run locally. This PC was at load 180-220 on 128 cores and the remote check host (old-desktop) at 40-50 on 32, so the remote run timed out waiting for a slot. This PR's CI Fast checks job runs it.