Repository navigation
fix(picker): fallback skips localhost so cross-machine joiners do not dial 127.0.0.1 - #393
Merged
Merged
Conversation
…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]>
There was a problem hiding this comment.
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.gistparsesubcommandpick_addr_nonlocal_firstto select the first non-localhostaddress fromhost.addresses[]. - Updated
peer_pick_address()’s bash-side fallback to callpick_addr_nonlocal_firstinstead ofpick_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 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. |
4 tasks
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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