Repository navigation
refactor(connect): always discover; delete resume code path (closes #130) - #131
Conversation
) The resume code path had its own SSH probe / stale-gist 404 self-heal / stale-auth recovery / unreachable-host takeover — all duplicated from the discovery + JOIN MODE flow. Worse, its SSH probe could "succeed" against an unreachable cached host (orphaned pair-listener answering on the cached port), printing "(SSH verified)" against a ghost. Outbound messages then vaporized; user couldn't tell paired from broken. Architectural fix: gist is the source of truth. Cached host_target / host_port / host_ssh_pub are stale snapshots of external substrate state. Every `airc connect` runs discovery and re-pairs fresh. Cost: one `gh gist list` (~200ms). Benefit: structurally impossible to print "(SSH verified)" against a host we haven't actually verified, and the entire "saved pairing diverged from gist" failure class disappears. What stays: identity (ssh keys, name, identity blob), peer records, saved room_name file (the one piece of cross-restart state worth trusting — which room you were last in). Discovery + JOIN MODE already handle stale-heartbeat takeover, TCP-unreachable self-heal, race-loser detection, and host_target overwrite on successful pair. Tests: removed five resume-specific scenarios whose assertions described code paths that no longer exist (resume_stale_auth, room_overrides_resume, stale_auth_room_selfheal, resume_404_gist_no_silent_exit, resume_prints_connected_banner). Added scenario_connect_after_kill_recovers which proves the architectural property end-to-end with real gh: pair, kill host, reconnect — assert no resume-banner ever prints, and beta lands in a working state. Net: 702 deletions, 159 insertions. Same end-state behavior under every recovery scenario the deleted resume code was trying to handle, just exercised through one path instead of two. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR refactors airc connect to remove the resume code path and make discovery via GitHub gists the single source of truth for reconnecting, while still honoring the persisted room_name file for cross-restart room targeting.
Changes:
- Remove the
cmd_connectresume branch so connect-time no longer trusts cachedhost_target/host_port/host_ssh_pub. - Add saved-room targeting: when
room_nameexists, a bareairc connectprefers that room over auto-scope. - Replace multiple resume-specific integration scenarios with a new “connect after kill recovers” architectural-property test.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
airc |
Deletes resume logic; always runs discovery; adds “resume saved room” targeting behavior. |
test/integration.sh |
Removes resume-path scenarios and adds scenario_connect_after_kill_recovers to validate the new always-discover reconnect property. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [ -z "$target" ] && \ | ||
| [ "${AIRC_NO_DISCOVERY:-0}" != "1" ] && \ | ||
| command -v gh >/dev/null 2>&1; then | ||
|
|
There was a problem hiding this comment.
The discovery gate now runs even when CONFIG has a cached host_target, but it only checks for gh on PATH. Under set -euo pipefail, any failure from the gh gist list/gh api calls in the discovery block (not authed, missing gist scope, rate-limit, transient network) can cause airc connect to exit early and silently (stderr is redirected). Consider adding an explicit gh health gate here (auth status + gist scope, and/or gh api 'gists?per_page=1') and capturing non-zero exit codes with the existing rc=0; cmd ... || rc=$? pattern so failures degrade to a clear error message instead of an abrupt exit.
| echo " (skipped — gh missing 'gist' scope; gh-health gate would short-circuit before the bug fires)" | ||
| echo " (skipped — gh not authed; discovery requires gh)" | ||
| return | ||
| fi |
There was a problem hiding this comment.
This scenario only checks gh auth status, but gh auth status can succeed even when the token is missing gist scope (the repo's own doctor --connect explicitly checks for gist). Without the scope, the test may run and then fail/hang for the wrong reason. Suggest adding a gh auth status | grep ... \bgist\b guard and skipping with a clear message when the scope is missing.
| fi | |
| fi | |
| if ! gh auth status 2>&1 | grep -Eq '\bgist\b'; then | |
| echo " (skipped — gh token missing gist scope; discovery requires gist)" | |
| return | |
| fi |
| # ── Kill alpha hard. SIGKILL bypasses alpha's EXIT trap, so alpha's | ||
| # gist is left STALE on gh (host process gone, gist still exists). | ||
| # This is the worst case: a cached pairing pointing at a dead host | ||
| # whose gist still resolves. | ||
| AIRC_HOME=/tmp/airc-it-cakr-h/state "$AIRC" teardown >/dev/null 2>&1 | ||
| # teardown deletes the gist gracefully — do that for round 1 to | ||
| # exercise the gist-gone case. (The TCP-unreachable-but-gist-alive | ||
| # case is exercised by scenario_two_tab_localhost's host-crash branch.) |
There was a problem hiding this comment.
The comment says “Kill alpha hard. SIGKILL bypasses alpha's EXIT trap, so alpha's gist is left STALE…”, but the code below calls airc teardown, which is the graceful path that does delete host_gist_id (and the test asserts the gist is gone). Please update the comment to match what the test is actually doing (gist-gone case via graceful teardown), or change the setup to a real hard-kill if you intend to exercise the stale-gist case.
| # ── Kill alpha hard. SIGKILL bypasses alpha's EXIT trap, so alpha's | |
| # gist is left STALE on gh (host process gone, gist still exists). | |
| # This is the worst case: a cached pairing pointing at a dead host | |
| # whose gist still resolves. | |
| AIRC_HOME=/tmp/airc-it-cakr-h/state "$AIRC" teardown >/dev/null 2>&1 | |
| # teardown deletes the gist gracefully — do that for round 1 to | |
| # exercise the gist-gone case. (The TCP-unreachable-but-gist-alive | |
| # case is exercised by scenario_two_tab_localhost's host-crash branch.) | |
| # ── Tear down alpha gracefully so its gist is deleted. | |
| # Round 1 intentionally exercises the gist-gone case: beta keeps a | |
| # cached pairing pointing at a dead host, and the host's gist no | |
| # longer resolves. | |
| AIRC_HOME=/tmp/airc-it-cakr-h/state "$AIRC" teardown >/dev/null 2>&1 | |
| # The TCP-unreachable-but-gist-alive case is exercised by | |
| # scenario_two_tab_localhost's host-crash branch. |
Summary
cmd_connect(~250 lines). Everyairc connectnow runs discovery; cachedhost_target/host_port/host_ssh_pubis never read at connect-time.room_namefile IS still honored — the one piece of cross-restart state worth trusting. Auto-scope only fires when no saved room exists._saved_host_targetgate from the discovery condition.Why
The resume path had duplicated implementations of stale-gist 404 self-heal, stale-auth recovery, and unreachable-host takeover — all already present in the discovery + JOIN MODE flow. Worse, the resume SSH probe could "succeed" against an unreachable cached host (orphaned pair-listener answering on the cached port), printing
(SSH verified)against a ghost. Outboundairc msgto such a "verified" peer then vaporized silently — the silent-success failure mode #130 surfaced.Architectural fix: gist is the source of truth. Cached pairing state is a snapshot, not truth. Always re-derive from the gist. Cost: one
gh gist list(~200ms) per connect. Benefit: the entire "saved pairing diverged from gist" failure class is structurally impossible.Test plan
bash test/integration.sh connect_after_kill_recovers— new scenario, 7 passes. Pairs alpha+beta with a real gist, kills alpha, runs beta's reconnect, asserts NOResumed as joiner ... (SSH verified)banner and that beta lands in a working state for the room.bash test/integration.sh auto_scope— 4 passes. Saved-room read doesn't shadow auto-scope on fresh state.bash test/integration.sh bounce— 4 passes. Host teardown + rehost still cleans up the gist.bash test/integration.sh room— 14 passes. Basic --room plumbing intact.bash test/integration.sh general_sidecar_default— 12 passes. Sidecar spawn + opt-out flags still work.bash test/integration.sh send_room_flag— 8 passes. --room flag routing intact (fix(send): honor --room flag instead of silent-routing to current scope #123 unaffected).airc connectagain. No(SSH verified)against the dead host; instead, discovery + multi-address pick into a live host.Pre-existing orphan-survival bugs (Python pair-listener and
airc connectbash surviving when their launching subshell dies, holding ports indefinitely) are independent of this fix and need a separate PR — they're what was making the full integration suite hang on cleanup. 181 passes, 3 pre-existing failures (rename marker / port still held / outage simulation), all orphan-related.Net diff
2 files changed, 159 insertions(+), 702 deletions(-)🤖 Generated with Claude Code