Skip to content

App launcher replaces and restarts a signed, running daemon on every launch (size-only up-to-date check after ad-hoc re-sign) #3835

Closed

Description

@mstomar125

What happens

packages/desktop-app/app-lib/src/daemon_setup.rs copies each bundled sidecar into ~/.nodespace/bin, re-signs the copy ad hoc (resign_binary: codesign --force --sign -), and on every launch treats the copy as up to date only when dest.len() == src.len() and codesign --verify --strict passes (extract_sidecar_if_changed; the same size-only test is in kill_stale_daemon_sync).

For a Developer ID signed bundle (every notarized release, the .pkg and .dmg included) the ad-hoc copy is always smaller than the bundled file (measured: daemon 74,186,368 vs 74,638,320 bytes; CLI 5,405,808 vs 5,455,552; /bin/sleep 115,728 vs 166,512). So on every launch:

  1. kill_stale_daemon_sync SIGKILLs a daemon running from ~/.nodespace/bin/nodespaced;
  2. extract_sidecar_if_changed re-extracts and returns binary_updated = true;
  3. bring_up_daemon calls kill_running_daemon, writes ~/Library/LaunchAgents/app.nodespace.daemon.plist and bootstraps it; when the label is already loaded from /Library/LaunchAgents (a .pkg install), the fallback boots that job out and the per-user job takes over.

The "already running and healthy" return is never reached, the daemon restarts on every app launch, and the daemon that runs is an ad-hoc copy whose code identity differs from the notarized binary's (keychain items are bound to the identity that wrote them).

Proposed change

  1. Up-to-date check that survives re-signing (extract_sidecar_if_changed, kill_stale_daemon_sync): either do not re-sign a copy whose bundled source already verifies with a real signing identity (codesign -dv reports an Authority=/TeamIdentifier= other than not set), copying it as is and re-signing ad hoc only ad-hoc or linker-signed sources (dev builds); or record what was extracted (a stamp ~/.nodespace/bin/.<name>.source with the bundled file's size and SHA-256) and treat the copy as current when the stamp matches and the copy verifies. kill_stale_daemon_sync reads the same stamp.
  2. A .pkg install's machine-wide registration is authoritative (bring_up_daemon): when /Library/LaunchAgents/<label>.plist exists, do not extract sidecars into ~/.nodespace/bin and do not write or bootstrap the per-user plist. If the daemon does not answer, launchctl kickstart gui/<uid>/<label> (or launchctl bootstrap gui/<uid> /Library/LaunchAgents/<label>.plist when not loaded), then wait for the socket as today. Today, after a tray Quit or an incompatible-database refusal, the next app launch registers a per-user job beside the machine-wide one (two plists under one label).
  3. Quit and the stale-daemon kill target the registered binary (signal_daemon_to_stop, kill_running_daemon, kill_stale_daemon_sync): they only signal a process whose argv0 is ~/.nodespace/bin/nodespaced, so on a .pkg install (daemon /usr/local/bin/nodespaced) quitting the app leaves the daemon running and a binary update never restarts it. Match the program of the loaded job (launchctl print gui/<uid>/<label> -> program), or both install locations.
  4. Per-user plists of other macOS users on the same Mac: a per-user plist the app wrote runs ~/.nodespace/bin/nodespaced without a product's service environment. With (2), the app could delete a per-user plist under the label when the machine-wide one exists.

Acceptance criteria

  • Two app launches in a row on a .pkg-style layout leave the daemon's PID unchanged (no SIGTERM, no bootstrap).
  • No per-user plist is written while /Library/LaunchAgents/<label>.plist exists.
  • App Quit stops the daemon the registration runs.
  • ADR-084 section 3.2 (Q3) and sections 3.3/4.3 state which registration wins on a .pkg install and that the app never installs its own daemon copy when the machine-wide registration exists.

Why it matters

A signed, healthy daemon is killed and replaced by an ad-hoc-signed copy on every launch, losing its code identity (and keychain access bound to it), and .pkg installs end up with two registrations and a Quit that does not stop the daemon.

Activity

  1. self-assigned this
    on Oct 16, 2026
  2. added
    bug
    on Oct 16, 2026
  3. mstomar125 commented on Oct 20, 2026

    @mstomar125
    ContributorAuthor

    Planned for core v0.3.9.

  4. mstomar125 commented on Oct 22, 2026

    @mstomar125
    ContributorAuthor

    Appears fixed on main by #3853 (4a8e68d): the size-only up-to-date test was replaced by a source stamp (installed_matches_source, daemon_setup.rs), used by both kill_stale_daemon_sync and extract_sidecar_if_changed. Not closing; needs a confirmation on a notarized build (a second launch should not restart the daemon).

    🤖 Generated with Claude Code

  5. mstomar125 commented on Oct 22, 2026

    @mstomar125
    ContributorAuthor

    Fixed by #3853 (source stamp instead of file size), shipped in v0.3.9. Confirmed by the user on a physical Mac with the real notarized .pkg: opening the app repeatedly keeps the same daemon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions