Skip to content

fix(app): an AppKit exception no longer aborts the app - #1066

Merged
dspv merged 1 commit into
masterfrom
fix/app-panic-unwind
Nov 24, 2026
Merged

dspv merged 1 commit into
masterfrom
fix/app-panic-unwind

Conversation

@dspv

@dspv dspv commented Nov 24, 2026

Copy link
Copy Markdown
Owner

The desktop app aborted about once a week with "panic in a function that cannot unwind" and nothing else in app.log (2026-10-31, 11-06, 11-23, 11-24).

Cause: not a Rust panic. AppKit raised an Objective-C exception (on 11-24 an assertion in NSCampoLightweightUIController during an external display reconfiguration) inside tao's sendEvent: override, an extern "C" frame. The unwind hit that frame and aborted the app; AppKit would otherwise have logged it and carried on. Confirmed by disassembling the 0.195.0 binary at the crash offset and by a scratch reproduction.

Fix:

  • tao patch: both sendEvent: overrides pass the event on inside objc2::exception::catch; a caught exception is logged and the event dropped. Guarded by a test so a tao update cannot lose it.
  • Release profile panic = "unwind" (required for the catch; arm64 binary 7.0 → 9.2 MB).
  • applog: every panic logged with message, location, thread and image+offset frames; a fatal abort names the last Objective-C exception; guard() wraps menu, tray, dock, window, navigation, popover and notification callbacks.
  • Docs: .ai/21-app.md "An exception in AppKit".

cargo fmt, clippy -D warnings, 193 cargo tests pass; release build compiles. Not launched locally by design.

…anic in full

The Mac app aborted about once a week with only "panic in a function that
cannot unwind" in app.log. There was no first panic: an NSException that
AppKit raised while handling an event (the 2026-11-24 system log shows an
NSCampoLightweightUIController assertion during a display reconfiguration)
unwound into tao's extern "C" TaoApp sendEvent: override, whose
abort-on-unwind landing pad is the app frame the crash report shows right
under -[NSApplication _handleEvent:].

- patched tao: both sendEvent: overrides hand the event on inside
  objc2::exception::catch and log the exception with its stack; the event
  is dropped, as AppKit's own run loop would.
- release profile: panic = "unwind" (under abort neither objc2's catch nor
  catch_unwind can catch anything).
- applog: the panic hook writes the thread and a backtrace (image +offset
  frames on macOS, the binary is stripped); an exception preprocessor keeps
  the last Objective-C exception and the hook names it under a cannot-unwind
  abort; a logger writes tao's caught exceptions; guard() keeps menu, tray,
  window, page-load, navigation, notification and click-monitor callbacks
  from ending the app on a panic.

Co-Authored-By: Claude <noreply@anthropic.com>
@dspv
dspv merged commit 40edce9 into master Nov 24, 2026
18 checks passed
@dspv
dspv deleted the fix/app-panic-unwind branch November 24, 2026 22:12
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