From 071d2042523c04402ae0e6ccd0fe6248754a8473 Mon Sep 17 00:00:00 2001 From: C_Tamas Date: Tue, 20 Oct 2026 14:39:20 +0700 Subject: [PATCH] server: a null control_vector is "not sent", and the alias yields to the field Reading the field's own name last made a null canonical value win over a non-null alias (JSON null leaves the parsed bool untouched, so it became an explicit off) and made a malformed alias fail a body whose canonical field was valid. The loop now walks the field first, skips absent and null keys as the rest of the parser does, and stops at the first one it finds: the field wins, null means "the deployment's default", and the alias is only read when the field is not. server_test covers both -- a body with both spellings, and a null field with the default on -- and cvec_test pins n_dirs, which the startup line now prints. --- core/server/oai.cpp | 12 +++++++----- tests/cvec_test.cpp | 7 ++++--- tests/server_test.cpp | 20 +++++++++++++++++--- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/server/oai.cpp b/core/server/oai.cpp index 20cbd947..8d247e86 100644 --- a/core/server/oai.cpp +++ b/core/server/oai.cpp @@ -846,14 +846,16 @@ static int parse_sampling(const json& b, const OaiLimits& lim, OaiRequest* r, Ap /* The control vector (core/cvec.h): an opt-in per request, and the only place an API client * turns it on when the deployment's default is off. `control_vector` is the field's name; * `experimental_speed_projection` is Strata's spelling of the same switch, kept as an alias so - * a client written against that reports what it means. */ - /* The field's own name is read last, so a request that sends both spellings is read as - * `control_vector`; the alias is Strata's name for the same switch. */ - for (const char* key : { "experimental_speed_projection", "control_vector" }) { - if (!b.contains(key)) continue; + * a client written against that reports what it means -- and read only when the request did not + * send the field itself, so the field wins when a body carries both. A JSON null is "not sent", + * as everywhere else in this parser. */ + for (const char* key : { "control_vector", "experimental_speed_projection" }) { + const auto it = b.find(key); + if (it == b.end() || it->is_null()) continue; bool on = false; if (!get_bool(b, key, &on, err)) return RAD_E_INVAL; r->control_vector = on ? 1 : 0; + break; } /* stop: a string or an array of strings. Bounded in count and length because every stop diff --git a/tests/cvec_test.cpp b/tests/cvec_test.cpp index 1988db7e..c65cb433 100644 --- a/tests/cvec_test.cpp +++ b/tests/cvec_test.cpp @@ -138,6 +138,7 @@ TEST(the_published_shape_loads_and_is_normalised) { CHECK_EQ(f.cv.last, 44); /* Indexed by layer, so row 0 exists (the format has no direction for it) and 47 rows follow. */ CHECK_EQ(f.cv.n_layers, (int64_t) 48); + CHECK_EQ(f.cv.n_dirs, (int64_t) 47); for (int l = 1; l <= 47; ++l) { double ss = 0.0; @@ -286,9 +287,9 @@ TEST(a_layer_range_past_the_model_is_refused) { CHECK(l.err.find("runs past") != std::string::npos); } -/* A layer index the table cannot hold: a 48-layer model's table is rows 0..47 and the format has - * no direction for the last row, so direction.48 and a JSON range ending at 48 are both refused - * rather than indexing one row past it. */ +/* A layer index the table cannot hold: a 48-layer model's table is rows 0..47, indexed by layer, so + * direction.48 names one row past it -- as does a JSON range ending at 48. Both are refused rather + * than writing or reading past the table. */ TEST(a_layer_at_the_models_own_count_is_refused) { const Loaded a = load(make_vector(2560, 48), 2560, 48, "layer-48.gguf"); CHECK(a.rc < 0); diff --git a/tests/server_test.cpp b/tests/server_test.cpp index 882fcbd5..9d9ac5bb 100644 --- a/tests/server_test.cpp +++ b/tests/server_test.cpp @@ -4538,9 +4538,13 @@ TEST(the_control_vector_field_overrides_the_default_or_is_refused) { f.sched.join_all(); CHECK_EQ(r.status, 400); CHECK(r.body.find("control_vector") != std::string::npos); - /* The route itself is present and answers 404: that is what the page tests for before it - * hides the panel, and what distinguishes "no vector here" from "not signed in". */ - CHECK_EQ(f.get("/admin/control-vector").status, 404); + /* The route itself is present and answers 404 on both methods: that is what the page tests + * for before it hides the panel, and what distinguishes "no vector here" from "not signed + * in". */ + const HttpResponse g0 = f.get("/admin/control-vector"); + CHECK_EQ(g0.status, 404); + CHECK(g0.body.find("not_found_error") != std::string::npos); + CHECK_EQ(f.post("/admin/control-vector", R"({"enabled":true})").status, 404); } { /* A vector loaded, default off: the request's own choice wins and reaches the engine. */ @@ -4582,6 +4586,16 @@ TEST(the_control_vector_field_overrides_the_default_or_is_refused) { CHECK_EQ(r3.status, 200); CHECK(!f.sched.last_sp.use_control_vector); + /* A JSON null is "not sent", not "false": the deployment's default (on, here) applies. */ + HttpResponse r4 = f.post("/v1/chat/completions", + R"({"messages":[{"role":"user","content":"hi"}], + "max_tokens":4, + "control_vector":null})"); + if (r4.streaming()) drain(r4); + f.sched.join_all(); + CHECK_EQ(r4.status, 200); + CHECK(f.sched.last_sp.use_control_vector); + const HttpResponse g = f.get("/admin/control-vector"); CHECK_EQ(g.status, 200); CHECK(g.body.find("\"default\":true") != std::string::npos);