From 6e8a2f0a94a48514cbf5b0d33f5597170a384931 Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 17:40:07 +0000 Subject: [PATCH] engine: the scored step refuses its union before pinning tries it The scheduler caps one request's scored candidate list at 4096 ids; nothing bounded the step's UNION. A step packed with maxed scored requests unions toward the whole vocabulary, the pinned readback buffer is sized from that union, and its size was discovered by ATTEMPTING it: a gigabyte-scale page-locked allocation whose only check was whether the box survived it. Survive it and the bytes stay pinned forever -- the buffer is grow-only. This was L-04: the round-one cancel-path invariant held (the engine never died on it), but the residual was an attacker-sized lever on page-locked memory. The cap is the step-wide sibling of the per-request one: 65536 unique candidate rows, sixteen maximally-loaded requests, while real scored questions name a few dozen ids each. A step past it takes the refusal the allocation failure already took -- the scored requests cancel, the engine and every other request on the step keep running -- except before the box is asked to pin anything to find out. The logits-row mode needs no sibling cap: its rows are one per scored request, bounded by the batch's max_seqs by construction. --- core/engine.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/engine.cpp b/core/engine.cpp index e2b4d23c..50986b87 100644 --- a/core/engine.cpp +++ b/core/engine.cpp @@ -1993,6 +1993,26 @@ int Engine::stage_scored_rows(const StepPlan& plan, const StepOut& so, score_ids_.erase(std::unique(score_ids_.begin(), score_ids_.end()), score_ids_.end()); } bool host_failed = false; + /* Step-wide sibling of the scheduler's kMaxScoredCandidates: that cap bounds one request's + * candidate list; nothing bounded the step's UNION, which grows toward the whole vocabulary. + * The pinned readback's size used to be discovered by ATTEMPTING it -- the cancel path below + * fired only when a gigabyte-scale page-locked allocation failed, so on a box that survives + * the attempt the bytes stay pinned forever (the buffer is grow-only). The cap is sixteen + * maximally-loaded requests -- d1's questions name a few dozen ids each, so every real + * scored step lands far under it. A step past it is refused the way an allocation failure + * refuses: the scored requests cancel, the engine does not, and the box is never asked to + * pin anything to find out. */ + static const size_t kMaxScoredStepIds = 1u << 16; + if (score_only_ && score_ids_.size() > kMaxScoredStepIds) { + RAD_ERR("scored rows: the step names %zu candidate rows, over the step budget of %zu; " + "cancelling the scored requests, not the engine", + score_ids_.size(), kMaxScoredStepIds); + cancel.insert(cancel.end(), scored.begin(), scored.end()); + score_rows_.clear(); + score_only_ = false; + score_ids_.clear(); + return RAD_OK; + } int64_t failed_rows = 0; for (auto& rk : ranks_) { const int64_t width = rk->sampler.config().n_vocab_local;