Skip to content

fix: bearer heartbeat — detect stuck-but-alive recv (the 'monitor dies' bug) - #312

Merged
joelteply merged 1 commit into
canaryfrom
fix-bearer-stuck-heartbeat
Apr 29, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix-bearer-stuck-heartbeat

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Joel: 'polling easily shuts down on its own OR never even worked.' Confirmed in production. #302 only catches DEAD; STUCK looks alive.

Fix: bearer_cli emits {airc_heartbeat:1} on stdout every AIRC_BEARER_HEARTBEAT_SEC (30s default). Formatter recognizes + arms watchdog + suppresses display. Stuck bearer → no heartbeats → watchdog trips → bash respawns pipe.

Watchdog re-enabled for hosts (heartbeats keep it armed during legitimate idle).

TDD: 2 new tests — test_recv_emits_heartbeats_when_bearer_idle and test_heartbeat_line_is_valid_json_with_sentinel. 68/68 pass.

Joel 2026-04-29: 'polling easily shuts down on its own OR never even
worked, only sending/pinging triggered anything to occur.' Confirmed
in production: 52 stale bearer_cli zombies machine-wide; current
scope's recv pipeline often had monitor_formatter alive but ZERO
bearer_cli children attached (after laptop sleep, after gh transient,
etc). #302's child-death detection only catches DEAD; STUCK looks
alive because kill -0 succeeds.

Fix: bearer_cli emits a sentinel JSON line {airc_heartbeat:1, ts, channel}
to stdout every AIRC_BEARER_HEARTBEAT_SEC (default 30s) regardless of
bearer activity. monitor_formatter recognizes the sentinel, arms its
inactivity watchdog, suppresses display. Stuck bearer → no heartbeats
reach formatter → existing 150s watchdog trips → formatter exits 2 →
bash multi-channel watcher kills children + respawns the pipe.

Watchdog re-enabled for hosts. Pre-fix it was disabled because hosts
had no inbound during idle (alarm tripped every 150s). With heartbeats
keeping it armed during legitimate idle, stuck-bearer detection works
on host AND joiner uniformly.

TDD coverage:
  test_recv_emits_heartbeats_when_bearer_idle — IdleBearer that yields
  nothing for 2.5s; assert ≥2 heartbeats at 1s interval (would fail
  pre-fix; now passes).
  test_heartbeat_line_is_valid_json_with_sentinel — heartbeat line
  parses as JSON with airc_heartbeat=1 so monitor_formatter can match.

This is the test that should have existed before bearer rewrite shipped.
68/68 unit tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@joelteply
joelteply merged commit 3c6db69 into canary Apr 29, 2026
@joelteply
joelteply deleted the fix-bearer-stuck-heartbeat branch April 29, 2026 15:22
joelteply added a commit that referenced this pull request Apr 29, 2026
…le, part) (#313)

test: add real-gh smoke scenarios — passive_recv, round_trip, idle_then_recv, part_deletes_host_gist

The TDD gap Joel called out 2026-04-29: 'not stupid unit, not faked
with some half assed local equivalent — what is the most basic
things, ping, new rooms, leaving, joining.'

New file test/integration_smoke.sh (focused, not bolted onto the
4000-line integration.sh). Each scenario:
  1. Uses the REAL gh substrate (no --no-gist, no --no-room).
  2. Spawns TWO real airc processes (host + joiner).
  3. Asserts user-visible outcomes (gist content, peer's local log,
     bearer state ticking).
  4. Cleans up every created gist on RETURN even on failure.
  5. Skips cleanly if gh missing/unauthed.

Scenarios:
  - passive_recv: A sends, B receives via polling without sending.
    THE missing test — would have caught every 'monitor frozen'
    report this session.
  - round_trip: A→B and B→A both arrive via polling.
  - idle_then_recv: 45s idle, B still receives. Validates #312
    bearer-heartbeat keeps the recv pipe alive across legitimate
    idle (pre-fix idle = pipe-stuck = monitor dead).
  - part_deletes_host_gist: airc part on host deletes the gist
    on gh; joiner's part doesn't.

All 4 pass live against the real gh substrate. Bumped per-scenario
wait window to 60s (gh poll cadence + bearer warmup + GET RTT can
exceed 30s on first-message after spawn).

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Apr 29, 2026
merge canary → main: bearer heartbeat + real-gh smoke tests (#312, #313)
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