Repository navigation
serve: register /completion, the path the short and spec warm-ups post to (Fixes #2853) - #2855
Conversation
…t to (Fixes #2853) The server registered /v1/chat/completions and /v1/completions; `warmup_requests()` posts the short and the spec warm-up to /completion with llama.cpp's own field names, so both answered 404 and the warm-up that docs/serve.md promises moved nothing. A warm-up is a POST the server makes to itself, so the 404 was invisible: no client sees it and no test asserted it. The fix follows the file's own convention rather than inventing one: /embeddings is registered beside /v1/embeddings and /rerank beside /v1/rerank, and /completion is llama.cpp's path for the same handler, which is what the warm-up bodies were written for. Registered in both route blocks (the serve table and the second one below it), so the alias holds wherever the handler is mounted. `tools/ci/serve_routes_check.py` is the arm, and it is static on purpose: the route table and the warm-up list are two literals in one file and the failure is their disagreement. It parses `srv.Post("<path>"` registrations and `{ "path", "<path>" }` warm-up entries and requires the second set to be a subset of the first. before: serve_routes: warm-up posts to /completion, which app/serve.cpp never registers (routes: /v1/chat/completions, /v1/completions, /v1/embeddings, /embeddings, /v1/rerank, /rerank) rc 1 after: serve_routes: all 2 warm-up request(s) post to registered routes (1 distinct path(s), 7 routes) rc 0 New ctest rows: `serve_warmup_routes` (the check) and `tool_selftest_serve_routes` (its three arms: a registered warm-up parses, a missing route shows as a subset failure, an empty file is not a pass).
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
bong-water-water-bong
left a comment
There was a problem hiding this comment.
VERDICT at 176dfb2: CHANGES
This is #2854's fix with a different checker, and neither PR touches the half that costs the time: the warm-up bodies still send n_predict, which this parser does not read.
warmup_short_body(): { "prompt": …, "n_predict": 0, "cache_prompt": false }
warmup_spec_body(): body["n_predict"] = 2;
forward_serve.cpp:348: max_tokens = int_field(body, "max_completion_tokens", int_field(body, "max_tokens", 256));
n_predict is read nowhere in app/ or npu/ (grep: only the two warm-up builders), and npu::options_from_body guards each key with if (body.contains(…)), so an unknown key is silently ignored rather than refused. After this PR the warm-ups stop 404ing and start decoding up to 256 tokens each instead of 0 and 2 — on a 27B the code's own comment prices one such step at 10.4 s. Before: cheap and useless. After: expensive and the wrong shape.
Fix, one of:
- send
max_tokens(0 / 2) from the body builders, or - honour
n_predictinforward_serve.cpp's parser — the route is llama.cpp-shaped, so this is the coherent one, and it makes the warm-up's own naming truthful.
The duplicate, which is the merge-order decision
#2854 does the same thing (registers /completion in both servers, adds a source-only checker) and additionally adds failed/sent accounting with a warm-up INCOMPLETE -- %d of %d request(s) failed … line — which is how the original 404s sat in the log unnoticed, one stderr line per warm-up. This PR's checker is the cleaner of the two interfaces (positional root, 117 lines, 3 arms) and it is load-bearing: deleting both srv.Post("/completion", post) lines gives
serve_routes: warm-up posts to /completion, which …/app/serve.cpp never registers (routes: /v1/chat/completions, /v1/completions, /v1/embeddings, /embeddings, /v1/rerank, /rerank)
serve_routes: 1 of 1 distinct warm-up path(s) have no route -- the request 404s and the warm-up moves nothing (engine#2853)
So: one of #2854 / #2855 should close, and whichever survives should carry this PR's checker interface and #2854's INCOMPLETE accounting, plus the field-name fix above.
What is right
- Registering
/completionin both servers (serve_modelsandserve_child) rather than one, with the comment noting it sits beside/v1/completionsexactly as/embeddingsand/rerankdo — so the route table stays coherent per server. - The reason a test was needed at all is stated precisely: "no test could see them because a warm-up is a POST the server makes to itself" — a self-request is invisible to any row that only exercises client-facing paths.
- The checker reads the two literals from one file (the route table and the warm-up list in
app/serve.cpp), so it cannot drift from what it checks, and itssubsetphrasing is the right predicate: every warm-up path must be among the registered routes.
…id not carry) (#2883) The two warm-ups that posted to "/completion" while this server served only /v1/* warmed nothing, and the only trace was one stderr line per request. #2855 registered the route; nothing yet keeps the two lists in step, so the next rename can orphan a warm-up the same way. Source-only: parses the literals in warmup_requests() and the paths handed to srv.Get/srv.Post, matches regex registrations as regexes, and exits 1 on a warm-up path with no registration, 2 when its own parser is out of date. origin/main rc 0 every warm-up path is a registered route d110d59 (pre-#2855) rc 1 NOT REGISTERED: warm-up posts to /completion --self-test 4/4 arms Refs #2853 Co-authored-by: pi-os3 <[email protected]>
…stead of 256 (Fixes #2884) (#2887) #2855 registered `/completion` -- llama.cpp's route -- for the two warm-ups, and they still did nothing useful because their bodies speak llama.cpp while the parser speaks OpenAI: `warmup_short_body()` sets `n_predict: 0` and `warmup_spec_body()` `n_predict: 2`, and `forward_serve.cpp` read only `max_completion_tokens`/`max_tokens`, so both kept the default `max_tokens = 256` and answered 200. The "spec" warm-up -- whose whole purpose is to pay a 5.6 GB host-copy step with a two-token request (the comment above it) -- was running a 256-token generation instead. The alias goes where the other limit fields are read, OpenAI first so nothing that works today moves: max_completion_tokens -> n_predict -> max_tokens -> 256 `n_predict` and not "fix the two builders", because `/completion` is llama.cpp's own path and a client written for llama-server posts `n_predict`: correcting only the warm-ups would leave the route lying to the dialect it now serves. `tools/ci/serve_routes_check.py` grows the body half the issue asks for, and it compares PER BUILDER, not the union -- a union hides this bug, because the chat warm-up sets `max_tokens` and makes the intersection non-empty: main's parser: warmup_short_body() sets n_predict, and the parser reads only max_completion_tokens, max_tokens warmup_spec_body() sets n_predict, … serve_routes: 2 warm-up body builder(s) set a token limit the parser never reads rc 1 with the fix: every warm-up body's token limit is read by the parser (3 builder(s), … n_predict) rc 0 `--self-test` still ok; `copyright.py --check` rc 0. What this does NOT prove: that the requests now really send 0 and 2 tokens on a live server — the arm is static, and the runtime proof is a `serve` run with the warm-up log, which needs a model and a ticket. Co-authored-by: bong-water-water-bong <[email protected]>
…o serve_routes_check.py (#2891) * ci: one warm-up check, not two — the route regex and srv.Get move into serve_routes_check.py (engine#2853, #2884) `main` runs two checks for the same property. `serve_routes_check.py` arrived with the fix in #2855 and now carries both halves (engine#2853's paths, engine#2884's token-limit fields); `warmup_route_check.py` arrived in #2883 and checked the route half a second time, with one capability the first lacked: it parses `R"(...)"` raw-string registrations and matches them as regexes, and it sees `srv.Get` as well as `srv.Post`. Keeping both means a change to `warmup_requests()` has to satisfy two baselines that nobody keeps in step, and a reviewer cannot tell which is authoritative. So the two capabilities move here, with arms, and the second file and its ctest row are deleted: ok a raw-string route registration parses ok a srv.Get route counts too ok a regex route covers a warm-up path `route_covers()` is the module-level predicate both the check and the arms use: a warm-up path is covered when it equals a literal route or full-matches a regex one, and an invalid regex route is skipped rather than trusted. Measured, on this tree and on a mutant: $ python3 tools/ci/serve_routes_check.py . # 14 routes now, srv.Get included serve_routes: every warm-up body's token limit is read by the parser (3 builder(s), ...) rc=0 $ <app/serve.cpp with the two srv.Post("/completion", post); lines deleted> serve_routes: warm-up posts to /completion, which ... never registers rc=1 The self-test is 9 arms, all green; `--self-test` and the `serve_warmup_routes` row both remain, so the property is checked exactly as often as before, by one file. * ci: resolve a warm-up's named constant, and refuse one this file cannot resolve (review at 7c186c1) The review's finding was right and it is the same shape as the bug this check exists for, one level up: `WARMUP` matched `{ "path", "<literal>" }` only, `app/serve.cpp` posts the chat warm-up as `{ "path", kWarmupPath }`, so the merged checker verified **two of the three** warm-ups and printed `ok`. The self-test could not catch it because its fixtures inlined the literal — a fixture easier than the artifact passes for the better reason and fails for none. - `WARMUP` now captures the expression and `CONST_DEF` resolves a `const char* const NAME = "..."` in the same file; - an identifier this file does not define is **cannot tell (77)** with its name, never a path silently skipped, so a future `const char* kSomething` cannot take a warm-up out of the check's view the way `kWarmupPath` did; - the fixtures now use the identifier form the artifact uses, plus an unresolvable-identifier arm. Measured on this tree and on two mutants: $ <this tree> all 3 warm-up request(s) post to registered routes (2 distinct path(s), 14 routes) rc=0 $ <srv.Post("/v1/chat/completions") renamed> warm-up posts to /v1/chat/completions, which ... never registers rc=1 $ <{ "path", kSomethingElse }> ... defines no string for it: an identifier it cannot resolve is cannot-tell, not a path to skip rc=77 The `3 request(s)` in the first line is the correction stated as a number: it was `2` before this commit, because the chat warm-up was invisible. --------- Co-authored-by: bong-water-water-bong <[email protected]>
Fixes #2853.
What was wrong
1bit serveregistered two completion routes, and the short and the spec warm-up posted to a third:So two of the three warm-ups moved nothing, while
docs/serve.mdpromises the short one ("a 16-token/completionrequest does not…"). A warm-up is a POST the server makes to itself — no client sees the 404 and nothing in the suite asserted the route existed.The fix, and why this shape
/completionis registered beside/v1/completions, in both route blocks (the serve table and the second one below it):That is the file's own convention, not a new one:
/embeddingsis registered beside/v1/embeddingsand/rerankbeside/v1/rerank. It is also what the warm-up bodies were written for — they use llama.cpp's field names (n_predict,cache_prompt) — so pointing them at/v1/completionsinstead would have been the smaller diff and the wrong decision: it would leave a llama.cpp client that posts to/completionstill 404ing, when the two lines above already show this server intends to be usable from that side.The arm
tools/ci/serve_routes_check.py, static on purpose: the route table and the warm-up list are two literals in one file, and the failure is their disagreement. It parsessrv.Post("<path>"registrations and{ "path", "<path>" }warm-up entries and requires the second set to be a subset of the first.The count says "2 requests / 1 distinct path" deliberately: the short and spec warm-ups share a path, and reporting distinct paths alone would hide one of them.
New ctest rows:
serve_warmup_routesplustool_selftest_serve_routes(three arms — a registered warm-up parses, a missing route shows as a subset failure, an empty file is not a pass). Hermetic, no device, ~0.1 s.copyright.py --checkrc 0; the three files areapp/serve.cpp+10,tools/ci/serve_routes_check.py+117,CMakeLists.txt+5.🤖 Generated with Claude Code