Skip to content

Prevent KeyEventMonitor launch crash - #256

Draft
danman231 wants to merge 1 commit into
kitlangton:mainfrom
danman231:agent/fix-key-event-monitor-launch-crash
Draft

danman231 wants to merge 1 commit into
kitlangton:mainfrom
danman231:agent/fix-key-event-monitor-launch-crash

Conversation

@danman231

Copy link
Copy Markdown

Summary

  • prevent Hex from synchronously re-entering its KeyEventMonitor queue when Input Monitoring is denied or reported stale
  • protect the event-proven Input Monitoring flag with a dedicated lock
  • add deterministic denied-permission regression coverage and a patch changeset

Root cause

handleInputEvent registers its first handler inside a barrier block on com.kitlangton.Hex.KeyEventMonitor and calls startMonitoring. When IOHIDCheckAccess reports denied, currentInputMonitoringTrust() synchronously dispatched back onto that same queue. Libdispatch terminates the app with SIGTRAP instead of allowing the self-sync.

The permission-proof flag now uses its own lock, so callers can safely read it from either inside or outside the state queue while preserving the stale-TCC recovery introduced for #250.

Validation

  • regression test reproduced the original BUG IN CLIENT OF LIBDISPATCH: dispatch_sync called on queue already owned by current thread failure before the fix
  • full Xcode test suite passes, including KeyEventMonitorClientTests
  • HexCore test suite passes: 67 tests
  • optimized Release build succeeds
  • fixed Release app remained alive through a 15-second launch smoke test and generated no crash report

Fixes #254

Avoid synchronously re-entering the KeyEventMonitor state queue when Input Monitoring is denied or reported stale. Protect the event-proven permission flag with a dedicated unfair lock and inject permission checks so the denied state has deterministic regression coverage.

Fixes kitlangton#254
@coderabbitai

coderabbitai Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a7139710-ba83-484f-8198-4fceae301bb3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Crash on launch (0.8.3): dispatch_sync on own KeyEventMonitor queue — macOS 26.5.1, M1

1 participant