Repository navigation
Fix crash on appearance change - #646
Merged
Merged
Conversation
The NSApplication (PBDarkMode) category overrode observeValueForKeyPath:ofObject:change:context:, shadowing AppKit's own implementation on NSApplication. On appearance change (dark/light or Increase Contrast), AppKit delivers its internal KVO notifications to NSApp using its own contexts; the override's else branch then forwarded to super, which reached NSObject's default implementation and raised the "message received but not handled" exception, aborting the app. Observe effectiveAppearance through a dedicated token object instead, so AppKit's own implementation is left untouched and our KVO change is delivered without shadowing anything. Fix gitx#578
tagliala
marked this pull request as ready for review
September 14, 2026 22:03
Contributor
Author
|
@goneng this looks good on my machine an GPT-6 did not complain about the solution If you can do some tests, it would be better. I have no idea of what the changes are about |
Collaborator
|
@tagliala @hannesa2 LGTM, I think we can merge this. I reviewed the diff and also checked the diagnosis against the runtime rather than
Two non-blocking notes for a follow-up, neither worth holding this up:
|
goneng
approved these changes
Sep 15, 2026
goneng
left a comment
Collaborator
There was a problem hiding this comment.
LGTM. Details in my comment above.
Contributor
Author
I've attempted a review from Copilot here: but actually it wasn't able to review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Author note: This PR was drafted by an AI coding assistant ("Big Pickle") based on crash-diagnosis and a local reproduction of the failure (SIGABRT on appearance toggle, crash reports from the shipped build on macOS 27). The proposed change was verified by building and toggling Dark ↔ Light with the patched binary; however it should be reviewed with the same scrutiny as any community contribution, and I'm happy to iterate on feedback.
Fixes #578
Root cause
NSApplication (PBDarkMode)overrodeobserveValueForKeyPath:ofObject:change:context:as a category method. This shadows AppKit's own implementation of that selector onNSApplication.On macOS appearance changes (dark/light toggle or Increase Contrast), AppKit's
NSSystemAppearanceProxyfires internal KVO notifications delivered toNSAppusing AppKit's own contexts. Those deliveries landed in the category override, whoseelsebranch called[super observeValueForKeyPath:...]— which resolved toNSObject's default implementation and raised the "message received but not handled" exception, aborting the app.NSKeyValueNotifyObserverand the throwing-[NSObject(NSKeyValueObserving) observeValueForKeyPath:...], and disassembly confirms it is the removedelsebranch's[super ...]call.Fix
Observe
effectiveAppearancethrough a dedicatedPBAppearanceObserverTokenobject instead ofself. The category no longer implementsobserveValueForKeyPath:at all, so AppKit's own implementation onNSApplicationis left untouched, while our KVO change is still delivered and re-posted asPBEffectiveAppearanceChanged.Verification
~/Library/Logs/DiagnosticReports.0x43380) disassembles to the removedelsebranch's[super observeValueForKeyPath:...]call.Notes
Also corrected stale comments in
GitX-Bridging-Header.handNSAppearance+PBDarkMode.swiftthat claimed the (never-compiled) Swift twin owns the implementations.AI review
GPT-6 reviewed and approved commit
26fc6bbc0133cc3db2361109eaec624ce334f571against the linked issue #578. Source review covered the AppKit KVO method collision, observer lifetime and re-registration, notification delivery to the web views, and Xcode source membership. No actionable findings.No tests were run as part of this review, as requested. Both existing CI jobs passed for the same commit in tagliala/gitx#3. Runtime appearance-toggle verification is the author-reported verification above.