Repository navigation
fix(self-heal): don't nuke gist when picker found no reachable scope (Bug C from #397) - #398
Merged
Conversation
… 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]>
There was a problem hiding this comment.
Pull request overview
This PR hardens cmd_connect’s join/self-heal flow so a joiner that cannot reach any advertised host scope does not delete the shared room gist for everyone else. It fits into the room-discovery and direct-pairing logic by refining when stale-host takeover is allowed after a failed handshake.
Changes:
- Track address-picker outcomes with
_addr_picker_stateto distinguish “no addresses published”, “picked a reachable-looking address”, and “no reachable scope matched”. - Gate the SSH-failure self-heal path so it does not delete the gist when the picker explicitly found no reachable scope for this peer.
- Emit a clearer user-facing message for the
no_matchcase, explaining that direct pairing failed due to topology mismatch while gist-based broadcasts still work.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1085
to
+1087
| if [ -n "$resolved_room_name" ] && [ -n "$_resolved_gist_id" ] \ | ||
| && command -v gh >/dev/null 2>&1; then | ||
| && command -v gh >/dev/null 2>&1 \ | ||
| && [ "$_addr_picker_state" != "no_match" ]; then |
Comment on lines
+1099
to
+1110
| elif [ "$_addr_picker_state" = "no_match" ]; then | ||
| # Picker found no scope this peer can reach. Surface the situation | ||
| # but do NOT nuke the gist. The host may be perfectly reachable | ||
| # for peers on the other matching scope (e.g. peers on the same | ||
| # tailnet when WE lack tailscale). Per the global "evidence is | ||
| # for the debugger, not the trash" rule — print explicit reason | ||
| # so users debugging "why didn't I auto-pair" know it's a network | ||
| # topology mismatch rather than a host-down event. | ||
| echo "" >&2 | ||
| echo " ⚠ Host of #${resolved_room_name} published no scope this peer can reach." >&2 | ||
| echo " Skipping self-heal (gist preserved for peers who CAN reach the host)." >&2 | ||
| echo " Direct pair unavailable; gh-bearer broadcasts still work via gist." >&2 |
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.
Summary
Defense-in-depth follow-up to #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:
Bug observed live 2026-05-02: a Mac without Tailscale joining a Windows host whose only non-localhost entry was Tailscale fell through to the invite-string ssh_target, TCP timed out, self-heal nuked the gist that 4 other peers were happily using.
Fix
Track picker outcome in
_addr_picker_state:no_addrs— noaddresses[]in gist → tried invite-string only → self-heal allowedpicked— picker selected a believed-reachable address that THEN failed → self-heal allowedno_match— picker found no reachable scope → self-heal SKIPPED (other peers can still reach this host)When skipped, surface explicit message so users know it's network topology, not host-down: "Host of #room published no scope this peer can reach. Skipping self-heal (gist preserved for peers who CAN reach the host). Direct pair unavailable; gh-bearer broadcasts still work via gist."
Cumulative effect with #397
no_matchfalls through to invite-stringTest plan
Out of scope
🤖 Generated with Claude Code