Skip to content

fix: 5 Copilot follow-ups on #92 (stale-pairing edge cases + winget pkg gaps) - #93

Merged
joelteply merged 2 commits into
canaryfrom
fix/copilot-92-followup
Apr 25, 2026
Merged

joelteply merged 2 commits into
canaryfrom
fix/copilot-92-followup

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

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.

# Sev What Where
1 HIGH gh api non-zero treated as gist-deleted; auth/rate-limit/network produced spurious teardown loops bash + ps1
2 HIGH preserved_name read after rm CONFIG so always "unknown" — identity lost on stale-gist re-exec bash + ps1
3 MED comment claimed cmd_part clears room_gist_id but joiner-side didn't bash + ps1
4 LOW redundant MINGW64* in pkgmgr case-arm (already matched by MINGW*) install.sh
5 MED winget empty-pkgname silently skipped ssh/openssl, leaving user with "installed" + broken state install.sh

Fix shapes

#1: Gate stale-pairing detect on gh auth status succeeding first, then capture stderr from gh api and only treat actual 404 / Not Found as gist-deleted. Other failures fall through to the regular SSH probe path.

#2: Capture preservedName BEFORE removing CONFIG. Otherwise get_name reads the deleted file and falls back to a no-op default.

#3: Joiner's cmd_part / Invoke-Part now removes room_gist_id alongside room_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

  • 133/133 integration tests pass
  • Bash + ps1 syntax checks
  • Live verify on Toby's AWS Windows Server 2022 VM

🤖 Generated with Claude Code

…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]>
Copilot AI review requested due to automatic review settings April 25, 2026 18:21

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 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_NAME across the re-exec path.
  • Joiner part now clears room_gist_id in addition to room_name (bash + PowerShell) to prevent false stale-pairing triggers on resume.
  • install.sh removes 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.

Comment thread install.sh
Comment on lines 184 to +189
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

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.

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.

Copilot uses AI. Check for mistakes.
Comment thread airc Outdated
Comment on lines +1321 to +1337
# 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

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.

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.

Copilot uses AI. Check for mistakes.
Comment thread airc
# 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"

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.

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.

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

Copilot uses AI. Check for mistakes.
Comment thread airc.ps1
Comment on lines +2154 to +2163
& 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

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.

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.

Copilot uses AI. Check for mistakes.
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]>
@joelteply
joelteply merged commit 00dc00a into canary Apr 25, 2026
1 check passed
@joelteply
joelteply deleted the fix/copilot-92-followup branch April 25, 2026 18:32
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