Skip to content

fix(picker): fallback skips localhost so cross-machine joiners do not dial 127.0.0.1 - #393

Merged
joelteply merged 1 commit into
canaryfrom
fix/picker-no-localhost-fallback
May 2, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/picker-no-localhost-fallback

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Joel live-observed: Windows peer subscribed to #cambriantech but stuck on 127.0.0.1 because peer_pick_address fallback returned the localhost entry from host.addresses[]. Fix: new pick_addr_nonlocal_first helper that skips localhost; empty result falls through to gh-bearer-only routing per the documented Phase 3c behaviour.

Tailscale-pick re-add is separate followup.

🤖 Generated with Claude Code

…dial 127.0.0.1

Symptom (Joel observed live, Windows peer joining mesh): subscribed to
#cambriantech but stuck on a 127.0.0.1 loopback connection. The
joiner's IP didn't match the host's lan/24 subnet check, so
peer_pick_address fell through to its "first entry of any kind"
fallback — and the gist's host.addresses[] happens to put the
localhost entry first. The joiner then dialed THEIR own loopback,
which never reaches the host.

Fix:
  1. New gistparse subcommand `pick_addr_nonlocal_first` — same shape
     as pick_addr_first but filters out scope=localhost entries. If
     only localhost remains, returns empty.
  2. peer_pick_address bash fallback (airc:803-806) switched to use it.
  3. Empty return → caller falls through to gh-bearer-only routing
     (broadcast still works; direct-pair handshake skipped). Aligns
     with the Phase 3c gh-as-bearer fallback behaviour already
     documented at airc:798-801.

The same-LAN subnet check (lines 772-796) is unchanged — when the
joiner IS on the same /24, that path matches first and never reaches
the fallback. This fix only affects the cross-subnet case where the
fallback was previously broken.

Tested:
  - Helper unit tests:
    [{localhost+lan}] → "192.168.1.250|7548" (lan picked, localhost skipped) ✓
    [{localhost only}] → "" (empty, falls through to gh-bearer) ✓
  - airc bash syntax: clean
  - Python helper imports: clean

Out of scope (separate PR):
  - Re-add Tailscale-pick path (currently removed per Phase 3c
    comment) — that's the real fix for cross-LAN/remote-grid peer
    reach. This PR just stops dialing 127.0.0.1 in the meantime.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings May 2, 2026 03: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 adjusts the address-selection fallback used when a joiner can’t find a same-machine or same-LAN match, to avoid selecting a localhost entry (which would cause cross-machine joiners to dial their own 127.0.0.1).

Changes:

  • Added a new airc_core.gistparse subcommand pick_addr_nonlocal_first to select the first non-localhost address from host.addresses[].
  • Updated peer_pick_address()’s bash-side fallback to call pick_addr_nonlocal_first instead of pick_addr_first.
  • Expanded in-code commentary explaining the observed failure mode and intended fallback behavior.

Reviewed changes

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

File Description
lib/airc_core/gistparse.py Adds the new non-localhost picker subcommand and wires it into the CLI parser.
airc Switches peer_pick_address fallback to skip localhost entries by using the new gistparse subcommand.

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

Comment on lines +176 to +177
remains, returns empty so the caller falls through to gh-bearer-only
routing instead of dialing an unreachable address.
Comment on lines +266 to +268
pnf = sub.add_parser("pick_addr_nonlocal_first")
pnf.set_defaults(func=cmd_pick_addr_nonlocal_first)

Comment on lines +163 to +167
def cmd_pick_addr_nonlocal_first(args) -> int:
"""Stdin is a list of {scope, addr, port, ...}. Print 'addr|port' for
the first entry whose scope is NOT 'localhost'. Empty if all entries
are localhost (or list is empty / malformed).

Comment thread airc
Comment on lines +810 to +814
# addresses[]. pick_addr_nonlocal_first skips localhost; if only
# localhost remains, returns empty so the caller falls through to
# gh-bearer-only routing (broadcast still works; direct-pair
# handshake is skipped). Aligns with the documented Phase 3c
# gh-as-bearer routing behaviour above.
@joelteply
joelteply merged commit c251dca into canary May 2, 2026
10 checks passed
@joelteply
joelteply deleted the fix/picker-no-localhost-fallback branch May 2, 2026 03:12
joelteply added a commit that referenced this pull request May 2, 2026
…397)

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]>
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