Skip to content

fix(airc): surface monitor-escalation to stdout + daemon-aware (#184) - #189

Merged
joelteply merged 1 commit into
canaryfrom
fix/airc-monitor-silent-exit
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/airc-monitor-silent-exit

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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:

  • Surfaces the escalation to stdout (single-line, `airc:` prefix) AND stderr (multi-line banner). Both eyes see it.
  • Daemon-aware: new helper `_daemon_installed` detects launchd plist / systemd user unit. The escalation message tells the user whether `exit 99` will self-heal (daemon present) or just kill the relay (no daemon → `airc join` again, hint to install).

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

  • bash -n airc passes
  • Manual: kill the host while a joiner is connected, verify stdout shows the escalation message (not just stderr)
  • CI clean-install matrix exercises the install path; the runtime escalation isn't covered yet (would need a long-running scenario test)

🤖 Generated with Claude Code

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]>
Copilot AI review requested due to automatic review settings April 28, 2026 03:07
@joelteply
joelteply merged commit f23c9e2 into canary Apr 28, 2026
8 checks passed
@joelteply
joelteply deleted the fix/airc-monitor-silent-exit branch April 28, 2026 03:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_installed helper 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 true loop ever falls through.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread airc
Comment on lines +4776 to +4787
# 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 ;;

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_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.

Suggested change
# 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
;;

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +1265 to +1269
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

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment thread airc
if _daemon_installed >/dev/null 2>&1; then
_daemon_present=1
fi
echo ""

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
echo ""

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +1265 to +1267
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

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”).

Suggested change
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

Copilot uses AI. Check for mistakes.
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.

2 participants