Skip to content

refactor(connect): always discover; delete resume code path (closes #130) - #131

Merged
joelteply merged 1 commit into
canaryfrom
joel/connect-always-discover-130
Apr 27, 2026
Merged

joelteply merged 1 commit into
canaryfrom
joel/connect-always-discover-130

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • Delete the entire resume code path in cmd_connect (~250 lines). Every airc connect now runs discovery; cached host_target / host_port / host_ssh_pub is never read at connect-time.
  • Saved room_name file IS still honored — the one piece of cross-restart state worth trusting. Auto-scope only fires when no saved room exists.
  • Drop the _saved_host_target gate from the discovery condition.
  • Replace 5 resume-specific test scenarios (whose assertions describe code paths that no longer exist) with one new architectural-property test.

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. Outbound airc msg to 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 NO Resumed 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).
  • Smoke: pair, kill host, run airc connect again. 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 connect bash 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

)

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]>
Copilot AI review requested due to automatic review settings April 27, 2026 00:06
@joelteply
joelteply merged commit 83cd508 into canary Apr 27, 2026
2 checks passed
@joelteply
joelteply deleted the joel/connect-always-discover-130 branch April 27, 2026 00:06

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

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_connect resume branch so connect-time no longer trusts cached host_target / host_port / host_ssh_pub.
  • Add saved-room targeting: when room_name exists, a bare airc connect prefers 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.

Comment thread airc
Comment on lines +1878 to 1881
if [ -z "$target" ] && \
[ "${AIRC_NO_DISCOVERY:-0}" != "1" ] && \
command -v gh >/dev/null 2>&1; then

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
Comment thread test/integration.sh
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

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

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.

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

Copilot uses AI. Check for mistakes.
Comment thread test/integration.sh
Comment on lines +1903 to +1910
# ── 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.)

Copilot AI Apr 27, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
# ── 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.

Copilot uses AI. Check for mistakes.
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