Auto-select next free serve port when default (4096) is taken#7
Merged
Auto-select next free serve port when default (4096) is taken#7
Conversation
Co-authored-by: mtsfoni <80639729+mtsfoni@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix serve command to use next available port
Auto-select next free serve port when default (4096) is taken
Mar 12, 2026
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.
When
--serve-portis omitted and port 4096 is already bound on the host,constructwould silently fail when Docker tried to publish the port. This adds a best-effort port scan to pick the next free port and warn the user.Behaviour
--serve-portis not specified (explicit ports are used as-is)127.0.0.1:<port>from 4096 upward, up to 100 ports--serve-portexplicitly)Changes
internal/runner/runner.go—isPortFree(port)probes a loopback TCP bind;findFreePort(start)scans up to 100 ports and returns 0 on exhaustion;Runuses these whencfg.ServePort == 0internal/runner/runner_test.go— 5 new unit tests covering free/busy detection and range exhaustiondocs/spec/serve-mode.md— documents the auto-fallback behaviour and 100-port search capCHANGELOG.md— entry under[Unreleased]Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.