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) --