Skip to content

fix(terminal): a herdr-core pane opens at its newest rows instead of scrolling through its history - #4768

Merged
devswha merged 3 commits into
mainfrom
fix/mobile-stutter
Nov 26, 2026
Merged

devswha merged 3 commits into
mainfrom
fix/mobile-stutter

Conversation

@devswha

@devswha devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Summary

On herdr-core, opening a terminal or switching to one in Terminal view showed its history scrolling down
before it settled at the newest rows. The owner saw it when switching between sessions.

Cause: hc replays an attach's history (TERMINAL_HISTORY_LINES, 2000 lines) in 16 KiB frames, all within
about 5 ms. The server passed each one to the browser as its own pty-data frame. The browser parses
each frame in its own task and draws between them, so the rows it shows climb through the history.
This happens with ovis:ghostty-only on and off, and at the main from before #4759/#4760/#4761
(22abe50). It is not new from last night.

Fix (server/core/attach-batch.ts): the server holds a herdr-core attach's first output until hc has
been quiet for 15 ms, then passes it on as one frame. A program that never goes quiet does not hold the
pane longer than 150 ms. A batch is sent every 256 KiB (OUTPUT_HIGH_BYTES), so it stays under the
viewer's output window. Output after the first gap goes on as it comes, and held output goes out before
an exit. Input readiness is unchanged: input-ready still goes on the first byte.

Because the change is in the server, phone app builds that carry an older client get it too. The
HTTP/WS contract does not change: there are fewer and larger pty-data frames, and nothing else.

Measured

Real herdr-core (isolated hc 0.1.18 core, isolatedHcEnv), two tabs that each printed 3000 lines. The
probe switched between them four times per arm and counted the distinct row ranges the page drew in each
animation frame after the click.

Before After
pty-data frames for the history 12 (137 KB) 1
Desktop, ghostty-only on: frames between the click and the newest rows 1-3 0
Desktop, ghostty-only off 3-4 0
Phone (390x844), on and off (not run before) 0

Server-side timing of hc's frames during a replay: 16 KiB frames 0.1-4.7 ms apart, then the attach's
replies 10-100 ms later.

Tests

server/core/terminals.test.ts:

  • The history comes as one frame once hc is quiet, and later output goes on as it comes.
  • A program that never goes quiet is passed on by the 150 ms deadline.
  • Held output is passed on at the attach's exit.

All three fail on main. With history?.end() removed from the exit path, the exit test fails (mutation
check). The existing core isolation test now advances the quiet window before it reads.

Validation

  • bun run check fast: workflow syntax, generated types and themes, typecheck, build and actionlint
    pass. Unit tests: 28424 pass, 1 fail. The failure is server/ssh-account-add.test.ts, which also fails
    on unchanged main in this checkout: its SSH forward socket path under the long TMPDIR is refused
    (Bad local forwarding specification). It is unrelated to this change.
  • bun test server/core/terminals.test.ts: 47 pass.
  • Not run: the browser regressions in the CI runner image (CI runs them).

…scrolling through its history

hc replays an attach's history in 16 KiB frames under 5 ms apart, and the
server passed each one on as its own pty-data frame. A browser draws between
frames, so every open or switch of a herdr-core pane showed the history
scrolling down before it settled at the newest rows.

The server now holds a herdr-core attach's first output until hc is quiet for
15 ms (at most 150 ms, sent every 256 KiB) and passes it on as one frame.
Output after that goes on as it comes, and held output goes out before an exit.
@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

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.

Run configuration

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
    • Newly opened or selected herdr-core terminals now show the latest output immediately, rather than visibly scrolling through older history while loading.
    • Initial terminal output is delivered in batches, helping the view settle sooner while still displaying output promptly.

Core terminal attachments now batch initial output and forward it as a joined frame when a size or timing condition is met, or when the attachment ends. Later output is forwarded immediately. The changelog documents the initial display behavior.

Changes: Core attach output

Layer / File(s) Summary
Batch buffering and flush conditions
server/core/attach-batch.ts
AttachBatch holds output and forwards joined data when it reaches the size threshold, after 15 ms without new output, or after 150 ms. Ending the batch clears its timers and flushes held data.
Attach integration and validation
server/core/terminal-process.ts, server/core/terminals.test.ts, changelog.d/core-switch-opens-at-newest.md
Core attachments route output through AttachBatch and end the batch with the attachment. Tests cover quiet-interval, maximum-duration, and attach-exit flushes. The changelog describes the initial display behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: nahwan-kim, odfalik

Merge Risk: Minimal · previous review ecc26

The change batches the initial herdr-core terminal output into fewer, larger frames and flushes it on exit. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a herdr-core pane opens at its newest rows instead of scrolling through history. The changeset batches a herdr-core attach's initial output, which addresses that behav…
Description check Passed The description follows the template. It has a Change section that describes the problem, the cause, the fix, and the resulting behavior. It has a Validation section that lists the commands run with r…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a herdr-core pane opens at its newest rows instead of scrolling through history. The changeset batches a herdr-core attach's initial output, which addresses that behavior. The title is specific and matches the changelog and the objectives. It is somewhat long at 98 characters, but it is clear.

Full details: Description check

Explanation

The description follows the template. It has a Change section that describes the problem, the cause, the fix, and the resulting behavior. It has a Validation section that lists the commands run with results, the failing unrelated test, and the checks not run (browser regressions, left to CI). The changelog pointer is not mentioned, but the changelog entry exists in the PR. Required content is present.

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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 741a7f1 and ecc26e8.

Files selected for processing: 4

  • changelog.d/core-switch-opens-at-newest.md
  • server/core/attach-batch.ts
  • server/core/terminal-process.ts
  • server/core/terminals.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.

@devswha

devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Reviews on ecc26e8: omo gate reviewer (BLOCK: HIGH pre-join bytes reached a joining viewer without replay; MEDIUM display query consumed the quiet window; MEDIUM frame over the 256 KiB cap; LOW timers after close) and Codex adversarial review gpt-6.2-sol-fast xhigh (BLOCK: MEDIUM flow-control stall past the 10 s pause and relay 4008 close; MEDIUM resize overtaking held output; MEDIUM replay flag; MEDIUM stale screen during recovery; MEDIUM display probe; LOW exit test). One fix round in a316ebe: flush before a viewer joins (newcomer gets them as replay), before resize, pane-move exit, recovery input-ready and process exit; only hc data arms the 15 ms quiet timer; frames capped at 40 KiB split on UTF-8 boundaries; timers cancelled on close. Eight regression tests, each failing on ecc26e8 and passing after the fix; 96 focused tests, build and typecheck pass locally. The full unit run is left to CI (the host was overloaded).

@devswha
devswha merged commit ed8fe8a into main Nov 26, 2026
22 checks passed
@devswha
devswha deleted the fix/mobile-stutter branch November 26, 2026 03:41
@devswha

devswha commented Nov 26, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 6e92b6c31. 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 moved but untouched: merged without update. Its new commits up to 2026d3718 change no file of this pull request, none imported by one, nothing that decides which checks run, and no core path.

Owner OK via Dori (2026-11-26). Reviews on ecc26e8: omo gate reviewer and Codex adversarial (gpt-6.2-sol-fast xhigh), both BLOCK; one fix round in a316ebe with eight regression tests (see the PR comment); not reviewed again (one fix round). CodeRabbit reviewed ecc26e8 with no findings and did not review the fixed head (limit).

devswha added a commit that referenced this pull request Nov 27, 2026
…ark, not after 15 ms of quiet (#4876)

## Summary

On herdr-core, the server holds an attach's first output (the history hc
replays) and sends it to the
browser as one frame, so a pane opens at its newest rows instead of
scrolling through its history (#4768).
Until now it guessed where the replay ends: 15 ms without a frame (at
most 150 ms). On a busy PC or a slow
link a pause inside the replay ends the hold early, and the pane scrolls
again.

hc already marks the end. Its first paint is queued whole before any
live byte, starts with CAN and closes
the screen with the win32-input-mode state, `CSI ?9001h` or `l`
(herdr-core `viewers.rs` `first_paint`, since
hc 0.1.11; the schema README lists it as part of the first paint). The
screen's own bytes never carry it.
`docs/tui/decisions.md` (probe c) and the fake core already record this
rule, and `adapter.ts` reads screens by it.

- `CoreAttachSession` watches the stream for that mark until it comes
(also when a frame splits it) and calls
  a new `onPaintEnd` right after the bytes that close the paint.
- `terminal-process.ts` ends the `AttachBatch` there. The 15 ms quiet
guess is gone; the 150 ms deadline
stays as the fallback for a core that never sends the mark. 40 KiB frame
splitting is unchanged.
- `PAINT_END` now lives in `attach-session.ts`; `adapter.ts` imports it
instead of keeping its own copy.

No HTTP/WS contract changes, no new hc call, no change to herdr-core.
Nothing visible changes in the UI
except that the scroll-through no longer comes back under load.

## How the end signal was chosen

- Latest hc releases (0.1.19 to 0.1.22, and herdr-core master):
`terminal.attach` and its result are
  unchanged in the schema, and no release note adds a replay-end field.
- A query sent into the attach (DSR/DA) reaches the program as typed
input: hc answers only the program's
  queries, not the viewer's, so it cannot serve as a marker.
- Reading the terminal's state first (`terminal.read`) gives text, not
the paint's bytes, so the replay's size
  cannot be known ahead.
- The 9001 mark: measured on isolated hc 0.1.17 and 0.1.22 cores, 3000
colored lines, `history: 2000`,
15 attaches each with the program idle and printing every 3 ms (60
attaches): every paint started with CAN
and held exactly one mark; the paint was 217-278 KB in 12-17 hc frames.
Live output after the mark shared its
  frame in some runs (up to 150 bytes), as probe c found.

## Validation

- Failing first: the new and changed cases in
`server/core/terminals.test.ts` and
`server/herdr-core/attach-session.test.ts` failed on main (5 failures: a
20 ms pause inside the paint sent
  the history early).
- `bun test server/core/terminals.test.ts
server/herdr-core/attach-session.test.ts
server/herdr-core/adapter.test.ts server/core/terminal-process.test.ts`:
243 pass.
- `server/herdr-core/live.test.ts` against real hc 0.1.17 and 0.1.18
(the CI matrix): 8 pass each; it now
checks that `onPaintEnd` comes once the mark is in. Against 0.1.22 the
paint-end case passes too; the
schema-freshness case fails there as it does on main (types are
generated from 0.1.18).
- `bun run check fast` on the commit: all steps ok (unit 29084 pass, 0
fail). No browser regression run: the
change is server-side and the browser receives the same bytes, only the
moment the held frame goes out moves.
- Reviews: an omo gate review and a Codex adversarial review run on this
head; results follow in a comment.
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