macOS: what "Quit" does, and which first-run prompts YazSes raises¶
Evidence note for #578 (a daemon survived "Quit") and #562 (a fresh .dmg install on macOS 26.6.2 shows no permission prompt). Written from the code and the reporter's daemon.log; nobody on this project has a Mac, so every statement about what macOS does is marked. Status labels: READ = seen in this repository's source or in the reporter's pasted log; DOC = from Apple documentation as recalled, not re-fetched here; UNVERIFIED = needs a real Mac.
1. The process model (READ)¶
| Piece | What starts it | Notes |
|---|---|---|
| Tray (menu-bar icon) | Double-clicking the .app runs the bundle with its default mode, --tray (packaging/macos/yazses.spec). | Holds tray.lock. |
| Daemon | The tray spawns it with start_new_session if lifecycle.is_running() is false; the launchd login item (com.yazses.daemon) also runs it. | Holds daemon.lock; blocks in CFRunLoopRun inside MacosHotkey.run. |
| Second tray | The daemon launches its own tray and a supervisor thread that relaunches it every 20 s if tray.lock is free. | When the user's tray already holds the lock the daemon's tray logs "A YazSes tray is already running; exiting." This is benign duplicate suppression, not an error. |
launchd (render_launch_agent): RunAtLoad true, KeepAlive is {Crashed: true} only. By the plist's own semantics a clean exit after SIGTERM or an IPC shutdown is not restarted (UNVERIFIED on a Mac; DOC for KeepAlive). So the launchd agent is not the reason a daemon survived Quit. Nothing was changed in the plist.
2. What Quit did before this change (READ for the code, UNVERIFIED for the mechanism)¶
MacosTray.run built rumps.App("YazSes", ...) with rumps' default quit button and then called self._app.run() followed by self._on_quit(). The on-quit callback is what sends the IPC shutdown (tray/app.py::_on_quit). rumps' built-in Quit calls NSApplication.terminate:, and AppKit's NSApplicationMain never returns (DOC), so the line after run() very probably never executed. The Windows tray puts the same call in a finally around icon.run(); the macOS one had no equivalent.
This explains every line of the #562 log without a second hypothesis:
2026-10-02 10:16the daemon starts (tray pid 1303 launched by the daemon exits at once: the user's own tray holdstray.lock).2026-10-05 16:17:01.129the supervisor findstray.lockfree and relaunches a tray. The tray the user quit was gone; noShutting down.line was ever written by that daemon, i.e. theshutdownRPC never arrived. That is the answer to "why did the supervisor say tray is not running while the lock was held": the lock was not held at that moment.- The text under "it said: A YazSes tray is already running" is not about the tray that just died.
_last_tray_errorreadstray-stderr.log, which holds the stderr of the last tray the daemon launched, that is the duplicate from 10-02 that exited at once. It is a stale, misleading attachment (not fixed; see section 6). 16:17:01.842the relaunched tray foundlifecycle.is_running()false (the case-sensitive process-name bug, already fixed on main in1e20ebd3), spawned a second daemon, and that one exited "Another YazSes daemon is already running".
What would falsify this: ps aux | grep -i [y]azses after pressing Quit on a build with the new menu still listing a daemon.
3. What was changed for Quit¶
The Quit fix that shipped is v2.43.1's (7326b59f): platform/macos/tray.py registers the shutdown call on rumps' before_quit event, which fires from applicationWillTerminate: on the stock Quit path, and keeps the post-run() call as a de-duplicated backstop (tests/test_macos_tray_quit_stops_the_daemon.py). An earlier draft of this note proposed a second mechanism (quit_button=None plus an explicit "Quit YazSes" entry that sent shutdown on a worker thread before rumps.quit_application); it was dropped when this work landed, so that one fix exists, not two. Contract either way: Quit stops the daemon, then the icon. (Linux differs on purpose: its "Quit tray" leaves the daemon running.)
MacosHotkey.stop calls CFRunLoopStop from the IPC thread. I believe CFRunLoopStop wakes a loop that is running (DOC), but CoreFoundation keeps the stop request in per-run state that a new run starts fresh (open-source CFRunLoop.c, READ; not observed on a Mac). So a shutdown that arrived while run() was still asking for Input Monitoring or creating the tap was dropped, and CFRunLoopRun() then blocked for good. Since the follow-up to #578, run() returns at once if stop() already happened, and drives the loop in bounded CFRunLoopRunInMode passes (0.5 s) that re-read the stop flag (run_loop_until_stopped, tests/test_w2_w01_macos_hotkey_stop_before_run.py). If a daemon still survives an IPC shutdown that did arrive (the log would then contain Shutting down.), that is the next suspect. yazses restart is unaffected: it escalates to SIGKILL.
4. Which first-run prompts exist (READ)¶
| Grant | Needed for | Requested by the code before this change | Requested now |
|---|---|---|---|
| Input Monitoring | The listen-only CGEventTap (the hotkey) | Yes, IOHIDRequestAccess in MacosHotkey.run (at daemon start, not on the first key hold as the docs said) | unchanged |
| Accessibility | Posting keystrokes (CGEventPost in MacosInjector) | No. request_keyboard_capture existed on the Protocol and on MacosPermissions with zero callers in src/ | Yes, at start when the check says denied |
| Microphone | Recording | No. The prompt waited for the first recording, which needs a hotkey that cannot work without Input Monitoring | Yes, at start when the status is NotDetermined (macOS-only request_microphone, via getattr, not on the Protocol) |
Consequences for the #562 flow: after tccutil reset Accessibility com.yazses.app the app is removed from the Accessibility list and, with no request, never re-added; the docs said "On first launch, YazSes triggers macOS to show an Accessibility prompt", which was false. Both new requests share the existing persisted five-minute rate limit (system/diagnosis.should_notify), so a login item cannot put a system dialog up at every start; only an undecided or denied grant asks.
A note on the doctor wording: the "Keyboard capture" row checks Accessibility, but the hotkey tap itself is listen-only and needs Input Monitoring; Accessibility gates typing. The wording was left as is (changing it is a product decision), but it is why a green Accessibility row with a dead hotkey reads as a contradiction.
5. A daemon that predates a grant (#578)¶
The Input Monitoring grant is read when the tap is created (the in-repo comments and the docs say so; UNVERIFIED on a Mac, though System Settings itself offers "Quit & Reopen" for several privacy toggles). The daemon now records the Input Monitoring answer at start and, only if it was not OK, re-asks from its own process (so the answer is about YazSes and not about the terminal a user typed doctor into, the attribution problem in #562), at most every 30 s, and reports stale_permissions: ["input_monitoring"] in status. doctor's Daemon row turns WARN with the restart command. Healthy installs never probe. Daemons built before this change cannot report it; for them doctor's existing version-skew WARN applies.
5a. Who acts on it: the tray (READ for the code, UNVERIFIED on a Mac)¶
Reporting stale_permissions and the v2.43.1 version takeover left one path open. The takeover (core/takeover.is_older) is asked by a starting daemon, and the tray starts a daemon only when lifecycle.is_running() is false. Double-clicking the .app starts a tray, so after an upgrade, or after a grant, reopening the app never ran the takeover. In
578's log the reopened tray did not even get as far as polling: the old daemon's own tray¶
still held tray.lock, so the new one logged "A YazSes tray is already running; exiting." and quit.
The tray now acts on the status reply it already polls (tray/app.py::StaleDaemonReplacer, rule in core/takeover.replacement_reason). It hands off to yazses restart (the menu's Restart command, which already stops and starts a daemon on every OS, systemd included) when the daemon reports a version strictly older than the tray's, or a non-empty stale_permissions. It is asked from two places, because the tray that holds the lock may predate this check:
- the running tray (the lock holder), on every poll;
- a tray that exits as a duplicate (
run()failinglock.acquire()), which makes onestatuscall throughplatform.ipc_client_factorybefore it returns (_replace_a_stale_daemon_once). It builds no icon and shows no notice. This is the path #578's reporter was on.
Constraints, each with a test in tests/test_tray_replaces_a_stale_daemon.py:
- only while the daemon's state is
idleorerror, and no meeting is active or finalizing — never mid-dictation; - at most once per tray process;
- not again for the same reason within an hour, recorded in
data_dir/daemon_replacements.jsonbefore the restart is launched. This is the loop guard: a daemon terminates the tray it launched when it shuts down, so a tray that restarts its own parent is replaced by a fresh tray, and only a record on disk stops a permission probe that flaps from becoming a restart loop. Writing it first removes the race with that termination; the cost is that a launch that fails is also silent for the hour (it is logged). The record is shared by both call sites, so a running tray and a duplicate do not both act within the hour (a near-simultaneous read by both is still possible; the secondyazses restartwould then restart a daemon that is already current, which is harmless); - the restart is launched in its own session (
start_new_session) so it survives that tray being terminated, and withCREATE_NO_WINDOWwhere the OS has it (Windows), since no user action started it.
Known limits. If a restart cannot clear the reason — a systemd or launchd unit whose ExecStart points at an older install than the tray — it repeats about once an hour, only while idle, each time restarting the daemon and its tray; the docs say so rather than the code suppressing it. The meeting guard reads meeting_finalizing, which daemons before v2.25.0 do not send on status, while version arrived in v2.24.0. A v2.24.x daemon that is finalizing a meeting reports state transcribing (read from the v2.24.0 _handle_meeting_stop), which is not replaceable, so the state rule covers it — unless a dictation during the post-pass returns the state to idle before the post-pass ends, which leaves a narrow window on that one release line. There is no config switch: the behaviour is default-on, like the v2.43.1 daemon-side takeover (owner decision under AGENTS.md rule 2).
Not changed: the daemon-side takeover still ignores stale_permissions (an equal-version daemon starting next to a stale one still exits as a duplicate); the tray is the process that the user reopens, so it is where the check was added, and core/daemon.py was left alone. UNVERIFIED: that the restarted daemon's tap actually receives events after the grant (§7 item 5).
6. Findings not acted on¶
_last_tray_errorcan attach another launch's stderr to a later death (section 2).- Double-clicking the
.appstarts two trays (the user's, and the daemon's duplicate that exits). Benign, but it makes the log read like an error. docs/macos-install.mdstill told Sequoia/Tahoe users to right-click Open, which those releases no longer offer for unsigned apps (DOC). The page now leads with Settings → Privacy & Security → Open Anyway, the flow the #562 reporter actually followed.- In #562 the reporter's headset microphone stopped working on 10-06; that is hardware and unrelated.
mic-level --setchoosing three different thresholds is #579. - The ad-hoc signature (
Signature=adhoc,Internal requirements count=0, from the pastedcodesignoutput) makes the code identity a cdhash, so every build is a new TCC identity. This is the existing, documented reason a grant "stops applying while the toggle looks on"; only signing fixes it (design/packaging/macos-signing.md).
7. UNVERIFIED on a real Mac¶
- rumps'
before_quitevent fires on the stock Quit path (from the rumps 0.4.0 source, not run). - Quit really stops the daemon, and no tray reappears 20 s later.
AXIsProcessTrustedWithOptions(prompt=True)shows a dialog from the background daemon process, and does so once per launch while untrusted.AVCaptureDevice.requestAccessForMediaType:completionHandler:through PyObjC accepts a Python lambda as the block and shows the microphone prompt from a non-GUI process.- A grant given after start leaves the existing tap deaf, so a restart is what is needed.
- Whether the Input Monitoring prompt (
IOHIDRequestAccess) appears for a daemon launched by the tray withstart_new_session, versus launched by launchd.
8. Questions for the #562 / #578 reporter¶
On a build containing this change (for 1 and 2, v2.43.1 or later):
- After pressing Quit in the menu bar, what do
ps aux | grep -i [y]azsesandlaunchctl list | grep yazsesprint? Then, 30 seconds later, again. - Does the icon come back after Quit? If so, how long after?
- On first launch after
tccutil reset Accessibility com.yazses.appandtccutil reset ListenEvent com.yazses.appandtccutil reset Microphone com.yazses.app: which system dialogs appear, in which order, and what does each say? - After switching a toggle on while YazSes is running, what does
yazses doctor(run as/Applications/YazSes.app/Contents/MacOS/YazSes --cli doctor) print on the Daemon row? - The last 40 lines of
~/Library/Logs/yazses/daemon.logafter step 3, and whetherShutting down.appears there after Quit.