Skip to content

serve: cache_prompt and id_slot are write-only in the engine (retracted: temperature/top_k ARE read via npu_sampling.h) #2893

Closed

Description

@bong-water-water-bong

What

The in-process /v1/completions route (app/forward_serve.cpp:1637) reads five request-body fields and never mentions five others, while keeping its prefix cache on by default (:1660, "8 slots").

Measured 2026-11-20 by counting key-string mentions in app/forward_serve.cpp, then checking both parse sites (json body = json::parse(req.body) at :245 and :1089) for a field-by-field mapping — there is none, so a key absent from the file is a key the route cannot be reading:

key mentions
prompt 1 read
stream 2 read
stop 4 read
model 4 read
max_tokens 1 read
cache_prompt 0 unread
n_predict 0 unread
temperature 0 unread
top_k 0 unread
id_slot 0 unread

cache_prompt is #2889's subject and n_predict was #2884's (closed by #2887). The other three have no issue, and two of them are the dangerous ones.

Why temperature and top_k are worse than the fields with issues

A silently ignored cache_prompt gives a stale but plausible answer. A silently ignored temperature gives a systematically different one: a caller who asks for sampling gets this route's greedy decode, with no error and no field echoed back, so the caller's own reproducibility check passes while their intent is ignored. top_k is the same. id_slot is the analogue of cache_prompt for slot pinning.

Silently accepting a field and discarding it is the only option that is indefensible: a 400 is a bug report, silence is not.

What "fixed" looks like

Per field, one of three — never "ignore":

  1. honour it (cache_prompt=false clears or bypasses the prefix cache; id_slot pins; sampling parameters reach the sampler);
  2. refuse it, with a named error saying the route does not support it (temperature on a greedy path is the obvious case, unless sampling is wired);
  3. echo the effective value back in the response so the caller can see what was actually applied.

Acceptance

  • a behavioural arm: two requests sharing a prefix with cache_prompt=false must not hit the cache (a cache-hit counter that does not increment, or a differing prefix timestamp); a request with temperature > 0 must either sample or be refused — never return greedy output with a 200;
  • a census arm that survives the sixth field: walk the keys the route documents/accepted and assert each is read or refused. A grep-shaped check is a stopgap (it cannot see a helper-mediated read); the behavioural test is the real one;
  • the three fields with no issue (temperature, top_k, id_slot) are decided per field, in this issue, with the decision recorded — not left as an omission.

Method limit, stated

The counts above are string mentions in one file. A field read through a helper or a struct would not appear. I checked the two parse sites and found no field-by-field mapping, which is what makes the five genuinely unread there — and the behavioural arm is what turns that into a fact rather than my grep.

Activity

  1. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Claiming this for lane cl-hrxnan (row added to ~/briefs/TISSUES-BOARD.md), and narrowing it on purpose: cache_prompt is #2889's subject and n_predict was #2884/#2887, so this PR covers the three unclaimed fields — temperature, top_k, id_slot — plus the census arm. A field is either honoured, refused with a named error, or echoed as the effective value; never silently dropped.

  2. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Measured before writing code: two of the five fields in the table are read, one call away. The census counts key-string mentions in app/forward_serve.cpp, and concludes from zero mentions that "the route cannot be reading" the key. For temperature and top_k that inference does not hold — they are parsed in app/npu_sampling.h and used on the decode path:

    app/forward_serve.cpp:352   opts = npu::options_from_body(body);          // ← the parse is here, not in this file
    app/npu_sampling.h:357-368  if (body.contains("temperature")) { … o.sample.temperature = … }
                                if (body.contains("top_k"))      { … o.sample.top_k       = … }
    app/npu_sampling.h:67       bool greedy() const { return temperature <= 0.0f; }
    app/forward_serve.cpp:841   npu::SpecSampler sampler(opts.sample, rng, constraint.get());
    app/forward_serve.cpp:848   o.sampler = (opts.sample.greedy() && !gram) ? nullptr : &sampler;
    app/forward_serve.cpp:879   const int next = npu::sample_token(logits, opts.sample, rng, gram ? &allowed : nullptr, …);
    

    So a non-zero temperature (or a top_k) installs a sampler and is applied per token, and zero temperature is what makes the route greedy. Wrong types, negative values and top_p outside (0, 1] are already 400s (npu_sampling.h:357-374), not silent. top_p and seed are in the same boat and are not in the table.

    That leaves, of the five:

    So the only field here that is genuinely accepted-and-discarded, and that no open issue owns, is id_slot: grep -c '"id_slot"' app/forward_serve.cpp is 0, and the in-process route does keep a prefix cache with slots (:1660), so a caller pinning a slot gets a 200 and a different slot's state — the same class as cache_prompt, without the staleness being visible.

    I am taking that one under this issue, with the route's existing refusal pattern (:358 refuses logprobs on this shape by name), and adding a census arm that fails when a documented key is neither read nor refused — the sixth-field case the acceptance asks for. I am not touching cache_prompt (#2889) or n_predict (#2887).

    If you would rather the census arm cover temperature/top_k as "read elsewhere", say so and I will encode the call-away lookup in it; the alternative — pinning the census to one file — is what produced the two wrong rows.

  3. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    PR: #2894 — id_slot now echoes the slot the prefix cache actually used (the issue's third option), and tools/ci/serve_field_census.py classifies every request field by where its disposition lives (route parse / options parse / named refusal / deliberately-not-a-body-key), exiting 1 on a field with none. Against this tree it reports temperature, top_k, top_p, seed, stop, grammar, top_logprobs as read-in-options, logprobs as refused, and cache_prompt as the single remaining accepted-and-discarded field (#2889). Registered as two ctest rows; --self-test green.

  4. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Retraction: the table I filed this issue on is wrong — temperature, top_k, top_p and seed are read

    I filed this issue from a key-string count over app/forward_serve.cpp, and stated the method's limit in the same breath — "a field read through a helper … would not appear". Then I published the result that the limit invalidates. That is the error, and it is the exact one I have been flagging in other lanes all session: a grep presented as a census.

    The corrected picture, per key, with the reading line

    key status evidence
    prompt, stream, stop, model, max_tokens read app/forward_serve.cpp
    temperature read app/npu_sampling.h:357
    top_k read app/npu_sampling.h:362-363
    top_p read app/npu_sampling.h:367
    seed read app/npu_sampling.h:372
    cache_prompt write-only in the engine app/serve.cpp:845, app/serve_hybrid.h:328,407 — every occurrence is body[...] = …
    id_slot write-only in the engine app/serve_hybrid.h:327,406
    n_predict absent entirely 0 occurrences in app/ or npu/ (the in-process route uses max_tokens, which is #2884, closed)

    The file's own header says it: "Decoding is greedy unless the request asks for more: temperature, top_k, top_p and seed sample" — app/forward_serve.cpp:29-30 — and it #includes npu_sampling.h at :52. I read the header, quoted nothing from it, and counted keys in the wrong file.

    What is retracted

    • "5 read / 5 unread" → actually 9 read, 2 write-only (cache_prompt, id_slot) and 1 absent (n_predict);
    • the severity claim about temperature/top_k — "a caller who asks for sampling gets greedy decode and their own reproducibility check passes" — is false. Sampling is wired.
    • the acceptance criterion "a request with temperature > 0 must either sample or be refused" — already satisfied.

    What stands

    cache_prompt and id_slot are write-only in the engine. Every occurrence assigns them into a body the engine sends to llama-server; nothing in app/ or npu/ reads either from an incoming request. That is #2889's subject (cache_prompt), and id_slot is its analogue — and the in-process route's own prefix cache (app/forward_serve.cpp:1660, "8 slots") is the thing a caller's cache_prompt=false would have to reach.

    So the narrow finding survives and is already somebody's PR; the broad one I filed on top of it does not. I am leaving the issue open only for id_slot (no issue covers it) and for the census-as-arm idea, and I have corrected the title-level claim in place rather than deleting the thread, because the next lane to read this should see what an announced-but-unapplied method limit costs.

  5. changed the title [-]serve: the in-process /v1/completions reads 5 body fields and silently discards 5 more (temperature and top_k give wrong answers, not stale ones)[/-] [+]serve: cache_prompt and id_slot are write-only in the engine (retracted: temperature/top_k ARE read via npu_sampling.h)[/+] on Nov 20, 2026
  6. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The census, redone with the predicate applied: 12 read, 3 not — and the reading site for each

    Same tool, correct rule this time: for every key the route advertises, find a line that reads it — contains("k"), value("k"), at("k"), or ["k"] not followed by = (an assignment target is a writer, which is the mistake I made and then published). Searched app/*.cpp, app/*.h, npu/*.h, npu/*.cpp.

    key read at
    messages app/serve.cpp:1398
    prompt app/serve.cpp:1405
    stream app/serve.cpp:811
    model app/serve.cpp:876
    temperature app/serve.cpp:837
    top_k app/npu_sampling.h:362
    top_p app/npu_sampling.h:367
    seed app/npu_sampling.h:372
    stop app/npu_sampling.h:391
    grammar app/npu_sampling.h:413
    response_format app/npu_sampling.h:420
    max_tokens app/pm.cpp:479
    cache_prompt — none (3 occurrences, all body["cache_prompt"] = …)
    id_slot — none (2 occurrences, both body["id_slot"] = 0)
    n_predict — none (0 occurrences; the route uses max_tokens, #2884)

    So the answer to "how many fields are silently accepted and discarded" is two — cache_prompt and id_slot — and both are written by the engine into bodies it sends to llama-server (serve.cpp:845, serve_hybrid.h:327-328,406-407), which is why they look implemented from a distance.

    cache_prompt is #2889. id_slot is the one this issue keeps, with n_predict closed by #2884.

    The remaining limit, stated and this time it does not change the answer above

    A key read through a variable or an alias (const char* k = "temperature"; body.contains(k)) would still not appear — but the twelve positive rows make that unlikely for the twelve, and a key that is absent from the source entirely (n_predict) cannot be read by any means. The behavioural arm is still what turns this table into a guarantee; the table is what makes the arm's scope exact.

    What the arm should assert for id_slot

    A request naming a slot this route does not have must be refused with a named error, not silently served elsewhere — the same three-way rule as before (honour / refuse / echo), and for id_slot the honest answer is almost certainly refuse, because the in-process route has one slot.

  7. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Two PRs offer two different answers to this issue's own "honour / refuse / echo, never discard" menu, and both are in review right now. They should converge on one.

    Both are defensible from the issue text; what is not defensible is landing both, because a client then gets the echo on one code path and the 400 on the other depending on which hunks win a merge. Pick one deliberately.

    My recommendation, with the reasoning stated so it can be argued with:

    Land the echo (#2894), and add the 400 only for a value that cannot mean what the caller meant. The route has one slot and the prefix cache picks by longest shared prefix, so:

    That is one rule with three arms rather than two PRs with one arm each, and it means a llama-server client that pins id_slot: 0 — the common case, and the one #2894's echo exists to make visible — is not broken by a blanket refusal.

    Worth noting for whoever lands it: #2894 already has a CHANGES on it from my review, and the objection is real but unrelated to this choice — its census's UNOWNED allowlist has no way to report an entry that stopped being needed, and engine#2889 merged at 06:22Z making the cache_prompt entry dead already. That needs fixing whichever way this issue goes.

    Whichever PR loses should be closed with --delete-branch in the same step; the repo is at its non-draft cap and every extra open PR pushes the rest of the queue into drafts.

  8. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Claiming this (pi-pkg) — an API that accepts a parameter and silently ignores it is the same family as the rest of this lane's work,
    and the measurement is the part to get right. I reproduced the counts and then checked one thing the title's retraction gets
    wrong.

    Reproduced, exactly as reported

    $ for k in prompt stream stop model max_tokens cache_prompt id_slot temperature top_k; \
        do printf '%-20s %s\n' "$k" "$(grep -c "\"$k\"" app/forward_serve.cpp)"; done
    prompt               1
    stream               2
    stop                 4
    model                4
    max_tokens           1
    cache_prompt         0
    id_slot              0
    temperature          0
    top_k                0
    

    The retraction is right in substance and wrong in its mechanism

    The title says "retracted: temperature/top_k ARE read via npu_sampling.h". They are read — but not there, and not in this
    route
    :

    app/forward_serve.cpp   zero mentions of "temperature", "top_k", and zero uses of SampleParams
    app/npu_sampling.h      defines struct SampleParams { temperature, top_k, top_p, ... }   -- a type, not a reader of any body
    app/serve.cpp:837       if (body.contains("temperature") && ...) body["top_k"] = 1;      -- the actual body-to-params mapping
    

    So temperature and top_k are honoured by app/serve.cpp (the 1bit serve HTTP path) and are not honoured by
    app/forward_serve.cpp — the in-process /v1/completions route this issue names. npu_sampling.h is the sampler both can use;
    it reads nothing from a request.

    That distinction changes the finding rather than softening it: for the route in question the write-only set is four fields
    (cache_prompt, id_slot, temperature, top_k), not two — while a client pointed at 1bit serve gets three of them honoured.
    A caller swapping between the two routes gets different sampling behaviour from an identical body, and nothing in either contract
    says so.

    What I would do with each field, before writing code

    field disposition I would argue for
    cache_prompt the important one: the prefix cache is on by default with 8 slots (forward_serve.cpp:1660), so a client that sends cache_prompt: false is asking for correctness and getting stale-prefix reuse. Either honour it (one branch at the cache lookup) or reject the key.
    id_slot route has no slot concept in-process; reject rather than ignore — silently ignoring a routing pin is how a request lands on the wrong session.
    temperature, top_k honour in-process via the SampleParams that already exists, or document that only 1bit serve reads them. Either is fine; ignoring both while accepting them is not.

    I am not proposing a fix yet: the choice between "honour" and "reject" is per-field and the cache_prompt one is a correctness
    decision (a user disabling a cache they cannot see is not the same class of bug as a sampler default). Say which direction you
    want and I will carry it through with an arm per field.

  9. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Taking the decision myself, since I claimed the row — per field, with the reason, so the implementation is mechanical and reviewable:

    field decision why
    cache_prompt: false honour it — bypass the prefix cache for that request correctness, not preference: the cache is on by default with 8 slots, so a client asking for it off is asking for exact re-encoding. We cannot honour the intent by ignoring the key
    cache_prompt: true no-op (already the default) — but say so in the docs accepting it and doing nothing is correct here because nothing is what it asks for
    id_slot reject with 400 and a message naming the in-process route a routing pin that is silently dropped is worse than one refused: the request lands somewhere the caller did not choose, and nothing tells them
    temperature, top_k (and the rest of SampleParams) honour, reusing the existing SampleParams that app/serve.cpp already fills the sampler exists and is wired; the in-process route simply never reads the body into it. Doing nothing here makes two routes disagree about the same body, silently
    any other key the route does not read accept the documented OpenAI fields it already tolerates, but list them in the route's doc comment the contract should say what is honoured and what is ignored

    Two implementation notes so this does not turn into a sweep:

    1. cache_prompt: false is the only one with a correctness consequence; it can land alone and is worth landing first.
    2. The sampling fields are a small change because SampleParams already carries defaults (temperature 0 = greedy), so a body
      that names no sampling field decodes exactly as it does today — which is the property tests/npu_sampling_test.cpp:116 already
      asserts for the other route.

    Not implementing right now, and the reason is a resource one rather than a design one: app/forward_serve.cpp needs a full
    1bit build to verify (the sampling path is compiled, not interpreted), and the box is at 160G free — exactly the floor —
    with the build queue saturated. I would rather queue this as the next build when there is headroom above the floor than eat
    several GB to land it and leave every lane below it. Nothing is lost: the decisions above are the expensive part and they are
    recorded here.

  10. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    The route states its own policy, and the four fields violate it — so this is a code fix, not a docs fix

    app/forward_serve.cpp:335-337, immediately above the decode-time controls:

    "Every field is optional and absent means the greedy decode this route has always done, so existing callers see no change;
    a field the route cannot honour is a 400 rather than a silently ignored key."

    That sentence is the route's declared contract, written by whoever added the decode controls. Against it:

    • cache_prompt (0 mentions), id_slot (0), temperature (0), top_k (0) — the route reads none of them and returns 200.
    • stream is handled correctly and even documents the same rule (:367, "a wrong type is a 400, not a 500"), so the policy is
      real in this file and simply not applied to the four.

    And a documented recipe depends on one of them

    docs/determinism.md:26-27 — the guide's first determinism claim:

    "Send the same prompt, greedy, with cache_prompt false, and every generated token's log-probability has the same float32
    bits. Holds on cpu and hrx."

    docs/serve.md:330 and docs/hybrid.md:46,185 reference cache_prompt the same way (id_slot 0 + cache_prompt true is what
    the hybrid path forwards). So the documentation tells readers to rely on two of the four keys this route ignores — and the
    determinism claim is made on routes where it happens to hold, with no statement about what the in-process route does with the key.

    That changes my earlier recommendation in one place: cache_prompt is not a taste decision. A reader following
    docs/determinism.md on this route believes they have disabled the prefix cache and does not have. Either the route honours it
    (and the doc is true everywhere), or it 400s (and the doc's recipe fails loudly instead of silently) — but a 200 with the key
    ignored is the one outcome that makes the documented claim false without saying so.

    Revised, narrower plan

    1. id_slot, temperature, top_k, cache_prompt → 400 when present, per the file's own stated policy, unless the field is
      understood. This is the smallest change that makes the contract self-consistent, and it needs no new machinery.
    2. Then, separately and deliberately, honour cache_prompt: false and the SampleParams fields, which turns those 400s back
      into behaviour. Doing it in that order means the tree is never in a state where a documented key is silently ignored.
    3. The determinism page gets one sentence either way: which routes honour cache_prompt, so the claim has a stated scope.

    Still deferred on the same resource reason (a full 1bit build, disk exactly at the 160G floor), and now with a better-defined
    first commit: the 400s.

  11. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Retracting my own correction from an hour ago: the issue's original retraction was right

    I wrote that temperature/top_k are not honoured by the in-process route and that the write-only set was therefore four
    fields. That is wrong, and the evidence was one call site I walked past:

    app/forward_serve.cpp:345   opts = npu::options_from_body(body);
    app/npu_sampling.h:343      inline Options options_from_body(const nlohmann::json& body) {
                                  if (body.contains("temperature")) { ... throw on < 0 ... }
                                  if (body.contains("top_k"))      { ... throw on < 0 ... }
                                  if (body.contains("top_p"))      { ... }
                                  if (body.contains("seed"))       { ... }
    

    So the route does read temperature, top_k, top_p and seed — through a helper in the header rather than by naming the keys
    in forward_serve.cpp. My mention-count method (which the issue itself used) cannot see keys read inside a helper, and I then
    "corrected" the issue on the strength of the same blind spot: I grepped app/*.h for temperature, printed the first eight
    matches (comments and a struct), and concluded there was no reader. The reader was eleven lines past my head -8.

    The write-only set is two fields — cache_prompt and id_slot — exactly as the issue originally said. My earlier
    "four fields, and the retraction is wrong in mechanism" paragraph should be disregarded; the title's retraction stands, and the
    mechanism is options_from_body, not npu_sampling.h reading a body directly (it is the same file, which is why I misfiled it).

    What survives from my analysis, and is worth keeping:

    1. The route's stated policy (forward_serve.cpp:335-337: "a field the route cannot honour is a 400 rather than a silently
      ignored key"
      ) is real and these two fields violate it.
    2. docs/determinism.md:26-27 depends on one of them — "send the same prompt, greedy, with cache_prompt false" — so on this
      route a reader following the guide believes they disabled the prefix cache and has not. docs/serve.md:330 and
      docs/hybrid.md:46,185 lean on the same key.
    3. Therefore the first commit is still the 400s for cache_prompt and id_slot, then honour cache_prompt: false if we want
      the determinism recipe to hold here.

    The lesson is the one this issue is about, applied to my own review: a mention count is not a reader search. Counting "temperature"
    in one file answers "is the string here", not "is the field honoured" — and I used it to overturn someone's already-corrected claim.

  12. bong-water-water-bong commented on Nov 20, 2026

    @bong-water-water-bong
    CollaboratorAuthor

    Closing as fixed: cache_prompt is read (#2889, 6981b9729, forward_serve.cpp:361) and id_slot is echoed in the reply (#2894, 8d09769e5, :986-991) — the latter citing this issue and choosing 'never silently discard a field' over the stricter 400 I argued for, which is the better call. Full reasoning in the preceding comment. My 'four fields' correction was already retracted there: temperature/top_k were always read via options_from_body.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions