mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #656] [CLOSED] serve: cooperative prefill preemption at safe chunk boundaries (--prefill-preempt) #2748
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#2748
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/656
Author: @j-luwierski
Created: 10/3/2026
Status: ❌ Closed
Base:
main← Head:feat/prefill-preempt📝 Commits (10+)
5327b2cserve: cooperative prefill preemption at chunk boundaries (engine)2bf3786serve: preemption scheduling over ownership periods (+YIELD, tests)0c75053serve: preemption parity harness green; YIELD cleared at RESUME6371de2bench: the preemption A/B latency measurement (group N)abd5745bench/harness: the repeat scenario waits for the RESUME echo before the next YIELDe012b68harness: pin the expert-cache geometry for every engine of a comparison run3af7bc2harness: constant verify-window shapes (--spec-min-p 0)e1ea03dharness: one fresh-engine retry per scenario6fa3c23harness: pin the adaptive tier the owner's way (--adapt-every 100000)68ed5d5harness: a paired control for every scenario📊 Changes
22 files changed (+3893 additions, -217 deletions)
View changed files
📝
CMakeLists.txt(+11 -0)➕
include/strata/core/crash_report.hpp(+100 -0)➕
include/strata/core/expert_pack.hpp(+43 -0)➕
include/strata/core/prefill_preempt_budget.hpp(+44 -0)📝
include/strata/prefill/prefill.hpp(+11 -0)➕
serve/engine_gate.py(+65 -0)📝
serve/server.py(+548 -6)➕
serve/test_engine_gate.py(+101 -0)➕
serve/test_preempt.py(+519 -0)➕
serve/test_preempt_regressions.py(+170 -0)➕
src/core/crash_report_test.cpp(+87 -0)➕
src/core/expert_pack_test.cpp(+66 -0)➕
src/core/prefill_preempt_budget_test.cpp(+38 -0)📝
src/core/verify.cpp(+23 -0)📝
src/prefill/prefill.cpp(+10 -0)📝
src/program/generate.cpp(+788 -211)➕
tools/kv_stream_sweep.py(+266 -0)➕
tools/prefill_preempt_bench.py(+156 -0)➕
tools/prefill_preempt_regression.sh(+30 -0)➕
tools/prefill_preempt_test.py(+596 -0)...and 2 more files
📄 Description
Problem
Serving is sequential by design: the FIFO holds a mutex for a request's entire lifecycle, so a short interactive request sent during a long prefill waits for the whole prefill plus decode.
For orchestrator + sub-agent workloads sharing one Strata server, this resulted in tens of seconds of head-of-line blocking.
Measured example:
40.5 sof queue wait behind a50K-token prefill.Solution
This PR adds cooperative prefill preemption at safe chunk boundaries.
A long-running request A (for example, a
200K-token prompt) can park at a completed prefill chunk boundary, allowing a short request B to run immediately. Once B finishes, A is restored and continues as if it had never been interrupted.The execution model remains intentionally simple:
Engine (
--prefill-preempt, opt-in)Prefill::should_suspendruntail still executes, which:ple_prevfor the boundarySuspReqidx_block_posEngine protocol:
SUSPENDED <pos> <total> id=NRESUME id=NCANCEL id=NYIELDid=Nsuffix for demultiplexingPreemption gates:
T18)Server (
--prefill-preempt, opt-in)The FIFO lock is split into ownership periods instead of being held for the request's entire lifecycle:
A parked request waits outside the FIFO lock and receives keep-alives while suspended.
Additional behavior:
EngineRequestsupportsid=Nsuffix demultiplexingNew observability:
/metricsprefill_preemptionsprefill_resumesmax_queue_wait_ms/statusparked_requestsResults
Test system:
A prefill = 50K)40.5 s2.9 s(-93%)43.8 s45.3 s(+3.4%)The task targets were:
Both targets are met with margin.
Verification
Bit-exact parity
Tokens and the complete state fingerprint are identical between:
park -> interim request -> restoreVerified state includes:
gdnpletailspooledkvdeadpooled_fullmtpple_prevTested suspension boundaries:
4096819212288An interim request was executed between park and restore with decode depths:
0132The drafter KV state is included in the parity check.
Trace diagnostics
Added diagnostics include:
STATE_POINTVERIFY_POINTWINDOWThese provide:
GPU scenarios
12 GPU scenarios: ALL PASS
Coverage includes:
1Scheduler tests
Fake-engine scheduler suite: 9 tests
Coverage includes:
Existing test suites
ctest: 63/65The two failing
ctestcases are environmental and reproduce on pristinemain.Bugs Found and Fixed During Verification
The tests caught several issues during development:
YIELDcould re-park a resumed request at its next boundary.preempt_countwas saved before the increment, allowing--prefill-preempt-maxto be bypassed.<= --short-readcould switch to verifier windows differently from an uninterrupted read.E-9failure across buffer layouts.All of these were fixed before the final validation runs.
Limitations / Future Work
Current limitations:
--prefill-preempt-max-wait-s30 sbad_alloc🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.