Fix serve-web port randomization when --port 0 is specified (#254676)

* Initial plan

* Fix serve-web port randomization when --port 0 is specified

Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>

* Fix serve-web to display actual bound port instead of 0

When --port 0 is specified, the OS assigns a random port but the
logging was showing port 0 instead of the actual assigned port.
Fixed by reading the local_addr() from the server builder after binding.

Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: connor4312 <2230985+connor4312@users.noreply.github.com>
This commit is contained in:
Copilot 2025-07-22 13:35:24 -07:00 committed by GitHub
parent ae03121880
commit 90072b47cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -127,7 +127,9 @@ pub async fn serve_web(ctx: CommandContext, mut args: ServeWebArgs) -> Result<i3
};
let builder = Server::try_bind(&addr).map_err(CodeError::CouldNotListenOnInterface)?;
let mut listening = format!("Web UI available at http://{addr}");
// Get the actual bound address (important when port 0 is used for random port assignment)
let bound_addr = builder.local_addr();
let mut listening = format!("Web UI available at http://{bound_addr}");
if let Some(base) = args.server_base_path {
if !base.starts_with('/') {
listening.push('/');