feat(interception): bound concurrent model requests per server - #2576
Draft
faresobeid wants to merge 1 commit into
Draft
feat(interception): bound concurrent model requests per server#2576faresobeid wants to merge 1 commit into
faresobeid wants to merge 1 commit into
Conversation
InterceptionServerConfig.max_concurrent_requests (None = unlimited) puts an asyncio semaphore around the upstream model request, shared by every session on the server: rendered calls hold a slot for get_response; streamed calls hold it from relay until the upstream connection closes. Tool execution, replay-cache hits and coalesced retries take no slot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
InterceptionServerConfig.max_concurrent_requests: PositiveInt | None = None. When set, anasyncio.Semaphorebounds the upstream model requests in flight across every session registered on that server:client.get_response(...)only — response interceptors /@stops run after release;client.relay(...)and release when the upstream connection closes (reply.close()), which now sits on oneAsyncExitStackwith the slot so the two always free together, on every exit path (afinallyin_streamcloses the stack beforerecord_call);/v1/modelsand aux routes take no slot;Nonekeeps today's behavior.The limit is per server: it applies to the
serverandstaticinterception shapes (staticlists oneInterceptionServerConfigper server). Theelasticpool mints servers with the default config and stays unlimited; a pool-wide knob is a separate change.The same concern was bundled into the closed #2552 with unrelated changes; this reimplements only the request limit on current
main.Why
Rollout concurrency does not bound inference load: a recursive harness (rho in the data-flywheel pipeline, ~90 concurrent rollouts) fans out several model requests per rollout, so the provider sees bursts well past the rollout cap and answers with 429s that then surface as rollout errors. A per-server admission limit puts the bound where every request already passes.
Validation
tests/v1/test_interception.py::test_max_concurrent_requests_bounds_upstream[rendered|streamed]: a realInterceptionServerwithmax_concurrent_requests=2, five sessions sharing a gated stubClientthat counts in-flight upstream requests (the streamed stub decrements only onclose()), five concurrentPOST /v1/chat/completionsover HTTP. Asserts exactly two reach upstream while the rest queue, peak in-flight stays 2, and all five complete with a committed turn. With the limit unset the same probe reaches peak 5.uv run pytest tests/v1 -m "not e2e": 88 passed.uv run ruff check,uv run pre-commit run --all-files: clean.Note
Bound concurrent upstream model requests in
InterceptionServermax_concurrent_requestsfield (PositiveInt) toInterceptionServerConfigin server.pysamplehandler and streamed relay handler to bound concurrent upstream model requestsGatedClienttest double and concurrency tests in test_interception.py to verify the limit is respected for both rendered and streamed pathsmax_concurrent_requestsset use a no-op context manager, preserving existing unlimited admissionMacroscope summarized 507e414.