Skip to content

tools: unsloth_probe self-test binds the SSE stub on port 0 (engine#3193) - #3309

Merged
bong-water-water-bong merged 1 commit into
mainfrom
cl-flm/3193-stub-port0
Nov 22, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
cl-flm/3193-stub-port0

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Advances #3193 (the fixed-port flake noted on the issue 2026-11-22T03:10Z).

What: tools/unsloth_probe.py --self-test started tools/sse_stub.py on a derived fixed port (53990 + len(shape)). Two overlapping runs (two lanes' pre-PR gates, a parallel ctest) collided, and the loser printed Connection refused, which reads like a stream-parser failure. Now the stub accepts port 0, prints the port it bound as its first stdout line, and the probe reads that line instead of sleep(0.6) + guess. If the stub dies before binding, the probe fails that shape with stub did not report its port, not a hang or a skip.

Measured (ryzen, CPU only):

  • old code, 3 overlapping --self-test runs: 1 PASS, 2 FAIL (2 of 3 stream shapes read), rc=1
  • this branch, 6 overlapping runs: 6 × PASS (3 of 3 stream shapes read), rc=0

Checks: bash scripts/pre-pr-checks.sh --base origin/main → all 16 checks green, 4 skipped, 0 could not be told. Existing ctest row unsloth_probe_self covers it, so no new registration. Two files touched, no behaviour change outside the self-test (the stub's positional port still accepts a fixed number).

🤖 Generated with Claude Code

…193)

The self-test started tools/sse_stub.py on a derived fixed port (53990 +
len(shape)), so two overlapping runs on a shared box collided and the
loser reported 'Connection refused' - read as a parser failure. The stub
now accepts port 0, prints the port it bound as its first stdout line,
and the probe reads it back instead of sleeping and guessing.

Measured on ryzen: 3 overlapping runs of the old code -> 1 PASS, 2 FAIL
(2 of 3 shapes); 6 overlapping runs of this code -> 6 PASS (3 of 3).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

3193 - Partially compliant

Compliant requirements:

  • Run self-test with overlapping processes to ensure no port collision
  • Verify that the stub binds to a free port when 0 is specified
  • Ensure the probe reads the bound port from stdout instead of guessing

Non-compliant requirements:

  • Measure performance improvement with new port binding method

Requires further human verification:

  • Measure performance improvement with new port binding method
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Port binding reliability

The change improves reliability of port binding in self-test by using port 0 and reading the actual bound port from stdout. This prevents collisions in overlapping runs, which was a known issue with the previous fixed port approach.

srv = subprocess.Popen([sys.executable, os.path.join(here, "sse_stub.py"), "0", shape],
                       stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True)
try:
    line = srv.stdout.readline().strip()
    if not line.isdigit():
        raise RuntimeError(f"stub did not report its port (got {line!r})")
    res, _ = call(f"http://127.0.0.1:{line}", "/v1/chat/completions", {"stream": True}, stream=True)
Dynamic port assignment

The stub now accepts port 0 and prints the actual bound port to stdout, which allows the caller to reliably determine the port without guessing or using fixed ports that can collide.

ap.add_argument("port", type=int, help="loopback port to listen on; 0 = let the kernel pick a free one")
ap.add_argument("shape", choices=sorted(SHAPES), help="which envelope each chunk uses")
a = ap.parse_args(argv)
global SHAPE
SHAPE = a.shape
srv = HTTPServer(("127.0.0.1", a.port), H)
# The bound port is the first line on stdout, so a caller that asked for port 0 reads it back instead of
# guessing one: a fixed port collides when two runs overlap on a shared box (engine#3193).
print(srv.server_address[1], flush=True)
srv.serve_forever()

@bong-water-water-bong
bong-water-water-bong merged commit 458d074 into main Nov 22, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the cl-flm/3193-stub-port0 branch November 22, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant