mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
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#4297
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/2843
Author: @andyhrc
Created: 10/17/2026
Status: 🔄 Open
Base:
main← Head:pr/slot-checkpoints📝 Commits (10+)
8d634bcbatch: STRATA_PIPELINE_ACTIVE_ROWS=1 - a pipelined group's window runs its active slots only, so an idle slot keeps its conversation (opt-in)da5a462batch: park=B keeps the main session's conversation in an idle slot before a different request replaces it (with STRATA_PIPELINE_ACTIVE_ROWS=1)2b64831serve: STRATA_SLOT_CACHE_AFFINITY=1 - place batch requests by what the slots hold, with the placement policy as an interface (serve/slot_policy.py)82ba0f4serve: the allocation event and a slot's live row show this request's own placement plan023edc2serve: /metrics live.solo_* clear when the solo request endsd926b13serve: no protection wait - place() always answers a free slot2d9b685serve: no PARK_MIN_TOKENS - a park is not cut off by lengthf89de46batch, serve: park=B tells another conversation by the main session's last turn, not by half of it17fad48serve: a continued request's record keeps its first read's cache source and placement hintc7edf14serve: test_cache_trace imports serve.* by name, so it also loads when serve/ is discovered on its own📊 Changes
19 files changed (+2367 additions, -48 deletions)
View changed files
📝
CMakeLists.txt(+6 -0)📝
docs/BATCHING.md(+221 -1)📝
include/strata/core/conversation_cache.hpp(+3 -0)📝
include/strata/core/verify.hpp(+2 -0)➕
include/strata/program/pipeline_rows.hpp(+16 -0)➕
include/strata/program/slot_checkpoints.hpp(+80 -0)➕
serve/cache_trace.py(+18 -0)📝
serve/server.py(+364 -18)➕
serve/slot_policy.py(+309 -0)➕
serve/test_cache_trace.py(+44 -0)📝
serve/test_parallel.py(+69 -2)📝
serve/test_parallel_yield.py(+28 -0)📝
serve/test_slot_alloc.py(+819 -1)📝
src/core/verify.cpp(+7 -2)📝
src/program/generate.cpp(+224 -20)➕
src/program/slot_checkpoints_test.cpp(+88 -0)📝
sycl/include/strata/core/verify.hpp(+2 -0)📝
sycl/src/core/verify.cpp(+8 -4)➕
tests/core/pipeline_rows_test.cpp(+59 -0)📄 Description
Problem and result
A client that rewrites the end of its history every time never finds a checkpoint to continue from. Claude Code's
safety classifier is one. Each query is the agent's transcript with the new tool calls inserted before the closing text
(
... </transcript>and the instruction), so the next query leaves this one a few dozen tokens before its end. Threethings then miss:
park=, or an admission continuing in its slot) keeps only its deepestcheckpoint.
On our server (3 x RTX A4000 layer split,
--batch 6), every classifier query of 2026-10-16 read its whole 42-74K-tokentranscript again. That was 15.6-27.4 s per call, with several calls per agent step.
With
STRATA_BRANCH_CHECKPOINT=1024, from the third query of a chain on, queries resume at a branch checkpoint. Theyread 534-1,329 tokens in 1.2-2.0 s instead of 43-45K tokens in about 14 s (table under Validation). All switches are
opt-in. Unset, every path is the one before.
Related discussion
There is no issue. This PR was opened on 2026-10-17 and closed in the 0.2.0-beta tracker reset; it is rebased on current
mainhere. It is part 3 and depends on #2527 and #2528: the branch includes their commits, and this PR's own arethe last six. The placement side of the same problem (
STRATA_SLOT_SIBLING_SHARE: a slot holding an older version ofthe conversation is the one to replace) is in #2528. A user with the same client pattern reported numbers in this PR's
earlier thread. I can open an issue for the scope first if you prefer.
Approach
STRATA_BRANCH_CHECKPOINT=<margin>(serve, batch or not). Before reading, the engine measures how far the promptruns along each conversation it holds (the main session's and every idle slot's) before leaving it. Two conditions
apply: that point is
<margin>tokens or more past where the read starts, and it lies before the turn boundary. Whenboth hold, the read stops there for one more checkpoint, like the root and turn cuts. The next query leaves this one
later, so it resumes there. With the switch on, a slot keeps the deepest such branch checkpoint of its conversation.
STRATA_SLOT_CHECKPOINTS=N(batch; unset means 1, as before) sets how many checkpoints a slot keeps: the deepest,then the deepest others, with the branch one counted in N. The two switches are separate:
STRATA_BRANCH_CHECKPOINTA slot that gives its conversation back to the main session brings its checkpoints along (main's port of #2526
since v0.2.7: the one continued from and every shorter prefix of what was copied back). The pure helpers are in
include/strata/program/slot_checkpoints.hpp, with unit testslot_checkpoints_test.With upstream's
STRATA_SLOT_CKPT_MOVE=1, an admission moves all of them into the slot instead of copying; thechain's root and a pinned prefix are still copied. The slot's are then the conversation's only ones, so a slot that
gives back all it holds moves them back whichever slot the request continues in. #2526 moves them only into the same
slot and copies them otherwise, which left a second running state (about 114 MiB) in the old slot until it was
overwritten, and the copy took its time: 99.8 ms against 25.6 ms for a 19,869-token conversation with one
checkpoint. A copy there goes into the checkpoint pool (
STRATA_CKPT_POOL), and after a move into another slot theengine sends
BCHECKSfor the old slot.BCHECKS <slot> <tokens> <lengths>(with N > 1 orSTRATA_BRANCH_CHECKPOINT). AfterPARKED,BADM 1andBYIELD, the engine says which checkpoints a slot keeps. The server:/metrics(checkpoint_tokens)place()use the deepest one that starts the prompt as the hint where no slot's history continues itThis is information only: the engine still picks what it reuses.
Rebase on
main(5e8a4cca, v0.2.7): main now brings a slot's checkpoints back at a give-back itself (#2526,with a prefix and picture check and an out-of-memory skip). This PR's own give-back code is dropped in favour of it;
what remains of it is the last commit (the move into another slot under
STRATA_SLOT_CKPT_MOVE, pool copies,BCHECKS). A branch checkpoint whose copy fails follows #3350 (skipped, the request goes on), and the checkpointpool clears the
branchmark beside the newdev_tag.Validation
Passed:
pr/slot-checkpointsat273ebac5, onmain5e8a4cca(v0.2.7). The serve tests andslot_checkpoints_testwere run on this head; the GPU runs name their own revision. Ubuntu, AMD EPYC 7543,3 x RTX A4000 16 GB, CUDA 13.3.
python -m unittest discover -s serve -t .on this branch: 1293 tests OK (38 skipped).requirements.txt, thentools/minimal_server_smoke.pyandpython -m unittest discover -s serve -p 'test_*.py'): smoke OK, 1293 tests OK (38 skipped). The previous head failed there onserve/test_cache_trace.py's relative imports (fine with-t .); the last commit of #2527 fixes them.slot_checkpoints_test(31checks),
pipeline_rows_testandbatch_groups_testpassed on v0.2.7 (built from our production tree: this stackserve/server.py(at58eef307, on v0.2.1.1; repeated with our v0.2.7 production build, which includes the last commit).Setup: Qwen3.8-Flash-Next IQ3_S, 200K context, int8 K/V,
--kv-resident 32768,--batch 6in 3 groups, theswitches we deploy (
STRATA_BRANCH_CHECKPOINT=1024 STRATA_SLOT_CKPT_MOVE=1 STRATA_CKPT_POOL=1, N unset) beside#2527 / #2528's.
Workload: a 43-45K-token classifier transcript growing by about 250 tokens per query, with an agent conversation
taking the main session between the queries. S: alone; B: a client decoding beside it.
Seconds per query 1-6:
From query 3 on, queries resume at the branch checkpoint (43,340 tokens reused, 534-1,329 read), as on 0.1.45. B's first query resumes at once because the chain's branch checkpoint from S is still in a slot. A thinking chat's next turn sent back without its thinking took 0.63 s (19,176 tokens reused + 154 read; 0.58 s on 0.2.7).
Throughput: 66.0 tok/s with one client, and 192.2 tok/s total with 6 clients x 2048 tokens (
tools/serve_load.py, temperature 0, one run each). On 0.1.45 with the same switches it was 62.8 / 180.6; the difference comes from upstream's changes since then, not from this PR.tools/serve_load.py, temperature 0):67.6 / 63.0 tok/s with one client (1,024 tokens), 190.7 / 191.5 tok/s total with 6 clients x 2,048 tokens (v0.2.2:
64.3 / 193.7).
short answers were the same tokens without and with the switches. Of 6 160-token answers, 5 were the same and one
differed from its first token. That one depends only on whether the read had a cut at 43,340, so the saved and
restored state is the one the read had there. The cut changes the chunks of the read after it, as
pin=does.Failed:
None observed. (The previous revision's note about
serve.test_responses.NoLeakedSamplerfailing on main here no longer applies: the whole suite passes.)Not run:
src/program/generate.cpponly, shared by every backend's serve loop.Limits
--prompt-cache. A slot keeps one more checkpoint where its conversation has one (N = 1). With 6 slots, the bound growsfrom 12 to 18 checkpoints (+0.67 GiB); in practice it grows by about 114 MiB per slot holding a classifier-like
conversation.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.