Repository navigation
fix(teardown): delete hosted gist before kill -9 (no more bounce orphans) - #110
Conversation
…ans) cmd_teardown uses kill -9 on the host process tree. SIGKILL skips the EXIT/INT/TERM trap that cmd_connect sets up, so the trap-based gist cleanup never fired during a normal `airc teardown`. Result: every bounce (`airc teardown && airc join`) orphaned the prior gist. Joel's other tab observed this directly: three #general gists accumulated across three bounces today. Fix: cmd_teardown reads $AIRC_WRITE_DIR/host_gist_id BEFORE the kill, and explicitly `gh gist delete`s it. The pidfile write at host startup also writes host_gist_id, so this always finds the right id when the scope was hosting. Joiner scopes don't write host_gist_id, so this path no-ops for them. Trap-based cleanup at lines ~2515 still runs on Ctrl-C / SIGTERM (belt-and-suspenders). The kill -9 path now has its own explicit cleanup instead of relying on the unreachable trap. Verified: spawn host (forced unique room name), confirm gist exists, run teardown, confirm "deleted hosted gist: <id>" in output, confirm `gh api gists/<id>` 404s. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes bounce-cycle orphan gists by explicitly deleting the hosted room gist during airc teardown before force-killing the airc connect process tree (since kill -9 bypasses the EXIT trap that normally performs gist cleanup).
Changes:
- Add pre-
kill -9teardown logic to readhost_gist_idand delete the hosted gist viagh gist delete. - Remove the local
host_gist_idstate file during teardown after attempting gist deletion.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # bouncing repeatedly and accumulating fresh #general gists each | ||
| # cycle. | ||
| if [ -f "$AIRC_WRITE_DIR/host_gist_id" ] && command -v gh >/dev/null 2>&1; then | ||
| local _td_gist; _td_gist=$(cat "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null) |
There was a problem hiding this comment.
Because the script runs with set -euo pipefail, the cat in the assignment can abort cmd_teardown if host_gist_id is removed between the -f test and the read (or becomes unreadable). Consider making the read non-fatal (e.g., guard with || true or use if _td_gist=$(...); then ...) so teardown still proceeds to kill/reap processes even under this race.
| local _td_gist; _td_gist=$(cat "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null) | |
| local _td_gist; _td_gist=$(cat "$AIRC_WRITE_DIR/host_gist_id" 2>/dev/null || true) |
| fi | ||
| rm -f "$AIRC_WRITE_DIR/host_gist_id" |
There was a problem hiding this comment.
host_gist_id is removed even when gh gist delete fails (e.g., transient network/auth issues), which prevents a later teardown/cleanup from retrying and can still leave an orphan gist. Suggest only deleting the state file after a successful delete, or keeping it and emitting a warning when deletion fails.
| fi | |
| rm -f "$AIRC_WRITE_DIR/host_gist_id" | |
| rm -f "$AIRC_WRITE_DIR/host_gist_id" | |
| else | |
| echo " warning: failed to delete hosted gist: $_td_gist; keeping $AIRC_WRITE_DIR/host_gist_id for retry" >&2 | |
| fi |
test: add scenario_bounce + scenario_two_tab_localhost Two new integration scenarios catching real user-encountered bugs the existing tests missed: scenario_bounce — host → teardown → host. Verifies the teardown gist cleanup (#110) actually fires, AND that round-2 publishes a fresh gist without leaving an orphan from round 1. Catches the bounce-orphan class. Pre-#110: this would have failed with two competing gists. scenario_two_tab_localhost — A hosts, B joins via discovery, asserts B picked 127.0.0.1 (multi-address machine_id match) NOT the LAN or Tailscale IP. Catches multi-address regression. Pre-#109: this would have failed because B would have used whatever single address A advertised in the legacy host.address field. Both require gh + auth, skipped if unavailable. Both run quick (~10-15s each) since they use real gh round-trips but small data. Joel: "how are integration tests not actually able to test my scenario?" — they couldn't, because the existing scenarios all use --no-gist (sidesteps the actual gh substrate code path) and only spawn one joiner (no concurrent / lifecycle coverage). These two scenarios use the real gh path and exercise the lifecycle edges. Windows parity: still NONE. test/integration.sh is bash-only. A matching test/integration.ps1 with PS-native commands is needed for Windows users to verify their install. Tracked but not in this PR. Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Bounce-cycle orphan-gist fix. cmd_teardown's kill -9 skipped the EXIT trap, so hosted gists survived every
airc teardown. Now cmd_teardown reads host_gist_id and gh-gist-deletes it explicitly before killing the process tree. Verified e2e.