sched: the preempted-prefill gate skips a KV group that holds no blocks

Every program carries a sentinel KV group at index 0. KVGeom reads its decl.kind 0 as RAD_KV_FULL
with block size 1, while the manager's plan for it pages nothing and owns no block. The gate
(e668d49) walked every group KVGeom calls paged, so for the sentinel it wanted the whole prompt,
one block a token, out of a pool of none: a preempted request was never readmitted. The bound on
the wait (33108e4) cannot help, since preempting running requests frees nothing in that group.
engine_e2e_test's qwen35_preemption_by_recompute_changes_no_logit hung on it (the KL recording of a
small pool: one preempted document, nothing left running); with the group skipped it passes in
0.9 s. It may also be the live request in #346 that waited 710 s with gen=0.

The gate now skips a group with no blocks (total_blocks 0), as KVManager::ensure skips a group its
plan does not page.

sched_test: a_preempted_prefill_ignores_a_kv_group_that_holds_no_blocks (a group the scheduler sees
as full and the manager as empty; the preempted request stayed Preempted after the pool emptied
before the fix). 173 cases pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-30 12:11:13 +01:00
1 parent 167595a9b4
commit 8df9240d65
2 files changed
+46 -1

No files matched your search

+42
View File
@@ -1725,6 +1725,48 @@ TEST(a_preempted_prefill_waits_for_the_whole_prompt_and_running_headroom) {
f.commit_plain();
}
/* Every program carries a sentinel KV group at index 0: decl.kind 0 (RAD_KV_FULL), block size 1, no
* layers, and the manager's plan for it pages nothing, so it holds no blocks. The gate must not ask
* that group for the prompt's blocks: it has none to give, and the preempted request would wait
* for ever (engine_e2e_test's preemption case hung on it, with nothing left running). Here the
* group is appended, not at index 0, so the fixture's bindings stay where they are. */
TEST(a_preempted_prefill_ignores_a_kv_group_that_holds_no_blocks) {
Fixture f;
f.build(/*blocks=*/26, /*states=*/64); /* 26 x 16 = 416 tokens */
KVGroupInfo none; /* as the sentinel: kind 0, no block size, no layers */
none.name = "none";
f.prog.kv_groups.push_back(none);
f.kv.setup(f.prog.kv_groups, f.cfg.max_ctx, 26, 64);
const size_t ng = f.prog.kv_groups.size() - 1;
f.kv.geom.g[ng].paged = false; /* the manager pages nothing there ... */
f.kv.total[ng] = 0; /* ... and owns no block of it */
f.kv.freelist[ng].clear();
f.kv.refcnt[ng].clear();
for (int k = 63; k >= 0; --k) f.kv.state_free[ng].push_back(k);
f.cfg.preempt_wait_ms = 60000;
CHECK_OK(f.start());
uint64_t a = f.submit(287, 64, /*priority=*/5);
uint64_t b = f.submit(128, 64, /*priority=*/0);
CHECK(f.sch.step() != nullptr);
CHECK_EQ(f.sch.plan().e.size(), 2);
f.commit_plain();
CHECK(f.sch.step() != nullptr); /* B's next block: B is preempted */
CHECK_EQ((int)f.sch.find(b)->state, (int)ReqState::Preempted);
f.commit_plain();
for (int i = 0; i < 80 && f.sch.find(a)->state != ReqState::Finished; ++i) {
CHECK(f.sch.step() != nullptr);
f.commit_plain();
}
CHECK_EQ((int)f.sch.find(a)->state, (int)ReqState::Finished);
/* A's blocks are back and nothing runs: B prefills its whole prompt again. */
CHECK(f.sch.step() != nullptr);
CHECK_EQ((int)f.sch.find(b)->state, (int)ReqState::Running);
f.commit_plain();
}
/* The gate's wait is bounded: after --preempt-wait-ms an overdue preempted prefill gets room by
* preempting the lowest-priority running request before the step is planned, so it cannot queue
* forever behind a long decode (the 710 s stall in the daily's log). */