Skip to content

fix(terminal): end a herdr-core attach's held history at hc's paint mark, not after 15 ms of quiet - #4876

Merged
devswha merged 4 commits into
mainfrom
fix/hc-attach-replay-end
Nov 27, 2026
Merged

devswha merged 4 commits into
mainfrom
fix/hc-attach-replay-end

Conversation

@devswha

@devswha devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner

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.

…ark, not after 15 ms of quiet

hc closes an attach's first paint with CSI ?9001h or l (viewers.rs first_paint, since hc 0.1.11), queued whole before any live byte. CoreAttachSession tells the paint's end there, also when a frame splits the mark, and the AttachBatch ends at it. The 150 ms deadline stays for a core that sends no mark.
@coderabbitai

coderabbitai Bot commented Nov 27, 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
    • Terminal history replay now completes when the first paint finishes, rather than after a brief pause in output.
    • Output continues to be held during pauses in the initial paint, then switches to live delivery after the paint-end marker or the maximum hold duration.

The server now holds initial herdr-core output until it detects hc’s first-paint end marker or reaches the maximum batch duration. The marker can span data frames. Tests cover the callback, held history, subsequent live output, and the deadline fallback.

Changes: First-paint history replay

Layer / File(s) Summary
Detect and expose paint completion
server/herdr-core/attach-session.ts, server/herdr-core/adapter.ts, server/herdr-core/attach-session.test.ts, server/herdr-core/live.test.ts
The attach session detects the first-paint terminator across frames and invokes onPaintEnd. Tests cover split markers and callback timing.
End held history on paint completion
server/core/attach-batch.ts, server/core/terminal-process.ts, server/core/terminals.test.ts, changelog.d/hc-attach-paint-end.md
AttachBatch no longer ends a batch after a quiet period. The terminal process ends it on onPaintEnd when the attachment is still current. Tests cover held output and the maximum-duration fallback.

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

Change: Bug fix

Possibly related PRs

  • devswha/ovis#4768: Adds the quiet-window batching behavior that this change replaces with paint-end detection.

Suggested reviewers: nocstah, yuuuxie

Merge Risk: Minimal · previous review 7a363

The change ends held attach history when the first paint finishes, instead of guessing from a 15 ms pause. No concrete merge-blocking risk was found, and a 150 ms fallback remains if the end mark never arrives.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: the herdr-core attach's held history now ends at hc's paint mark instead of after a 15 ms quiet period. The changeset matches this: attach-session.ts detects PAINT_END…
Description check Passed The description follows the template's Change and Validation sections. The Change section describes the problem (a 15 ms quiet guess ending the hold early under load), the new behavior, and the fallba…
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: the herdr-core attach's held history now ends at hc's paint mark instead of after a 15 ms quiet period. The changeset matches this: attach-session.ts detects PAINT_END and calls onPaintEnd, terminal-process.ts ends the AttachBatch there, and the quiet-period constant is removed. The title is specific and within the length guidance, though it is long.

Full details: Description check

Explanation

The description follows the template's Change and Validation sections. The Change section describes the problem (a 15 ms quiet guess ending the hold early under load), the new behavior, and the fallback. The Validation section lists the commands run, their results, and the known failing case on 0.1.22. It does not explicitly mention contract-test coverage for HTTP/WS changes, though the author states there are no contract changes. The description is thorough and mostly complete.

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 675f200 and 7a363cb.

Files selected for processing: 8

  • changelog.d/hc-attach-paint-end.md
  • server/core/attach-batch.ts
  • server/core/terminal-process.ts
  • server/core/terminals.test.ts
  • server/herdr-core/adapter.ts
  • server/herdr-core/attach-session.test.ts
  • server/herdr-core/attach-session.ts
  • server/herdr-core/live.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.

…etween sequences

The paint mark ends the held history at once, so it can now stop where a frame cut an escape sequence. A viewer's focus-in asked ASK_DISPLAY right there and broke the sequence (CSI 31m drew as text). The session follows hc's stream (escape, CSI, OSC/DCS/APC strings) and makes an ask that came mid-sequence once the sequence ends. Tests also cover the h mark and a frame cut just before its last byte.
@devswha

devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Reviews on 7a363cb: an omo gate review and a Codex (gpt-6.2-sol-fast, xhigh) adversarial review. Both blocked on the same MEDIUM; fixed in 942283d.

  • MEDIUM (both, reproduced): the paint mark ends the hold at once, so the held history can now stop where an hc frame cut an escape sequence (...9001l...ESC[ | 31mRED). A viewer's focus-in made the session ask its display query right there, and CSI 31m drew as text. Fixed: CoreAttachSession follows hc's stream (escape, CSI, OSC/DCS/APC/PM/SOS strings, CAN/SUB) and makes an ask that came mid-sequence once the sequence ends. This also closes the same cut on main, where it only needed a focus-in between two frames. New test cuts a CSI, an OSC before its ST, and an OSC between its ESC and \; it fails on 7a363cb.
  • LOW (Codex, test gap): the fixtures only covered the l mark and a cut after ESC[?90. Now one fixture uses h with the frame cut just before the last byte, and the live test checks the full mark.
  • LOW (Codex): a replacement attach whose newest rows come in a second frame now holds them until the mark or the 150 ms deadline instead of 15 ms of quiet. Kept: that is the paint being completed, which is the point of the change.
  • LOW (Codex): a core before 0.1.11 sends no mark, so an idle pane there shows after the 150 ms deadline instead of ~17 ms. Kept: Ovis installs and bundles hc 0.1.17, and the deadline is the fallback the plan asked for.

Validation on 942283d: bun run check fast all ok (unit 29085 pass, 0 fail); focused suites 244 pass; server/herdr-core/live.test.ts against real hc 0.1.17 and 0.1.18, 8 pass each.

@devswha
devswha merged commit 5898eb1 into main Nov 27, 2026
22 checks passed
@devswha
devswha deleted the fix/hc-attach-replay-end branch November 27, 2026 08:18
@devswha

devswha commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Merged through pr-merge at head 059547b9d. 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 942283d45: pr-merge --update merged it in (02c915e15), and every required check was green at this head.

CodeRabbit did not review this head (review limit). Reviews that ran: an omo gate review and a Codex adversarial review (gpt-6.2-sol-fast, xhigh) on 7a363cb; both blocked on one MEDIUM, fixed in 942283d (see the review comment). Merged on the lead session's word for the owner's plan step.

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