Skip to content

fix: speed up alternate-screen history reads - #2426

Open
ogulcancelik wants to merge 1 commit into
masterfrom
fix/fast-alt-screen-read
Open

fix: speed up alternate-screen history reads#2426
ogulcancelik wants to merge 1 commit into
masterfrom
fix/fast-alt-screen-read

Conversation

@ogulcancelik

Copy link
Copy Markdown
Collaborator

Summary

  • advance alternate-screen history traversal from parsed PTY output instead of paying a fixed 120ms delay after every wheel batch
  • coalesce fragmented redraws, honor synchronized-output boundaries, and keep traversal/restore deadlines bounded
  • preserve conservative wheel batches across Pi, Claude Code, and OpenCode while restoring the original viewport

Validation

  • just check
  • Pi/Luna, 500 rows: 4.42s → 2.73s with contiguous output
  • Claude Haiku, 300 rows: 0.57s across five repeated reads with contiguous output
  • OpenCode, 300 rows: 0.63s across five repeated reads with contiguous output

refs #2387

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ogulcancelik, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 21 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d24c91c3-22b1-402b-aa02-ae41804228ab

📥 Commits

Reviewing files that changed from the base of the PR and between 3825c0c and 39e52d8.

📒 Files selected for processing (4)
  • src/pane.rs
  • src/server/alt_screen_read.rs
  • src/server/headless.rs
  • src/terminal/runtime.rs
📝 Walkthrough

Walkthrough

The change adds PTY content-sequence tracking, sequence-stable terminal snapshots, and deadline-based alternate-screen traversal. Alternate-screen reads now coordinate output quiet periods, synchronized redraws, harvesting, and restoration with expanded test coverage.

Changes

Alternate-screen read synchronization

Layer / File(s) Summary
Track PTY content updates
src/pane.rs
PaneRuntime tracks content updates around PTY processing. Runtime construction and test fixtures initialize the counter.
Capture stable snapshots
src/terminal/runtime.rs, src/server/headless.rs
TerminalRuntime returns snapshots only when the content sequence is even and unchanged. Headless read specifications propagate the sequence.
Coordinate traversal and restoration
src/server/alt_screen_read.rs
Pending reads use quiet periods, redraw tracking, synchronized output handling, per-step deadlines, and sequence-validated snapshots. Tests cover traversal deadlines, redraw coalescing, harvesting, and restoration retries.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PTY
  participant PaneRuntime
  participant TerminalRuntime
  participant PendingAltScreenRead
  PTY->>PaneRuntime: process terminal bytes
  PaneRuntime-->>TerminalRuntime: expose content_seq
  TerminalRuntime-->>PendingAltScreenRead: return stable snapshot and sequence
  PendingAltScreenRead->>PendingAltScreenRead: track output and deadlines
  PendingAltScreenRead->>PTY: issue traversal or restore step
  PTY-->>PendingAltScreenRead: produce redraw output
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improving the speed of alternate-screen history reads.
Description check ✅ Passed The description directly explains the traversal, redraw, deadline, viewport, and validation changes in the pull request.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fast-alt-screen-read

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

@kangal-bot kangal-bot added the ai-review Trigger automated AI reviews for pull requests admitted by the PR gate label Aug 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b0ac5f89-a3cc-426c-8452-6fd3cda3dc97

📥 Commits

Reviewing files that changed from the base of the PR and between 3825c0c and 660e2e2.

📒 Files selected for processing (4)
  • src/pane.rs
  • src/server/alt_screen_read.rs
  • src/server/headless.rs
  • src/terminal/runtime.rs

Comment thread src/server/alt_screen_read.rs
@ogulcancelik
ogulcancelik force-pushed the fix/fast-alt-screen-read branch from 660e2e2 to 852c33d Compare August 6, 2026 14:48
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026

Copy link
Copy Markdown

Greptile Summary

The PR replaces fixed alternate-screen polling delays with PTY-output-driven traversal while preserving bounded traversal and viewport restoration.

  • Adds an atomic content sequence around PTY processing so snapshots can detect concurrent updates.
  • Coalesces fragmented redraws and observes synchronized-output boundaries.
  • Adds traversal, restoration, redraw, and timeout regression tests.
  • Passes the initial snapshot sequence from the headless server into each pending read.

Confidence Score: 4/5

The PR should not merge until the outstanding alternate-screen deadline bug is fixed because delayed output can make the headless event loop busy-poll.

Delayed PTY output can establish a quiet window while the separate wheel-step deadline is already expired, and the pending read's deadline feeds the single-threaded headless timer loop directly, leaving the previously reported busy-poll path unresolved.

Files Needing Attention: src/server/alt_screen_read.rs, src/server/headless.rs

Important Files Changed

Filename Overview
src/server/alt_screen_read.rs Reworks traversal into output-driven, deadline-bounded phases and adds extensive tests; the previously reported deadline-scheduling issue remains outstanding.
src/pane.rs Adds an atomic sequence counter bracketing terminal processing for stable snapshot detection.
src/terminal/runtime.rs Adds a bounded retry helper that returns a snapshot only when the content sequence remains stable.
src/server/headless.rs Captures the initial snapshot sequence, supplies it to pending reads, and schedules their reported deadlines in the main loop.

Sequence Diagram

sequenceDiagram
  participant API as Pane read request
  participant H as Headless server loop
  participant R as PendingAltScreenRead
  participant T as TerminalRuntime
  participant P as PTY application

  API->>H: request alternate-screen history
  H->>T: snapshot_with_seq()
  H->>R: start(snapshot, content_seq)
  R->>T: send wheel batch
  P-->>T: process PTY redraw bytes
  T->>T: increment content_seq before/after parsing
  H->>R: poll(now)
  R->>T: read content_seq and stable snapshot
  alt synchronized output active
    R-->>H: wait for frame boundary
  else output still fragmented
    R-->>H: wait for quiet deadline
  else stable redraw
    R->>R: merge history or restore viewport
  end
Loading

Reviews (2): Last reviewed commit: "fix: speed up alternate-screen history r..." | Re-trigger Greptile

Comment thread src/server/alt_screen_read.rs
@ogulcancelik
ogulcancelik force-pushed the fix/fast-alt-screen-read branch from 852c33d to 39e52d8 Compare August 6, 2026 14:56
@ogulcancelik

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 6, 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.

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

Labels

ai-review Trigger automated AI reviews for pull requests admitted by the PR gate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants