mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1808] [CLOSED] serve: a queue cap (max_queue) answers 429 + Retry-After instead of queueing without end #3689
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3689
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1808
Author: @streber42
Created: 10/10/2026
Status: ❌ Closed
Base:
main← Head:queue-cap-upstream📝 Commits (1)
9df9251serve: a queue cap (max_queue) answers 429 + Retry-After instead of queueing without end📊 Changes
4 files changed (+374 additions, -6 deletions)
View changed files
📝
docs/DETAILS.md(+50 -3)📝
serve/runconfig.py(+2 -0)📝
serve/server.py(+78 -3)➕
serve/test_queue_cap.py(+244 -0)📄 Description
Issue: Resolves #1809
Summary
"max_queue": Ninstrata-<model>.json(or--max-queue N) lets at most N generation requests wait beyond the running slots. One more gets an immediate 429 with a whole-secondRetry-After(1-60 s), sent before any byte of the answer, so a streamed request never starts a stream it cannot finish. If it is unset, the queue has no limit, as before;0rejects whatever cannot start at once.The status is 429 and not 503 because litellm and the OpenAI and Anthropic SDKs retry a 429 and read it as "busy". litellm cools the deployment down for
Retry-Afterand moves to another deployment in the group, or waits and retries when Strata is the only one. A 503 counts as a server failure there.What changed
serve/server.pyService.admit()/release()count admitted requests (running and waiting) understatus_lock. They use a new counter instead ofstatus["queued"], which reads about 0 while--batchrequests wait on the slots. The counter lives on the Service, so an engine restart (#1012) keeps it.do_POSTchecks right afterbegin_requestfor/v1/chat/completions,/v1/messagesand/v1/responsesonly, and releases in itsfinally, so every way out (disconnect,EngineDied, a 400) frees the place.Service.retry_after()is the meanduration_sof the last 8 finished requests divided by the slots, rounded up and clamped to 1-60 s, or 10 s before any request has finished. It is a whole number because litellm reads it withint().rate_limit_error/rate_limit_exceeded, Anthropicrate_limit_error, the Responses error body)._jsongains an optionalheadersargument for theRetry-Afterheader./metricsgainstotals.rejected,live.inflightandlive.max_queue, and/v1/statusactivitygainsadmitted,max_queueandrejected. No field was renamed.--max-queue; a bad config value stops the start with a message, and the start prints one line when the cap is on.serve/runconfig.py:max_queueis editable from the web page's Model settings (int>=0, empty means no limit).serve/test_queue_cap.py: 25 tests.Retry-Afterand the right body for all three dialects; a streamed request over the cap gets a JSON 429, not a stream; count_tokens and status are not limited; no limit when unset; the count returns to 0 after a finished, streamed, 400,EngineDiedand disconnected request.docs/DETAILS.md: a "Limiting the queue" section with measurements and notes for litellm, the/metricsfield, and the web-editable key.Extra Notes
python -m unittest serve.test_queue_cap serve.test_runconfig serve.test_parallelgives 57 OK on this branch, which is currentmainwith the commit on top. The fullservesuite runs 622 tests; its 7 errors are allNo module named 'regex'in my Python, intest_detokandtest_server, and none come from this change.max_queue2: of 5 requests sent at once, 3 were answered in 5.1, 7.7 and 10.1 s, and 2 got the 429 in under 2 ms.max_queue4: theRetry-Afterit sent over 5,379 rejections had a median of 8 s and a maximum of 31 s.serve.test_queue_cap,serve.test_parallelandserve.test_server(including #1673'sQueuedHeartbeat) pass; the only errors are the sameregexones.🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.