web: --port 0 lets the OS choose a free port - #2684
Open
acinader wants to merge 1 commit into
Open
Conversation
The chosen port is reported in the startup message and used in the default base url, so scripts can discover it. To learn the port, we bind the listening socket ourselves (with streaming-commons' bindRandomPortTCP, which warp's own helpers build on) and hand it to warp. Supported with --serve and --serve-api; --serve-browse reports an error, since it needs a known port up front to open the browser at. AI usage: Claude Fable 5, ~50k output tokens
acinader
force-pushed
the
web-port-zero
branch
from
August 12, 2026 19:47
549999b to
2dd327b
Compare
acinader
marked this pull request as ready for review
August 12, 2026 19:59
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.
Closes #2559.
With this change,
hledger-web --port 0now asks the operating system for a free port. The chosen port is reported in the startup message and used in the default base url, so scripts (and humans) can discover it:Implementation notes, as discussed on the issue:
runSettingsSocket. The binding uses streaming-commons'bindRandomPortTCP(the same function warp's ownopenFreePortbuilds on), so--hostvalues are interpreted exactly as warp does. streaming-commons was already in the build plan as a transitive dependency; it's now a direct one.--base-urlis left untouched; only the default host:port base url is rebuilt with the chosen port.--port 0with--serve-browsereports a clear error suggesting--serve/--serve-api, since browse mode needs a known port up front to open the browser at. (Supporting it would require reworking wai-handler-launch; deliberately out of scope, per the issue discussion.)Tested by hand:
--serveand--serve-apiwith--port 0(banner, base url, and HTTP responses on the reported port), the--serve-browseerror,--base-urlpassthrough, and normal explicit-port operation.AI usage: Claude Fable 5, ~50k output tokens (also noted in the commit message).