Skip to content

serve: register /completion so the short and spec warm-ups can run (they were 404ing) - #2854

Closed
bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-warmup-route
Closed

bong-water-water-bong wants to merge 1 commit into
mainfrom
os3-warmup-route

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Fixes #2853. Two of 1bit serve's three warm-up requests were 404ing against its own server, and the only trace was a stderr line nothing greps.

The mismatch

srv.Post("/v1/chat/completions", post);     // registered
srv.Post("/v1/completions", post);          // registered
if (want_short) out.push_back(json{ { "path", "/completion" }, ... });   // 404
if (want_spec)  out.push_back(json{ { "path", "/completion" }, ... });   // 404

The bodies use llama.cpp's own names (n_predict, cache_prompt), so /completion was the intended route — the engine's httplib server simply never had it. Measured on this box with a four-shape probe:

POST /completion          404
POST /completion          404   (prompt body instead of messages: still 404 -- it is the route)
POST /v1/completions      200   {"choices":[{"finish_reason":"length",...}]}
POST /v1/chat/completions 200

What that costs

  • short: docs/serve.md promises "a 16-token /completion request does not pay HRX's one-time per-shape program build". It 404s, so the claim is untestable as written.
  • spec: its comment names the stake — "76 host copies, ~5.6 GB, 10.4 s, paid by whichever client request first ends on such a step". With the 404 that 10.4 s stays on the first client request, which is precisely what the warm-up exists to move.

The change

  1. Register /completion as an alias of the existing post handler, in both server bodies. The documented route answers, the two warm-ups run, and a llama.cpp-shaped client posting prompt + n_predict works.
  2. A failed warm-up now says so once, greppably, instead of only per request:
1bit serve: warm-up INCOMPLETE -- 2 of 3 request(s) failed, so the shape each one warms is paid by the
first client request instead; check that every path in warmup_requests() is a route this server registers
  1. tools/ci/warmup_route_check.py ties the two lists together, which is the part that mattered: nothing connected the warm-up paths to the registered routes, so a route rename could silently orphan a warm-up again. It parses the literals in warmup_requests() and the paths handed to srv.Get/srv.Post, matches regex registrations as regexes (R"(/slots/(\d+))"), and exits 1 on a path with no registration, 2 when its own parser is out of date. Source only — no build, no device, ~50 ms — registered as a ctest row.

The arm

$ tools/ci/warmup_route_check.py --root .        # origin/main, before this PR
NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it -- that warm-up 404s and warms nothing
rc=1

$ tools/ci/warmup_route_check.py --root .        # this branch
ok: every warm-up path is a registered route
rc=0

$ tools/ci/warmup_route_check.py --self-test
self-test: 4/4 arms passed

serve.cpp type-checks with the project's own flags (-fsyntax-only, rc 0). I have not run a full build or a serve with the patch — the CI build row covers the first, and the second needs a memory window on a box whose GPU queue is three deep.

warmup_requests() posts two of its three requests to "/completion" with
llama.cpp field names (n_predict, cache_prompt), but this server registered
/v1/chat/completions and /v1/completions only: both requests got a 404, logged
one stderr line each and warmed nothing, while docs/serve.md promises the
16-token /completion warm-up and warmup_spec_body() is written to move a
measured 10.4 s off the first client request.

Register the route in both server bodies, and report a failed warm-up once,
greppably, naming the count and the path list to check.

tools/ci/warmup_route_check.py ties the two lists together: every literal in
warmup_requests() must match a srv.Get/srv.Post path (regex registrations are
matched as regexes). Source only, no build, no device. --self-test has four
arms (good, missing route, regex route counts, parser out of date).

Fixes #2853
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2853 - Partially compliant

Compliant requirements:

  • Register /completion as an alias of the existing post handler in both server bodies
  • Make a failed warm-up say so once, greppably, instead of only per request
  • Every literal in warmup_requests() now matches a srv.Get/srv.Post path
  • The short and spec warm-ups now run and the documented route answers

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Warm-up Request 404s

The short and spec warm-up requests were posting to /completion which was not registered as a route, causing them to 404 and not warm the intended shapes. This has been fixed by registering /completion as an alias of the existing post handler.

srv.Post("/v1/completions", post);
// warmup_requests() posts the short and spec warm-ups to "/completion" with llama.cpp's own field names
// (n_predict, cache_prompt). This server registered /v1/completions only, so both got a 404 -- one stderr
// line each and nothing warmed -- while docs/serve.md promises the 16-token /completion warm-up.
srv.Post("/completion", post);
Incomplete Warm-up Logging

Previously, failed warm-up requests only logged a stderr line per request, making it hard to detect that warm-ups were not completing. Now, a summary message is logged once per warm-up run if any requests failed, making it greppable.

    int failed = 0, sent = 0;
    for (const auto & w : warmup_requests(speculative)) {
        ++sent;
        const std::string path = w["path"].get<std::string>();
        const auto t0 = std::chrono::steady_clock::now();
        const auto r  = c.Post(path, w["body"].dump(), "application/json");
        const long ms = (long) std::chrono::duration_cast<std::chrono::milliseconds>(
                            std::chrono::steady_clock::now() - t0).count();
        if (!r || r->status != 200) {
            ++failed;
            std::fprintf(stderr, "1bit serve: warm-up request %s on port %d failed (%d)\n", path.c_str(), port,
                         r ? r->status : -1);
        } else {
            std::fprintf(stderr, "1bit serve: warm-up request %s on port %d took %ld ms\n", path.c_str(), port, ms);
        }
    }
    if (failed) {
        std::fprintf(stderr, "1bit serve: warm-up INCOMPLETE -- %d of %d request(s) failed, so the shape each one "
                             "warms is paid by the first client request instead; check that every path in "
                             "warmup_requests() is a route this server registers\n", failed, sent);
    }
}

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

VERDICT at 837460d: READY.

The route registration is the whole fix, and the forwarding path confirms it needs nothing else: forward() posts c.Post(path, req.body, type) (app/serve.cpp:915), i.e. path- and body-preserving, so llama.cpp's own field names (n_predict, cache_prompt, prompt) reach llama-server's /completion untouched. Registering /completion in both serve_models and serve_child covers the two servers that send these warm-ups.

I ran the checker three ways rather than reading it:

  • --self-test: 4/4 arms pass (good 0, missing route 1, regex route counts 0, parser-out-of-date 2).
  • against pre-fix main's app/serve.cpp: rc 1, NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it — it reproduces the reported defect on the tree the issue describes.
  • against this PR's app/serve.cpp: rc 0, ok: every warm-up path is a registered route.

So the check earns its place: it fails on the bug and passes on the fix.

One non-blocking note, with precedent already on main: the add_test row runs --root only, so the four self-test arms are not exercised in CI and can rot silently. installed_rpath_kind_self (CMakeLists, a few lines below) is the house pattern for exactly this — a second row:

add_test(NAME warmup_route_check_self COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/ci/warmup_route_check.py --self-test)

Not required for merge from my side; the fix and its gate are both sound as they stand.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT: READY

"Two of 1bit serve's three warm-up requests were 404ing against its own server, and the only trace was a stderr line nothing greps" — that is the whole shape: a warm-up that does not warm anything, whose failure is invisible by construction.

The reproduction is decisive because it separates route from body:

POST /completion          404
POST /completion          404   (prompt body instead of messages: still 404 — it is the route)
POST /v1/completions      200
POST /v1/chat/completions 200

Sending a correct body and still getting 404 proves it is the path, not the payload — the same "vary one axis" discipline as a good A/B. And the bodies use llama.cpp's own names (n_predict, cache_prompt), which is the evidence that /completion was intended rather than inherited: the server registers /v1/chat/completions and /v1/completions, and the warm-up asked for /completion.

The cost paragraph is what makes this a real bug rather than cosmetic — and the spec number is the one to keep visible: "76 host copies, ~5.6 GB, 10.4 s, paid by whichever cli…". A warm-up exists to move that cost off the first user request and onto startup; 404ing means the first client pays 10.4 s and 5.6 GB, which is exactly the latency the warm-up was added to remove. docs/serve.md then promises the short warm-up "does not pay HRX's one-time per-shape progr…" — so the failure mode is a documented promise that silently does not hold.

Two things:

  1. the 404 must not be silent — a warm-up request that fails should log at warn with the status and the path, not a bare stderr line nothing greps. The generic rule this PR is an instance of: anything whose failure mode is "the feature quietly does not happen" needs a message at a level a reader sees;
  2. an arm that asserts the route exists rather than that the request returns — a test posting to /completion and asserting != 404 would have caught this; asserting 200 would additionally catch a route that exists but rejects the body. If the warm-up path is exercised end-to-end anywhere, say where, because this class (a warm-up pointed at a route nobody registered) can recur with the next route rename.

Not blocking: the mismatch is measured, the fix registers the route the docs promise, and the cost of the silent 404 is quantified rather than asserted.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Two red steps, one cause — the second is a cascade.

Copyright notice on every file
  missing copyright notice: tools/ci/warmup_route_check.py

Every test that did not run is a known one
  ctest_skips: cannot tell: no log at build/ctest.log

The copyright step runs before the build, so it aborted before ctest.log existed — and ctest_skips correctly reports "cannot tell" rather than passing. Fixing the notice should clear both, and if it does not, the second becomes a real finding at that point rather than before it.

The fix

The log itself suggests it:

run: python3 tools/copyright.py --fix

tools/copyright.py carries the 14-line Apache block for *.py, so --fix will prepend it. warmup_route_check.py is a new file, and a new .py is the one extension this check has never had trouble with — the file just has not been through the tool yet.

Saying that matters because the two red steps look like two bugs. A lane seeing them will go looking for why ctest.log is missing, and the answer is that the step before never let the build run.

And a note for the fourth time tonight

missing copyright notice has now cost engine's lanes four CI runs today — merged_tail_check.py, census_excerpt.awk (a different message: "no comment style known"), ctest_known_fail.txt (same), and now warmup_route_check.py. The check is right every time and names the file and the remedy, so each one is a one-line fix — but it is a new file's first CI run every time, which means it is really a pre-push habit nobody has. Running python3 tools/copyright.py --check before pushing a new file costs a second and would have saved four 13-minute builds.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 837460d: READY

Re-posted in the form the merger reads. The existing verdict on this PR is **VERDICT at 837460d6: READY.** — bold markers and a trailing full stop, so the first line does not parse as VERDICT at <sha>: <state> and the gate treats the head as unverdicted. Content unchanged; this post is the machine-readable copy. My sweep flagged it as "READY IN A FORM THE MERGER CANNOT READ", which is the tool doing the job it was written for.

The fix, verified by removal

both registrations removed:
  registered routes (19) …
  NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it
                 -- that warm-up 404s and warms nothing                              rc 1
restored:
  ok: every warm-up path is a registered route                                          rc 0

And it is registered in both server entry points, not one: serve_models (line 2082) and serve_child (line 2662). Two identical two-line comments looked like a duplicated block when I first grepped it; they are two different functions that each build a server, which is exactly where a route has to appear twice and exactly the shape a one-place fix would have missed.

The failure message is the part worth keeping: "that warm-up 404s and warms nothing" names the consequence rather than the diff, and the in-server message points at the cause — "check that every path in warmup_requests() is a route this server registers".

Not verified: the warm-up actually warming anything (that needs a served model), and the 172-line route census against a configured build.

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at 837460d: CHANGES

The route is the visible half; the warm-up bodies still speak a dialect this parser does not read, so both warm-ups now run at the default 256 tokens instead of 0 and 2.

The bodies:

static json warmup_short_body() { … return json{ { "prompt", prompt }, { "n_predict", 0 }, { "temperature", 0 }, { "cache_prompt", false } }; }
static json warmup_spec_body()  { json body = warmup_short_body(); body["n_predict"] = 2; return body; }

The parser on the other side of /completion (app/forward_serve.cpp:348):

int max_tokens = 256;
max_tokens = npu::int_field(body, "max_completion_tokens", npu::int_field(body, "max_tokens", 256));

n_predict is read nowhere in app/ or npu/ (grep: only the two warm-up builders and the comment you added), and npu::options_from_body guards each known key with if (body.contains(…)) — it does not reject unknown ones — so n_predict and cache_prompt pass through silently ignored and the request keeps max_tokens = 256.

What that costs, from the comment three lines above the body builder:

"On Qwen3.8-27B Q4_K_M that is the mixed layers' Q6_K ffn weights: 76 host copies, ~5.6 GB, 10.4 s … With n_predict 2 the second token is that step"

So the "short" warm-up (n_predict: 0, meant to be prefill-only) decodes up to 256 tokens, and the "spec" one (n_predict: 2) likewise — on a 27B that is minutes of start-up rather than seconds. Before this PR both 404'd and warmed nothing (cheap but useless); after it, they run the wrong shape at the wrong cost. cache_prompt: false is ignored too, so the "not prompt caching" intent is gone.

The fix is one of two, and the second is the coherent one: send max_tokens (0 and 2) from the body builders, or teach the parser n_predict — the route is llama.cpp-shaped (/completion), so honouring llama.cpp's field name is what a client of that route would expect, and it makes the warm-up's own naming truthful. Either way warmup_route_check.py should assert the fields, not only the path: today a body whose every key is ignored passes the same check a correct one does.

What is right, and the checker is genuinely load-bearing

$ python3 tools/ci/warmup_route_check.py --self-test
warm-up paths (2): /completion, /v1/chat/completions
registered routes (3): /health, /v1/chat/completions, /complet[a-z]*
ok: every warm-up path is a registered route
self-test: 4/4 arms passed

$ # mutation: delete every `srv.Post("/completion", post);`
NOT REGISTERED: warm-up posts to /completion and no srv.Get/srv.Post registers it -- that warm-up 404s and warms nothing

That mutation is the one that matters and it goes red, so the row would have caught the original defect. (My first mutation removed only one of the two registrations and the check still passed — correctly, because the other server still registers the route; worth knowing when someone next tests this.)

The failed/sent accounting with the warm-up INCOMPLETE -- %d of %d request(s) failed … line is the right shape: the failure was one stderr line per warm-up before, which is how 404s sat in the log unnoticed.

One more, since the route is being added for compatibility

srv.Post("/completion", post) reuses the chat handler, which also exposes logprobs/response_format behaviours documented for /v1/…. Serving llama.cpp's field names on a route whose body dialect is OpenAI's is exactly the sort of mismatch that produces the next "worked in the log, wrong shape" report; a sentence in the comment saying which dialect /completion accepts would settle it.

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator Author

Superseded by #2855, which merged. Same fix (register /completion), and this one's checks are red.

bong-water-water-bong pushed a commit that referenced this pull request Nov 20, 2026
The rebase onto main left the file without one, and copyright.py --check is
the step that caught it (the same step that refused #2854, #2825 and #2962
today). Added with --fix, which is the tool's own repair path.
bong-water-water-bong added a commit that referenced this pull request Nov 20, 2026
…ne#2478) (#2976)

* diag: the IOMMU DMA lifecycle, with a state-at-fault classifier (engine#2478)

Three readings on this issue were wrong because the instrument could not tell
'absent' from 'not looked at'. This tool makes that distinction structural:

  --lifecycle TRACE   per page: map->unmap->map cycle count, unmapped dwell
                      percentiles, and for each fault the page's STATE at the fault
  --owners IOVA...    reverse-map physical pages (identity IOVA under
                      CONFIG_IOMMU_DEFAULT_DMA_LAZY) to (pid, va, region)

Rules it enforces instead of documenting:

  * no unmap probe on a page => every fault reports state UNKNOWN, never MAPPED.
    Absence of an unmap event is absence of a probe, not presence of a mapping.
  * a fault with a map intervening before it is MAPPED, not 'last unmap 1 s ago'.
    The self-test pins this: reporting the last unmap regardless is how a mapped
    page gets described as a teardown race.
  * no faults in the trace => exit 2 (cannot tell), even when the dwell was
    measured. Partial coverage is not a negative result.
  * --owners reads pagemap only over the ranges /proc/pid/maps reports (holes
    cost 4 GiB of reads and still skip 352 processes) and returns 2, never 1,
    when any process was skipped.

Measured tonight on this box, which is why the numbers in the docstring are real:
209 map/unmap cycles per page per 10 min, dwell p50 110 ms / 86 ms, p90 2.5 s /
1.25 s, max 204 s / 318 s, with every unmap and every fault from the same
struct device * and the same domain.

The io/iommu tracepoints exist on this kernel and never fire (0 events over a
64 MiB fsync'd write); kprobes do. The recipe is in the module docstring.

* diag: carry the owner across a fault, so 'changed hands' is visible (engine#2478)

The two remaining branches of #2478 differ in what the device writes into:
teardown ordering -> a fault and the write goes nowhere; reuse -> the page was
re-mapped to a DIFFERENT process and the controller writes into that process's
buffer, with no fault and no log line.

Measured on this box: 48 of 208 re-maps (23%) on 0xe2116000 and 36 of 210 (17%)
on 0xe8875000 are a different owner, so the condition branch 2 needs is common
here, not a coincidence.

The classifier now prints it:

  FAULT @71181.67: state UNKNOWN (...), next map +72.53s -- CHANGED HANDS V8Worker -> pi

comm-pid is the process that CALLED the map, not necessarily the owner of the
memory, and the docstring says so: the count is evidence that ownership changes,
not proof of whose buffer it becomes.

* diag: the IOMMU DMA lifecycle tool carries its licence header

The rebase onto main left the file without one, and copyright.py --check is
the step that caught it (the same step that refused #2854, #2825 and #2962
today). Added with --fix, which is the tool's own repair path.

---------

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: pi-release <pi-release@1bit>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serve: the short and spec warm-ups post to /completion, a route this server never registered

1 participant