From b44f7a9bb13928d16f48414091253139e5226966 Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 17:20:47 +0000 Subject: [PATCH] sched: an over-cap request would stall every queue behind it A plugin that declared plugin_words gets a fixed carrier in the batch -- [max_seqs * plugin_words] rows, carved only because the program said how many words a sequence may carry. The build stage already refuses a sequence past that bound, but nothing at admission did, and a refused build restages its step forever: one request carrying more words than the plugin declared stalls every queue behind it, permanently. add_locked now reads the same bound the batch carves by (BatchBuilder:: plugin_words_cap, the program's declaration) and refuses an over-cap request with RAD_E_INVAL, where the server turns it into a clean 400. The current route caps its own words already; this is the promise no future route can miss, checked once at the gate every request passes. --- core/sched/batch.h | 4 ++++ core/sched/scheduler.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/core/sched/batch.h b/core/sched/batch.h index afb9b641..8cada3c5 100644 --- a/core/sched/batch.h +++ b/core/sched/batch.h @@ -135,6 +135,10 @@ public: /* The last build's batch for one rank: build()'s result with that rank's slab pointers. */ const RadBatch* batch_for(int rank) const; + /* Program::plugin_words as declared: the most words one request may carry. Admission checks + * it -- the build stage refuses an over-cap sequence, and a refused build restages forever, + * so a request admitted past the cap stalls every queue behind it. */ + int64_t plugin_words_cap() const { return pw_cap_; } /* The last build's slab and offsets on one rank, for the advance. The caller supplies mode, * round, slot state and inputs (advance.h). */ diff --git a/core/sched/scheduler.cpp b/core/sched/scheduler.cpp index 7a98be20..b461fcf9 100644 --- a/core/sched/scheduler.cpp +++ b/core/sched/scheduler.cpp @@ -388,6 +388,13 @@ int Scheduler::add_locked(std::unique_ptr r) { /* An embedding input runs in one step or not at all (Request::embed); one longer than a step * could never be admitted. */ if (r->embed && (int64_t)r->prompt.size() > cfg_.max_tok) return RAD_E_INVAL; + /* The words a request hands the plugin are bounded by the plugin's declaration. The batch + * stage refuses a sequence past it, and a refused build restages the step forever -- an + * over-cap request admitted here would stall every queue behind it. The server-side route + * caps its own words; this is the promise no future route can miss. */ + if (!r->plugin_words.empty() && + (int64_t)r->plugin_words.size() > builder_.plugin_words_cap()) + return RAD_E_INVAL; /* Every prompt id, tokenised or client-supplied, names a real vocabulary row: an id past the * embedding table is refused at admission, never staged into a pass. Raw id arrays reach here * straight from the request body, and an op failing mid-step is a device fault (spec ยง17) --