Skip to content

fix(orchestrator): keep router session releases working after a burst - #4408

Merged
garrett361 merged 3 commits into
mainfrom
fix/orchestrator-session-release
Nov 6, 2026
Merged

garrett361 merged 3 commits into
mainfrom
fix/orchestrator-session-release

Conversation

@garrett361

Copy link
Copy Markdown
Collaborator

This PR gives the orchestrator's router-session releases their own HTTP client and caps how many run at once. Before, a burst of releases could leave the shared client permanently unable to send any request, so releases silently stopped for the rest of the run. From then on the router treated every finished rollout as still running, and placed new rollouts on inference replicas based on that wrong picture of their load.

Background. With the sticky_least_loaded router policy, each rollout is a session pinned to one inference replica so later turns reuse its prefix cache. The router places each new session on the replica holding the fewest sessions. When an episode ends, the orchestrator calls /finish_session so the router stops counting it. If a release never arrives, the router keeps counting the session until its time to live (TTL) expires, 2 h by default.

Bug 1: a burst loses most of its releases. All releases shared one httpx client with 4 connections, a 10 s wait per attempt for a free connection, and errors logged at DEBUG. When many episodes end at once (for example, a sandbox outage failing thousands of episodes), thousands of releases queue for those 4 connections:

 episodes ending at once        shared httpx pool (4 connections)        router
 release ─┐
 release ─┼─► wait up to 10 s ─► [ conn ][ conn ][ conn ][ conn ] ─► /finish_session
 release ─┘     for a connection
   ...  (thousands)

Most time out waiting, which loses those releases. On its own this is temporary: once the burst drains, releases work again.

Bug 2: those timeouts permanently break the client. httpcore 1.0.9 (the latest release) has a race in exactly that timeout. It is reported upstream in encode/httpcore#1099 (open, unmerged), where a comment reproduces this pool-timeout case on the same versions; the pydantic fork fixed it in pydantic/httpx2#983.

 time        queued request R                       pool (4 slots)
 ─────────────────────────────────────────────────────────────────────────────────
 0 s         joins the queue, 10 s timer starts     slots 1-4 busy
 ...
 10 s        (still asleep)                         request in slot 1 finishes;
                                                    pool creates connection C
                                                    (CONNECTING) and hands it to R
 10 s        timer fires before R wakes up:
             R raises PoolTimeout and leaves
             (C is never used)                      C stays in slot 1: never opened,
                                                    so never "closed", "idle" or
                                                    "expired", so never cleaned up

The pool opens a new connection instead of reusing the one that just finished because the old client kept at most 1 idle connection, and httpcore 1.0.9 counts every connection, busy or idle, against that limit. So with 4 connections open, each one is closed the moment it frees up.

Thousands of requests time out at nearly the same moment, so this fires reliably and each occurrence costs one slot for good:

 slot 1   busy ──► dead C ──────────────────────────────────────────────►
 slot 2   busy ─────────► dead C ───────────────────────────────────────►
 slot 3   busy ───────────────► dead C ─────────────────────────────────►
 slot 4   busy ─────────────────────► dead C ───────────────────────────►
                                      └─ from here on, every release waits 10 s
                                         for a slot and fails with PoolTimeout

A fresh client works immediately, which is how the reproducer confirms the pool, not the router, is at fault.

Consequence. The router keeps treating finished sessions as active until its TTL removes them. It sends each new session to the replica with the fewest sessions, so a replica holding many finished ones looks busier than it is and receives less new work, while a replica holding few receives more. The session counts look even across replicas, but the actual work is not. If the table reaches VLLM_ROUTER_SLL_MAX_SESSIONS (100,000 by default), new sessions are no longer pinned to one replica and lose their prefix cache on every turn (we have not hit this; the largest table we have seen peaked at about a third of the limit). Training data and rewards are unaffected; this is purely a routing-efficiency problem, and it was invisible because nothing was logged above DEBUG.

The fix. A release now needs one of 32 tickets (a semaphore) before it sends anything, and the release client has exactly 32 connections. Releases that find no free ticket wait in clients.py, not inside httpx, so httpx's pool wait and its race never come into play:

 thousands of releases arrive at once (one per finished session)
        │
        ▼
 ┌─ waiting for a ticket ───────────┐
 │ (semaphore in clients.py)        │──► waited 30 s, still no ticket?
 │ R  R  R  R  R  R  ...            │    give up: never sent, counted as failed,
 └───────────────┬──────────────────┘    router removes the session after its TTL
                 │ takes 1 of 32 tickets
                 ▼
 ┌─ httpx client, 32 connections ───┐
 │ a ticket holder always finds an  │──► POST /finish_session ──► router
 │ idle connection, so it never     │
 │ waits inside httpx               │
 └───────────────┬──────────────────┘
                 │ request done (success or error)
                 ▼
          ticket returned; the next release in line goes
  • Releases use a dedicated client with one connection per ticket, so requests never wait inside httpx's pool.
  • A PoolTimeout can then only mean a leaked connection, so the release path replaces the client and the next releases go out on a fresh one.
  • Failures log a WARNING each time their total doubles, so a burst logs a handful of lines, and sessions/released / sessions/release_failed report cumulative counts.
Reproducer (httpx 0.28.1, httpcore 1.0.9) Before After
Burst of 6,000 releases, 10 ms server 21 delivered (0.35%) all delivered
Single releases after each burst of 4,000 against a 2 s server 0/3, every burst 3/3, every burst
Pool state after those bursts 4 connections stuck CONNECTING 32 IDLE

Trade-offs a reviewer should know:

  • If the router answers releases slowly (for example, under heavy load), a release that waits more than 30 s for a ticket is dropped, so an episode never waits longer than that to finish.
  • Replacing a broken client fails up to 31 releases already in flight on it; those sessions wait for the router TTL.
  • Two other call sites keep the original 4-connection client unchanged: weight-update admin calls (AdminPlane) and the Dynamo frontend's startup checks. Each sends only a few requests at a time, so none ever waits for a connection.

Verification

Commit bbd2d3b adds tools/repro_session_release_pool_leak.py and the next commit removes it, so it stays in this PR's history without landing on main. It copies the old and new release paths, runs them against a local /finish_session server through the dispatcher's cancellation pattern, and prints delivery, follow-up releases and pool state per burst. It runs anywhere, without the repo's dependencies:

git show bbd2d3baa:tools/repro_session_release_pool_leak.py > /tmp/repro.py
uv run --no-project --with httpx==0.28.1 --with httpcore==1.0.9 --with anyio==4.13.0 \
    --with tenacity==9.1.4 --with starlette --with uvicorn python /tmp/repro.py old   # or: new

--server-delay 0.01 --episodes 3000 --bursts 1 gives the first table row; new --undersized-pool gives the pool 4 connections for 32 tickets, so its connections leak and the client replacement path recovers it.

🤖 Generated with Claude Code

garrett361 and others added 3 commits November 5, 2026 21:10
A burst of releases on the shared 4-connection admin pool hits an httpcore
1.0.9 race that leaves connections CONNECTING forever, so every later release
failed silently at DEBUG. Releases now use their own 32-connection client
behind a matching semaphore, replace the client on a pool timeout, log
failures as a warning and report cumulative released/failed counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… a burst

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kept in history at bbd2d3b for verification.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@garrett361
garrett361 marked this pull request as ready for review November 6, 2026 02:22
@garrett361
garrett361 merged commit 030d245 into main Nov 6, 2026
19 of 20 checks passed
@garrett361
garrett361 deleted the fix/orchestrator-session-release branch November 6, 2026 03:02
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.

3 participants