Skip to content

fix: guard GhosttyNSView screen observers against stale delivery (mechanism 2, part 2) - #259

Merged
arzafran merged 1 commit into
mainfrom
fix/ghostty-nsview-observer-guard
Aug 5, 2026
Merged

fix: guard GhosttyNSView screen observers against stale delivery (mechanism 2, part 2)#259
arzafran merged 1 commit into
mainfrom
fix/ghostty-nsview-observer-guard

Conversation

@arzafran

@arzafran arzafran commented Aug 5, 2026

Copy link
Copy Markdown
Member

What this does

Completes the stale-notification hardening from #258. Gate forensics on the re-land found the residual crasher: 5/6 new minidumps byte-identical to the mechanism-2 signature, and the only unguarded sibling of the fixed pattern is GhosttyNSView's windowObserver/screenParametersObserver — same queue:.main registration, re-registered on every viewDidMoveToWindow, no generation guard. The evidence pins it precisely: one fault address decodes to ASCII 'New Term' (window-title memory), and the handler's notification.object as? NSWindow downcast requires exactly the objc_retain-of-freed-object that is frame 0 in four dumps.

Ports the identical generation-guard pattern from GhosttySurfaceScrollView (#258): generation captured at registration, bumped on teardown/re-registration and deinit, checked before anything else in both closures — before the downcast that crashes.

Test plan

…istration

Ports the #258 stale-notification generation guard to GhosttyNSView's
windowObserver/screenParametersObserver, the one sibling that didn't get it.
removeObserver does not cancel a block already handed to the main queue, so a
block enqueued against a torn-down registration batch could still fire after
viewDidMoveToWindow re-registered for a new window — reaching the
notification.object as? NSWindow downcast against freed state. Forensic
match: 5/6 reland-gate minidumps traced to this exact mechanism.

windowObserverGeneration bumps on teardown (viewDidMoveToWindow) and deinit;
each closure captures its generation at registration and no-ops before doing
any work if the instance has since moved on.
@arzafran
arzafran merged commit ae4e105 into main Aug 5, 2026
10 checks passed
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