Skip to content

fix(window): reflow via scale factor so terminals stop re-gridding - #10485

Merged
nwparker merged 1 commit into
mainfrom
nwparker/reflow-sigwinch-fix
Jul 25, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/reflow-sigwinch-fix

Conversation

@nwparker

@nwparker nwparker commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #10473. That PR replaced the deadlock-prone frame jiggle with a +1px emulated viewport. The +1px was a real CSS-geometry change, and it re-grids terminals.

The regression

renderer-viewport-reflow.ts emulated height + 1. For a terminal whose pane height sits one pixel under an xterm row boundary, that adds a row. The pane fit observer's two-frame stability check (pane-fit-resize-observer.ts:101-138) sees the same proposed grid on two consecutive animation frames — ~16.7ms apart, comfortably inside the 32ms hold — declares it stable, and fits. performSafeFit's no-op guard (pane-fit.ts:137) doesn't help, because the grid genuinely differs. The PTY gets a real resize, and the restore reverses it.

Measured with real xterm + FitAddon + the real stability loop, sweeping window heights across a full cell height (cellH=16, 54 configs):

mechanism configs with SIGWINCH PTY resizes
height + 1 (#10473) 3/54 (5.6%) 6
old setSize jiggle 0/54 0
scale factor (this PR) 0/54 0

Concretely, at paneH=655: rows 40 → 41 → 40, two SIGWINCHes per reveal. createMainWindow.ts's 250ms second repaint doubles that on show/restore.

Worth being direct: #10473 made this worse than the code it replaced on this axis. The old jiggle changed window width, which doesn't cross row boundaries; the new one changed viewport height, which does.

The fix

Nudge deviceScaleFactor by +0.25 instead, leaving viewSize at the real content size. Layout re-runs, dvh recomputes, and the CSS box is byte-identical, so no terminal re-grids.

The delta is derived from screen.getDisplayMatching(window.getBounds()).scaleFactor rather than a constant — a hardcoded 1.25 would equal the real factor on a 1.25x display and reflow nothing. || 1 guards a display reporting 0.

Verification (real Electron 43.1.0, macOS 26.3.1)

Full 54-config sweep against the shipped logic, with the WebGL renderer (what Orca actually uses — pane-webgl-renderer.ts) and a real PTY resize listener:

  • SIGWINCH 0/54
  • reflow signal fired 54/54 (the fix still does its job)
  • DPR restored 54/54, layout correct 54/54
  • WebGL context loss: 0; canvas/atlas dimensions unchanged
  • burst of 8 → 1 resize event, still re-arms

Also fixes the third reported issue: <webview> guests sat under the same 100dvh chain and took two native resizes per reflow. No CSS geometry change means no guest resize.

Tests

Four new tests in renderer-viewport-reflow.test.ts pin the mechanism: emulated viewSize/screenSize must equal the real content size, the delta must come from the window's own display, and the 0-scale-factor fallback. Mutation-tested — restoring height + 1 fails 4 tests.

typecheck:node clean, oxlint clean, full src/main/ suite 15,003 passed | 47 skipped.

Credit

Both the maximized/fullscreen gap (fixed in #10473) and this row-boundary SIGWINCH were surfaced by adversarial review agents. My original "no SIGWINCH" check used paneH=544 — exactly on a 32px row boundary, the safe case — so it passed while the bug was real. The boundary-crossing height is what exposes it.

Limits

The stale-dvh state this reflow exists to fix still does not reproduce locally — I tried again here, manufacturing it by resizing the frame while the window was hidden, and layout was already correct on show, so invalidate() had nothing to fix and the test couldn't discriminate. Carried forward from #10473: the reflow is verified at the mechanism level (it demonstrably drives a real layout recomputation with the frame untouched), not against a reproduced stale state.

The 32ms restore still has no renderer acknowledgement, so a renderer blocked past the hold can coalesce the cycle away. That degrades to "no reflow this time," not to a wrong layout. A renderer-ack handshake is the principled fix and is not in this PR.

The +1px emulated viewport changed the CSS box, so a terminal sitting one
pixel under an xterm row boundary gained a row. The pane fit observer's
two-frame stability check reads that transient grid as stable well inside
the 32ms hold, forwards a real PTY resize, then reverses it on restore —
two SIGWINCHes per reveal, measured on 3/54 window heights (~1/cellHeight).

Nudging the device scale factor instead re-runs layout with byte-identical
CSS geometry. Same reflow, 0/54 SIGWINCH, no WebGL atlas rebuild or context
loss, and webview guests stop seeing spurious native resizes too.

Co-authored-by: Orca <[email protected]>
@nwparker
nwparker force-pushed the nwparker/reflow-sigwinch-fix branch from 8106701 to d628ebc Compare July 25, 2026 03:35
@coderabbitai

coderabbitai Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 33079b4e-da72-4aa7-badc-696adadf6c57

📥 Commits

Reviewing files that changed from the base of the PR and between 810670108d0e61ba798a47a3acc6b185eb836738 and d628ebc.

📒 Files selected for processing (3)
  • src/main/window/createMainWindow.test.ts
  • src/main/window/renderer-viewport-reflow.test.ts
  • src/main/window/renderer-viewport-reflow.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/main/window/renderer-viewport-reflow.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/renderer-viewport-reflow.test.ts

📝 Walkthrough

Walkthrough

Updates macOS viewport repaint handling to use scale-aware Electron device emulation without changing native window bounds. Adds lifecycle guards, deferred execution, coalescing, failure recovery, and bounded restoration retries. Expands tests for scale calculations, destroyed windows, retry behavior, maximized/fullscreen repainting, and resume-from-sleep flows.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change well, but it omits the template's required Summary, Screenshots, Testing checklist, AI Review Report, Security Audit, and Notes sections. Rewrite the PR description using the repository template and add the missing sections, including screenshots or 'No visual change', testing checklist, review, and security notes.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. 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 is specific and matches the main change: switching viewport reflow to a scale-factor-based approach.
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

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.

@nwparker
nwparker merged commit 4694278 into main Jul 25, 2026
1 check passed
@nwparker
nwparker deleted the nwparker/reflow-sigwinch-fix branch July 25, 2026 03:53
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…tablyai#10485)

The +1px emulated viewport changed the CSS box, so a terminal sitting one
pixel under an xterm row boundary gained a row. The pane fit observer's
two-frame stability check reads that transient grid as stable well inside
the 32ms hold, forwards a real PTY resize, then reverses it on restore —
two SIGWINCHes per reveal, measured on 3/54 window heights (~1/cellHeight).

Nudging the device scale factor instead re-runs layout with byte-identical
CSS geometry. Same reflow, 0/54 SIGWINCH, no WebGL atlas rebuild or context
loss, and webview guests stop seeing spurious native resizes too.

Co-authored-by: Orca <[email protected]>
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