Skip to content

fix(window): defer the repaint size nudge and skip it on macOS 26 - #10253

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/macos26-repaint-jiggle
Jul 24, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/macos26-repaint-jiggle

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A macOS 26.5.1 user hit a permanent main-thread deadlock (kernel-confirmed via spindump: unresponsive 1305+s) inside AppKit/FrontBoardServices scene-update handling: a window-frame update delivered from the window server re-entered frame code, sent a scene update back with performAsyncAndWait on the FrontBoard callout queue the main thread was already draining, and waited on itself forever. The deadlock stack is entirely Apple frames, but it requires re-entrant frame updates — and our show/restore repaint jiggle calls setSize synchronously inside AppKit's window-state dispatch, which is exactly that re-entrant shape. The jiggle also fires up to 4 frame updates per visibility transition since #9395 doubled it.

macOS 26 (Tahoe) windows are scene-backed; this machinery does not exist pre-26.

Fix

  • Defer the size nudge to a fresh event-loop turn so it never runs inside show/restore dispatch (applies to all macOS versions; frame mutation from inside a windowing callback is never safe).
  • Skip the nudge entirely on Darwin 25+ (macOS 26) and rely on webContents.invalidate() alone. The nudge exists to work around a pre-Tahoe black-surface compositor bug; on Tahoe it is unneeded risk. New macos-tahoe-release.ts holds the version gate.

Behavior is unchanged pre-Tahoe apart from the one-turn deferral (revert still lands 32ms later; the terminal SIGWINCH pattern is identical).

Testing

  • Updated the visibility-repaint test to assert the nudge never runs inside the show/restore dispatch and still completes after timers advance.
  • New test: on Tahoe, both immediate and delayed repaints invalidate without any setSize.
  • New unit tests for the Darwin-version gate (25+, older, unparseable).
  • vitest (77 tests), oxlint, typecheck:node all green.

ELI5

When the Orca window comes back on screen (un-minimize, reopen), macOS sometimes forgets to repaint it, leaving it black. Our workaround was to "wiggle" the window — make it 1px wider, then put it back — which forces a repaint. The problem: we did the wiggle at the exact moment macOS was in the middle of its own window bookkeeping, and on macOS 26 interrupting that bookkeeping can freeze the entire app forever (that's the deadlock a user hit). This PR waits until macOS finishes its bookkeeping before wiggling, and on macOS 26 it doesn't wiggle at all — it just asks the window to repaint directly, because the wiggle is dangerous there and the bug it worked around is a pre-macOS-26 bug.

Trade-offs

  • The nudge is skipped on Tahoe without proof the black-surface bug is gone there. If macOS 26 still has the compositor bug, Tahoe users could see a black window after restore that invalidate() alone doesn't fix. Accepted deliberately: a black flash is recoverable; the deadlock is not. If reports come in, the follow-up is a Tahoe-safe repaint path, not restoring the nudge.
  • The nudge now lands one event-loop turn later on pre-Tahoe macOS, so black-surface recovery is delayed by ~one tick (imperceptible), in exchange for never mutating the frame inside AppKit's dispatch.
  • The nudge is kept (deferred) pre-Tahoe rather than deleted everywhere, because its need there is proven and the deadlock machinery doesn't exist pre-26.
  • OS gate reads the Darwin major version only (25+ = macOS 26) — no build/minor granularity. If Apple fixes the deadlock in a later 26.x, we still skip the nudge there; that stays correct since it's unneeded on 26 anyway.

The show/restore repaint jiggle mutated the window frame synchronously
inside AppKit's window-state dispatch. On macOS 26 (Tahoe), windows are
scene-backed and a frame update sent re-entrantly from scene-update
handling can self-deadlock the main thread in FrontBoardServices
(kernel-confirmed spindump: performAsyncAndWait on the callout queue the
main thread was draining).

- Defer the setSize nudge to a fresh event-loop turn so it never runs
  inside the show/restore dispatch.
- On Darwin 25+ (macOS 26) skip the nudge entirely and rely on
  webContents.invalidate(); the nudge works around a pre-Tahoe
  black-surface compositor bug.
@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Darwin release helper that identifies macOS Tahoe or newer from Darwin major versions. Updates forceRepaint() to skip the window size nudge on those systems while retaining existing repaint invalidation behavior elsewhere. Extends tests with mocked version detection, revised timing assertions, Tahoe-specific repaint coverage, and helper classification cases.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is detailed, but it misses required template sections like Summary, Screenshots, AI Review Report, Security Audit, and Notes. Rewrite the PR description to match the template: add Summary, Screenshots, AI Review Report, Security Audit, and Notes sections, and keep Testing complete.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly summarizes the main window repaint change and the macOS 26 exception.
✨ 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.

@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: Pro Plus

Run ID: 7c4fb293-2480-4448-b4b2-078572dfa3a0

📥 Commits

Reviewing files that changed from the base of the PR and between 87c59dd and 10a87ef.

📒 Files selected for processing (4)
  • src/main/window/createMainWindow.test.ts
  • src/main/window/createMainWindow.ts
  • src/main/window/macos-tahoe-release.test.ts
  • src/main/window/macos-tahoe-release.ts

Comment on lines +6 to +7
const major = Number.parseInt(darwinRelease, 10)
return Number.isFinite(major) && major >= 25

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does JavaScript Number.parseInt('25-invalid', 10) return 25, and does it accept trailing invalid characters?

💡 Result:

Yes, Number.parseInt('25-invalid', 10) returns 25 [1][2]. The function operates by parsing the string from left to right [3][4]. When it encounters a character that is not a valid numeral for the specified radix (in this case, base 10), it stops parsing, ignores that character and all subsequent characters, and returns the integer value parsed up to that point [5][3][6]. Because the sequence "25" is valid in base 10 and the hyphen ("-") is not a valid numeral, the function successfully parses "25" and discards "-invalid" [5][3][4]. This behavior confirms that JavaScript's parseInt (and by extension, Number.parseInt) accepts and ignores trailing invalid characters [7][6].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Files:"
git ls-files | rg '(^|/)macos-tahoe-release(\.test)?\.ts$' || true

echo
echo "Source outline:"
for f in $(git ls-files 'src/main/window/macos-tahoe-release.ts' 'src/main/window/macos-tahoe-release.test.ts'); do
  echo "--- $f ---"
  wc -l "$f"
  cat -n "$f"
done

echo
echo "JS parseInt semantics for relevant inputs:"
node - <<'JS'
const inputs = ['', 'unknown', '25-invalid', '25.0.bad', '25', '25.0', '26.1', '24', 'foo25', '25invalid']
for (const s of inputs) {
  const major = Number.parseInt(s, 10)
  const current = Number.isFinite(major) && major >= 25
  console.log(JSON.stringify(s), { major, current })
}
JS

Repository: stablyai/orca

Length of output: 2097


Reject partially numeric release strings.

Number.parseInt('25-invalid', 10) returns 25, so malformed inputs like 25-invalid or 25.0.bad are classified as Tahoe while still falling through to pre-Tahoe for non-numeric releases.

  • src/main/window/macos-tahoe-release.ts#L6-L7: validate the complete release format before comparing the major version.
  • src/main/window/macos-tahoe-release.test.ts#L15-18: add false expectations for 25-invalid and 25.0.bad.
Proposed fix
-  const major = Number.parseInt(darwinRelease, 10)
-  return Number.isFinite(major) && major >= 25
+  const match = /^(\d+)(?:\.\d+)*$/.exec(darwinRelease)
+  return match !== null && Number(match[1]) >= 25
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const major = Number.parseInt(darwinRelease, 10)
return Number.isFinite(major) && major >= 25
const match = /^(\d+)(?:\.\d+)*$/.exec(darwinRelease)
return match !== null && Number(match[1]) >= 25
📍 Affects 2 files
  • src/main/window/macos-tahoe-release.ts#L6-L7 (this comment)
  • src/main/window/macos-tahoe-release.test.ts#L15-L18

@brennanb2025
brennanb2025 merged commit 4569a4f into main Jul 24, 2026
2 checks passed
nwparker added a commit that referenced this pull request Jul 25, 2026
…e the reveal reflow (#10473)

* fix(window): restore the macOS 26 reflow without touching the native frame

#10253 stopped the main-thread deadlock by skipping the repaint size nudge on
macOS 26, but invalidate() repaints without reflowing, so the h-dvh root kept a
stale viewport height and the status bar stayed clipped off-screen (STA-2383) on
every Tahoe reveal, restore and wake.

Drive the reflow through device emulation instead: a +1px emulated viewport,
reverted a frame later, makes the renderer recompute layout without any NSWindow
mutation, so the FrontBoardServices re-entrancy that wedged the main thread for
109 minutes is still never triggered.

Verified against real Electron 43.1.0 on macOS 26.3.1 (Darwin 25.3.0): the
renderer sees the resize and relayouts, the native frame is untouched, the
viewport and devicePixelRatio restore exactly across zoom levels, overlapping
calls collapse to one cycle, and a 1px delta never crosses a terminal cell
boundary so no pane reports new geometry (no SIGWINCH to running shells).

Also close two gaps in the surrounding code:
- the pre-Tahoe size jiggle now clears its WeakSet latch in a finally block, so a
  throwing setSize can no longer suppress every later repaint for that window
- cover powerMonitor 'resume' under the Tahoe guard, the other AppKit dispatch
  context implicated in the freeze

* fix(tray): keep NSStatusItem scene updates off the AppKit callout stack

The main-window repaint was only one of the two doors into the macOS 26
FrontBoardServices deadlock. Showing or restoring the window calls
setTrayAttention(false) straight from the window event handler, and
tray.setImage/setToolTip drive an NSStatusItem scene update — the same
re-entrant scene mutation from inside AppKit's own dispatch, matching the
stackshot in openai/codex#23695.

Defer the native mutation to a fresh event-loop turn so the callout frame is
vacated first. The attention flag itself still flips synchronously: rapid
show/hide would otherwise mis-dedupe against a value that had not landed yet.

Bursts collapse to a single repaint, and because the deferred pass reads current
module state rather than a captured value, a coalesced schedule can never apply
a stale icon. applyTrayImage already no-ops on a destroyed tray, so a repaint
still queued when the tray goes away is harmless.

* fix(window): reflow maximized and fullscreen windows on macOS 26 too

The maximized/fullscreen bail-out predates the Tahoe path and exists only to
keep the size nudge from resizing a window out of those states. Emulation never
touches the frame, so that guard was suppressing the reflow for no reason — and
a maximized window strands its dvh layout exactly like a normal one.

Run the Tahoe branch before the guard. Verified on macOS 26.3.1 that the
emulated viewport reflows a maximized and a fullscreen window while leaving both
states intact.

* fix(window): retry the viewport restore instead of stranding the renderer

If disableDeviceEmulation threw while the webContents was still alive, the
previous code swallowed the error and cleared the latch anyway, leaving the
renderer pinned at the emulated 1px-taller viewport for the rest of the window's
life — and letting the next reveal stack a fresh cycle on top of it.

Retry the restore on a bounded schedule and hold the latch while a retry is
pending. A destroyed webContents still short-circuits, since the emulated
viewport dies with it, and the attempt budget keeps a permanently failing
restore from pinning the latch forever.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ablyai#10253)

The show/restore repaint jiggle mutated the window frame synchronously
inside AppKit's window-state dispatch. On macOS 26 (Tahoe), windows are
scene-backed and a frame update sent re-entrantly from scene-update
handling can self-deadlock the main thread in FrontBoardServices
(kernel-confirmed spindump: performAsyncAndWait on the callout queue the
main thread was draining).

- Defer the setSize nudge to a fresh event-loop turn so it never runs
  inside the show/restore dispatch.
- On Darwin 25+ (macOS 26) skip the nudge entirely and rely on
  webContents.invalidate(); the nudge works around a pre-Tahoe
  black-surface compositor bug.
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…e the reveal reflow (stablyai#10473)

* fix(window): restore the macOS 26 reflow without touching the native frame

stablyai#10253 stopped the main-thread deadlock by skipping the repaint size nudge on
macOS 26, but invalidate() repaints without reflowing, so the h-dvh root kept a
stale viewport height and the status bar stayed clipped off-screen (STA-2383) on
every Tahoe reveal, restore and wake.

Drive the reflow through device emulation instead: a +1px emulated viewport,
reverted a frame later, makes the renderer recompute layout without any NSWindow
mutation, so the FrontBoardServices re-entrancy that wedged the main thread for
109 minutes is still never triggered.

Verified against real Electron 43.1.0 on macOS 26.3.1 (Darwin 25.3.0): the
renderer sees the resize and relayouts, the native frame is untouched, the
viewport and devicePixelRatio restore exactly across zoom levels, overlapping
calls collapse to one cycle, and a 1px delta never crosses a terminal cell
boundary so no pane reports new geometry (no SIGWINCH to running shells).

Also close two gaps in the surrounding code:
- the pre-Tahoe size jiggle now clears its WeakSet latch in a finally block, so a
  throwing setSize can no longer suppress every later repaint for that window
- cover powerMonitor 'resume' under the Tahoe guard, the other AppKit dispatch
  context implicated in the freeze

* fix(tray): keep NSStatusItem scene updates off the AppKit callout stack

The main-window repaint was only one of the two doors into the macOS 26
FrontBoardServices deadlock. Showing or restoring the window calls
setTrayAttention(false) straight from the window event handler, and
tray.setImage/setToolTip drive an NSStatusItem scene update — the same
re-entrant scene mutation from inside AppKit's own dispatch, matching the
stackshot in openai/codex#23695.

Defer the native mutation to a fresh event-loop turn so the callout frame is
vacated first. The attention flag itself still flips synchronously: rapid
show/hide would otherwise mis-dedupe against a value that had not landed yet.

Bursts collapse to a single repaint, and because the deferred pass reads current
module state rather than a captured value, a coalesced schedule can never apply
a stale icon. applyTrayImage already no-ops on a destroyed tray, so a repaint
still queued when the tray goes away is harmless.

* fix(window): reflow maximized and fullscreen windows on macOS 26 too

The maximized/fullscreen bail-out predates the Tahoe path and exists only to
keep the size nudge from resizing a window out of those states. Emulation never
touches the frame, so that guard was suppressing the reflow for no reason — and
a maximized window strands its dvh layout exactly like a normal one.

Run the Tahoe branch before the guard. Verified on macOS 26.3.1 that the
emulated viewport reflows a maximized and a fullscreen window while leaving both
states intact.

* fix(window): retry the viewport restore instead of stranding the renderer

If disableDeviceEmulation threw while the webContents was still alive, the
previous code swallowed the error and cleared the latch anyway, leaving the
renderer pinned at the emulated 1px-taller viewport for the rest of the window's
life — and letting the next reveal stack a fresh cycle on top of it.

Retry the restore on a bounded schedule and hold the latch while a retry is
pending. A destroyed webContents still short-circuits, since the emulated
viewport dies with it, and the attempt budget keeps a permanently failing
restore from pinning the latch forever.
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