Skip to content

fix(python): bracket IPv6 hosts in managed server URLs - #3003

Merged
inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/python-managed-ipv6
Nov 14, 2026
Merged

inureyes merged 2 commits into
lablup:mainfrom
Jaeyeong-CHOI:fix/python-managed-ipv6

Conversation

@Jaeyeong-CHOI

Copy link
Copy Markdown
Contributor

Summary

LLM(model, host="::1") failed during startup with httpx.InvalidURL: the manager put the raw IPv6 literal into its readiness and base URLs. Both URLs now come from one origin that brackets a raw IPv6 literal. The --host argument passed to the server is unchanged.

Related issues

Closes #3002.

Type of change

  • fix — bug fix

Cause

ManagedServer.base_url and ManagedServer._health_url (python/src/mlxcel/_server.py) formatted f"http://{self.host}:{self.port}/…", which for ::1 is http://::1:18080/….

Change

  • ManagedServer._http_origin (new): http://mlxcel for a Unix socket as before; otherwise http://{host}:{port} with the host bracketed when it contains : and is not bracketed already. base_url and _health_url append /v1 and /health to it.
  • _build_command is untouched: the server still receives the host as the caller gave it.
  • Tests: six host / port / path checks, and four lifecycle cases that start the package's fake server on the IPv6 loopback behind the managed sync and async clients, with ::1 and with [::1], through shutdown. python/tests/fake_server.py can now bind AF_INET6. The lifecycle cases skip on a host that cannot bind the IPv6 loopback; they ran here.

Before / after

Linux aarch64, Python 3.12.3, real loopback HTTP, no model.

Dependencies main with the new tests This PR, whole suite (-m "not e2e")
openai 1.40.0, httpx 0.27.0 (the declared lower bounds) 4 failed, 6 passed 61 passed, 2 deselected
openai 3.49.0, httpx 0.28.1 4 failed, 6 passed 61 passed, 2 deselected

The four failures on main are the two raw-IPv6 URL checks and the two raw-IPv6 lifecycles (httpx.InvalidURL). The bracketed, IPv4, hostname and Unix-socket cases pass before and after.

Test plan

Run on this PR's source (one commit on 955335a38, tree eab5f3ba11d9).

  • python -m pytest -m "not e2e" in python/ with both dependency pairs above: 61 passed, 2 deselected each; none of the IPv6 cases skipped
  • The new tests on main: 4 failed, 6 passed with both pairs
  • ruff check python, ruff format --check python, mypy python/src: pass
  • Together with five other Python client fixes proposed separately, on Python 3.9.25 (openai 1.40.0 / httpx 0.27.0, and openai 2.48.0 / httpx 0.28.1): 101 passed, 2 deselected, mypy with the 3.9 target clean. This PR on its own was run on 3.12 only
  • A real mlxcel serve on an IPv6 address: not run. The lifecycle cases use the fake server; the Rust listener's own IPv6 handling is not touched
  • Rust gates: not applicable, no Rust file changes
  • Windows and macOS: not run

Notes for reviewers

  • A host that already contains brackets is passed through, so [::1] keeps working and is not bracketed twice.
  • Implemented and validated with AI assistance (Claude). Every number above comes from the logs of those runs.

Checklist

  • PR title uses a Conventional Commits prefix
  • One logical change per PR
  • Updated docs/: not needed
  • Updated // Used by: ... comments: not applicable (Python)
  • No secrets, credentials, or .env files committed

`ManagedServer` built its readiness URL and its OpenAI base URL as
`http://{host}:{port}/…`. With an IPv6 literal such as `::1` that is
`http://::1:8080/health`, which httpx rejects (`InvalidURL: Invalid port`),
so `LLM(model, host="::1")` failed during startup although the server was
given a valid `--host`.

Both URLs now come from one origin that brackets a raw IPv6 literal. The
host passed to the server command line is unchanged, and an already
bracketed literal, an IPv4 address, a hostname and a Unix socket are
formatted as before.
@inureyes

Copy link
Copy Markdown
Member

Thanks for the fix. Reviewed against #3002: base_url and _health_url now share one origin that brackets a raw IPv6 literal, --host still reaches the server as given, and the Rust side (resolve_socket_addr) already accepts both ::1 and [::1], so both spellings work end to end. No security or performance concerns.

I merged current main into the branch (no conflicts) and reran locally on macOS, where the IPv6 loopback lifecycle cases ran rather than skipped: 122 passed, 2 deselected on Python 3.11 and 3.9; ruff and mypy clean. No further changes were needed. A minor note for later, not blocking: the auto-chosen port is probed on IPv4 (_free_tcp_port), so an IPv6 host relies on the same port also being free there. The test (Python 3.9) CI job fails only in setup-python (tracked by #3013).

@inureyes
inureyes merged commit f13e60c into lablup:main Nov 14, 2026
34 of 35 checks passed
@inureyes inureyes added the status:done Completed label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:done Completed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(python): managed mode builds an invalid URL for an IPv6 host such as ::1

2 participants