sched_test: assert the slot reuse the recycled-slot case depends on

The case that guards the admitted_us reset read two timing inequalities and never checked
that the second request landed in the first request's slot. It rests on that: if the reap
defers, or the free list is pre-populated, the second request gets a fresh struct, the stale
stamp is absent by construction, and the invariant holds with the bug unpatched. A test whose
precondition is a property of the fixture rather than an assertion goes quiet without saying
so, which is worse than not having it.

Read the slot from the published row before the reap and assert it afterwards. This also
settles the one thing the review could not: whether the reap releases immediately or defers.
It releases, because the assertion holds -- proven by running it rather than by reading the
ahead-step planning that decides it.

Verified: the case passes, and removing the reset line still fails it, so the added assertion
did not blunt it. sched_test 62646 checks over 184 cases, no failures.

Found by an independent review pass on the fix itself.

Authored at: Memoria Qwen 3.8 Flash-Next 125B MoE (level not visible) via Open WebUI
This commit is contained in:
Memoria (Noblistic) authored and StillDeadcode committed 2026-11-03 18:09:49 +01:00
1 parent e53286cdbe
commit 4e35a00493
1 file changed
+13
+13
View File
@@ -7393,6 +7393,18 @@ TEST(a_recycled_slot_does_not_carry_the_previous_request_s_admission) {
f.commit_plain();
}
REQUIRE_EQ((int)f.sch.find(a)->state, (int)ReqState::Finished);
/* The slot A held, read while its row is still published. The whole case rests on B landing
* in this same slot: if the reap ever defers, or the free list is pre-populated, B gets a
* fresh struct, the stale stamp is gone by construction, and the invariant below would hold
* with the bug unpatched. So the precondition is asserted rather than trusted. */
int slot_a = -1;
{
std::vector<Scheduler::ReqStat> st(8);
const int n = f.sch.requests(st.data(), 8);
for (int j = 0; j < n; ++j) if (st[(size_t)j].id == a) slot_a = st[(size_t)j].slot;
}
REQUIRE(slot_a >= 0);
CHECK_OK(f.sch.reap(a));
/* A's slot is on the free list, so B takes the slot and the struct that came with it. */
@@ -7408,6 +7420,7 @@ TEST(a_recycled_slot_does_not_carry_the_previous_request_s_admission) {
if (st[(size_t)j].ttft_s < 0) break; /* no first token yet */
/* Both figures describe this request alone, so prefill -- admission to first token --
* is bounded by ttft, arrival to first token. */
CHECK_EQ(st[(size_t)j].slot, slot_a); /* the reuse this case is about */
CHECK(st[(size_t)j].prefill_s >= 0);
CHECK(st[(size_t)j].prefill_s <= st[(size_t)j].ttft_s);
return;