Repository navigation
fix(desktop-gpui): stop the Touch Bar finder's KVO exception from crashing the app - #2699
Merged
Merged
Conversation
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
@greptileai review |
…im narrating comments
Member
Author
|
@greptileai review |
Member
Author
|
@greptileai review |
richiemcilroy
marked this pull request as ready for review
October 19, 2026 09:02
This branch was successfully deployed
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.
A user on a 2020 Intel MacBook Pro with a Touch Bar (MacBookPro16,3, macOS 15.7.9) reported that the GPUI app (
0.6.2-nightly.202610101017) crashed every time they started a recording, in every capture mode. The crash is an Objective-C exception that AppKit itself throws and then turns into a crash:On Macs with a Touch Bar, AppKit's Touch Bar finder watches the key window's responder chain with key-value observing. Starting a recording hides and closes several windows at once (main window, target overlays), and when the finder rebuilds its observation during the next display-cycle flush, removing an old observer throws "Cannot remove an observer ... because it is not registered as an observer". AppKit catches that in its CATransaction commit handler and calls
_crashOnException:. Cap never puts anything on the Touch Bar, and the exception is raised inside AppKit, so nothing in Cap's own code can catch it today.Fix
-[_NSTouchBarFinderObservation invalidate]is routed through a guard at startup (platform/macos_exception_guard.rs). The guard calls the original implementation and, if it throws, logs the exception's name and reason and returns.@try/@catchis in a small Objective-C file,native/exception_guard.m, built bybuild.rson macOS only. An Objective-C exception must not unwind through a Rust frame (Rust aborts), so the original method is called from Objective-C with no Rust frame between the throw and the catch. objc2's owncatchwould need its nightly-onlyunstable-c-unwindfeature to be safe here.Dropping a failed teardown leaves at most one stale observation in AppKit's Touch Bar bookkeeping. Modern Foundation removes observers when the observed object is deallocated, and Cap shows nothing on the Touch Bar, so nothing user-visible depends on it.
Tests
an_unbalanced_kvo_removal_throws_the_reported_exceptionreproduces the report's exception (removing a KVO observer that was never added) and checks the trampoline catches it with the same reason text.a_guarded_method_survives_the_exception_every_timeinstalls the guard on a test class whoseinvalidatethrows that exception, then calls it three times. Without the guard the test process aborts.appkit_still_has_the_touch_bar_finder_method_this_guardsfails if a macOS update renames_NSTouchBarFinderObservationorinvalidate, so the guard cannot silently stop applying.guarded the Touch Bar finder's observation teardownon macOS 27 (Apple Silicon).I could not reproduce the crash itself: this needs Touch Bar hardware. The fix does not depend on what triggers the exception, only on where AppKit throws it.


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues were found.Summary
This PR catches the Touch Bar finder's teardown exception before it can crash the app.
Reviews (4) · Last reviewed commit: "fix(desktop-gpui): count exception-guard..." · Reviewed by Greptile