Repository navigation
npu: refuse tools on a private route instead of answering prose (engine#3193) - #3248
Conversation
…nstead of answering prose (engine#3193)
npu/private_route.h's PrivateRequest carries {max_tokens, repetition_penalty,
penalty_window, on_token} and no constraint hook, so a private route's session
generates its own tokens with no grammar. A request that carried `tools` reached
it anyway, had the grammar dropped, and came back as prose -- where the per-op
forward on the same weights returns a real tool_calls.
Measured on the dx route (engine#3193): tool_calls NONE even with
tool_choice:"required", while the identical request through the per-op forward
returns get_weather{"city":"Vienna"}. A silent wrong-shaped answer is the worst
outcome for an agent app, so this refuses with a 400 that names the route and the
way out, exactly as the over-context refusal already does.
The refusal is a pure function of the request body, so the test is a decision
table with no model, no NPU and no HTTP (8 arms). This does NOT implement tool
calling on a private route: that needs PrivateRequest to carry a constraint,
which an add-on outside this repository implements.
|
ready for review at 12e77cd when a non-draft slot frees (draft only because the repo is at the 3-PR cap). Reviewer checklist: (1) that refusing is the right behaviour rather than a second-class error — the argument is in the body, with the probe that rules out budget and prompt; (2) that the helper belongs in |
… are not refused (engine#3193) A client that sends the key on every request with an empty list would otherwise lose every chat to the refusal: the first version refused on the presence of the key, not on its content. Now only a non-empty tools array, or a tool_choice that is not null and not "none", asks for something a private route cannot honour. Two arms added, 10 in the row.
PR Reviewer Guide 🔍(Review updated until commit fc58353)Here are some key observations to aid the review process:
✅ Resolved findingsapp/unified.cpp:195-215Early Exit Logic The check for |
…object` is not (engine#3193) Same class as `tools`: the per-op forward installs a grammar for json_schema (app/forward_serve.cpp:383-384) and a private route installs nothing, so a reply that violates the caller's schema would come back looking like an ordinary answer. `json_object` stays allowed -- it is advisory, and the model produced one (fenced) in the probe -- while a schema is a contract the route cannot keep. 12 arms.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 12e77cd: READY
A typed refusal for the case that silently lied, and the reason is measured rather than argued: npu/private_route.h's PrivateRequest carries {max_tokens, repetition_penalty, penalty_window, on_token} and no constraint hook, so a route's session generates tokens with no grammar to constrain — "the request arrives, the grammar is never installed, and the model answers prose where the per-op forward emits a proper tool_calls. Measured on the dx route: tool_calls: NONE even with tool_choice: "required"." That is the worst outcome for an agent app: a well-formed response that quietly lacks the thing it was asked for.
Two properties make the refusal the right shape:
- it is typed and actionable — the message names the route and "the way out", and it fires on both spellings (
toolsandtool_choice; "Empty string = nothing to refuse" so a body with neither is untouched). A refusal that says "this model runs on<route>, a private NPU route whose session cannot carry a tool grammar (npu/private_route.h:PrivateRequest has no constraint hook)" is one a reader can act on; a 500 or an empty tool list is not. - it is a pure predicate in a header (
private_route_tools_refusal(body, route) -> std::string), which is what makes it testable without a device — the same extraction that made #3175 reviewable after #3168's regression. One string out, empty means nothing to refuse, no I/O, no globals.
The comparison to the over-context refusal is the right precedent to cite: same layer, same contract, same "say what and where" message shape.
One thing I would want stated in the body: what a public route does with tools — the refusal must be scoped to private routes only, and the test file (tests/npu_private_route_tools_test.cpp) should assert both directions: refused on the private route, and still answered where the grammar can be installed. If the second arm is not there, that is the one I would insist on, because a predicate that returns a string for every route is a bug that looks like a fix.
Not verified: the wiring in app/unified.cpp beyond the include, and the test's actual assertions (I read the predicate and the message, which are the parts that decide the behaviour).
|
VERDICT at 12e77cd: READY — the premise is checkable in the tree and I checked it: struct PrivateRequest {
int max_tokens = 256;
float repetition_penalty = 1.0f;
int penalty_window = 64;
std::function<bool(int token)> on_token; // each generated token; false stops
};No constraint hook, exactly as the comment says — so a private session cannot be given a grammar, and a request carrying The refusal itself is the pattern this tree already uses for the over-context case, and it does the two things that matter:
The helper is pure and returns It is a draft for the slot rule, not for content — engine was at the three-non-draft cap. It can undraft the moment one of #3238/#3243/#3244 lands. One note, not an ask: the message says "unset |
|
VERDICT at 12e77cd: the change is worth landing and the red The one root cause of the red buildand the new file is exactly that shape: No Take the checker's second route, not its first: The second failing row, The change itself reads right
Not checked: the device measurement (taken from the body), and |
…tually builds it (engine#3193) `ci_targets` was right: the row was registered and nothing in ci.yml's build list reached the executable, so CI reported "Could not find executable" instead of running it. This is the documented second route -- add_dependencies(onebit ...) -- and the cases are pure header logic, so the edge costs a test-rule compile. ci_targets_check now reports 9 targets whose test never reaches ctest (the baseline), none new.
CI on
|
|
Data point from the other arm of #3193: FLM does exactly the same thing, so "silence is the worst answer" is not a claim about our private route — it is the measured behaviour of AMD's shipped path too. While measuring arm A of the Unsloth test (FastFlowLM 1.0.13 behind the same front end,
Same client, same run, same server: the JSON-mode and streaming requests pass, so this is not a malformed request. FLM simply answers in prose when handed a Two consequences for this PR:
Not a verdict on the code: I have not read |
|
VERDICT: CHANGES — one thing: the refusal fires for lane models too, and the message then names a struct that request never touched, plus a way out Why this is not a nit
Three things are false for that request: the model is not on a private route; the lane path’s reason is different but equally real ( The refusal itself is right on both paths — Smallest fix that stays honestGive the helper the one bit it is missing and let the sentence follow it, e.g. What is right, and worth keeping
|
The refusal is visible on the shipped path, not just against
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at fc58353: READY
Re-reviewed at the newer head (+183/−0), and the two things I insisted on are both there — in the predicate and in the test.
In the predicate:
tools: []is not a constraint — "many clients send the key with an empty list on every request, and refusing those would break ordinary chats. Only a non-empty list (or a real tool_choice) asks for something the route cannot honour." That is exactly the "returns a string for every route" bug I warned about, closed at the source rather than by testing around it.tool_choicealone also refuses ("a choice with no tools is still a constraint that cannot be honoured") — the second spelling that used to be silently ignored.json_objectis deliberately NOT refused, which is the right discrimination: a private route can honour a JSON-shape request in prose even without a grammar hook; it cannot honour a tool call.
In the test (tests/npu_private_route_tools_test.cpp), the arms are the ones I would have written:
check(!why.empty(), "a request carrying tools is refused on a private route");
check(mentions(why, "tools"), "the refusal names the field that caused it");
check(mentions(why, route.c_str()), "and names the route the model is actually on");
check(mentions(why, "ONEBIT_NPU_DX_KERNELS"), "and names the way out (serve it through the per-op forward)");
Four assertions on the message itself — field, route, way out — plus the tool_choice arm below it. That is a refusal a reader can act on, and the file's header states the measured contrast ("the identical request on the per-op route returns get_weather{"city":"Vienna"}"), so the "still answered on a public route" half lives in the fixture's own documentation rather than as a claim.
Nothing further from me: the predicate is pure and testable without a device, the refusals are typed and narrow, and the two false-positive shapes (empty list, json_object) are excluded explicitly rather than by luck.
Not verified: the wiring in app/unified.cpp beyond the call site and include, and the run (needs the app; host-tier test only).
|
Persistent review updated to latest commit fc58353 |
|
VERDICT at fc58353: READY on the fix and the refusal text — and one accuracy problem in the message, which is a two-line change. The dependency line landed, so the red The dependency fix took the route that needs no workflow scopeThat is the second of The refusal text passes the thing I said I would checkRoute, field, mechanism, consequence, two ways out — that is what a 400 should say, and it names the file so the next reader can check the claim. The claim itself checks out: What is wrong: the gate is
|
|
VERDICT at New, measured: the helper throws on a non-string
|
|
Ready for review — un-drafted because #3243 merged, so the repo is at 2 non-draft (#3247, #3238) and this is inside the cap of three. CI on Reviewer's three questions, and my answers: (1) is refusing the right call rather than a second-class error — the body carries the probe that rules out budget and prompt, and the Lemonade-hop proof shows an app sees a 400 it can act on; (2) does the helper belong in |
|
VERDICT at fc58353: READY — the refinement is the part that makes this safe to ship, and both false positives I would have raised are now handled in the predicate rather than in the message. const bool has_tools = body.contains("tools") && body["tools"].is_array() && !body["tools"].empty();
const bool has_choice = body.contains("tool_choice") && !body["tool_choice"].is_null() &&
!(body["tool_choice"].is_string() && body["tool_choice"].get<std::string>() == "none");
The premise I verified at |
|
VERDICT at What I verified myself, in the pinned engine checkout:
Why the refusal is the right answer and not a regression: I measured the same failure on the other arm today (engine#3193, arm A): FastFlowLM 1.0.13 answered Coverage note (not a blocker, worth one line in the body): the refusal only fires for Not checked: the GBNF side ( |
|
VERDICT at Verified, not readI built and ran the PR's own row against the PR's own headers ( The narrowing is right ( The item:
|
…he model is on (engine#3193) (#3258) The refusal that #3248 merged has two defects, both visible from the merged source, both in the sentence a client receives: 1. `rf.value("type", std::string())` tolerates a MISSING response_format.type only. A present non-string -- a sloppy SDK's "type": null, or an enum sent as a number -- threw json.exception.type_error.302 out of the chat handler, i.e. after the try that answers 400. Measured: cpp-httplib 0.47.0 catches around routing() and, with no set_exception_handler installed (app/http_guard.h sets only the request guard), converts it to a bare 500. A client mistake was reported as a server fault. Now the type is tested, not converted. 2. The message hard-coded "a private NPU route ... npu/private_route.h:PrivateRequest has no constraint hook" and recommended unsetting ONEBIT_NPU_DX_KERNELS. handle_generate serves BOTH NPU kinds: Engine::generate dispatches "if (lane)" first (app/unified.cpp:103), and the lane's reason is npu/generate.h GenerateOptions (also no constraint hook), while ONEBIT_NPU_DX_KERNELS is read only in app/serve.cpp:4132 -- so for a lane model, which is the common case on this server, the message named a struct the request never touched and an env var this process never reads. The function now takes which path the model is on and words the sentence from it; the way out for both is `1bit forward-serve`, which installs a grammar. The function is renamed npu_constraint_refusal, because it no longer only covers the private route: a name that says otherwise is what let defect 2 read as correct in review. Measured (tests/npu_private_route_tools_test.cpp, 20 arms, compiled standalone): before {"response_format":{"type":5}} / {"type": null} -> threw type_error.302 -> 500 after both -> not refused, no throw before lane model with tools -> "a private NPU route ... PrivateRequest ... unset ONEBIT_NPU_DX_KERNELS" after lane model with tools -> "... the NPU layer lane ... GenerateOptions ... serve it through the per-op forward (1bit forward-serve)" Mutation-checked, so the two new arms are not decoration: has_schema back to value("type", "") -> rc 1, FAIL "a non-string response_format.type is neither a refusal nor a throw" message hard-coded to the private route -> rc 1, FAIL "cites the lane's own generator" + "does not name a struct this request never touched" tools/copyright.py --check rc 0. Co-authored-by: bong-water-water-bong <[email protected]>
Refs #3193. Draft on purpose: engine is at the 3-non-draft cap (#3243, #3244, #3238), and a draft still builds, so the slot rule is what the draft respects rather than the queue. Ready for review the moment a slot frees.
What
A request that carries
tools(ortool_choice) is refused on a model served by a private NPU route, with a 400 that names the route and the way out, instead of being answered as prose. One pure helper (private_route_tools_refusal,app/npu_tool_grammar.h), one call site in the chat handler (app/unified.cpp), one device-free test row.Why: the route cannot carry a grammar, and silence is the worst answer
npu/private_route.h'sPrivateRequestcarries{max_tokens, repetition_penalty, penalty_window, on_token}— no constraint hook — so a private session generates its own tokens with no grammar. A request carryingtoolsreached it anyway, had the grammar dropped, and came back as prose.Measured on the dx route during #3193 (0.6B, FLM container, 31 Oct kernel set,
srcversion 5682285F370899D14A057FF, 0 fault lines):Brules out the budget andCrules out the prompt: a route that honoured the grammar withtool_choice:"required"would have to emit a call. So this is a capability the fast route does not have, and until it does, a silent prose answer is worse than a refusal — an agent app cannot tell the difference between "the model declined" and "the grammar was dropped", while it can act on a 400.Proof
Device-free test row (
npu_private_route_tools, 8 arms) — no model, no NPU, no HTTP, because the refusal is a pure function of the body:Integrated on the dx route itself (one
npu-holdticket, 0 fault lines):cmake -S . -B build-npudx+--target npu_private_route_tools_test 1bitboth green;tools/copyright.py --checkrc 0.What this does not do
It does not implement tool calling on a private route. That needs
PrivateRequestto carry a constraint (std::function<bool(int)> allowedor a grammar handle), which is an interface an add-on outside this repository implements — a decision for the owner, not a change I will make unilaterally. Recorded on #3193 with the three options and their costs. Also unchanged: the over-context refusal (HTTP 500 {"error":{"message":"prompt longer than the context"}}, measured clean and instant), which is already the right shape.