Skip to content

fix(teardown): delete hosted gist before kill -9 (no more bounce orphans) - #110

Merged
joelteply merged 1 commit into
canaryfrom
fix/teardown-deletes-host-gist
Apr 25, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/teardown-deletes-host-gist

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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.

…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]>
Copilot AI review requested due to automatic review settings April 25, 2026 22:22
@joelteply
joelteply merged commit 6370eac into canary Apr 25, 2026
@joelteply
joelteply deleted the fix/teardown-deletes-host-gist branch April 25, 2026 22:22

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

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 -9 teardown logic to read host_gist_id and delete the hosted gist via gh gist delete.
  • Remove the local host_gist_id state file during teardown after attempting gist deletion.

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

Comment thread airc
# 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)

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread airc
Comment on lines +3880 to +3881
fi
rm -f "$AIRC_WRITE_DIR/host_gist_id"

Copilot AI Apr 25, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
joelteply added a commit that referenced this pull request Apr 25, 2026
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]>
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