Skip to content

fix(monitor,self-heal): auto-rediscover host gist on rotation, no human in loop - #405

Merged
joelteply merged 1 commit into
canaryfrom
fix/host-gist-auto-rediscover
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/host-gist-auto-rediscover

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Why

Closes the satellite-killer scenario from tonight's blackout: host (Mac) tore down + rejoined → new mesh gist on the same gh account → joiner (b69f) kept polling the dead old gist for hours → Joel had to relay 'rejoin' over chat.

Substrate failed at the BIOS-level concern Joel called out tonight verbatim:

"we are going to put one of you on a satellite someday and airc is our lifeline ... You have the easy part, must self-heal, no one can be there to fix your umbilical cord for you."

"airc=bios level concern"

"stop, fix, then when working well with others, only then get back to what we were working on. It is the backbone bus"

#400 (silence beacon) detects bearer-side silence but only warns — doesn't act. This PR fills the detect-AND-act gap.

What

Two paired changes in airc bash:

1. New _mesh_rediscover_loop subshell

Spawned by monitor() alongside reminder_timer_loop. Every AIRC_MESH_REDISCOVER_SEC seconds (default 300s):

  • calls _mesh_find (1 gh API list, ~150 bytes wire, free under rate limit)
  • compares against current channel_gists in config
  • on mismatch: writes new gist to ALL subscribed channels + emits stdout warning + force-respawns bearer_cli children via pkill

2. _monitor_multi_channel re-reads channel_map from config at top of each outer-while iteration

Previously the map was a parameter set ONCE at startup, so config changes mid-flight didn't take effect until full daemon restart. Now the next bearer respawn picks up fresh config naturally — what made the swap from (1) above immediately effective without exit-99 + daemon-wrapper restart.

Together: rotation detection → config update → bearer respawn → fresh gist polling, all within one 300s cycle, no human required.

Repro (real, tonight 2026-05-02)

  • b741 host: airc teardown && airc connect → new gist b7c8295 on joelteply gh account
  • b69f joiner: bearer kept polling dead b9d473f indefinitely
  • Joel: your code sucks / he is not receiving
  • Manual recovery: airc teardown && airc connect on b69f side — should be automatic

Post-fix: same rotation detected within next 300s cycle, swapped automatically. STDOUT warning surfaces the swap to Monitor so the operator sees what self-healed.

Smoke test (manual, this PR)

# planted fake gist in config
$ airc_core.config set_channel_gist --channel general --gist deadbeef0000000000000000000000ff

$ # ran rediscover logic standalone (sourcing mesh.sh)
found via _mesh_find: b7c8295b8a6069da735e2e0e694743a7
current in config: deadbeef0000000000000000000000ff
ROTATION DETECTED — swapping

$ airc_core.config list_channel_gists
general	b7c8295b8a6069da735e2e0e694743a7   ← healed

Cost

  • 1 gh gist list per AIRC_MESH_REDISCOVER_SEC (default 300s) = 12 calls/hour, well under gh's 5000/hr ceiling
  • pkill on rotation only — zero-cost steady state

Scope

  • Single-account scope: _mesh_find lists CURRENT gh account's gists. Mac and b69f both auth'd as joelteply tonight (the dominant case). Same-gh-account multi-machine coordination is the primary use.
  • Cross-account peers (friend on a different gh) take legacy invite path; this loop no-ops because _mesh_find returns empty there. Mac's fix/airc-bearer-loud-failures covers that path with loud-fail surfacing.

Pairs with

PR Role
#400 Silence beacon — detects bearer silence, doesn't act
#401 #-prefix tolerance — formatter bug
#402 Loud display-filter drops — visibility for cross-channel
fix/airc-bearer-loud-failures (Mac, in flight) Recv-side silent-swallow loud-fail
this PR Detect AND act on host rotation — closes the auto-recovery gap

Pre-existing test reds (NOT caused by this PR)

🤖 Generated with Claude Code

…an in loop

Closes the satellite-killer scenario from tonight's blackout: host
(Mac) tore down + rejoined → new mesh gist on the same gh account →
joiner (b69f) kept polling the dead old gist for hours → Joel had
to relay "rejoin." Substrate failed at the BIOS-level concern Joel
called out: "you have the easy part, must self-heal, no one can
be there to fix your umbilical cord for you."

## What

Two paired changes, both in airc bash:

1. New `_mesh_rediscover_loop` subshell spawned by monitor() alongside
   reminder_timer_loop. Every 300s (env-tunable via
   AIRC_MESH_REDISCOVER_SEC):
   - calls `_mesh_find` (1 gh API list, ~150 bytes wire)
   - compares against current channel_gists in config
   - on mismatch: writes new gist to ALL channels + emits stdout
     warning + force-respawns bearer_cli children via pkill

2. `_monitor_multi_channel` re-reads channel_map from config at top of
   each outer-while iteration. Previously the map was a parameter set
   ONCE at startup, so config changes mid-flight (e.g. from the
   rediscover loop above) didn't take effect until full daemon restart.
   Now the next bearer respawn picks up fresh config naturally.

Together: rotation detection → config update → bearer respawn → fresh
gist polling, all within one 300s cycle, no human required.

## Repro (real, tonight 2026-05-02)

- b741 host: `airc teardown && airc connect` → new gist b7c8295 on
  joelteply gh account
- b69f joiner: bearer kept polling dead b9d473f indefinitely; #400
  silence beacon eventually fires but doesn't ACT, only warns
- Mac had to message me on substrate (which itself relied on Joel
  manually relaying because of #399 etc) to tell me to teardown+rejoin

Post-fix: same rotation detected within next 300s cycle, swapped
automatically. STDOUT warning surfaces the swap to Monitor so the
operator sees what self-healed without needing to dig logs.

## Smoke test (manual, this commit)

- planted fake gist `deadbeef0000...ff` in config.channel_gists.general
- ran the detect-and-swap logic standalone (sourcing mesh.sh):
  - `_mesh_find` returned real gist b7c8295
  - mismatch detected → swap fired → config back to b7c8295
- before/after `list_channel_gists` confirmed the heal

## Cost

- 1 `gh gist list` per AIRC_MESH_REDISCOVER_SEC (default 300s) = 12
  calls/hour, well under gh's 5000/hr ceiling
- pkill on rotation only — zero-cost steady state

## Scope

- Single-account scope: `_mesh_find` lists CURRENT gh account's gists.
  Mac and b69f both auth'd as joelteply tonight (the dominant case).
- Cross-account peers (friend on a different gh) take legacy invite
  path; this loop no-ops because `_mesh_find` returns empty there.
  Loud-fail (Mac's bearer_gh.py PR) covers that path.

## Pairs with

- #400 (silence beacon — detects bearer-side silence, doesn't act)
- #401 (#-prefix tolerance — formatter bug)
- #402 (loud display-filter drops — visibility for cross-channel)
- Mac's fix/airc-bearer-loud-failures (recv-side silent-swallow)

This PR fills the "detect AND act" gap. Loud-fail is necessary; auto-
recovery is what makes airc satellite-grade. Both needed.

## Pre-existing test reds (NOT caused by this PR)

test_bearer.py: 3 CRLF-vs-LF assertions fail on Windows (line endings
on tempfiles). Same on raw canary, verified pre-this-branch.
test_crypto.py: 1 failure + 1 error, also on raw canary.
test_monitor_formatter.py: 11/11 pass (including #402's tests).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 15:27
@joelteply
joelteply merged commit b94eb82 into canary May 2, 2026
8 checks passed
@joelteply
joelteply deleted the fix/host-gist-auto-rediscover branch May 2, 2026 15:28

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

This PR adds automatic mesh gist rediscovery to the bash monitor so a joiner can recover when the host rotates to a new GitHub gist without requiring a manual airc teardown && airc connect. It fits into the recent monitor/self-heal work by turning the earlier “detect silence” safety net into an active recovery path for same-account mesh setups.

Changes:

  • Added _mesh_rediscover_loop, a background monitor helper that periodically re-runs mesh discovery and attempts to rewrite channel_gists when the host gist changes.
  • Updated _monitor_multi_channel to refresh channel_gists from config on each outer restart cycle so runtime config changes can take effect without restarting the daemon.
  • Registered the new rediscovery loop as an auxiliary monitor process and included it in PID tracking.

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

Comment thread airc
while IFS= read -r ch; do
[ -z "$ch" ] && continue
"$AIRC_PYTHON" -m airc_core.config set_channel_gist \
--config "$CONFIG" --channel "$ch" --gist "$found_gist" 2>/dev/null || true
Comment thread airc
# use a name-based pkill as a best-effort. The watchdog/death-watch
# in _monitor_multi_channel will catch any survivors on its 2s
# poll. Safe to call even if no children match (idempotent no-op).
pkill -f 'airc_core.bearer_cli recv' 2>/dev/null || true
Comment thread airc
Comment on lines +1883 to +1888
_mesh_rediscover_loop() {
local _parent_pid="$PPID"
# Cadence in seconds. 300s = 5min. Joel's "satellite" framing argues
# for tighter cadence on critical infra; 60s would also be fine cost-
# wise but bursty races during legitimate teardowns get noisy.
local interval="${AIRC_MESH_REDISCOVER_SEC:-300}"
joelteply added a commit that referenced this pull request May 2, 2026
… missing) (#408)

The Windows daemon launcher .bat (generated by 'airc daemon install')
called the airc binary with NO stdout redirect:
  "$bash_exe" -c "exec '$airc_bin_unix' connect"

So airc's event stream (the entire stdout output: hosting messages,
peer joins, channel state, beacons) went to NOTHING. Only the
launcher's own restart-record messages reached daemon.err.

Symptom (b69f 2026-05-02): airc daemon-installed on Windows; daemon
"running" per the registry entry; but `airc daemon log` reports
"daemon.log doesn't exist" because no process ever wrote to it.
Operator has no way to see what airc actually did — bios-critical
substrate is opaque on the very platform users need it most.

Fix: 1>> daemon.log 2>> daemon.err on the airc invocation. Now
daemon.log captures the actual airc event stream while daemon.err
keeps the launcher's restart records separate.

Per the global "evidence is for the debugger, not the trash" rule
+ tonight's bios-resilience sweep (everything airc does must be
visible AND self-healing). Daemon mode is the OS-supervised path
that survives Claude session ends — but only useful if its logs
exist.

## Cumulative effect

Tonight's airc sweep now closes:
- Receive path silent failures (#400/#401/#402/#403/#404/#406)
- Self-heal of host rotation (#405/#407)
- Daemon-log invisibility on Windows (THIS PR)

Last remaining bios-fragility I know of: `airc daemon install` on
Windows succeeded BEFORE this fix — so b69f's daemon may be running
right now but wrote nothing all session. After this lands + b69f
re-installs, daemon.log will populate.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
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