Repository navigation
fix(monitor): surface degraded channel health - #455
Merged
Merged
Conversation
There was a problem hiding this comment.
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_tstracking inbearer_state.*.jsonwithout mutatinglast_recv_ts. - Add per-channel monitor health reporting to
airc status, and show degraded-only health summaries duringairc 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
airc statusmonitor health that fails closed when subscribed channels lack fresh heartbeat/pid evidenceairc inbox, so Codex/non-Monitor runtimes see listener failures during normal catch-upVerification
bash -n airc lib/airc_bash/cmd_status.shpython3 -m py_compile lib/airc_core/bearer_cli.pygit diff --checkpython3 test/test_bearer.py./test/integration.sh inbox/private/tmp/airc-monitor-visible/airc status --probeshowed monitor health for #general/#cambriantech;/private/tmp/airc-monitor-visible/airc inbox --peekexercised Codex catch-up pathThis addresses the silent-failure class Joel flagged: wrapper/daemon presence is no longer enough; the UI surfaces actual bearer heartbeat evidence.