feat: persist VS Code serve-web port across restarts (#21)#46
Merged
Conversation
serve-web ran with --port 0, so the OS assigned a fresh ephemeral port on every launch and the embedded browser had to re-navigate to a new URL each restart. Persist the assigned port under the serve-web data dir and request it again on the next launch. The port is only reused when it is still bindable on loopback; a now-occupied port falls back to --port 0 so it can never fail the launch. Completes #21 (the data dir and connection token were already persisted in d0fe6fa).
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.
What this does
The embedded VS Code (serve-web) browser used to jump to a different URL every time you restarted Programa, because VS Code was launched with
--port 0and the OS handed it a fresh random port each run. This pins the port: Programa now remembers the port VS Code was assigned and asks for the same one next launch, so the browser URL stays stable.It does this safely — if that remembered port is already taken by something else when Programa starts, it quietly falls back to letting the OS pick one (exactly the old behaviour), so a stale port can never break serve-web.
This is the last remaining piece of #21; the
--server-data-dirand persistent connection token were already handled ind0fe6faf.Summary
Sources/AppDelegate.swift:ServeWebPortStore(alongsideServeWebOutputCollector): persists the port to<ApplicationSupport>/programa/vscode-server/serve-web-port, mirroring the existing connection-token file pattern (no UserDefaults).launchServeWebProcessnow passesServeWebPortStore.portArgument(persistedIn:)instead of the literal"0". The store returns the persisted port only whenisPortAvailable(a loopbackbindprobe withSO_REUSEADDR) confirms it's free, otherwise"0".serve-webreports its URL, the assignedserveWebURL.portis written back viaServeWebPortStore.persist(port:in:).TODO(#21)comment is resolved.makePersistentConnectionTokenFile), withisPortAvailableinjectable for tests.No user-facing config or UI — purely internal state persistence.
Test Plan
cmux-unit/ServeWebPortStoreTests(7 tests): missing-file →"0", persist→reuse round-trip, unavailable-port fallback, nil dir, out-of-range rejection,parsePortedge cases, and a live-listener occupied-port probe returning unavailable../scripts/reload.sh --tag serve-web-portbuilds clean.127.0.0.1:<port>URL, quit and relaunch Programa → same port/URL; occupy that port with another process, relaunch → serve-web still comes up (on a new port).