Skip to content

perf(terminal): narrow the delayed Windows foreground repair span - #25233

Closed
paoValle wants to merge 3 commits into
stablyai:mainfrom
paoValle:perf/narrow-followup-terminal-repair
Closed

paoValle wants to merge 3 commits into
stablyai:mainfrom
paoValle:perf/narrow-followup-terminal-repair

Conversation

@paoValle

@paoValle paoValle commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Author: @paolovalletta_

ELI5

When an agent redraws one line in a Windows terminal pane, Orca fixes that line straight away — then, one frame later, fixes it again but asks the terminal to redo the entire screen, even though nothing else changed. This repeats the immediate fix over just the rows that actually changed, and keeps asking for the whole screen whenever it cannot prove that is still safe.

What Changed

Before: a forced foreground repair on a native-Windows ConPTY pane computed a narrow row span, applied it immediately, then repeated the repaint on the next frame as 0..rows-1. In a 120×60 pane a one-row status rewrite therefore ended up walking 7,200 cells on the following frame instead of 120.

After: the queued repeat carries the span the immediate repair used. When the frame runs it unions in the rows parsed since the write plus the caret row, and requests that. Anything it cannot prove still applies falls back to the whole grid.

Mechanism. The delayed refreshVisibleRows call in scheduleViewportSettleRefresh passed no span, and a missing span means 0..rows-1 (pane-terminal-foreground-render-settle.ts). The span now travels with the pending refresh, and pendingRepairRowSpan re-validates it against a geometry snapshot before it is used: same buffer type, same grid height, and baseY/viewportY provably unchanged, plus a still-observable parse span. The repeat is a superset of the immediate repair by construction, because the immediate span is the union's seed.

Two details that follow from the existing code rather than from this change:

  • readParsedDirtyRowSpan returns the union of every parse since the last reset, so rows written by an intervening non-forced chunk are included; a parse that xterm answers with a whole-viewport request (undefined) yields null, so the whole grid is repainted.
  • shouldRefreshViewportSynchronously is re-resolved when the frame runs, and its producers read the attached renderer (() => !manager.hasWebglRenderer(pane.id)). A flipped value therefore means a renderer was swapped mid-frame, where only the whole viewport can be proven converged for the replacement — so the span is dropped in that case too.

Why

Issue #19622 is a bounded finding in the delayed repair after #18169: the immediate repair was already narrowed, and the remaining whole-grid request turns every in-place redraw into a full-viewport _updateModel walk one frame later. The module already documents this cost as the reason the immediate repair was narrowed at all ("xterm's render debouncer unions ranges, so a 0..rows-1 repair request turns every frame into a full-viewport cell walk"), so this finishes the narrowing the surrounding code intends rather than introducing a new strategy.

Alternatives considered:

  • Remove the delayed repair. Rejected: it exists to repaint content Chromium paints a frame late on Windows. [Bug]: Native-Windows follow-up terminal repaint expands a one-row update to the full grid #19622 states removing it is not a proposed fix, and this PR keeps its timing and its full-grid fallbacks.
  • Reuse the stored span unconditionally. Rejected: the delay crosses a frame, so another chunk, a scroll, a resize, a buffer flip or a renderer swap can land in between.
  • Add a write option so only native-Windows in-place rewrites narrow. Rejected as unnecessary API surface. The repeat never covers less than the repair it repeats, and the fallbacks already exclude everything that cannot be proven, so the general rule is the safer one to maintain.

Linked Issue

Fixes #19622

Visual Proof

N/A

No visual change is intended or expected: the same rows are repainted, one frame later, and content coverage can only grow relative to the immediate repair. The difference is how many rows Orca asks xterm to walk. Confirming pixel convergence needs the Electron visual gate (terminal-render.pixel-refresh-repair), which this machine cannot build — see Limitations.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Measurement. Deterministic operation counts on the real @xterm/headless parser, driving the production writeForegroundTerminalChunk implementation with real escape bytes. The instrument is the test file itself, so the baseline is reproducible by reversing the production file only.

120×60 pane, one-row in-place rewrite (#19622 shape) Baseline (origin/main) After
Rows the delayed repair requests 60 (0..59) 1 (55..55)
Cells requested (rows × 120 cols) 7,200 120

(−98.3% for both.)

23-shape in-place redraw corpus (real xterm parser) Baseline After
Shapes whose delayed repair widened a narrowed immediate repair back to the full grid 12 0
Coverage oracle: every changed viewport row and both caret rows inside the requested span green green
Fallbacks keeping the whole grid (scroll, resize, buffer flip, renderer swap, whole-viewport parse, disposal) full grid full grid
terminal-foreground-repair-convergence.test.ts Baseline After
Result 14 failed / 40 passed 54 passed

Baseline command:

git checkout origin/main -- src/renderer/src/lib/pane-manager/pane-terminal-foreground-render-settle.ts
node node_modules/vitest/vitest.mjs run --config config/vitest.config.ts src/renderer/src/lib/pane-manager/terminal-foreground-repair-convergence.test.ts
git checkout HEAD -- src/renderer/src/lib/pane-manager/pane-terminal-foreground-render-settle.ts

Fails with expected { start: +0, end: 59 } to deeply equal { start: 55, end: 55 } for the fixture and expected { start: +0, end: 23 } to not deeply equal { start: +0, end: 23 } for each corpus shape. The new cases extend the file's existing convergence oracle to the delayed repair; that oracle is the losslessness check (every changed row and both caret rows must be inside the requested span).

Also run, all green:

Check Command Result
Terminal pane + output manager suites vitest run --config config/vitest.config.ts src/renderer/src/lib/pane-manager/ src/renderer/src/components/terminal-pane/replay-guard.test.ts src/renderer/src/components/terminal-pane/xterm-write-buffer-stall.repro.test.ts 87 files, 990 passed, 1 skipped
Operation-count/retention contracts vitest run --config config/vitest.performance.config.ts 11 files, 78 passed
Typecheck node config/scripts/run-typecheck-projects-in-parallel.mjs exit 0 (node, cli, web)
Changed-code quality gate node config/scripts/check-changed-code-quality.mjs 0 findings
Anti-slop rules on changed files oxlint --config config/oxlint-anti-slop.json <2 files> 0 findings
File size limits .oxlintrc.json max-lines 247/300 prod, 560/800 test

Full lint (pnpm lint) constituent gates, run individually because pnpm's verify-deps-before-run refuses to run any script until the native modules compile (no MSVC on the measuring machine):

Gate Result
oxlint (repo-wide) pass
audit:anti-slop (repo-wide) pass
audit:code-quality:native, audit:code-quality:type-aware pass
check:dead-classes pass
check:max-lines-ratchet, check:ts-nocheck-ratchet, check:runtime-electron-ratchet pass
check:reliability-gates, check:readme-local-links, check:node-runtime-pin pass
verify:rpc-params-catalog, verify:bundled-skill-guides, verify:localization-coverage pass
verify:skill-bundle-manifest fails on origin/main too — see below

verify:skill-bundle-manifest reports resources/skills/{current-manifest,snapshot-registry,release-mapping}.json as stale. This is pre-existing and unrelated to this change: it reproduces identically in a pristine detached worktree of origin/main (87bc51d371) with no local modifications, and the two files in this PR are not inputs to that generator. Flagging it rather than silently excluding it.

Platforms: the tests above ran on Windows in Node. No Electron, DOM, WebGL or live-PTY validation was performed — see Limitations. Nothing was validated on macOS or Linux at runtime; the logic is platform-neutral and non-Windows reaches the changed path only through the replay producers.

AI Disclosure

Written with an AI coding agent. Session model: deepseek-v4.1-flash (provider opencode-go), with research sub-agents on the same model. All measurements in this description were produced by the commands shown above on this machine; the agent could not build Electron or run the visual gate.

Review

AI code-review summary over the full diff, per the checklist in CONTRIBUTING.md:

  • Cross-platform: the change is platform-neutral renderer logic with no process.platform or path assumptions. The only producer of followupViewportRefresh is nativeWindowsRewriteNeedsFollowupRenderRefresh (native Windows ConPTY, foreground, in-place rewrite), so macOS and Linux see no change on that path; SSH/WSL/remote panes do not set it at all (it requires executionHostId === 'local', no connection, and a non-WSL cwd). The replay producers set it on every platform, but there the repeat stays full-grid whenever the parse span is unobservable or xterm asks for a whole viewport, which is what snapshot restores do.
  • SSH / remote / local: no wire fields, RPC params, buffering or host-side execution changed; only how many rows the viewer asks xterm to repaint. SSH/WSL/remote panes do not reach the narrowed path.
  • Agent and integration compatibility: no CLI-agent, provider, or skill-facing surface changed. The paths that produce the flag are agent-agnostic (any PTY output matching an in-place rewrite on native Windows).
  • Performance risk: strictly less work per delayed repair (1 row instead of 60 in the fixture). Added cost is one geometry snapshot comparison and one dirty-span read per delayed repair, both O(1) reads, plus one small object retained per pane only until the frame fires; it is deleted on fire, cancel and discard.
  • UI quality: no layout, styling, token or component change; no components/ui/ primitive touched.
  • Security: no new input, output, IPC, filesystem, network or credential path; no new parsing of untrusted data.

Self-review of the diff specifically looked for: leaked or duplicated pending refreshes (the schedule path still cancels first, and the fire path deletes before refreshing), duplicated listeners (onRequestRefreshRows subscriptions are unchanged), cleanup on discard (covered by a new test), and the timer-cancellation path (clearTimeout unchanged, cancelAnimationFrame still guarded).

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: unchanged; no new boundary.
  • Cross-platform: platform-neutral logic; effect limited to native-Windows in-place rewrites plus replay paths, all with the previous whole-grid behavior as fallback.
  • Remote SSH / WSL / remote runtime: unaffected (the follow-up flag is not set for those panes).
  • Mobile: the module compiles into the mobile web client, but the flag is desktop-native-Windows-only, so mobile rendering behavior is unchanged.
  • Backwards compatibility: internal renderer function only, no exported API, no persisted state, no wire format.
  • Performance: row and cell counts measured above; no millisecond claim, per config/performance-audit.md.
  • Open neighbour PR: Fix frozen terminals: guard xterm write pipeline, cap unbounded output buffers, probe-certified replay-guard release #7150 also edits pane-terminal-foreground-render-settle.ts, but only in its import and writeForegroundTerminalChunk write-callback hunks (the guarded write pipeline). This change is confined to the scheduling helpers below it, so the two do not overlap semantically; whichever lands second should expect at most a trivial rebase.

Limitations

  • The numbers are rows/cells requested from xterm, measured with the real @xterm/headless parser but without the DOM or WebGL renderer. They are not painted-pixel counts and not wall-clock: [Bug]: Native-Windows follow-up terminal repaint expands a one-row update to the full grid #19622 itself notes the finding "establishes additional rendered row coverage, not a wall-clock speedup".
  • No Electron build exists on this machine (the native modules need MSVC), so terminal-render.pixel-refresh-repair (Electron visual golden) and pnpm build were not run. Pixel convergence for the narrowed repeat is argued from the coverage oracle, not observed.
  • The corpus is synthetic escape sequences covering the shapes the previous oracle already used, not recorded live agent sessions.
  • The full unit suite was not run end to end (pnpm test first runs ensure-native-runtime, which compiles native modules); the affected directory and the whole performance-contract set were run instead, plus typecheck and the changed-code gate.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass — typecheck passes and every pnpm lint gate passes except the pre-existing verify:skill-bundle-manifest failure shown above; test/build could not run locally (no MSVC); CI will cover

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Narrow the queued Windows foreground repair — the span the immediate repair used now travels with the pending next-frame refresh. pendingRepairRowSpan re-validates it against a fresh viewport snapshot (buffer type, grid rows, baseY, viewportY) and unions in the rows parsed since the write plus the current caret row, falling back to 0..rows-1 on any mismatch or a flipped sync-render path.
  • Tests — a deterministic requestAnimationFrame queue, a controllable terminal double, an extension of the existing convergence oracle over the existing CASES, the Issue #19622 one-row fixture, and explicit full-grid fallbacks for scroll, resize, buffer flip, renderer swap, whole-viewport parse, and disposal.

I traced the superset invariant: pendingRepairRowSpan seeds its union with repair.span and readParsedDirtyRowSpan only resets on forceViewportRefresh, so the delayed span is always a superset of the immediate repair (or falls back whole-grid). I also confirmed the new oracle has teeth by reverting only the production file to 87bc51d and watching the suite fail (14 failures, including { start: 0, end: 59 } vs { start: 55, end: 55 }); with the change it passes 54/54, and pane-manager/ + replay-guard.test.ts pass 988/988.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9c4d8789-6479-4e94-9ffb-e85261c5a637
📥 Commits

Reviewing files that changed from the base of the PR and between e9e88d151ff700de4541c13d29aac1b477ba10fd and 952a71b.

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. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c3d154f9-612f-434d-b9c0-d9ae582ebf96
📥 Commits

Reviewing files that changed from the base of the PR and between 748012127206f5cd22d7c5d97ef83cd74f68bcfb and e9e88d151ff700de4541c13d29aac1b477ba10fd.

📒 Files selected for processing (2)
  • src/renderer/src/lib/pane-manager/pane-terminal-foreground-render-settle.ts
  • src/renderer/src/lib/pane-manager/terminal-foreground-repair-convergence.test.ts

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


📝 Walkthrough

Walkthrough

The foreground render path now records the original repair span, viewport state, and synchronous-render choice for queued follow-up work. Before the delayed refresh, it checks for changes to buffer type, terminal size, scroll position, dirty rows, cursor row, and renderer path. It uses a narrow combined span when possible and otherwise refreshes the full viewport. Tests cover delayed repairs, fallback conditions, multiple writes, and pane discard.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to e9e88

The change narrows delayed terminal repaints when it is safe and falls back to a full refresh otherwise. No concrete merge-blocking risk was identified. Electron visual validation was not run, so a manual visual check is worthwhile.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 6fd31

The impact is limited to terminal display repair. Overlapping writes can lose part of the delayed repaint coverage, but both writes still receive immediate repairs. No expanded permissions or cross-service exposure was identified.

Retained concerns

  • Low · reliability · inferred: Pending repaint coverage is not preserved across forced-write resets and supersession. A second forced write clears shared dirty-row history; when it schedules a replacement follow-up, the earlier pending span is discarded. With stable geometry, the resulting narrow repeat can omit earlier or intervening rows that the previous whole-viewport repeat covered. This can weaken recovery from delayed rendering defects, although actual stale-display persistence was not demonstrated.
Security review details

Security Blast Radius

  • inferred — The directly affected outcome is repaint convergence within a terminal instance. The identified history-loss sequence does not demonstrate exposure of another tenant, service or data store, or an increase in authority.

Trust Boundaries and Controls

  • inferred — PTY output can influence refresh policy and row selection through the existing output pipeline. The inspected base-to-head change adds no new identity or authorization transition along that path. The ultimate origin and trustworthiness of all terminal bytes were not established.

Resilience and Maintainability Implications

  • observed — Parse-completion settling and the subsequent onParsed callback remain separately guarded, so a settling failure does not prevent the completion callback from running. Synchronous write failure retains its separate recovery callback.
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning [#19622] The change retains the delayed repair and unions its span with intervening dirty rows and the current cursor row. It falls back when the buffer, row count, scroll position, parse coverage, or… Track column geometry or equivalent reflow state in the pending repair validation, and add a regression test that verifies a column-only resize or reflow selects the full grid. Add or run automated Electron pixel-convergence validation for …
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: narrowing delayed Windows terminal foreground repair spans.
Description check ✅ Passed The description covers the required sections, links issue #19622, explains the change and rationale, reports tests and platform limits, and gives a reason for the visual-proof N/A. It also clearly sta…
Out of Scope Changes check ✅ Passed The production changes are limited to foreground repair scheduling and geometry validation. The added tests exercise dirty-row coverage, fallback behavior, and queued-repair cleanup. These changes sup…
Full details: Linked Issues check

Explanation

[#19622] The change retains the delayed repair and unions its span with intervening dirty rows and the current cursor row. It falls back when the buffer, row count, scroll position, parse coverage, or renderer path changes. However, ViewportSnapshot records rows but not cols, and pendingRepairRowSpan does not check column geometry. A column-only resize or reflow can therefore pass the current geometry checks. The issue requires a full-grid fallback when resize makes narrow correctness uncertain. The PR also reports no Electron pixel-convergence validation. The headless row-coverage tests and requested-cell counts do not establish pixel convergence, which #19622 says still needs validation.

Resolution

Track column geometry or equivalent reflow state in the pending repair validation, and add a regression test that verifies a column-only resize or reflow selects the full grid. Add or run automated Electron pixel-convergence validation for the delayed narrowed repair.

  • Autopilot · 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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b8221cf5-2500-4915-b67a-674ed230185a
📥 Commits

Reviewing files that changed from the base of the PR and between 87bc51d and 6fd313b4ef7e1cdee951672c8cfb2d5758e61aee.

📒 Files selected for processing (2)
  • src/renderer/src/lib/pane-manager/pane-terminal-foreground-render-settle.ts
  • src/renderer/src/lib/pane-manager/terminal-foreground-repair-convergence.test.ts

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This run re-reviewed only the commit added since the prior Pullfrog review (7480121, perf(terminal): keep dirtied rows across a parse-span reset).

  • Carried dirtied rows across a tracker reset — writeForegroundTerminalChunk now reads the accumulated parse span before resetParsedDirtyRows and threads it as carriedDirtySpan. A forced write that resets the shared tracker can no longer drop rows an intervening ordinary write dirtied. carryRowsIntoPendingRepair widens the already-queued repair record in place (the queued frame closes over that record), and settleForegroundRender unions the same span into any repair the write schedules itself.
  • Carry cannot narrow a fallback — it is skipped when the carried span is null or the queued repair is already whole-grid (span: null), so a scroll / resize / buffer flip / renderer-swap / unobservable-parse repair still repaints the whole viewport. Geometry is re-validated at frame time regardless.
  • Regression test — forced write queues a repair, an ordinary write dirties another row, then a later forced write resets the tracker without queueing its own repair; the pending repeat must include the intervening row. It asserts the exact widened span ({ start: 3, end: 20 }), so it would fail if the carry were removed.

Verified on 7480121: the convergence file passes 55/55 (up from 54) and pane-terminal-foreground-render-settle.test.ts passes 3/3. The added test is behavioural rather than theatre — the author's own report shows it failing without the fix. No specialist dispatch was warranted: the incremental delta is one self-contained carry helper plus its test, and the superset/fallback reasoning traces cleanly.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@paoValle

paoValle commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — both bot findings here were worth acting on, and the second one found a case I had wrongly dismissed at design time.

Analysis of the two findings

  1. "Preserve dirty rows across tracker resets" (inline comment). Valid, and demonstrable rather than theoretical: a forced write resets the shared parse-span tracker before it parses, so rows an earlier ordinary write had dirtied were dropped from a repair that was still queued. I had considered this interleaving and dismissed it on the grounds that ordinary writes are xterm's own responsibility — that reasoning breaks once a later forced write resets the tracker underneath a pending repair.

  2. "Pending repaint coverage is not preserved across … supersession" (retained concern in the review summary). Also valid, and a different case from the first: a replacement repair is built from the tracker plus its own parse, but the queued repair's own span can hold rows the tracker never saw — repairRowSpan widens the parse span with the caret rows on both sides of the write, and a caret that moved without a line update never reaches the tracker. Superseding such a repair discarded those rows.

What changed

  • 7480121272 — read the accumulated span before the reset, and carry it into the queued repair and into any repair this write schedules for itself. The carry only ever widens a repair that already had a proven span; null still means the whole viewport, which covers the carried rows anyway, so a scroll/alt-screen/unknown-span repair cannot be narrowed by it.
  • e9e88d151f — union the queued repair's own span into that carry too, so supersession cannot discard it.

One implementation detail worth recording for review: the queued frame closes over the repair record it was scheduled with, so the widened span is applied to that record in place. My first attempt replaced the queued map entry instead, which was a complete no-op — the test caught it immediately.

Results

case (requests[2] = the repeated repair) before after
forced write → ordinary write dirties another row → forced write resets without queueing { start: 10, end: 20 } (row 3 dropped) { start: 3, end: 20 }
forced write → forced write queues its own repeat, superseding it { start: 10, end: 20 } (caret row 5 dropped) { start: 5, end: 20 }

Both cases were confirmed to fail on the preceding commit with exactly those values, and pass now.

Full state after both commits: 56/56 in terminal-foreground-repair-convergence.test.ts; 992 passed / 1 skipped across src/renderer/src/lib/pane-manager/ plus the replay-guard and write-buffer-stall suites; 78/78 operation-count and retention contracts; tsc web project clean; changed-code quality gate 0 findings.

On the reproduced baseline — thank you for reverting only the production file to 87bc51d and reporting the 14 failures including { start: 0, end: 59 }. That is exactly how the numbers in the PR body were produced, so it is good to see them reproduced independently.

Still not validated: pixel convergence in Electron (terminal-render.pixel-refresh-repair) was not run — this machine has no MSVC, so no Electron build. That remains the honest gap in this PR.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

This run re-reviewed only the commit added since the prior Pullfrog review (e9e88d1, perf(terminal): carry a superseded repair's span into its replacement), reading it against the full PR.

  • Carry a superseded repair's span into its replacement — when a forced write queues its own repeat, scheduleViewportSettleRefresh cancels the previously queued repair. That repair's span can hold caret rows the parse tracker never saw. writeForegroundTerminalChunk now unions queuedRepairRowSpan(terminal) into carriedDirtySpan before the tracker reset, so the replacement repair seed (span ? unionRowSpans(span, carriedDirtySpan) : null) retains those rows instead of dropping them.
  • Still cannot narrow a fallback — the union only runs on a proven span; a null queued span or null carried span leaves the replacement whole-grid, and frame-time geometry validation is unchanged.
  • Regression test — a first forced write queues a narrow repair with a caret row outside the parse span; a second forced write supersedes it; the flushed repeat must be { start: 5, end: 20 }. I confirmed it fails ({ start: 10, end: 20 }) when only this commit's production hunk is reverted, and passes with it.

I traced the superset invariant for the new path: carriedDirtySpan seeds from repair.span as well as the parse tracker, and pendingRepairRowSpan still unions repair.span with rows parsed since and the caret. Over-coverage is safe by design — only narrowing would be a defect — and the added width is discarded whenever the frame-time type/rows/baseY/viewportY check or the synchronous path check fails. No specialist dispatch was warranted: the delta is one self-contained helper plus one union site and its test. No open Pullfrog threads to retire; the two CodeRabbit threads on the PR are already resolved.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

A native-Windows in-place rewrite repairs the rows it dirtied immediately,
then repeats the repair on the next frame as `0..rows-1`. The repeat exists
to repaint content Chromium paints a frame late, but requesting the whole
grid turns every such frame into a full-viewport cell walk (stablyai#19622):
xterm's render debouncer unions ranges, so one whole-grid request widens
the frame it merges into.

The queued repeat now carries the span the immediate repair used and, when
the frame runs, unions in the rows parsed since plus the caret row. It
falls back to the whole grid whenever that span cannot be proven to still
apply: a scroll, a resize, a buffer flip, a renderer swap, an unobservable
parse (including xterm's own whole-viewport request), or an immediate
repair that was itself whole-grid. The repeat therefore never covers less
than the repair it repeats.

Fixes stablyai#19622
Review follow-up (CodeRabbit on the first commit). A forced write resets
the shared parse-span tracker before it parses, so rows an earlier
ordinary write had dirtied were dropped from a repair that was still
queued, and the repeated repair then covered less than the whole-grid
request it replaced.

Read the accumulated span before the reset and widen the queued repair
with it, and carry it into a repair this write schedules for itself. The
carry only ever widens a repair that already had a proven span: `null`
still means the whole viewport, which covers the carried rows anyway.

The queued frame closes over the repair record it was scheduled with, so
the widened span is applied to that record in place; replacing the queued
entry would leave the frame on the old span.

The new case fails on the previous commit with
`expected { start: 10, end: 20 } to deeply equal { start: 3, end: 20 }`.
Second review follow-up on the same thread. The previous commit preserved
rows the parse tracker had accumulated, but a replacement repair is built
from the tracker plus its own parse, and a queued repair's span can hold
rows the tracker never saw: `repairRowSpan` widens the parse span with the
caret rows on both sides of the write, and a caret that moved without a
line update never reaches the tracker. Superseding such a repair dropped
those rows.

The carry now unions the queued repair's own span with the tracker's, so
whichever repair ends up running still owes the same rows. A `null` span
is untouched and still means the whole viewport.

The new case fails on the previous commit with
`expected { start: 10, end: 20 } to deeply equal { start: 5, end: 20 }`.
@paoValle
paoValle force-pushed the perf/narrow-followup-terminal-repair branch from e9e88d1 to 952a71b Compare October 5, 2026 07:30
@paoValle

paoValle commented Oct 5, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (63 commits) and re-verified on macOS / Node 24: pnpm tc (node + cli + web) exit 0 and terminal-foreground-repair-convergence.test.ts 56 passed. No open findings from either reviewer; the CodeRabbit thread from the first review is resolved and the two follow-up commits answer it.

Nothing else changed beyond the rebase. Ready for review whenever there is a slot — @nwparker.

@paoValle

Copy link
Copy Markdown
Contributor Author

Closing to keep my queue honest: the repository merges within about a day and this has sat six with no review, so it is not being picked up. #19622 stays open for anyone who wants to take it, and the branch stays in my fork.

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.

[Bug]: Native-Windows follow-up terminal repaint expands a one-row update to the full grid

1 participant