Skip to content

brew upgrade leaves the previous daemon running #6

Closed

Description

@TerrifiedBug

What happens

brew upgrade --cask yap replaces /Applications/yap.app, but the launchd job keeps executing the old image — replacing a file does not touch a process that already mapped it. So after an upgrade you are silently still running the previous version until something restarts the daemon:

brew upgrade --cask yap
yap stop && yap start   # currently required, and nothing says so

Observed on the 0.1.1 → 0.1.2 upgrade. Nothing in the upgrade output hints at it, and yap --version answers from the new binary on disk, so it agrees with the version you just installed while the daemon in memory is the old one. That is the worst shape for this bug: it looks fixed.

Why the obvious fix is wrong

A cask uninstall stanza. Homebrew runs uninstall directives on upgrade as well as uninstall, and the reasoning is already recorded in .github/workflows/release.yml (the cask heredoc, ~L159-169):

  • uninstall launchctl: deletes ~/Library/LaunchAgents/com.terrifiedbug.yap.plist, so every upgrade would quietly switch launch-at-login off.
  • uninstall quit: is recorded and then reopened with open -b, which starts the daemon outside launchd, where neither yap stop nor the login item can reach it.

So the current no-uninstall-stanza cask is deliberate, and this issue must not undo it.

Proposed fix

postflight in the generated cask — the package manager restarts the service it just replaced, through launchd rather than around it:

postflight do
  system_command "/bin/launchctl",
                 args: ["kickstart", "-k", "gui/#{Process.uid}/com.terrifiedbug.yap"],
                 must_succeed: false
end
  • kickstart -k replaces the job launchd already owns, so the daemon stays inside launchd and the plist is untouched.
  • must_succeed: false because most installs have no login item, and brew upgrade should not fail over its absence.
  • The cask is regenerated by the release workflow on every tag, so this lands in the release after the one that merges it, and applies from that upgrade onward.

One thing to decide: kickstart -k will interrupt a dictation press or an in-progress meeting recording. brew upgrade is user-initiated, and a session's CAF/AAC tracks are written incrementally, so the exposure is small — but it should be a conscious call, not an accident.

Alternative considered

Have the daemon notice its own executable changed and exit non-zero, letting the existing KeepAlive { SuccessfulExit: false } relaunch it into the new image. A vnode watch is kernel-notified, so it costs nothing while idle and does not break the no-polling rule, and it would cover every install path rather than only Homebrew.

Against it: it auto-adopts a binary nobody has verified starts (turning a working old daemon into a dead new one without being asked), it needs gating so it never fires mid-press or mid-recording, and it is materially more machinery than a package-manager problem the package manager already has the information to solve. Recorded here so it is not re-proposed without a reason to prefer it.

Not covered by either

Someone who installed by dragging the .dmg still restarts by hand. A yap doctor line comparing the running image against the executable on disk would at least name the situation instead of leaving it invisible.

Acceptance

  • With launch-at-login installed, brew upgrade --cask yap leaves the running daemon on the new version, with no manual step.
  • ~/Library/LaunchAgents/com.terrifiedbug.yap.plist still exists afterwards, and launchctl print gui/$UID/com.terrifiedbug.yap still resolves — the daemon is still a launchd job, not a stray process.
  • Upgrading on a machine with no login item installed does not fail the upgrade.

Activity

  1. added
    bug
    on Aug 14, 2026
  2. TerrifiedBug commented on Aug 19, 2026

    @TerrifiedBug
    OwnerAuthor

    Verified end to end on the real 0.1.3 → 0.1.4 upgrade, not simulated — this landed in the 0.1.4 cask, so the upgrade that shipped the fix is the one that exercised it.

    brew upgrade --cask yap        # 0.1.3 -> 0.1.4, no manual step
    
    installed: 0.1.4
    old pid=9921   new pid=14933
    running image node=265840666   ← the process's mapped executable
    on-disk    node=265840666      ← the newly installed binary: same inode
    plist mtime still=1786729370   (unchanged)
    launchd job resolves: yes
    "LastExitStatus" = 0;
    

    The inode comparison is the part that actually answers this issue: before the upgrade the running daemon mapped inode 264600889, and afterwards it maps the new file's inode. So it is genuinely executing the new image rather than agreeing with a version string it read off disk.

    All three acceptance criteria hold — new version running, plist and launchd job intact, and launchctl exits 113 with must_succeed: false where there is no login item.

    The open question, resolved by measurement

    One thing to decide: kickstart -k will interrupt a dictation press or an in-progress meeting recording.

    It interrupts, but non-destructively, and that was measured rather than argued. A throwaway LaunchAgent mimicking yap's signal posture showed kickstart -k delivers SIGTERM, not SIGKILL, and that launchd starts the job again after a caught SIGTERM and a clean exit 0 (~5 s later).

    yap already installs DispatchSource handlers for SIGINT/SIGTERM routing to NSApp.terminate(nil), so SIGTERM runs applicationWillTerminate: a live session is stopped cleanly, keeps its meta.json, and transcribes on the next start. The upgrade log confirms the graceful path ran rather than the process being killed:

    shutting down
    loading parakeet-tdt-ctc-110m...
    ✓ parakeet-tdt-ctc-110m ready
    listening on fn hold · parakeet-tdt-ctc-110m · watching for meetings → …
    

    A dictation press in flight loses that press's audio; a meeting recording does not lose the meeting. That seems the right trade for a user-initiated brew upgrade.

    One correction to the issue

    The cask is regenerated by the release workflow on every tag, so this lands in the release after the one that merges it.

    It applies one release earlier than that. Homebrew runs the new cask's postflight during an upgrade, and the tag's cask is generated from the workflow at that tag — so merging before tagging v0.1.4 made the 0.1.3 → 0.1.4 upgrade itself restart the daemon. Which mattered more than usual here: 0.1.4 also ships the transcript-ready banner (#9), and without the restart it would have looked like that feature did not work.

    Still open, deliberately

    The yap doctor line comparing the running image against the executable on disk, for the .dmg install path. Outside this issue's acceptance criteria, and it needs a heuristic with its own false-positive modes, so it wants its own change rather than a rider on a release. The inode comparison above is a decent basis for it if it gets picked up.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions