Skip to content

Studio tests: give managed engines ports another worker cannot be handed - #15915

Merged
danielhanchen merged 1 commit into
mainfrom
tests-engine-ports-outside-the-ephemeral-range
Oct 29, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
tests-engine-ports-outside-the-ephemeral-range

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

(Python 3.13, g-r) on #15656's staging run failed a test #15656 does not touch:

tests/test_managed_engines_rocm.py:613: in test_a_startup_timeout_names_where_the_engine_stalled
    with pytest.raises(RuntimeError, match = "(?s)timed out.*JIT kernel warmup finished"):
E   Failed: DID NOT RAISE RuntimeError

It passes on main when run alone.

Cause

The fake engine in that test never listens; it prints a line and sleeps. The only way ManagedEngine._start_once returns instead of timing out is a 200 from GET {base_url}/health. managed_engine._free_port() binds port 0, reads the port and closes the socket, so the port goes back to the ephemeral pool before the engine is spawned. Any bind(0) on the runner in that gap can be handed the same port. On a busy runner that is mostly another xdist worker's test server, and its 200 on /health turns a start that must time out into "ready".

About a dozen engine tests depend on nothing answering. A plugin that hands the released ephemeral port to a listener answering 200 (only ephemeral ports, since only those can reach another bind(0)) fails these on main:

  • test_a_startup_timeout_names_where_the_engine_stalled
  • test_rocm_engine_sees_one_device_mask_and_its_own_memory_budget
  • test_server_outlives_short_lived_start_thread
  • test_startup_deadline_counts_engine_silence
  • test_vllm_does_not_retry_other_failures_or_twice
  • test_vllm_drafter_retry_respects_an_external_stop
  • test_vllm_mamba_retry_respects_a_cancelled_load
  • test_vllm_mamba_retry_respects_an_external_stop
  • test_vllm_relaunches_at_the_tightest_data_parallel_rank
  • test_vllm_relaunches_once_at_the_mamba_block_count
  • test_vllm_retries_once_without_a_drafter_that_breaks_startup

Fix

A backend conftest autouse fixture replaces managed_engine._free_port during tests. Each xdist worker gets its own block of 250 ports from 21000 up. That is below the ephemeral range on Linux (32768+), macOS and Windows (49152+), so bind(0) never hands those ports out, and two workers never share one.

The two tests of the allocator itself request the new real_engine_free_port fixture and get the real function back:

  • test_engine_port_stays_below_the_limit_when_the_os_offers_high_ports
  • test_only_sglang_reserves_space_for_its_derived_port

New guard, test_the_suite_hands_engines_ports_no_other_process_can_be_given: the ports engines get in the suite are in that block. Against main's conftest it fails (43577).

Verification

run main 9258bfc732 this branch
test_managed_engines.py + test_managed_engines_rocm.py, -n 8 with the port-stealing plugin 12 failed, 251 passed (twice) 263 passed (three times)
the same two files, normal 263 passed
every backend test file that touches managed_engine (24 files), -n 16 2381 passed, 5 skipped

Cross-platform run of this branch

test_engine_ports.py + test_managed_engines_rocm.py on the staging cross-platform legs, including the new guard:

  • ubuntu-latest: 40 passed
  • macos-15: 20 passed, 20 skipped
  • windows-latest: 20 passed, 20 skipped

The skips are the Linux-only tests of the ROCm file.

Not changed

The product side of this: a foreign listener that answers /health on the port Studio picked is taken as the engine. In real use the window is milliseconds and needs another local process to bind that port in it. llama_cpp._find_free_port already notes the same gap. A real fix would have the engine report its pid on /health or bind the port itself, which is a separate change.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T06:39:44.955146Z 7ff9967 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 7ff9967a0d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen
danielhanchen merged commit d035dff into main Oct 29, 2026
0 of 37 checks passed
@danielhanchen
danielhanchen deleted the tests-engine-ports-outside-the-ephemeral-range branch October 29, 2026 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant