feat: model SGLang's prefill admission controls and shortest-prefill-first in replay #1148
All Vouch review confidence checks passed
Residual risk 0.36 = Change Risk (0.64) × (1 − Review Confidence (0.44)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.64 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 10%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
No Reviewer Assigned
no_reviewer_assigned
0.120
Real PR Conversation Timeline
1 comments
"Review active on #1148"
general
weight: 0.35
simone-chen
Depends on #1120, and through it on #1104; must merge after both. This PR is stacked on #1120's branch (
aisim-sglang-overlap-first-token), which is stacked on #1104's.What
SGLang v0.5.23 has three controls that admit new requests in fewer, larger prefill batches. Replay modeled none of
them. They are now opt-in fields on
workers.<role>.scheduler(nativesglang.*). Unset, admission and the serializedconfig are unchanged.
| field | SGLang flag | behaviour (v0.5.23, 297e54fd) |
|---|---|---|
|
min_free_slots_delay: N|--min-free-slots-delay| While requests run and no prefill chunk is in flight, admit no new request until N running-request slots are free (min_free_slots_delayer.py,scheduler.py:4103-4113). Capped atmax_sequences; 1 or less disables it. ||
prefill_max_requests: N|--prefill-max-requests| At most N requests in one prefill batch, a continuing chunk included (schedule_policy.py:1398-1399). ||
prefill_delayer: {max_delay_passes, queue_min_ratio, max_delay_ms}|--enable-prefill-delayerand its controls | See below (prefill_delayer.py). |How the prefill delayer works:
- free slots are fewer than the largest of the last 16 prefill batches;
- with
queue_min_ratio, the waiting queue is shorter thanmin(floor(running x ratio), prefill_max_requests).max_delay_passes - 1passes.- the queue condition lapses after
max_delay_ms, measured in simulated time;- a pass with no candidate ends the hold;
- passes blocked by
prefill_decode_intervalneither count nor end a hold, because SGLang skips the delayer there.How the delays count the running batch:
overlap_output_release, a request whose last forward finished it is still in SGLang'srunning batch while the next batch forms (
len(running_batch.reqs),scheduler.py:4103;running_batch.batch_size(),schedule_policy.py:1449). The delays count it too.decodeworkers and AFD.-
min_free_slots_delayand the delayer are also rejected with pipeline parallelism, as SGLang does(
validation_hook.py:165-169).- The delayer also needs
attention_data: 1, because SGLang negotiates it across the DP group.Shortest-prefill-first
workers.<role>.scheduler.schedule_policy: shortest_prefill_first(nativesglang.schedule_policy) models SGLang's--schedule-policy shortest-prefill-first(v0.5.23schedule_policy.py):- duplicate short prefix first;
- then
max(1, input + output - matched)uncached tokens (:398-416);- then queue entry. Every enqueue stamps the entry, a retracted request's re-enqueue included (
scheduler.py:3493-3494,:4539-4540).:418-438,scheduler.py:4176-4184).:1646-1652).calc_priorityonly then(
scheduler.py:4100-4131). That excludes passes with a full batch, an empty queue, a min-free-slots delay, no freeslot or a deferred prefill.
fcfskeep the native FIFO path.Docs:
docs/replay/engine/workers.mdhas the field table rows and the "SGLang prefill admission controls" and "SGLang shortest-prefill-first" sections. Thenew
crates/core/src/engine/scheduler/sglang/admission.rstranslates SGLang's delay logic, andpolicy.rsits SPF sortand chunk cap. Both are attributed in
THIRD_PARTY_NOTICES.md, and the notice copies are byte-identical.Evidence
E2E replay of the 26 InferenceX AgentX points for Qwen3.8-Flash-Next (whole agent sessions, host CPU overhead on).
The rules were recorded before scoring. The full results are in
benchmarks/evidence/accuracy/qwen38-sglang-admission-spf.md(scoring commit 1433d669a).
- c20 and c36:
min_free_slots_delay: 2and shortest-prefill-first.- c56 and c80: also
prefill_max_requests: 4and the delayer, with ratios 0.2 / 0.1 and 300 ms.- c8: shortest-prefill-first only.
The 21 other points are bit-identical.
| | TTFT e2e | TTFT p5-p95 | TPOT e2e | TPOT p5-p95 | all four |
|---|---|---|---|---|---|
| flags unset | 20 | 17 | 17 | 19 | 12 |
| admission controls only | 20 | 19 | 20 | 21 | 13 |
| admission controls + shortest-prefill-first (this PR) | 19 | 21 | 19 | 21 | 14 |
At the flagged points (error %, unset -> this PR):
| point | TTFT e2e | TTFT p5-p95 | TPOT e2e | TPOT p5-p95 | TPOT pred/sil |
|---|---|---|---|---|---|
| GB300 c8 | 9.5 -> 16.6 | 21.7 -> 8.6 | 4.5 -> 4.4 | 4.7 -> 4.8 | 1.045 -> 1.044 |
| GB300 c20 | 5.3 -> 22.7 | 46.3 -> 12.8 | 9.0 -> 6.2 | 9.2 -> 5.4 | 1.090 -> 1.062 |
| GB300 c36 | 11.7 -> 8.9 | 85.6 -> 10.3 | 2.4 -> 1.1 | 2.9 -> 2.1 | 1.024 -> 0.989 |
| GB300 c56 | 1.7 -> 4.1 | 21.5 -> 5.3 | 7.8 -> 2.1 | 9.7 -> 3.6 | 1.078 -> 1.021 |
| GB300 c80 | 9.5 -> 9.9 | 15.9 -> 6.5 | 9.6 -> 5.1 | 10.6 -> 6.1 | 1.096 -> 1.051 |
What the controls change:
now within 0.01-0.08 of it. Fewer prefill passes interrupt decode, so TPOT e2e error falls at all four.
short-request p50 TTFT gap falls from 0.9 s to 0.14 s at c20 and from 2.3 s to 0.05 s at c36. The p5-p95 TTFT error
falls at all three points that set it.
Accepted rule exception (owner's decision). At c20, shortest-prefill-first raises TPOT pred/sil from 1.026 (admission
controls alone) to 1.062. That breaks this change's pre-declared rule that TPOT must not move by more than 2 SE and 1
point (+3.6 points against 3.0). The owner kept it anyway: about 5 points of c20's TPOT over-prediction is a truth
caveat, not a model error.
replay models.
Tests
cargo test --workspace: 4,080 passed, none failed, at a1f9a5005. The two later commits change only tests.- At the head, the SGLang scheduler, config and rank tests pass (711).
- The new test fails when the gate's min-free-slots check is removed.
pytest -c pytest.ini tests: everything this change touches passes. The 35 local failures need modules notinstalled in the local venv (
sklearn,requests,collector,pip-licenses,cryptography) or the manylinuxtoolchain.
pytest -c python/aisim/pytest.ini python/aisim/tests -m "unit or build": 24,576 passed before SPF was added. Thelocal failures are in collector, onboarding and CLI-binary tests that this change does not touch.
- each control alone and the free-slot threshold;
- the delayer's skip, cap, queue ratio, time cap and end-of-hold rules;
- a continuing chunk that runs while the delayer holds;
- interval-blocked passes during a hold;
- finishing requests counted in the running batch.
- the CLI value, the order (least uncached work first, queue-entry ties, duplicate prefixes last, generated tokens
counted);
- the chunk cap and its stop cases, and the second-chunk refusal;
- a retracted request re-stamped;
- host-cached tokens under HiCache;
- the queue left unordered on passes that cannot admit (no free slot, a min-free-slots hold).
through the native scheduler.