Repository navigation
Conversation
accessibility-helper and transcription-helper both sit in a readLine() command loop, so a SIGKILL'd parent closes their stdin pipe and they exit on their own. hotkey-helper never reads stdin at all - CFRunLoopRun() never returns on its own - so a hard kill of the Electron parent (Force Quit, kill -9, a native crash) used to leave it running forever, still holding the Input Monitoring tap. A relaunch would then race a second tap against it on every keystroke. Now polls getppid() every 2 seconds and exits once it no longer matches the pid captured at startup - macOS reparents an orphan to launchd almost immediately, so this is a reliable signal without needing a pipe of our own. Verified the polling mechanism itself against a real kill -9 this session, isolated from the CGEventTap (which needs Input Monitoring permission this sandbox doesn't have): a standalone binary with the identical getppid()/Timer/CFRunLoopRun shape, spawned as a child and orphaned by killing its parent, detected the reparent and exited within one poll cycle. swift build is clean. Everything that needs the real tap and a real Electron parent is in docs/testing/hotkey-helper-watchdog-443.md. Claude-Session: https://claude.ai/code/session_0144sxo5CJiyk99vaR7sgjuj
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.
Closes #443.
The bug
All four resident helpers are spawned with plain
spawn(...)- nodetachedoption. Graceful termination works fine:SIGTERM/SIGINT/SIGHUProute throughapp.quit()→will-quit, which stops every helper cleanly.SIGKILL(Force Quit,kill -9, a hard native crash) can't be caught, so that path never runs - and what happens next depends on an incidental protocol difference.accessibility-helperandtranscription-helperboth runwhile let line = readLine(...), so the parent dying closes the stdin pipe's write end and they exit naturally.hotkey-helpernever reads stdin - it callsCFRunLoopRun(), which never returns on its own - so it used to survive indefinitely, still holding the Input MonitoringCGEventTap. A relaunch then spawns a second instance, racing two taps on every keystroke.The fix
Design decision from the two the issue laid out: a lightweight watchdog, per the issue's own suggested approach, rather than restructuring how Electron spawns/groups the four helpers.
hotkey-helpernow captures its parent's pid at startup and pollsgetppid()every 2 seconds on the same run loop that already drives the tap; once the pid no longer matches (macOS reparents an orphan to launchd almost immediately), it logs and exits.Tests
main.swiftis OS-glue with no existing unit coverage (same as the rest of this file -HotkeyMatcherTestscovers the pure decision logic in theHotkeyMatchertarget, not this executable).swift build --package-path native/hotkey-helperis clean.Went a step further than a bare compile check: this sandbox can't grant Input Monitoring, so the real
CGEventTappath is untestable here - but the watchdog logic itself doesn't depend on the tap. Built a standalone binary with the identicalgetppid()/Timer/CFRunLoopAddTimer/CFRunLoopRunshape, spawned it as a child of a throwaway parent,kill -9'd the parent, and confirmed it detected the reparent (ppid → 1) and exited within one poll cycle. That's real evidence the mechanism works on this OS, not just that it compiles - what's left needs the actual tap and a real Electron parent, checklist indocs/testing/hotkey-helper-watchdog-443.md.🤖 Generated with Claude Code