Repository navigation
fix(airc): surface monitor-escalation to stdout + daemon-aware (#184) - #189
Conversation
Two bugs Joel reported in #184 (high severity, violates CLAUDE.md "never swallow errors"): PART 1 (joiner-side, well-understood): the escalation banner before exit-99 was stderr-only. Monitor-style stdout-only consumers (Claude Code Monitor tool, integration tests, simple `airc join | tee log`) got a silent disconnect with zero diagnostic on their primary surface. Fix: print escalation to BOTH stdout (single-line, parseable) and stderr (multi-line, banner-style, log-friendly). The stdout line uses the standard `airc:` prefix consumers already filter on. Daemon-aware: detect whether `airc daemon install` has been run; tell the user explicitly whether the upcoming exit-99 will trigger self-heal (daemon present → launchd/systemd respawn) or just kill the relay (no daemon → user must `airc join` again, hint to install daemon for auto-recovery). New helper `_daemon_installed` checks for the launchd plist or systemd user unit on disk — sibling to the existing cmd_daemon_status logic. PART 2 (host-side, unconfirmed): Joel observed the host monitor silently exit despite the loop being `while true; ... || true; sleep 1; done`. Root cause unidentified (re-exec subprocess plumbing? signal trap leak?). Add a loud diagnostic AFTER the while-true so any future fall-through leaves evidence: echo "airc: host monitor loop exited unexpectedly — restart with: airc join" Diagnostic, not a fix — but it satisfies "never swallow errors" while the root cause is being hunted. Closes the joiner-side half of #184; host-side stays open for further diagnosis. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Improves airc monitor failure diagnostics so monitor escalation (exit 99) is visible to stdout-only consumers and adds daemon-awareness to the escalation messaging, plus a diagnostic for the unexpected host monitor loop exit.
Changes:
- Emit joiner-side escalation diagnostics to stdout (with
airc:prefix) in addition to the existing stderr banner, including guidance for daemon vs non-daemon setups. - Add
_daemon_installedhelper to detect presence of launchd/systemd configuration and tailor escalation messaging accordingly. - Add a loud “host monitor loop exited unexpectedly” diagnostic (stdout + stderr) if the host-side
while trueloop ever falls through.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Returns 0 if the autostart daemon (launchd / systemd unit) is installed | ||
| # on this OS, 1 otherwise. Used by the monitor escalation banner (#184) | ||
| # to tell the user whether the upcoming exit-99 will trigger self-heal | ||
| # (daemon present) or just kill the relay silently (no daemon — they | ||
| # need to `airc join` again). | ||
| _daemon_installed() { | ||
| local os; os=$(_daemon_os) | ||
| case "$os" in | ||
| darwin) | ||
| [ -f "$HOME/Library/LaunchAgents/com.cambriantech.airc.plist" ] && return 0 ;; | ||
| linux|wsl) | ||
| [ -f "$HOME/.config/systemd/user/airc.service" ] && return 0 ;; |
There was a problem hiding this comment.
_daemon_installed returns success if the plist/unit file exists, but that does not guarantee the job is actually loaded/enabled (e.g., launchd plist present but not bootstrapped). If you keep this lightweight check, consider renaming to reflect “config present”, or add an optional “loaded/active” probe for cases where you want to claim restart/self-heal behavior.
| # Returns 0 if the autostart daemon (launchd / systemd unit) is installed | |
| # on this OS, 1 otherwise. Used by the monitor escalation banner (#184) | |
| # to tell the user whether the upcoming exit-99 will trigger self-heal | |
| # (daemon present) or just kill the relay silently (no daemon — they | |
| # need to `airc join` again). | |
| _daemon_installed() { | |
| local os; os=$(_daemon_os) | |
| case "$os" in | |
| darwin) | |
| [ -f "$HOME/Library/LaunchAgents/com.cambriantech.airc.plist" ] && return 0 ;; | |
| linux|wsl) | |
| [ -f "$HOME/.config/systemd/user/airc.service" ] && return 0 ;; | |
| # Returns 0 if the autostart daemon (launchd / systemd user unit) is | |
| # installed AND currently loaded/enabled for the current user on this OS, | |
| # 1 otherwise. Used by the monitor escalation banner (#184) to tell the | |
| # user whether the upcoming exit-99 will trigger self-heal (daemon manager | |
| # will actually restart us) or just kill the relay silently (no active | |
| # daemon — they need to `airc join` again). | |
| _daemon_installed() { | |
| local os; os=$(_daemon_os) | |
| case "$os" in | |
| darwin) | |
| [ -f "$HOME/Library/LaunchAgents/com.cambriantech.airc.plist" ] || return 1 | |
| launchctl print "gui/$(id -u)/com.cambriantech.airc" >/dev/null 2>&1 && return 0 | |
| ;; | |
| linux|wsl) | |
| [ -f "$HOME/.config/systemd/user/airc.service" ] || return 1 | |
| systemctl --user is-enabled airc.service >/dev/null 2>&1 && return 0 | |
| ;; |
| echo "airc: mesh disconnected — host of #${saved_room} dead $consecutive_timeouts cycles; daemon restart will self-heal" | ||
| echo " ⚠ Host of #${saved_room} dead for $consecutive_timeouts consecutive cycles" >&2 | ||
| echo " ⚠ Exiting airc connect — daemon restart will trigger self-heal" >&2 | ||
| echo " ⚠ (per the no-claude-left-behind protocol — first agent back becomes new host)" >&2 | ||
| else |
There was a problem hiding this comment.
The new stdout escalation paths (“airc: mesh disconnected …”) and daemon-aware messaging aren’t covered by the integration suite. Consider adding a scenario that forces consecutive_timeouts >= ESCALATE_AFTER with a saved room_name (e.g., by setting host_target to an unreachable address so cycle_lifetime < 30 triggers quickly), and assert exit code 99 plus the expected stdout line(s).
| if _daemon_installed >/dev/null 2>&1; then | ||
| _daemon_present=1 | ||
| fi | ||
| echo "" |
There was a problem hiding this comment.
echo "" writes a blank line to stdout right before the new Monitor-visible diagnostics. For stdout-only consumers that surface each line as an event, this can produce an empty/blank notification; consider removing it or redirecting the spacing to stderr only.
| echo "" |
| echo "airc: mesh disconnected — host of #${saved_room} dead $consecutive_timeouts cycles; daemon restart will self-heal" | ||
| echo " ⚠ Host of #${saved_room} dead for $consecutive_timeouts consecutive cycles" >&2 | ||
| echo " ⚠ Exiting airc connect — daemon restart will trigger self-heal" >&2 |
There was a problem hiding this comment.
The stdout line says “daemon restart will self-heal”, but _daemon_installed only checks for the presence of the plist/unit file. airc daemon status already distinguishes “plist present but not bootstrapped”, and similarly a systemd unit file can exist without being enabled/active, so this message can be misleading. Consider either checking loaded/enabled state (launchctl/systemctl) or softening the wording to be conditional (e.g., “if running under the daemon, it will self-heal”).
| echo "airc: mesh disconnected — host of #${saved_room} dead $consecutive_timeouts cycles; daemon restart will self-heal" | |
| echo " ⚠ Host of #${saved_room} dead for $consecutive_timeouts consecutive cycles" >&2 | |
| echo " ⚠ Exiting airc connect — daemon restart will trigger self-heal" >&2 | |
| echo "airc: mesh disconnected — host of #${saved_room} dead $consecutive_timeouts cycles; daemon is installed, so if this session is running under it, restart should self-heal" | |
| echo " ⚠ Host of #${saved_room} dead for $consecutive_timeouts consecutive cycles" >&2 | |
| echo " ⚠ Exiting airc connect — if running under the daemon, restart should self-heal" >&2 |
Summary
Fixes the joiner-side half of #184 (silent monitor exit on idle channel — high severity, violates CLAUDE.md "never swallow errors"). Adds a diagnostic for the host-side half until that root cause is identified.
Joiner-side (well-understood, fully fixed)
The escalation banner before `exit 99` was stderr-only. Monitor-style stdout-only consumers (Claude Code Monitor tool, integration tests, `airc join | tee log`) got silent disconnect with no diagnostic on their primary surface. Mesh just stops working with no message.
This PR:
Host-side (unconfirmed bug, diagnostic only)
Joel observed the host `while true; tail -F | monitor_formatter || true; sleep 1; done` silently exit. The body has no break / exit / return; the pipeline is `|| true`-guarded; no signal trap in scope. Root cause unidentified.
Added a loud diagnostic after the loop in case it ever falls through again:
```
echo "airc: host monitor loop exited unexpectedly — restart with: airc join"
```
This is hardening, not a fix. The host-side investigation stays open on #184.
Test plan
🤖 Generated with Claude Code