From 6964d05f75b0c9327116e0f11cc9ab46ebc8f8ed Mon Sep 17 00:00:00 2001 From: C_Tamas Date: Tue, 20 Oct 2026 14:39:20 +0700 Subject: [PATCH] server: the control-vector switch answers 404 where it has no vector The route's own comment, server.h and the dashboard's page all say a deployment without a vector answers 404, and the page uses exactly that to tell "no vector here" (hide the panel) from "not signed in" (show it, disabled). The handler answered 501 instead, so such a deployment showed a panel claiming the vector was present. The route now assembles the same 404 the server uses for a model it does not serve, and the case that had no coverage -- a deployment without a vector -- checks it. The unreachable 405 arm goes: only GET and POST are registered. --- core/server/dashboard.cpp | 16 ++++++++++------ tests/server_test.cpp | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/core/server/dashboard.cpp b/core/server/dashboard.cpp index 7732e9cf..64626724 100644 --- a/core/server/dashboard.cpp +++ b/core/server/dashboard.cpp @@ -43,10 +43,16 @@ namespace server { * no such feature, and its requests refuse `control_vector: true` by name. */ HttpResponse Server::handle_control_vector(const HttpRequest& req) { const bool have = deps_.control_vector.available && deps_.control_vector.available(); - if (!have) - return error_response(err_not_implemented( - "this deployment found no control vector for its model; there is nothing to switch"), - req.peer); + if (!have) { + /* 404, like a model the server does not serve: the route exists, this deployment has nothing + * behind it, and that is what the page tests for before hiding the panel. */ + ApiError e; + e.status = 404; + e.type = "not_found_error"; + e.message = "this deployment found no control vector for its model; there is nothing to " + "switch"; + return error_response(e, req.peer); + } if (req.method == "POST") { json body; @@ -62,8 +68,6 @@ HttpResponse Server::handle_control_vector(const HttpRequest& req) { if (deps_.control_vector.set_default) deps_.control_vector.set_default(on); RAD_INFO("control vector: default %s by an admin request%s", on ? "ON" : "OFF", req.peer.empty() ? "" : (" from " + req.peer).c_str()); - } else if (req.method != "GET") { - return HttpResponse::json_body(405, err_bad("method", "GET or POST").dump()); } metrics_.observe_http(200); diff --git a/tests/server_test.cpp b/tests/server_test.cpp index fcd558bd..b1311b3c 100644 --- a/tests/server_test.cpp +++ b/tests/server_test.cpp @@ -4538,6 +4538,9 @@ 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); } { /* A vector loaded, default off: the request's own choice wins and reaches the engine. */