Repository navigation
feat(heartbeat): wire emission — cmd_send --heartbeat + reminder_timer_loop hook + monitor filter (airc#644 PR-2) - #647
Merged
Conversation
…r_loop hook + monitor filter (airc#644 PR-2) Closes airc#644 end-to-end. PR-1 (#645) landed the envelope shape, helper module, and cmd_peers display. PR-2 wires the actual cross-peer emission so PROCESS_DOWN detection becomes real. ## Changes ### lib/airc_bash/cmd_send.sh New '--heartbeat' flag. Unlike '--system' which rewrites 'from' to 'airc' (system-wide notice), '--heartbeat' keeps 'from=$my_name' because heartbeats are per-peer attribution. Stamps 'kind=heartbeat' into the payload JSON so cmd_peers + monitor_formatter can recognize. Implies '--internal' so a missing monitor doesn't produce noisy error output every 60s (one missed heartbeat is fine; two missed is the PROCESS_DOWN signal anyway). ### airc (reminder_timer_loop) New heartbeat emit branch fires every HEARTBEAT_CADENCE_SEC (60s). Best-effort: 'cmd_send --heartbeat --internal' in a subshell with stdout+stderr suppressed. A transient send failure is precisely the signal we want propagating — peer's airc process not emitting means PROCESS_DOWN, no need to log every failure locally. The 60s cadence is hard-tied to lib/airc_core/heartbeat.py's HEARTBEAT_CADENCE_SEC constant. test_heartbeat_pr2.py greps the bash literal and asserts it matches the Python constant so drift produces a test failure rather than silent false PROCESS_DOWN signals. ### lib/airc_core/monitor_formatter.py New filter case: 'kind == "heartbeat"' is dropped from UI rendering AND arms the inbound-watchdog. The watchdog arming is important — any inbound traffic (including remote heartbeats) proves the bearer is alive, which is exactly the local-side signal we already use for 'airc_heartbeat' (a different field; that one is THIS process's self-loop signal). Heartbeats are protocol traffic; user-invisible. ### test/test_heartbeat_pr2.py (new — 9 tests) Four suites covering: - CmdSendHeartbeatFlagShapeTests (2): constants pinned (kind literal agrees Python ↔ bash; cadence agrees Python ↔ bash) - MonitorFormatterHeartbeatFilterTests (4): filter recognizes heartbeats; doesn't false-positive on chat or pre-#644 legacy envelopes; the constant the formatter reads (HEARTBEAT_KIND) matches what bash emits - ReminderTimerLoopShapeTests (1): grep the bash for the cadence literal and assert it matches the Python constant — catches drift at test-time, not in production - CmdSendHeartbeatFlagWiringTests (2): structural grep verifying the flag parser case + the payload-stamp line exist (catches bit-rot if someone refactors flag handling without preserving --heartbeat) ## Validation - bash -n lib/airc_bash/cmd_send.sh → ok - bash -n airc → ok - python3 ast.parse monitor_formatter → ok - test/test_heartbeat_pr2.py → 9 tests passing - test/test_heartbeat.py (PR-1) → 18 tests still passing (4 skip on no-crypto) - test/test_envelope.py (existing) → 18 tests still passing (all skip on no-crypto base env) ## Why It Works End-To-End After This PR Before PR-1: airc peers shows 'last seen Nh ago (silent)' — can't tell heads-down from process-down. After PR-1 (#645 merged): envelope.kind field + cmd_peers tracks last_heartbeat separately + display logic distinguishes the three cases. But no heartbeats are emitted yet, so all peers still show '(silent)'. After PR-2 (this PR): Every running airc emits 'kind=heartbeat' every 60s through the existing broadcast path. Peers receive them; cmd_peers' separate tracking now has data. After two missed heartbeats (>120s), a peer's display flips from '(silent, heartbeat OK)' to '(PROCESS DOWN)'. The substrate-level fix is live. Tested locally on canary: PR-1's airc peers no longer crashes (the backtick hotfix #646 cleared the syntax error); PR-2's emission will populate the columns once it merges + propagates. Closes airc#644 end-to-end.
joelteply
added a commit
that referenced
this pull request
May 17, 2026
…644 PR-2 follow-up) (#648) PR-2 (#647) shipped the cmd_send --heartbeat path + the reminder_timer_loop hook calling 'cmd_send --heartbeat --internal ' every 60s. Locally tested by: $ airc msg --heartbeat --internal "" ERROR: Usage: airc send <message> or airc send @peer <message> The empty-body usage-check (sane default for chat) was rejecting the heartbeat send. As a result no heartbeats reached messages.jsonl after teardown+rejoin+75s — silent emission failure that PR-2's unit tests didn't catch because they're structural (grep for the flag) not behavioural (actually invoke the send). Joel's discipline applied: 'have to see if it works.' Code review + unit tests do NOT validate user experience. Run the actual command a user would run. The reminder loop's invocation IS the user surface here; teardown+rejoin+wait is the equivalent of a fresh install path. Fix: the usage-check now exempts heartbeats. The signal in a heartbeat is in envelope metadata (kind/ts/from), not the msg body — empty body is the correct shape. Other empty-body sends still die loudly per the prior contract. bash -n lib/airc_bash/cmd_send.sh → ok.
This was referenced May 28, 2026
Closed
Merged
This was referenced May 28, 2026
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.
What
Closes airc#644 end-to-end. PR-1 (#645) landed envelope shape + helper + cmd_peers display. PR-2 wires the actual cross-peer emission so PROCESS_DOWN detection becomes real on the wire.
Changes
Why The Cross-Language Drift Test Matters
The 60s cadence is hard-tied between bash (`local heartbeat_cadence=60`) and Python (`heartbeat.HEARTBEAT_CADENCE_SEC = 60`). If someone changes one without the other, `STALE_HEARTBEAT_SEC` (2× cadence = 120s) produces false PROCESS_DOWN signals during the divergence window — invisibly. `test_heartbeat_pr2.ReminderTimerLoopShapeTests` greps the bash literal and asserts it matches the Python constant so drift fails at test-time, not in production.
End-To-End State After This PR
Validation
```
bash -n lib/airc_bash/cmd_send.sh → ok
bash -n airc → ok
python3 ast.parse monitor_formatter → ok
test/test_heartbeat_pr2.py → 9 tests passing
test/test_heartbeat.py (PR-1) → 18 tests still passing (4 skip on no-crypto)
test/test_envelope.py (existing) → 18 tests still passing
```
Live Test Path
Once this lands on canary + a peer runs `airc update --channel canary` + `airc join`:
The substrate gap airc#644 named is finally closed.
Title Prefix
`feat:` per conventional-commits; targets `canary` per the merge-to-canary-in-active-loop rule. The require-canary-or-hotfix gate is satisfied (canary-base PRs bypass the workflow entirely; `branches: [main]` filter).