Repository navigation
Studio: skip the vLLM / SGLang port ownership scan until the engine is listening - #19242
Conversation
The vLLM / SGLang readiness poll ran the full psutil ownership scan on every 0.25 s tick before the engine had bound its port, costing CPU and logging a false 'not listening' error each time. Connect first (sending nothing); only once something accepts does the unchanged ownership check and keyed /health probe run.
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Delightful! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
#19296) ## Problem `studio/backend/tests/test_managed_engine_readiness_poll.py` fails on main (6 of 9 tests) and on every PR based on it, for example #19284 and #19285, which do not touch Studio: ``` > child_env["WSL_UTF8"] = "1" E TypeError: 'NoneType' object does not support item assignment ``` ## Cause Two PRs merged within an hour of each other, each green on its own base: - #19167 added `vllm` to `MANAGED_ENGINE_LOG_FAMILIES`, so a vLLM start now captures logs and, on the WSL path, sets `child_env["WSL_UTF8"] = "1"` on the environment `_wsl_command` returns (the SGLang half of this came in #19166). - #19242 added this test file. Its `_wsl_command` stub returned `(command, None)`, and its base predated #19167, so vLLM did not capture logs there and the `None` was never touched. The code is right: the real `_wsl_command` always returns `wsl_host.guest_command(...)`, whose second element is the `wsl.exe` environment dict, and `test_managed_engine_logs.py` already stubs it with `dict(os.environ)`. The stub was the part that did not match the contract. ## Fix - The stub returns `dict(os.environ)`, the same shape the real launcher hands back. - The fixture sets `UNSLOTH_STUDIO_HOME` to `tmp_path`, since the vLLM start now opens a per-attempt log under the Studio home and the tests should not write into the real one. No product code changes. ## Verification - `tests/test_managed_engine_readiness_poll.py`: 9 passed (6 failed on main before the change). - Reverting only the stub's return value back to `None` brings back the same 6 failures. - `test_managed_engine_logs.py`, `test_engine_ports.py` and this file together: 50 passed; this file under `-n 4`, 3 repeats: 27 passed.
Problem
While a vLLM or SGLang model loads, the Studio readiness loop in
ManagedEngine._start_oncepolls every 0.25 s. Since #19199 every poll first runsLlamaCppBackend._health_listener_is_ours, which walks the child process tree with psutil, reads each child's sockets and then scans every inet socket on the host. Until the engine binds its port nothing is listening, so each of those scans is wasted, and on Linux and macOS each one also logsat error level, for the whole 1 to 5 minute load. Every other caller of the check runs it once, after
/healthhas already answered.Change
Before the ownership check, the poll now makes a plain TCP connection to the same host and port the
/healthprobe uses (parsed frombase_url, so an IPv6[::1]URL connects to::1) and sends nothing./healthprobe. Both still run on every iteration, and nothing is cached.Timeouts, stall detection, cancellation, the exited-child path and the Windows ownership rules are untouched. The connect timeout is 2 s, the same as the probe client's.
Results
A fake engine is launched through the real
ManagedEngine.startpath, with the same Popen flags and stdin pipe. It spawns 4 idle workers, prints progress lines for 30 s, then binds 127.0.0.1 and serves/health. There were 3 interleaved runs per arm on the same Linux host. The spread across each arm's 3 runs is the A/A noise./healthprobesThis host has many sockets, so one scan costs about 0.5 s of CPU, which is more than a typical desktop. The call count and the error lines do not depend on the host.
Tests
New
studio/backend/tests/test_managed_engine_readiness_poll.py:_port_acceptssends no bytes, returns False once the listener is gone, and follows an IPv6[::1]URL.The 5 behaviour tests pass on main and on this branch. The other 3 fail on main as expected.
The related suites (managed engine, engine ports, API key transport, llama-server port owner, sidecar port owner, health wait, STT sidecars, IPv6 loopback hold, WSL host, NPU failure output) were run on main and on this branch, and the failing test IDs were compared. No test fails only on this branch:
test_a_load_that_stalls_times_out_one_timeout_after_its_last_workandtest_runner_stops_the_engine_group_when_studio_closes_the_pipe. Both pass on a serial rerun here, and the WSL runner test then failed on main.test_unload_waits_for_inflight_transcriptionis timing sensitive on both arms.