Skip to content

fix(bind): report a reachable LAN address for wildcard binds - #207

Closed
abu-tahir-0 wants to merge 1 commit into
jonocodes:mainfrom
abu-tahir-0:fix/wildcard-pairing-url
Closed

abu-tahir-0 wants to merge 1 commit into
jonocodes:mainfrom
abu-tahir-0:fix/wildcard-pairing-url

Conversation

@abu-tahir-0

Copy link
Copy Markdown

Problem

url_for built the pairing URL from the bind host verbatim, so --bind 0.0.0.0 (or ::) reported http://0.0.0.0:8765/ on /health, /diag, and deckctl status. A phone cannot open that address. Since #204 the macOS app binds 0.0.0.0 by default, so this is now the common case. Closes #206.

Root cause

bind.url_for selected the preferred resolved bind and formatted its host unchanged. A literal 0.0.0.0 / :: resolves to itself, so the wildcard leaked into the URL. addresses is correct either way; only the single pairing URL is wrong.

Solution

  • url_for now detects an unspecified address (ipaddress.is_unspecified) and substitutes a reachable IPv4: the source address of the default route (a connected UDP socket, which sends nothing), then a host-name lookup; if neither yields a usable address it falls back to 127.0.0.1. Never returns a wildcard.
  • The substitution happens before IPv6 bracketing, so a :: bind with an IPv4 substitution is rendered unbracketed.
  • Discovery is behind a lan_host keyword hook so tests inject a stub and never touch the network.
  • addresses and concrete/iface: binds are unchanged.
  • CONTEXT.md, docs/GUIDE.md, and docs/REFERENCE.md describe the wildcard handling.

Testing

  • python -m pytest tests/test_bind.py -q → 28 passed (5 new: IPv4 wildcard, IPv6 wildcard, loopback fallback, concrete bind skips discovery, default discovery hook).
  • python -m pytest tests/test_bind_surface.py -k "health or diag" tests/test_diag_endpoints.py -q → 23 passed.
  • pyright daemon/deckd/bind.py → 0 errors.

The full suite cannot run on my Windows machine: tests/test_install_helper.py imports os.geteuid at module scope, and test_start_port_in_use_with_multi_bind / watcher tests block on this platform. Those are pre-existing and unrelated; Linux CI's just test-all should confirm.

Impact

Phones get a URL they can actually type when the daemon is bound to all interfaces. No change to auth, addresses, or explicit binds.

The pairing URL was built from the bind host verbatim, so --bind
0.0.0.0 (or ::) produced http://0.0.0.0:8765/ — an address no phone
can open. That is now the common case on macOS, which binds 0.0.0.0
by default.

url_for now substitutes a wildcard bind with the host's LAN IPv4
(default-route source address, then host-name lookup) and falls back
to 127.0.0.1 when none is found. `addresses` still lists the raw
bound sockets; only `url` changes. Literal and iface: binds are
untouched.

The discovery hook is injectable so the regression tests never touch
the network (jonocodes#206).
@jonocodes

jonocodes commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Note

🤖 Claude Opus 5.5 responding on behalf of jonocodes

Closing this as superseded by #208, which fixed #206 and merged today. This PR came first: it was open ~14 hours before #208, and #208 was filed without checking for an existing PR. That's on us, not you.

The two take the same approach (default-route source address, then hostname lookup, then loopback), so your read of the problem was right. The one behavioural difference is the bare :: case:

  • This PR reports a :: bind as the LAN IPv4 (_url_host → lan_host() or "127.0.0.1").
  • But _open_bind_sockets sets IPV6_V6ONLY=1 on every IPv6 socket (daemon/deckd/server.py ~L291), so --bind :: listens on v6 only. An IPv4 URL gets connection refused.
  • fix(bind): pairing URL a phone can open when bound to 0.0.0.0 / :: #208 picks a LAN address of the wildcard's own family, so :: gives a LAN IPv6 or [::1]. It also ranks a non-loopback bind above a loopback one (["127.0.0.1", "::"] reports the v6 address).

#208 made the same :: mistake in its first commit, and review caught it. The branch also conflicts with main now.

If you'd like to keep contributing, issues labelled ready-for-agent or ready-for-human are the triaged ones. Thanks for your help.

@jonocodes jonocodes closed this Nov 19, 2026
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.

Pairing URL shows http://0.0.0.0:8765/ when bound to all interfaces

2 participants