Skip to content

macOS: intermittent NSRangeException from _NSTouchBarFinderObservation removing a nextResponder observer #3192

Description

@h-rica

An application built on gpui-kit intermittently aborts on macOS with an uncaught AppKit exception raised by the Touch Bar finder. No application frames are involved: the throw happens inside AppKit during a display-cycle flush on the main run loop.

Environment

  • gpui-kit git revision 86f9c0fb5907549d9a5b0aff53b4b6865933a8e8 (GPUI gpui-pre =0.3.6)
  • MacBookPro17,1 (M1, with Touch Bar), macOS 26.6.2
  • Window opened with gpui_kit::open_window and TitleBar::window_options(), a TitleBar in the view, default key bindings and an app menu

Exception

*** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <_NSTouchBarFinderObservation 0x…> for the key path "nextResponder" from <NSView 0x…> because it is not registered as an observer.'

Top of the exception backtrace:

Foundation  -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:]
Foundation  -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:]
Foundation  -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:]
AppKit      -[_NSTouchBarFinderObservation invalidate]
AppKit      ___NSTouchBarFinderSetNeedsUpdateOnMain_block_invoke_2
AppKit      NSDisplayCycleObserverInvoke
AppKit      NSDisplayCycleFlush
QuartzCore  CA::Transaction::run_commit_handlers(CATransactionPhase)
QuartzCore  CA::Transaction::commit()
...
AppKit      -[NSApplication run]
<app>       gpui_macos::platform::MacPlatform::run

Reproduction

Rare and timing dependent. It occurred:

  1. once during normal use of the app, about four minutes after launch, while focus was moving between two instances of the same app;
  2. once in a single instance while programmatically switching the frontmost app between it and Finder (Accessibility AXFrontmost), within the first 25 switches.

A further ~320 switches did not reproduce it, neither in the app nor in a minimal gpui_kit::open_window window, so I cannot yet say whether anything specific to the app raises the rate.

Possibly related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions