Skip to content

fix(monitor): isolate failed channel bearer restarts - #452

Merged
joelteply merged 1 commit into
canaryfrom
fix/channel-monitor-heal
May 4, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/channel-monitor-heal

Conversation

@joelteply

@joelteply joelteply commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • keep healthy channel bearers running when one subscribed channel bearer dies
  • restart only the failed channel after re-reading its latest channel_gists mapping
  • leave channels with missing mappings offline without breaking other subscribed channels
  • change recv lock natural key from per-channel state-file to per-scope/per-gist so two channel labels mapped to the same gist do not spawn duplicate bearers

Why

Two common monitor failures were found live:

  1. A stale/flaky project-room gist can poison the whole multi-channel monitor because one bearer death kills all other channel bearers and rebuilds the formatter pipe. Healthy rooms like #general should keep flowing while the bad channel retries.
  2. Two subscribed channel labels can resolve to the same gist. The fix(bearer): per-(scope, channel, gist) lock prevents duplicate emission #451 lock keyed by state-file allowed both bearers to run, so each yielded every message. Gist is the wire; channel is the display label.

Verification

  • bash -n airc
  • git diff --check
  • ./test/integration.sh inbox
  • python3 -m py_compile lib/airc_core/bearer_cli.py
  • python3 test/test_bearer.py (90 tests OK)

QA ask

Please test both common scenarios:

  • healthy room + stale/flaky room: failed channel logs/retries, healthy channel messages continue
  • two channel_gists entries pointing at the same gist: only one bearer should claim the gist lock; messages should emit once.

Copilot AI review requested due to automatic review settings May 4, 2026 16:39
@joelteply
joelteply force-pushed the fix/channel-monitor-heal branch from eb18985 to d65fae9 Compare May 4, 2026 16:43

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 updates airc’s multi-channel monitor so an individual bearer_cli recv failure is handled per-channel instead of tearing down the entire multi-channel monitor. It fits into the monitor/self-heal path by trying to preserve healthy channel delivery while retrying only the failed subscription.

Changes:

  • Replaced the “one child dies → restart everything” watch loop with per-channel restart logic.
  • Re-read channel_gists for the failed channel before respawning, so gist rotation can be picked up without rebuilding the whole formatter pipe.
  • Leave channels with missing mappings offline instead of killing other active channel bearers.

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

Comment thread airc
Comment on lines +1366 to +1373
if [ -n "$gid" ]; then
sleep 3
"$AIRC_PYTHON" -u -m airc_core.bearer_cli recv "self" \
--room-gist-id "$gid" \
--offset-file "$AIRC_WRITE_DIR/monitor_offset.${ch}" \
--state-file "$AIRC_WRITE_DIR/bearer_state.${ch}.json" \
2>>"$AIRC_WRITE_DIR/bearer_recv.${ch}.log" &
_alive+=("$!:$ch")
Comment thread airc
Comment on lines +1374 to +1375
else
echo "airc: #${ch} has no channel_gists mapping; leaving it offline while other channels continue" >&2
Comment thread airc
Comment on lines +1352 to +1356
echo "airc: bearer recv for #${ch} died — see ${AIRC_WRITE_DIR}/bearer_recv.${ch}.log; restarting that channel only" >&2
# Surface the last-error tail so the user sees WHY without
# having to know to read the log file.
if [ -s "$AIRC_WRITE_DIR/bearer_recv.${ch}.log" ]; then
tail -3 "$AIRC_WRITE_DIR/bearer_recv.${ch}.log" | sed 's/^/airc: /' >&2
@joelteply
joelteply merged commit 9ef316c into canary May 4, 2026
6 checks passed
@joelteply
joelteply deleted the fix/channel-monitor-heal branch May 4, 2026 16:44
joelteply added a commit that referenced this pull request May 4, 2026
…inite respawn loop when channels share a gist (#458)

fix(monitor): dedup bearer spawns by gist, not by channel

Real-world repro Joel hit 2026-05-04: channel_gists collapsed
useideem and general onto the SAME gist (host advertising one mesh
gist for both subscribed channels). #452's per-(scope, gist) lock
correctly admitted only ONE bearer for that gist — but the bash
supervisor in _monitor_multi_channel iterated channels and spawned
one bearer per channel REGARDLESS of gist sharing. Result: the
lock-loser bearer exits 0 cleanly with "another bearer for gist X
already running"; supervisor sees the exit as a death, respawns,
loses lock again, ad infinitum. bearer_recv.<ch>.log filled with
identical exit-cleanly lines, the channel's events_total stayed at
0, and inbound messages on that channel never reached the user.

This was the third bearer-related design-mismatch bug in the same
session (#451 was process lifecycle, #452 was the lock-key
mismatch, this is the supervisor-key mismatch). Fixing at the
supervisor: dedup by gist BEFORE spawning. Same invariant in both
paths:

  - Initial spawn (channel_map iteration): track _served_gists set;
    skip channels whose gist already has a bearer from earlier in
    the iteration.
  - Live-refresh add path: build _live_gists from current _pids
    (resolving each entry's channel→gist via the current map);
    skip channels whose gist is already covered by another live
    bearer.

The bearer reads the gist once and yields each line; monitor_formatter
routes to subscribed channels via the envelope's `channel` field
downstream. State files stay per-channel for now (per-gist state-
files would be a deeper refactor that touches status/doctor/cmd_send;
not blocking tonight's Toby remote-conn test).

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