[PR #4341] [CLOSED] [Engine] serve: STRATA_ADMIT_SHORT_FIRST orders the single-stream queue too #5016

Closed
opened 2026-11-07 16:32:02 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4341
Author: @suifei
Created: 10/27/2026
Status: ❌ Closed

Base: main ← Head: feat/single-stream-short-first


📝 Commits (1)

  • d9569fd [Engine] serve: STRATA_ADMIT_SHORT_FIRST orders the single-stream queue too

📊 Changes

2 files changed (+109 additions, -15 deletions)

View changed files

📝 serve/server.py (+52 -15)
📝 serve/test_queue_keepalive.py (+57 -0)

📄 Description

Problem

Without --batch the single turn is strictly first come, first served (Service.fifo). A short request - a chat
question, a health check, a tool's side request - waits behind every agent prompt that arrived before it, including the
decode of a long answer, even though STRATA_ADMIT_SHORT_FIRST already gives it priority in the batched queue. On this
box a queued request can wait one whole agent turn (~1-2 min), with keep-alives so it does not time out, but it waits.

Result

With the same opt-in setting (STRATA_ADMIT_SHORT_FIRST; unset or 0 keeps the old behaviour exactly), the requests
waiting for the single turn are ordered as StrataEngine._admit_next orders them:

  • a prompt of at most STRATA_ADMIT_SHORT_FIRST tokens goes before longer ones, arrival order within the short group and
    within the long group;
  • a longer one that has waited STRATA_ADMIT_MAX_WAIT_S (default 30 s) counts as short, so a long request is never held
    back for good;
  • the request that holds the turn is never interrupted - only the waiters' order changes;
  • a waiting request still sends its keep-alive every QUEUE_BEAT_S, and a client that leaves while queued gives its
    place up.

Validation

Revision d9569fd (branch feat/single-stream-short-first). Unit tests use the mock engine on this revision.

Passed:

  • python -m unittest serve.test_queue_keepalive: 6 tests - the 3 existing ones plus 3 new: a late short request takes the turn first over three rounds; the age-out restores arrival order; an ordered waiter still beats and drops out when its client leaves. The 3 new tests fail cleanly on main (no ordering).
  • the existing default path is untouched when the setting is unset: same fifo.acquire loop as before.

Failed, unrelated:

  • the full serve suite (1038 tests) has two failures: test_lifeline's watcher, which fails on unmodified code in this container, and test_responses.NoLeakedSampler, which fails 4 of 6 runs on unmodified main when it runs after test_queue_keepalive (a leftover sampler thread from the previous test).

Not run:

  • a real engine or a GPU (the tests use the mock engine);
  • the --batch path, which has its own _admit_next ordering already.

Usage

STRATA_ADMIT_SHORT_FIRST=2048 (tokens) turns it on. If the long requests are agent turns that take minutes, raise
STRATA_ADMIT_MAX_WAIT_S too (e.g. 300), otherwise a long request that has waited only 30 s is treated as short and the
ordering does little.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4341 **Author:** [@suifei](https://github.com/suifei) **Created:** 10/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `feat/single-stream-short-first` --- ### 📝 Commits (1) - [`d9569fd`](https://github.com/Niko1221/Strata/commit/d9569fda846dbc3efa0b4813b56c23bbb280b72f) [Engine] serve: STRATA_ADMIT_SHORT_FIRST orders the single-stream queue too ### 📊 Changes **2 files changed** (+109 additions, -15 deletions) <details> <summary>View changed files</summary> 📝 `serve/server.py` (+52 -15) 📝 `serve/test_queue_keepalive.py` (+57 -0) </details> ### 📄 Description ## Problem Without `--batch` the single turn is strictly first come, first served (`Service.fifo`). A short request - a chat question, a health check, a tool's side request - waits behind every agent prompt that arrived before it, including the decode of a long answer, even though `STRATA_ADMIT_SHORT_FIRST` already gives it priority in the batched queue. On this box a queued request can wait one whole agent turn (~1-2 min), with keep-alives so it does not time out, but it waits. ## Result With the same opt-in setting (`STRATA_ADMIT_SHORT_FIRST`; unset or `0` keeps the old behaviour exactly), the requests waiting for the single turn are ordered as `StrataEngine._admit_next` orders them: * a prompt of at most `STRATA_ADMIT_SHORT_FIRST` tokens goes before longer ones, arrival order within the short group and within the long group; * a longer one that has waited `STRATA_ADMIT_MAX_WAIT_S` (default 30 s) counts as short, so a long request is never held back for good; * **the request that holds the turn is never interrupted** - only the waiters' order changes; * a waiting request still sends its keep-alive every `QUEUE_BEAT_S`, and a client that leaves while queued gives its place up. ## Validation Revision `d9569fd` (branch `feat/single-stream-short-first`). Unit tests use the mock engine on this revision. **Passed:** * `python -m unittest serve.test_queue_keepalive`: 6 tests - the 3 existing ones plus 3 new: a late short request takes the turn first over three rounds; the age-out restores arrival order; an ordered waiter still beats and drops out when its client leaves. The 3 new tests fail cleanly on `main` (no ordering). * the existing default path is untouched when the setting is unset: same `fifo.acquire` loop as before. **Failed, unrelated:** * the full `serve` suite (1038 tests) has two failures: `test_lifeline`'s watcher, which fails on unmodified code in this container, and `test_responses.NoLeakedSampler`, which fails 4 of 6 runs on unmodified `main` when it runs after `test_queue_keepalive` (a leftover sampler thread from the previous test). **Not run:** * a real engine or a GPU (the tests use the mock engine); * the `--batch` path, which has its own `_admit_next` ordering already. ## Usage `STRATA_ADMIT_SHORT_FIRST=2048` (tokens) turns it on. If the long requests are agent turns that take minutes, raise `STRATA_ADMIT_MAX_WAIT_S` too (e.g. 300), otherwise a long request that has waited only 30 s is treated as short and the ordering does little. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:32:02 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5016
No description provided.