Avoid deferred tab-hint lookups of a deallocating window
A deferred tab-bar window lookup can read NSView.window during window deallocation. Storing that value in the shortcut-hint monitor's weak reference aborts the app. This surfaced in cmux PR #14536, shard 2.
Track the window weakly when AppKit attaches the view, and use that tracked reference for deferred callbacks. A window being torn down now resolves to nil.
Validation: swift test --filter TabBarHostWindowLifetimeTests reproduces the same weak-reference abort at eaea51d, then passes at de8e3d2. The hidden-window test drains pending work during deallocation; it does not rely on repeatedly running the app until it crashes. The full package suite passes: 230 XCTest cases and 50 Swift Testing cases. No user-facing strings changed.
— MoonlitBadger pending
run: run_9383_20260925T110137Z
session: dddc2e7e-7af7-4f2f-b6ea-643036b3193e
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.
Summary by cubic
Fixes a crash where a deferred tab-hint lookup read NSView.window while its window was deallocating, aborting the app when the value was stored in the shortcut-hint monitor's weak reference.
- Captures the window weakly in
viewDidMoveToWindowand resolves deferred callbacks through it, so a torn-down window now resolves to nil. - Adds a
TabBarHostWindowLifetimeTestssuite that reproduces the window-deallocation abort and passes with the fix.
Summary by CodeRabbit
- Bug Fixes
- Improved tab bar handling as its host window is attached or updated, including during window teardown. This helps prevent window-lifetime issues when views are being laid out while a window is released.