fix(desktop): keep the advertised LAN host in sync with the current network - #67
Merged
Merged
Conversation
…etwork The desktop resolved its LAN address once during startup and cached it in the exposure runtime state, so a machine that moved networks (or renewed its DHCP lease) kept handing pairing links and QR codes the address it had at launch. Phones then couldn't reach the backend even though it had been bound to every interface the whole time. Re-resolve the advertised host on every exposure-state and advertised-endpoint read. The bind host, loopback URL, and port stay untouched, so picking up a new address never needs a backend relaunch. A local-only run — including one that fell back for want of an address — still advertises nothing, since it only listens on loopback until the next relaunch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
Pairing a phone from the store build failed with:
The desktop resolves its LAN address once, during startup (
configureFromSettings), and stores it in the exposure runtime state. Every later read — the Connections settings row, the pairing link, the QR code, the advertised-endpoint list — returned that stored string until the app relaunched.In the reported case the desktop had been running for three days and had bootstrapped with
endpointUrl: http://192.168.2.37:3773, while the machine had since moved to192.168.1.21. The backend was bound to0.0.0.0and reachable at the new address the entire time; only the advertised host was stale, so the QR sent the phone to an IP nobody answers on.Fix
Re-resolve the advertised host from the live interface list on every
getState/getAdvertisedEndpointscall, reusing the existingresolveLanAdvertisedHostpicker (so theT3CODE_DESKTOP_LAN_HOSToverride still wins).bindHost,localHttpUrl, andportare deliberately left untouched — picking up a new address never triggers a backend relaunch.Tests
Two regression tests in
DesktopServerExposure.test.ts:vp test run src/backend/DesktopServerExposure.test.ts→ 11/11 pass, and the roaming test fails without the fix (Expected: "192.168.1.21" / Received: "192.168.2.37"). Lint and format clean.🤖 Generated with Claude Code