Skip to content

Studio listeners and provider URLs: IPv6 loopback, sidecar owners, metadata addresses - #19199

Merged
danielhanchen merged 5 commits into
mainfrom
sec/listeners-and-provider-urls
Nov 24, 2026
Merged

danielhanchen merged 5 commits into
mainfrom
sec/listeners-and-provider-urls

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Listener and outbound-address hardening:

  • IPv6 loopback. A plain-HTTP Studio on 127.0.0.1 now also holds [::1]:<port>. Otherwise a sandboxed tool or another local user could listen there and catch the browser's localhost traffic, including the session token. URLs and origins are unchanged.
  • Sidecar listeners. The whisper.cpp and vLLM / SGLang launchers only accept a listener owned by their own child process. Before, a port squatter could receive dictation audio and the engine key.
  • Provider URLs. These now refuse the missing IPv6 and Azure cloud-metadata addresses, and judge NAT64 addresses by the IPv4 address inside them.
  • Shared provider connections. A shared connection always uses the owner's saved URL and headers. Before, a failed "is a key saved" read could send the owner's key to the managed account's URL.

Tests: each change has a test that fails on main and passes here; the provider, launcher and sidecar suites pass on both.

…ch another listener

(cherry picked from commit 73b3091de291be6462895e397f6266aee57ed5af)
… child's listener

(cherry picked from commit 9ed0f5f1045c12de626858064ed927ccf113c813)
…IPv6 metadata services

(cherry picked from commit bf06defef0d63a3c7860bca75d626207626dfcfe)
…ndpoint and headers

(cherry picked from commit 2d1c95b2a6bbaa598061f5ad7ced8e081d86bdb6)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T02:03:33.519181Z 0d8f74a 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 0d8f74a24a

ℹ️ 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 a24e80e into main Nov 24, 2026
32 of 40 checks passed
@danielhanchen
danielhanchen deleted the sec/listeners-and-provider-urls branch November 24, 2026 04:52
rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Nov 24, 2026
…s listening (unslothai#19242)

## Problem

While a vLLM or SGLang model loads, the Studio readiness loop in
`ManagedEngine._start_once` polls every 0.25 s. Since unslothai#19199 every poll
first runs `LlamaCppBackend._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 logs

```
llama-server port N answered /health but our child PID is not listening on it; refusing to use it
```

at error level, for the whole 1 to 5 minute load. Every other caller of
the check runs it once, after `/health` has already answered.

## Change

Before the ownership check, the poll now makes a plain TCP connection to
the same host and port the `/health` probe uses (parsed from `base_url`,
so an IPv6 `[::1]` URL connects to `::1`) and sends nothing.

- Refused or unreachable: wait 0.25 s and loop, as before. The old path
also waited here: the check returned False on Linux and macOS, and on
Windows it returned True and the probe then failed to connect to the
same address.
- Accepted: the unchanged ownership check runs, then the unchanged keyed
`/health` probe. 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.start` path,
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.

| Metric (median of 3, range) | Base | Head |
| --- | --- | --- |
| Ownership checks per load | 38 (36 to 39) | 1 (1 to 1) |
| False "not listening" error lines | 37 (35 to 38) | 0 |
| CPU in the ownership check | 20.09 s (20.08 to 20.35) | 0.38 s (0.34
to 0.42) |
| Studio process CPU during the load | 20.18 s (20.17 to 20.43) | 0.49 s
(0.47 to 0.55) |
| Keyed `/health` probes | 1 | 1 |
| Ready after engine bind | 0.42 s (0.40 to 0.50) | 0.45 s (0.41 to
0.48) |
| Total load time | 30.53 s | 30.56 s |

This 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`:

- With nothing listening there is no ownership scan, no error and no
probe, and the load still times out the same way (fails on main: one
scan plus one false error inside the window).
- Once something listens, the ownership check runs on every poll before
the keyed probe: a refused first answer is asked again and the key goes
out only after a yes. Repeated non-200 probes are each preceded by a
fresh check, and the load still times out.
- A listener that is not owned by our child is still refused with the
same error.
- With a listener whose owner psutil cannot name, mocked Windows still
probes it and Linux/macOS still refuse.
- `_port_accepts` sends 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:

- In the parallel run, two timing tests failed only here:
`test_a_load_that_stalls_times_out_one_timeout_after_its_last_work` and
`test_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_transcription` is timing sensitive on
both arms.
- Four ROCm and support-probe tests fail on main and here alike.
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