Repository navigation
fix(heartbeat): fold cleanup into canonical exit trap - #101
Merged
Merged
Conversation
The heartbeat-cleanup trap I set inside the gist-publish block was being clobbered by the canonical cmd_connect exit trap set later in the same shell — bash traps are last-set-wins per shell. Effect: graceful Ctrl-C killed the acceptor + children but left the host gist orphaned, forcing the next joiner to wait ~90s for heartbeat staleness before taking over. Fix: stash heartbeat PID + gist id to scope-local files (heartbeat.pid, host_gist_id) at gist-publish time. The canonical exit trap reads those files and reaps everything in one place — accept loop, heartbeat loop, gist deletion, pidfile cleanup. cmd_part still does its own gist delete + room_gist_id cleanup as before; the trap is the defense-in-depth path for SIGTERM / Ctrl-C / Monitor-tab-close. Verification: scenario_heartbeat 8/8 still passes after restructure. airc.pid now correctly records host + acceptor + heartbeat PIDs. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes a bash trap-clobbering issue in cmd_connect host mode where the heartbeat/gist cleanup trap was being overwritten, leaving room gists orphaned on graceful exit (Ctrl‑C / SIGTERM). The PR centralizes heartbeat + gist cleanup into the canonical cmd_connect exit trap by persisting the heartbeat PID and gist id into scope-local state files.
Changes:
- Replace the heartbeat-site EXIT/INT/TERM trap with persisted state files (
heartbeat.pid,host_gist_id) for later cleanup. - Extend the canonical
cmd_connecttrap to kill the heartbeat loop and delete the hosted gist on graceful exit. - Include the heartbeat PID (when present) in
airc.pidsoairc teardowncan reap it.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2500
to
2511
| _exit_hb_pid="" | ||
| _exit_gist_id="" | ||
| [ -f "$AIRC_WRITE_DIR/heartbeat.pid" ] && _exit_hb_pid=$(cat "$AIRC_WRITE_DIR/heartbeat.pid" 2>/dev/null) | ||
| [ -f "$AIRC_WRITE_DIR/host_gist_id" ] && _exit_gist_id=$(cat "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null) | ||
| [ -n "$_exit_hb_pid" ] && kill $_exit_hb_pid 2>/dev/null | ||
| if [ -n "$_exit_gist_id" ] && command -v gh >/dev/null 2>&1; then | ||
| gh gist delete "$_exit_gist_id" --yes >/dev/null 2>&1 | ||
| fi | ||
| rm -f "$AIRC_WRITE_DIR/airc.pid" "$AIRC_WRITE_DIR/heartbeat.pid" "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null | ||
| for p in $PAIR_PID $(pgrep -P $PAIR_PID 2>/dev/null) $(pgrep -P $$ 2>/dev/null); do | ||
| kill $p 2>/dev/null | ||
| done |
Comment on lines
+2489
to
+2491
| _hb_pid_persisted="" | ||
| [ -f "$AIRC_WRITE_DIR/heartbeat.pid" ] && _hb_pid_persisted=$(cat "$AIRC_WRITE_DIR/heartbeat.pid" 2>/dev/null) | ||
| echo "$$ $PAIR_PID $_hb_pid_persisted" > "$AIRC_WRITE_DIR/airc.pid" |
Comment on lines
+2489
to
+2490
| _hb_pid_persisted="" | ||
| [ -f "$AIRC_WRITE_DIR/heartbeat.pid" ] && _hb_pid_persisted=$(cat "$AIRC_WRITE_DIR/heartbeat.pid" 2>/dev/null) |
Comment on lines
+2502
to
2510
| [ -f "$AIRC_WRITE_DIR/heartbeat.pid" ] && _exit_hb_pid=$(cat "$AIRC_WRITE_DIR/heartbeat.pid" 2>/dev/null) | ||
| [ -f "$AIRC_WRITE_DIR/host_gist_id" ] && _exit_gist_id=$(cat "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null) | ||
| [ -n "$_exit_hb_pid" ] && kill $_exit_hb_pid 2>/dev/null | ||
| if [ -n "$_exit_gist_id" ] && command -v gh >/dev/null 2>&1; then | ||
| gh gist delete "$_exit_gist_id" --yes >/dev/null 2>&1 | ||
| fi | ||
| rm -f "$AIRC_WRITE_DIR/airc.pid" "$AIRC_WRITE_DIR/heartbeat.pid" "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null | ||
| for p in $PAIR_PID $(pgrep -P $PAIR_PID 2>/dev/null) $(pgrep -P $$ 2>/dev/null); do | ||
| kill $p 2>/dev/null |
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]>
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
Trap-clobber fix discovered after PR #100 landed. Bash traps are last-set-wins per shell; my heartbeat-cleanup trap (set at gist-publish) was being silently overwritten by the canonical cmd_connect exit trap (set later). Effect: graceful Ctrl-C left host gist orphaned, forcing next joiner to wait 90s for heartbeat staleness.
Fix: single canonical trap reads heartbeat PID + gist id from scope-local files and reaps everything in one place.
Test plan
🤖 Generated with Claude Code