sched: refuse a prompt id that names no vocabulary row

The scored-prompt path (Request::token_scores) has always vetted its ids against the
vocabulary; the prompt itself never was. Raw id arrays arrive at admission verbatim from
the request body -- /v1/completions, /v1/embeddings and the generator take them -- and an
id past the embedding table is gathered by the step, fails it, and a failed step is a
device fault (spec 17): one request, {"prompt":[2147483647]}, ended every session on the
server. The check belongs at admission, where a refusal is a 400, not mid-pass, where it
is an exit.

The sched fixture's model declares 512 vocabulary rows and its requests spell prompts
from 1000 up; admission now refuses those, so the fixture's vocabulary moves above the
ids it uses.
This commit is contained in:
fl0l0u authored and StillDeadcode committed 2026-10-29 16:22:35 +01:00
1 parent ed5f990d92
commit a28221eb6a
2 files changed
+39 -1

No files matched your search

+11
View File
@@ -263,6 +263,17 @@ int Scheduler::add_locked(std::unique_ptr<Request> 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;
/* 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) —
* the whole engine would die for one bad number. Same bound as the scored-prompt check below.
*/
for (int32_t t : r->prompt)
if (t < 0 || t >= prog_->meta.n_vocab) {
RAD_WARN("request %llu refused: prompt token id %d is outside the vocabulary [0, %lld)",
(unsigned long long)r->id, t, (long long)prog_->meta.n_vocab);
return RAD_E_INVAL;
}
/* Nor could a prompt the KV pool cannot hold even alone: admission takes only what the pool
* holds, so it would wait at the head of the queue, and everything behind it, forever. The
* prompt is the least a request needs: its first token comes from the prefill's last row.
+28 -1
View File
@@ -11,6 +11,7 @@
#include "server/sink.h"
#include <algorithm>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <new>
@@ -97,7 +98,9 @@ struct Fixture {
g_gdn_row = KernelRow{ &g_gdn_ki, "fake", 0, 0 };
prog.meta.n_ctx_train = 4096;
prog.meta.n_vocab = 512;
/* Above the 1000 + i the requests below spell: admission refuses ids past the
* vocabulary, and these prompts must be admissible. */
prog.meta.n_vocab = 65536;
/* index 0 is the sentinel every handle table in Program carries */
prog.ops.emplace_back();
@@ -1280,6 +1283,30 @@ TEST(a_scored_request_names_real_vocabulary_rows) {
CHECK(!kept->may_speculate);
}
/* The prompt itself names real vocabulary rows too: raw id arrays arrive verbatim from the
* request body, and an id past the embedding table must die at admission, never staged into a
* pass — the embedding gather would fail the step, a failed step is a device fault, and a
* device fault stops the engine (spec §17). One bad number must not be a server kill. */
TEST(a_prompt_names_real_vocabulary_rows) {
Fixture f;
f.build(/*blocks=*/20, /*states=*/64);
CHECK_OK(f.start());
const int32_t n_vocab = (int32_t)f.prog.meta.n_vocab;
std::unique_ptr<Request> rs[5];
const std::vector<std::vector<int32_t>> ids = { { 1, 2, n_vocab - 1 }, { n_vocab }, { -1 },
{ 7, INT32_MAX }, { 0, 1, 2, n_vocab + 9 } };
int rc[5] = { -1, -1, -1, -1, -1 };
for (int i = 0; i < 5; ++i) {
rs[i] = std::make_unique<Request>();
rs[i]->id = f.next_id++;
rs[i]->max_tokens = 1;
rs[i]->prompt = ids[(size_t)i];
}
f.sch.add_all(rs, 5, rc);
CHECK_EQ(rc[0], RAD_OK);
for (int i = 1; i < 5; ++i) CHECK_EQ(rc[i], RAD_E_INVAL);
}
TEST(a_prefix_hit_starts_the_request_at_the_last_usable_checkpoint) {
Fixture f;
f.build();