Repository navigation
fix: 5 Copilot follow-ups on #92 (stale-pairing edge cases + winget pkg gaps) - #93
Conversation
…t pkg gaps) Five issues Copilot caught on PR #92's post-merge review, all real: 1. **(HIGH) gh api non-zero != gist deleted**: stale-pairing detect was wiping joiner state on ANY non-zero exit from `gh api gists/<id>`. Auth issues, missing scope, rate limits, transient network all fail non-zero — would trigger spurious teardown loops on flaky networks. Fix: gate on `gh auth status` succeeding first AND classify stderr for actual 404 / "Not Found" before triggering re-pair. Other failures fall through to the regular SSH probe. 2. **(HIGH) _preserved_name read AFTER rm of CONFIG**: get_name reads from config.json, so capturing it AFTER `rm -f $CONFIG` always returned "unknown". Result: every stale-pairing re-exec lost the user's identity. Fixed: capture preservedName BEFORE the deletes. Same fix in ps1. 3. **(MED) cmd_part comment lifecycle wrong**: comment at the joiner- side write-site of `room_gist_id` claimed "cleared by cmd_part" but joiner's cmd_part / Invoke-Part only removed `room_name`. Fix: also rm `room_gist_id` on joiner-part. Otherwise a parted- then-rejoined joiner would spuriously trigger stale-pairing detect on the next resume. 4. **(LOW) MINGW64* redundant in case-arm**: MINGW* already matches MINGW64_NT-* — drop the duplicate pattern. 5. **(MED) winget pkgname empty silent skip**: pkgname_for returned "" for ssh/openssl on Windows (bundled with OpenSSH/Git-for-Windows), and the install loop silently skipped — but if those bundles ARE missing, ensure_prereqs printed "Prereqs installed" and left the user broken. Fix: collect unmappable prereqs separately, surface them with platform-specific install guidance. 133/133 integration tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR follows up on PR #92 by hardening stale-pairing recovery (avoid false “gist deleted” detections and preserve joiner identity), aligning “part” behavior across bash/PowerShell, and tightening Windows/Git-Bash winget prereq handling so missing unmappable tools are surfaced clearly.
Changes:
- Stale-pairing detection now treats only authoritative 404s as “gist deleted” (bash + PowerShell) and preserves
AIRC_NAMEacross the re-exec path. - Joiner
partnow clearsroom_gist_idin addition toroom_name(bash + PowerShell) to prevent false stale-pairing triggers on resume. install.shremoves a redundant uname pattern and improves winget prereq reporting for commands without a winget package mapping.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
install.sh |
Refines Windows pkgmgr detection and improves winget prereq handling/reporting (including unmappable prereqs). |
airc |
Hardens stale-pairing detection (404-only) and preserves joiner identity across re-exec; clears cached gist id on joiner part. |
airc.ps1 |
Mirrors bash stale-pairing hardening + preserved name behavior; clears cached gist id on joiner part. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if [ ${#missing[@]} -gt 0 ]; then | ||
| info "Installing missing prereqs via $mgr: ${missing[*]}" | ||
| if install_with_pkgmgr "$mgr" "${pkgs[@]}"; then | ||
| ok "Prereqs installed" | ||
| else | ||
| warn "Package install reported failure; airc may not run until you fix: ${missing[*]}" | ||
| if [ ${#pkgs[@]} -gt 0 ]; then | ||
| if install_with_pkgmgr "$mgr" "${pkgs[@]}"; then | ||
| ok "Auto-installable prereqs installed" | ||
| else |
There was a problem hiding this comment.
ensure_prereqs always prints "Installing missing prereqs" even when all missing prereqs are unmappable (e.g., winget + missing openssl/ssh-keygen ⇒ pkgs is empty so nothing is actually installed). This is misleading for users and makes troubleshooting harder. Consider adjusting the messaging to only say "Installing..." when pkgs is non-empty, and otherwise print a "Missing prereqs" warning + the manual guidance.
| # Guard: only proceed if gh auth is healthy. If not, skip the | ||
| # check entirely — the regular SSH probe below handles network/ | ||
| # auth issues with their own diagnosis. We never want a flaky | ||
| # network to be misread as "the host's gist disappeared." | ||
| if gh auth status >/dev/null 2>&1; then | ||
| # Probe with --silent so gh's own error text doesn't pollute | ||
| # our output. Capture stderr for 404-vs-other classification. | ||
| local _gist_probe_err; _gist_probe_err=$(mktemp -t airc-gist-probe.XXXXXX) | ||
| gh api "gists/$_saved_gist_id" >/dev/null 2>"$_gist_probe_err" | ||
| local _gist_probe_rc=$? | ||
| local _gist_probe_stderr; _gist_probe_stderr=$(cat "$_gist_probe_err" 2>/dev/null) | ||
| rm -f "$_gist_probe_err" | ||
| # 404 (gist gone) shows as "Not Found" or "404" in gh's stderr. | ||
| # Other failures (rate limit "API rate limit", auth "401", | ||
| # network "could not resolve") are explicitly NOT treated as | ||
| # gist-deleted. | ||
| if [ "$_gist_probe_rc" -ne 0 ] && echo "$_gist_probe_stderr" | grep -qiE '404|not found'; then |
There was a problem hiding this comment.
The stale-pairing guard only checks gh auth status before running the gist probe, but elsewhere in the repo you explicitly note that gh auth status can succeed even when the token lacks gist scope. To align with that established behavior (and the comment here mentioning missing scope), gate this probe on gh auth status and a gist-scope check (similar to airc doctor --connect) so a scope-less token can’t be misinterpreted as a missing gist.
| # Probe with --silent so gh's own error text doesn't pollute | ||
| # our output. Capture stderr for 404-vs-other classification. | ||
| local _gist_probe_err; _gist_probe_err=$(mktemp -t airc-gist-probe.XXXXXX) | ||
| gh api "gists/$_saved_gist_id" >/dev/null 2>"$_gist_probe_err" |
There was a problem hiding this comment.
Comment says "Probe with --silent" but the gh api invocation doesn’t pass --silent (it relies on stdout/stderr redirection instead). Either add --silent or update the comment to match the actual behavior.
| gh api "gists/$_saved_gist_id" >/dev/null 2>"$_gist_probe_err" | |
| gh api --silent "gists/$_saved_gist_id" >/dev/null 2>"$_gist_probe_err" |
| & gh auth status 2>$null | Out-Null | ||
| if ($LASTEXITCODE -eq 0) { | ||
| # Capture stderr to distinguish 404 from other failures. | ||
| $probeErrFile = [System.IO.Path]::GetTempFileName() | ||
| & gh api "gists/$savedGistId" 1>$null 2>$probeErrFile | ||
| $probeRc = $LASTEXITCODE | ||
| $probeErrText = (Get-Content $probeErrFile -Raw -ErrorAction SilentlyContinue) -as [string] | ||
| Remove-Item $probeErrFile -Force -ErrorAction SilentlyContinue | ||
| if ($probeRc -ne 0 -and $probeErrText -match '(?i)\b(404|not found)\b') { | ||
| $preservedName = Get-Name 2>$null |
There was a problem hiding this comment.
Similar to the bash implementation, stale-pairing detect only gates on gh auth status, but the repo’s doctor flow treats “authed but missing gist scope” as a distinct state because gh auth status can still succeed. Consider checking for gist scope (parse gh auth status output) before treating a 404 as authoritative to avoid wiping joiner state under a scope-less token.
Round 2 of Copilot review on the stale-pairing safety + winget messaging: 1. install.sh: "Installing missing prereqs via winget: <list>" was being printed even when the list contained only unmappable items (winget has no auto-install for ssh-keygen/openssl). Pre-fix, the message claimed action that didn't happen. Now: only print "Installing..." when there's an actual pkg to install; print "Missing prereqs not auto-installable" otherwise. 2. bash + ps1 stale-pairing detect: was gating only on `gh auth status` succeeding, but elsewhere in the codebase (and doctor --connect specifically) we treat "authed but no gist scope" as distinct because gh's API can return 401/403/404 inconsistently when scope is missing. Now: gate on auth-status AND gist-scope present (matching doctor --connect chain) before running the gist freshness probe. 3. bash: comment claimed "Probe with --silent" but the flag wasn't passed; the redirection was actually doing the work. Updated comment to match the actual mechanism. 4. ps1: same as #2 - mirror the gist-scope check for parity. 133/133 integration tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Summary
Five issues Copilot caught on PR #92's post-merge review. Two are HIGH — preserved-name was always "unknown" because we deleted CONFIG before reading it, and stale-pairing-detect would falsely trigger on any non-404 gh failure (rate limits, network, auth). Three are smaller hygiene wins.
gh apinon-zero treated as gist-deleted; auth/rate-limit/network produced spurious teardown loopspreserved_nameread afterrm CONFIGso always "unknown" — identity lost on stale-gist re-execcmd_partclearsroom_gist_idbut joiner-side didn'tMINGW64*in pkgmgr case-arm (already matched byMINGW*)Fix shapes
#1: Gate stale-pairing detect on
gh auth statussucceeding first, then capture stderr fromgh apiand only treat actual404 / Not Foundas gist-deleted. Other failures fall through to the regular SSH probe path.#2: Capture
preservedNameBEFORE removing CONFIG. Otherwiseget_namereads the deleted file and falls back to a no-op default.#3: Joiner's
cmd_part/Invoke-Partnow removesroom_gist_idalongsideroom_name. Otherwise a parted-then-rejoined joiner would trigger stale-pairing detect spuriously on the next resume.#4: dropped redundant pattern.
#5: Track unmappable prereqs separately; surface with platform-specific install guidance instead of "all installed!" + silent broken state.
Test plan
🤖 Generated with Claude Code