Skip to content

feat: heartbeat-in-gist for deterministic dead-host detection - #100

Merged
joelteply merged 1 commit into
canaryfrom
feat/heartbeat-gist-host-presence
Apr 25, 2026
Merged

joelteply merged 1 commit into
canaryfrom
feat/heartbeat-gist-host-presence

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Structural fix for the orphan-gist class. Hosts that died ungracefully (sleep, kill -9, OOM, bash-bg-and-die) left their room gist pointing at a corpse forever — every messy state cascade today's session traced to this missing presence signal.

  • Room gist now carries last_heartbeat; bg loop refreshes every 30s; EXIT/INT/TERM trap (bash) + Register-EngineEvent PowerShell.Exiting (ps1) deletes gist on graceful shutdown.
  • Joiner parses last_heartbeat, computes age (GNU/BSD date fallback), short-circuits SSH attempt + self-heals as new host if older than 90s.
  • Skill names: dropped misleading airc: prefix from YAML — /canary now displays + works consistently (was silently failing as /airc:canary).

Backward compat

  • old host + new joiner: no last_heartbeat → falls through to existing SSH-failure self-heal.
  • new host + old joiner: extra field ignored by old jq paths.
  • old host + old joiner: untouched.
  • new host + new joiner: deterministic takeover.

Test plan

  • scenario_heartbeat — kill -9 the host, verify joiner detects stale + takes over (8/8 on real gh)
  • scenario_room regression check (14/14)
  • Joel's macOS canary tab e2e after merge

🤖 Generated with Claude Code

Structural fix for the orphan-gist class. Hosts that died ungracefully
(sleep, kill -9, OOM, bash-bg-and-die) left their room gist pointing
at a corpse forever — every messy state cascade today's session traced
to this missing presence signal.

Changes:
- airc (bash) + airc.ps1: room gist envelope carries last_heartbeat;
  background loop refreshes every AIRC_HEARTBEAT_SEC (default 30s);
  EXIT/INT/TERM trap (bash) + Register-EngineEvent PowerShell.Exiting
  (ps1) deletes gist on graceful shutdown so peers don't even hit the
  stale window.
- Joiner-side: parse last_heartbeat, compute age (GNU date / BSD date
  fallback), short-circuit SSH attempt if older than AIRC_HEARTBEAT_STALE
  (default 90s = 3 missed beats) and self-heal as new host directly.
  Backward compat: gists without last_heartbeat treated as fresh; the
  existing SSH-failure self-heal still catches them.
- skills/*/SKILL.md: drop misleading 'airc:' prefix from YAML name
  fields. Slash-command resolution is by dirname, not YAML name; the
  prefix made /airc:canary look like a plugin-namespaced command (it
  isn't) and silently fail. /canary now displays + works consistently.
- test/integration.sh: scenario_heartbeat exercises the full failure
  shape end-to-end with real gh — host published, kill -9'd, joiner
  detects stale, deletes orphan gist, publishes fresh as new host.

Backward compat matrix (none of these break):
- old host + new joiner: no last_heartbeat → falls through to existing
  SSH-failure self-heal
- new host + old joiner: extra field ignored by old jq paths
- old host + old joiner: today's behavior, untouched
- new host + new joiner: deterministic takeover via heartbeat freshness

Verification:
- scenario_heartbeat: 8/8 pass on real gh
- scenario_room: 14/14 pass (no regression on inline-invite path)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings April 25, 2026 20:43
@joelteply
joelteply merged commit 32f28df into canary Apr 25, 2026
1 check passed
@joelteply
joelteply deleted the feat/heartbeat-gist-host-presence branch April 25, 2026 20: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

Adds a deterministic “host presence” signal to the GitHub room gist so joiners can detect dead hosts quickly and take over cleanly, plus aligns skill names by removing the airc: prefix.

Changes:

  • Add last_heartbeat to room gists; host refreshes it periodically; joiners treat stale heartbeat as positive evidence to take over.
  • Implement stale-heartbeat fast-path takeover in both bash (airc) and PowerShell (airc.ps1).
  • Rename skills to drop the airc: prefix and add an integration scenario to validate orphan-gist self-heal.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.

File Description
airc Adds heartbeat fields/loop and stale-heartbeat takeover logic in bash implementation.
airc.ps1 Adds heartbeat parsing/takeover + heartbeat refresh job and graceful cleanup on PowerShell exit.
test/integration.sh Adds scenario_heartbeat to validate heartbeat advance + stale takeover + gist replacement.
skills/*/SKILL.md Updates skill name: fields to remove the airc: prefix.

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

Comment thread test/integration.sh
Comment on lines +1438 to +1441
if ! gh auth status >/dev/null 2>&1; then
echo " (skipped — gh not authed: 'gh auth login -s gist')"
return
fi
Comment thread skills/canary/SKILL.md
Comment on lines 1 to 3
---
name: airc:canary
name: canary
description: Switch this airc install to the canary channel — pre-merge features queued for the next main release. Use when Joel asks you to test something that hasn't landed on main yet, or when you want the bleeding edge.
Comment thread airc.ps1
Comment on lines +2655 to +2658
# Track heartbeat job-id so cmd_part / teardown can
# stop it cleanly. Job is also killed automatically
# when this PowerShell process exits (Start-ThreadJob
# is in-process), which is the kill -9 / OOM path.
Comment thread airc
Comment on lines +2326 to +2329
trap "
kill $_hb_pid 2>/dev/null
gh gist delete '$_gist_id' --yes >/dev/null 2>&1
" EXIT INT TERM
Comment thread airc
Comment on lines +1701 to +1716
_hb_iso=$(printf '%s' "$raw_content" | jq -r '.last_heartbeat // empty' 2>/dev/null)
_hb_stale_sec="${AIRC_HEARTBEAT_STALE:-90}"
if [ -n "$_hb_iso" ]; then
# Convert ISO-8601 UTC to epoch. GNU date and BSD date
# have incompatible flags; try GNU first (linux + git-bash),
# fall back to BSD (mac default). If both fail (busybox?),
# skip the check rather than mis-classify.
_hb_ts=$(date -u -d "$_hb_iso" +%s 2>/dev/null \
|| date -u -j -f "%Y-%m-%dT%H:%M:%SZ" "$_hb_iso" +%s 2>/dev/null \
|| echo "")
if [ -n "$_hb_ts" ]; then
_now_ts=$(date -u +%s)
_resolved_heartbeat_age=$(( _now_ts - _hb_ts ))
if [ "$_resolved_heartbeat_age" -gt "$_hb_stale_sec" ]; then
_resolved_heartbeat_stale=1
fi
joelteply added a commit that referenced this pull request Apr 25, 2026
I dropped the airc: prefix in PR #100 thinking it was a broken
plugin-namespace string. Wrong diagnosis. The prefix is namespacing —
without it, /update, /list, /join, /version, /teardown collide with
any other skill in the user's ~/.claude/skills/ that uses the same
generic verb.

Reverts only the skill name change. Heartbeat work (#100, #101) stays.

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