[FIX] restore the prompt vocabulary check, the empty --api-key refusal and scored steps' issue-ahead rule

33108e48 (the preempted-prefill gate's wait bound) was cut from an older main and, landing, took
back three changes that had merged before it:

- a28221eb: a prompt id outside the vocabulary is refused at admission (Scheduler::add_locked),
  never staged into a pass where the embedding gather faults the device and stops the engine; and
  its test, a_prompt_names_real_vocabulary_rows.
- b9c685a9: --api-key "" is a startup error, not a server that looks guarded and answers every
  keyless request; and the guide's lines on it and on the loopback-only routes.
- ed1e5caf: a scored row the step in flight finishes gets no step issued ahead; and its two tests,
  the non-scored one with a token left after the step in flight so that a step ahead exists (#349).

The wait bound itself, the lookup index and the rest of 33108e48 are unchanged. sched_test 176,
config_test 62 and server_test 177 cases pass.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qthwau4zwWgAaD8vZrycp1
This commit is contained in:
DeadcodeandClaude Opus 5.5 committed 2026-10-30 12:18:29 +01:00
1 parent 8df9240d65
commit d773992abc
4 files changed
+104 -5

No files matched your search

+8 -1
View File
@@ -821,7 +821,14 @@ int config_parse(int argc, char** argv, Config* c) {
}
else if (S("--host")) { if (!(v = need(i))) return RAD_E_INVAL; c->host = v; }
else if (S("--port")) { if (!num(0, 65535, &c->port)) return RAD_E_INVAL; }
else if (S("--api-key")) { if (!(v = need(i))) return RAD_E_INVAL; c->api_key = v; }
else if (S("--api-key")) {
if (!(v = need(i))) return RAD_E_INVAL;
/* An empty key is no key: --api-key "" or --api-key "$UNSET_VAR" must not start a
* server that looks guarded and answers everything keyless. */
if (!*v) { RAD_ERR("--api-key takes a non-empty key; an empty value guards nothing");
return RAD_E_INVAL; }
c->api_key = v;
}
else if (S("--served-model-name")) {
if (!(v = need(i))) return RAD_E_INVAL;
if (!*v) { RAD_ERR("--served-model-name takes a non-empty name"); return RAD_E_INVAL; }
+17
View File
@@ -308,6 +308,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.
@@ -2248,6 +2259,12 @@ const RadBatch* Scheduler::step_next_locked() {
* that cannot rewind decides at commit whether the next step may speculate; one that can,
* or no grammar, keeps its answer. */
if (!e.produces_token || !r.speculation_fixed) return nullptr;
/* A SCORED row (Request::token_scores, a /v1/systemone question) that the step in flight
* brings to max_tokens gets no step issued ahead: it would run a whole forward pass for a
* request that finishes at the commit, and max_tokens=1 pays a decode step after its
* prefill. Scored rows only -- every other decode keeps the step of overlap it had. */
if (r.token_scores && r.max_tokens > 0 &&
(int64_t)r.output.size() + 1 >= r.max_tokens) return nullptr;
/* The furthest context the row can reach: every position this step verifies committed,
* counted from the last commit rather than this step's own bound (which would add a
+8 -3
View File
@@ -2129,7 +2129,7 @@ by 0.002-0.003 nats.
|---|---|---|
| `--host ADDR` | 0.0.0.0 | listen address |
| `--port N` | 8000 | listen port |
| `--api-key KEY` | none | require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but `/health`, `/v1/health`, `/ping` and the dashboard page (§6.6) |
| `--api-key KEY` | none | require `Authorization: Bearer KEY` or `X-Api-Key: KEY` on every request but `/health`, `/v1/health`, `/ping` and the dashboard page (§6.6); the key must be non-empty |
| `--served-model-name NAME` | container's name | the model id `/v1/models` lists, the metrics carry and a response names when its request named none. A request may name any model; the loaded one serves it |
| `--mm-max-patches N` | auto | patches one vision-encoder pass carries, and so the largest image (a patch is 16x16 pixels, 14x14 on GLM-5.3). `auto` is 16384 when the container carries a vision tower; 0 serves text only and keeps the tower off the card. A pass is not one tower invocation: inside it the tower batches at most 8 tiles per weight read, and the pass size may reduce that (4 tiles at the 64-pixel grid with the default 16384 patches); a picture contributes a separate pass per grid. See the concurrency notes for Unlimited-OCR (§5.17) |
| `--override-chat-template PATH` | container's | a Jinja chat template file served in place of the container's. The reply format (reasoning markers, tool calls) is derived from it too, unless the architecture plugin declares one. An unreadable or empty file stops startup |
@@ -3685,11 +3685,16 @@ With a key, every request must carry `Authorization: Bearer KEY` (or Anthropic's
or it is answered 401, `/tokenize` and `/server_info` included. Exempt are `/health`, `/v1/health` and
`/ping`, because load balancers cannot send a bearer token, and the dashboard page (`/`,
`/dashboard`), which holds no data: on a 401 it asks for the key, keeps it in the browser's storage
and sends it on every data fetch.
and sends it on every data fetch. The exemption follows those paths' methods -- reads, plus the
`POST /ping` of the health-check convention -- so it cannot follow a method no route answers.
An empty `--api-key` value is a startup error: it would guard nothing.
Without a key, `/diagnostics` answers only loopback clients (others get 403), because it describes
the host: kernel, boot parameters, PCI layout, memory limits. Read it on the machine, or start the
server with `--api-key`.
server with `--api-key`. The same loopback-only rule covers the control-vector default and runtime
LoRA loads, and a browser page on another origin does not qualify as a loopback client even when
its own machine serves the port: that is how a hostile web page would reach these routes through a
victim's browser, and a request that says `Origin: http://evil` is refused the way a remote one is.
The key is not encrypted in transit. On a network you do not control, bind to localhost behind a
TLS-terminating reverse proxy:
+71 -1
View File
@@ -12,6 +12,7 @@
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <new>
@@ -98,7 +99,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();
@@ -1281,6 +1284,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();
@@ -6363,6 +6390,49 @@ TEST(a_request_finishing_under_a_step_issued_ahead_keeps_its_blocks_for_that_ste
CHECK_EQ((int)f.sch.find(a)->output.size(), 2); /* the step ahead emitted nothing */
}
/* A SCORED row (Request::token_scores) the step in flight brings to max_tokens gets no step issued
* ahead: it would be a forward pass for a request that finishes at the commit. The step after the
* commit is planned as usual. */
TEST(no_step_is_issued_ahead_for_a_scored_request_the_step_in_flight_finishes) {
Fixture f;
f.build(/*blocks=*/20, /*states=*/64);
CHECK_OK(f.start());
const int64_t before = f.kv.free_blocks(0);
auto r = f.request(40, /*max_tokens=*/2);
r->speculation_fixed = true;
r->token_scores = std::make_shared<TokenScores>();
r->token_scores->tokens = { 1, 2 };
const uint64_t a = f.add(std::move(r));
REQUIRE(f.sch.step() != nullptr);
f.commit_plain();
REQUIRE(f.sch.step() != nullptr);
CHECK(f.sch.step_next() == nullptr);
f.commit_plain(); /* the second token: finished */
CHECK_EQ((int)f.sch.find(a)->state, (int)ReqState::Finished);
CHECK_EQ(f.kv.free_blocks(0), before);
CHECK_EQ((int)f.sch.find(a)->output.size(), 2);
CHECK(f.sch.step() == nullptr);
}
/* A row without token_scores whose step in flight leaves a token to decode is an ordinary decode:
* the step ahead is issued. (A request any step in flight finishes gets none, scored or not.) */
TEST(a_non_scored_row_keeps_the_step_issued_ahead) {
Fixture f;
f.build(/*blocks=*/20, /*states=*/64);
CHECK_OK(f.start());
auto r = f.request(40, /*max_tokens=*/3);
r->speculation_fixed = true;
const uint64_t a = f.add(std::move(r));
REQUIRE(f.sch.step() != nullptr);
f.commit_plain();
REQUIRE(f.sch.step() != nullptr);
CHECK(f.sch.step_next() != nullptr);
f.commit_plain();
f.sch.promote_next();
f.commit_plain(); /* the step ahead: the third token */
CHECK_EQ((int)f.sch.find(a)->output.size(), 3);
}
/* ================================================================== terminal paths */
/* A lone request that outgrows the whole pool fails with the reason the client sees and gives its
* blocks back; nothing is preempted, since there is nobody to preempt and preempting itself would