Skip to content

fix(picker,host): joiner reachability + Windows host LAN enumeration - #397

Merged
joelteply merged 1 commit into
canaryfrom
fix/picker-reachability-and-windows-host-lan
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/picker-reachability-and-windows-host-lan

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

Two cross-machine bugs uncovered when Joel's Windows peer hosted #cambriantech and a Mac without Tailscale tried to join. The Mac's monitor self-healed and demolished the working room gist because its picker chose a Tailscale address it couldn't reach.

  • Bug A (joiner picker, destructive): post-fix(picker): fallback skips localhost so cross-machine joiners do not dial 127.0.0.1 #393 fallback picked tailscale entries even when the joiner had no Tailscale interface. Picking an unroutable scope is worse than picking nothing — empty falls through to gh-bearer-only routing; a doomed dial triggers the destructive self-heal-as-new-host chain that nukes the gist for everyone else too.
  • Bug B (Windows host LAN enumeration): host_address_set used ifconfig to enumerate LAN IPs, but Git Bash on Windows has no ifconfig — Windows uses ipconfig. Result: Windows hosts emitted only [localhost, tailscale] in host.addresses[], blocking same-LAN joiners from connecting directly.

Fix

Bug A — joiner reachability gating:

  1. New gistparse subcommand pick_addr_excluding <scope>+ filters multiple scopes at once.
  2. New _have_tailscale_locally() helper probes for usable Tailscale (binary signed-in OR 100.x interface present).
  3. peer_pick_address restored Tailscale-pick path BUT gated on local presence.
  4. Final fallback uses pick_addr_excluding localhost tailscale — empty return → gh-bearer-only routing as designed.

Bug B — Windows ipconfig path:

  • host_address_set adds MINGW*/MSYS*/CYGWIN* branch parsing ipconfig output (CRLF-stripped, IPv4 Address. . : lines split on : , last field). Same loopback/link-local/CGNAT filtering as the ifconfig path.

Tests

  • test/test_gistparse.py (new, 10/10 passing): pick_addr_excluding happy paths, empty-returns, malformed input, pick_addr_nonlocal_first backward-compat.
  • bash syntax clean.
  • Synthetic Windows ipconfig output → parser correctly extracts real LANs (192.168.1.42, 10.0.0.50) and excludes 100.x (Tailscale CGNAT, handled separately).

Test plan

  • CI green (Python tests + bash syntax)
  • Live: Mac without Tailscale joining a Windows host → no destructive self-heal
  • Live: Windows host's host.addresses[] includes lan|<ip>|... entries (verifiable via gh api gists/<id> after host comes online)
  • Live: Mac WITH Tailscale joining same-tailnet host → still picks tailscale (regression check)

Out of scope (separate PR)

Self-heal guard in cmd_connect.sh:1050 — even with Bug A fixed, the self-heal still demolishes the gist when the handshake fails for ANY reason (e.g. TCP timeout on a routable address class because of firewall). Worth a guard like "only self-heal after N failed attempts on a believed-reachable address" — bigger refactor, separate PR.

🤖 Generated with Claude Code

Two cross-machine bugs uncovered when Joel's Windows peer hosted
#cambriantech and a Mac without Tailscale tried to join:

## Bug A — joiner picker dialed unreachable Tailscale (DESTRUCTIVE)

Symptom (live, 2026-05-02): Mac monitor self-healed and DEMOLISHED
the working room gist because its picker chose Windows host's
tailscale 100.x address. Mac had no Tailscale → TCP connect failed →
"host unreachable" → self-heal-as-new-host triggered → gist deleted.
Other peers happily talking to the host suddenly orphaned.

Root cause: the post-#393 fallback (`pick_addr_nonlocal_first`)
correctly skipped localhost but still picked tailscale even when
the joiner had no tailscale interface. Picking an unroutable
scope is worse than picking nothing — empty return falls through
to gh-bearer-only routing (broadcasts still work); a doomed dial
triggers the destructive self-heal chain.

Fix:
  1. New gistparse subcommand `pick_addr_excluding <scope>+` that
     filters multiple scopes at once. Returns empty if every entry
     is excluded.
  2. New `_have_tailscale_locally()` bash helper that probes for
     a usable Tailscale (binary signed-in OR 100.x interface).
  3. `peer_pick_address` restored Tailscale-pick path BUT gated on
     local presence — only picks tailscale entries when this peer
     can actually route to them.
  4. Final fallback now calls `pick_addr_excluding localhost
     tailscale` since both have already been tried with proper
     reachability checks. Empty return = caller falls through to
     gh-bearer-only routing as designed.

## Bug B — Windows host emitted only [localhost, tailscale]

Symptom: Windows host's `host.addresses[]` had no `lan` entry, so
same-LAN Mac joiners couldn't reach it directly (had to fall back
to Tailscale, which then triggered Bug A).

Root cause: `host_address_set` used `ifconfig` to enumerate LAN
IPs. Git Bash on Windows has no `ifconfig` — Windows uses
`ipconfig`. The bash command silently returned nothing on Windows,
so no `lan|...` lines were emitted.

Fix: add `MINGW*/MSYS*/CYGWIN*` branch to `host_address_set` that
parses `ipconfig` output (CRLF-stripped, "IPv4 Address. . :"
lines split on `: `, last field). Same loopback/link-local/CGNAT
filtering as the ifconfig path.

## Tests

- `test/test_gistparse.py` (new, 10/10 passing): covers
  `pick_addr_excluding` happy paths, empty-returns, malformed
  input, and `pick_addr_nonlocal_first` backward-compat.
- bash syntax clean.
- Synthetic Windows ipconfig output → parser extracts 192.168.1.42
  + 10.0.0.50 (real LANs) and correctly excludes 100.x (Tailscale
  CGNAT, handled by the separate Tailscale block).

## Out of scope (separate PR)

- Self-heal guard: even with Bug A fixed, the self-heal in
  cmd_connect.sh:1050 still demolishes the gist when handshake
  fails for ANY reason. Future bug: a TCP timeout on a routable
  address class (e.g. host firewall blocking the port) still
  triggers the destructive chain. Worth a guard like "only
  self-heal if we picked an address we believed reachable AND
  it failed AFTER N attempts" — but bigger refactor, separate PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 03:28
@joelteply
joelteply merged commit 7853bf7 into canary May 2, 2026
8 checks passed
@joelteply
joelteply deleted the fix/picker-reachability-and-windows-host-lan branch May 2, 2026 03:29

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 two cross-machine connectivity issues in the address selection + host address publication flow used during airc connect join, especially for Windows hosts and non-Tailscale joiners.

Changes:

  • Adds gistparse pick_addr_excluding to allow joiners to skip multiple unreachable address scopes.
  • Restores Tailscale address picking in peer_pick_address, gated by a new local Tailscale presence probe.
  • Extends host_address_set to enumerate LAN IPv4 addresses on Windows Git Bash via ipconfig.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
test/test_gistparse.py New unit tests covering pick_addr_excluding and backward-compat for pick_addr_nonlocal_first.
lib/airc_core/gistparse.py Adds new pick_addr_excluding subcommand to filter out multiple scopes when choosing an address.
airc Windows LAN IP enumeration via ipconfig; joiner-side Tailscale reachability gating + updated fallback picker.

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

Comment thread airc
Comment on lines +940 to +948
local ts_out; ts_out=$("$ts_bin" status 2>&1) || true
case "$ts_out" in
*"Logged out"*|*"NeedsLogin"*|*"stopped"*) ;; # daemon down / signed out
*)
# Anything else from `tailscale status` (including the IP
# listing or "Tailscale is running") means we can route.
return 0
;;
esac
Comment thread airc
Comment on lines +906 to +917
# Fallback: first entry whose scope we can REACH. We've already
# tried localhost (machine_id match), lan (subnet match), and
# tailscale (local-presence check) above. What remains in
# addresses[] is some scope we don't model — e.g. a future "wan"
# entry, or a bespoke routing tag — give that a chance instead of
# ignoring it. But excluding localhost and tailscale here ensures
# we don't dial them blindly: localhost would mean our own loopback
# (never the host), and tailscale was already gated above on local
# presence — picking it here would re-introduce the destructive
# self-heal chain. Empty return → caller falls through to
# gh-bearer-only routing (broadcast still works; direct pair
# skipped).
continue
addr = entry.get("addr", "")
port = entry.get("port", "")
if addr and port != "":
Comment thread test/test_gistparse.py
Comment on lines +57 to +60
# Tailscale was first in the list after exclusion; lan was second.
# First-after-exclusion wins, so this should be lan if lan came first.
# Order in input: [localhost, lan, tailscale] → after excluding
# localhost: [lan, tailscale] → first = lan.
joelteply added a commit that referenced this pull request May 2, 2026
…(Bug C from #397) (#398)

fix(self-heal): don't nuke host's gist when picker found no reachable scope

Bug uncovered by the same 2026-05-02 incident as #397. The address-picker
fix in #397 prevents the most common shape (joiner picks unreachable
tailscale on a Mac without tailnet), but a second path remained: when
peer_pick_address returns empty, the caller falls through to the
invite-string ssh_target. That fallback dial fails the same way —
no route — and triggers the destructive self-heal-as-new-host chain
that DELETES the host's gist for every other peer on the substrate.

Concrete failure shape (now defended against):
  - Mac without Tailscale joins room hosted by Windows host whose
    addresses[] is [localhost, lan, tailscale].
  - Picker correctly excludes localhost (other machine) and tailscale
    (no local tailnet), and the LAN scope's subnet doesn't match (Mac
    is on a different /24). Result: empty pick.
  - ssh_target stays at the invite-string default (Windows host's
    advertised primary, often tailscale on Windows pre-#397 hosts).
  - TCP handshake fails.
  - Pre-fix: self-heal triggers, gh deletes the gist, Mac re-execs as
    new host. Three other peers still happily talking to the Windows
    host suddenly orphaned because the gist is gone.

Fix: track the picker outcome in `_addr_picker_state` ("no_addrs",
"picked", "no_match") and gate the self-heal block on it. Self-heal
only fires when:
  1. Original conditions: room context + gh CLI + handshake failed
  2. NEW: picker either succeeded OR there were no addresses[] to
     pick from (legacy gists / no multi-address protocol). Picker-
     ran-but-found-no-match means THIS peer's network mismatch, not
     host-down — nuking would damage other peers.

When skipped: surface explicit message ("published no scope this peer
can reach. Skipping self-heal. Direct pair unavailable; gh-bearer
broadcasts still work via gist") so users debugging "why didn't I
auto-pair" know it's topology, not host failure. Per the global
"evidence is for the debugger" rule.

## Tests

- bash syntax clean.
- Unit tests for peer_pick_address reachability (#397 already added
  test_gistparse.py covering the upstream picker behavior). The
  guard here is a control-flow gate; the existing integration suite's
  scenario_two_tab_localhost exercises the picked-address path. The
  no_match guard would only manifest in cross-machine + scope-
  mismatch scenarios that integration tests don't simulate today —
  worth adding once the test rig has multi-network simulation, but
  out of scope here.

## Cumulative effect with #397

#397 (Bug A): Joiner picker excludes scopes it can't route. Most
common cross-machine bad-pair shapes never reach the self-heal path.

This PR (Bug C): When picker correctly finds nothing reachable, the
fall-through to invite-string ssh_target no longer nukes the gist
on TCP failure. Defense in depth.

#397 + this = "no peer can take down the substrate for others by
joining + failing to reach the host."

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