Skip to content

fix(monitor): surface degraded channel health - #455

Merged
joelteply merged 1 commit into
canaryfrom
fix/monitor-visible-failures
May 4, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/monitor-visible-failures

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • write bearer heartbeat timestamps into bearer_state without faking message receive timestamps
  • add airc status monitor health that fails closed when subscribed channels lack fresh heartbeat/pid evidence
  • show degraded monitor health from airc inbox, so Codex/non-Monitor runtimes see listener failures during normal catch-up
  • group heartbeat evidence by gist so channels sharing a wire after fix(monitor): isolate failed channel bearer restarts #452 do not false-alarm

Verification

  • bash -n airc lib/airc_bash/cmd_status.sh
  • python3 -m py_compile lib/airc_core/bearer_cli.py
  • git diff --check
  • python3 test/test_bearer.py
  • ./test/integration.sh inbox
  • live smoke: /private/tmp/airc-monitor-visible/airc status --probe showed monitor health for #general/#cambriantech; /private/tmp/airc-monitor-visible/airc inbox --peek exercised Codex catch-up path

This addresses the silent-failure class Joel flagged: wrapper/daemon presence is no longer enough; the UI surfaces actual bearer heartbeat evidence.

Copilot AI review requested due to automatic review settings May 4, 2026 17:01
@joelteply
joelteply merged commit c62f2f5 into canary May 4, 2026
8 checks passed
@joelteply
joelteply deleted the fix/monitor-visible-failures branch May 4, 2026 17:02

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 improves monitor observability by separating “bearer loop is alive” evidence (heartbeat) from “a real message was received” evidence, then surfacing per-channel degraded health in airc status and airc inbox (including multi-channel/shared-gist scenarios introduced in #452).

Changes:

  • Add last_heartbeat_ts tracking in bearer_state.*.json without mutating last_recv_ts.
  • Add per-channel monitor health reporting to airc status, and show degraded-only health summaries during airc inbox.
  • Extend unit tests to cover heartbeat touching behavior and ensure it does not fake receive timestamps.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/airc_core/bearer_cli.py Writes heartbeat timestamps into bearer state to distinguish idle-but-live from dead/wedged bearers.
lib/airc_bash/cmd_status.sh Adds a Python-backed monitor health report and surfaces degraded health from both status and inbox.
test/test_bearer.py Adds tests validating heartbeat state updates do not alter receive timestamps.

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

Comment on lines +466 to +480
def _touch_state_heartbeat(path: str, ts: float) -> None:
"""Record bearer-loop heartbeat without pretending a peer message arrived.

last_recv_ts remains the timestamp of the last real envelope. The
heartbeat timestamp lets `airc status` distinguish an idle but live
bearer from a dead channel, which is the signal users and agents need
when a monitor silently wedges.
"""
try:
with open(path) as f:
state = json.load(f)
except Exception:
state = {}
state["last_heartbeat_ts"] = ts
_write_state_file(path, state)
Comment on lines +36 to +69
subs = list(cfg.get("subscribed_channels") or [])
gists = dict(cfg.get("channel_gists") or {})
if not subs:
subs = list(gists.keys())
if not subs:
sys.exit(0)

def safe_gist(gist: str) -> str:
return "".join(c if c.isalnum() else "_" for c in gist)

def pid_alive(pid: int) -> bool:
if pid <= 0:
return False
try:
os.kill(pid, 0)
return True
except PermissionError:
return True
except OSError:
return False

state_cache = {}

def load_state(ch: str):
if ch in state_cache:
return state_cache[ch]
path = os.path.join(home, f"bearer_state.{ch}.json")
try:
state_cache[ch] = (json.load(open(path)), None, path)
except FileNotFoundError:
state_cache[ch] = ({}, "no bearer_state file", path)
except Exception as e:
state_cache[ch] = ({}, f"unreadable bearer_state: {e}", path)
return state_cache[ch]
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