Skip to content

fix(heartbeat): detect active-host-evicted; surface stderr; self-heal (#224) - #228

Merged
joelteply merged 1 commit into
canaryfrom
fix/active-host-evicted-self-heal
Apr 28, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/active-host-evicted-self-heal

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Closes #224. Tracks consecutive gh gist edit failures in the heartbeat loop; after 3 in a row, surfaces [HOST EVICTED] to messages.jsonl with stderr inlined and SIGTERMs the parent for daemon respawn / clean reconnect.

stderr captured to .airc/heartbeat.stderr (was suppressed via 2>/dev/null — never-swallow-errors fix).

Verification: tabs 19/0, sidecar-default 10/0. Manual takeover scenario is a follow-up.

…failures (#224)

Closes #224 — the bug surfaced during Phase 1 e2e where vhsm-d1f4's
takeover deleted my mesh gist while my host was still actively running,
and my heartbeat hammered the deleted gist forever (`gh gist edit X
2>/dev/null || true` swallowed the 404). Two-day-old split-brain
risk; never noticed because evidence was suppressed.

## Fix

cmd_connect.sh heartbeat loop:
  - Capture gh gist edit stderr to .airc/heartbeat.stderr (per
    never-swallow-errors rule — evidence stays accessible to the
    next debugger).
  - Track consecutive failure count.
  - After N (default 3, AIRC_HB_MAX_FAIL override) consecutive 404s,
    surface a [HOST EVICTED] system event into messages.jsonl with
    the last stderr inlined, drop stale host_gist_id / room_gist_id
    files, and SIGTERM the parent.
  - Parent's EXIT trap reaps children. With daemon installed
    (launchd/systemd), respawn picks up the new mesh via discovery
    and joins as peer. Without daemon, the user gets a clean
    [HOST EVICTED] log line and `airc connect` rejoins.

## Why kill the parent

Heartbeat runs in a subshell, can't exec the parent's _self_heal_stale_host
directly. Cleanest signal is SIGTERM → parent's existing EXIT trap +
cmd_connect's reconnect loop. Daemon respawns are the natural recovery
path; users without daemon get evidence + manual rejoin.

## Verification

  bash -n: clean
  test/integration.sh tabs:                    19/0 ✓
  test/integration.sh general_sidecar_default: 10/0 ✓

  Manual: needs a takeover-during-active-host repro to e2e validate
  the kill path. Will add scenario_active_host_evicted in a follow-up
  PR (it requires either two real airc processes racing or a mock
  gh — non-trivial to set up in the existing harness).

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.

1 participant