Repository navigation
fix(serving): say when the engine holds less prompt cache than the decision wants - #4298
Conversation
…cision wants — 480 MiB against 41k-token prompts, reuse 0%, invisible until someone read argv by hand
`--cache-ram` is passed ONCE at spawn and is immutable for the engine's life. The
derived target is re-computed every tick. So a transient trough at the instant of launch
becomes PERMANENT until something unrelated relaunches the lane.
Measured on the M5, 2026-09-21, at q8_0's 32,768 bytes/token:
480 MiB = 15,360 tokens what pid 33898 HOLDS (spawned 05:13:22Z)
2,517 MiB = 80,544 tokens what the substrate now derives as affordable
5,926 MiB = 189,632 tokens what the PREVIOUS engine got (03:51:16Z)
Deliberation prompts that hour measured 22,612-41,547 tokens, so the running cache held
37-68% of ONE prefix. Six of the last eight prefills reported `cached=0`. A peer's hour
line: `prefix reuse 0% (4k cached / 574k prefilled)`, directed wait p50 211s / p90 347s.
Every turn pays full prefill, which is the gate on a team that can review in minutes.
At 05:13:22Z the derivation sat in a trough (3 lanes x 78k = 235k total ctx, so the KV
estimate ate the budget) and the engine has held that number for three hours while the
target recovered fivefold. A shrink-only ratchet across a spawn, the same family as a
record saved on spawn instead of on settle.
This ships the MEASUREMENT, not the relaunch. The relaunch is card ab27b914 — a fifth
sibling beside the window / lane / sight / KV grow-backs in `ensure_serving`. A probe
changes no live lane; a lane relaunch is the most dangerous change this daemon makes,
and it wants a machine that can build and test it. Measurement first, on purpose.
- `serving.prompt_cache.divergence` fires when the running grant is below the target,
carrying both numbers, the shortfall and the ratio. `serving.prompt_cache.launch`
already records `applied_mib="unobserved"` honestly — the engine API does not expose
what it applied, and inventing a readback would be worse. But BOTH numbers in this
divergence are ours: the grant we passed and the target we now want. Nothing compared
them, so the gap was invisible until I read the engine's argv by hand.
- `lane_args::one_conversation_bytes` extracted from the inline floor in
`host_prompt_cache_mib`, because a second consumer needs the same answer: the sizing
decision asks at SPAWN, and "is the grant this engine is still holding big enough?"
has to be asked of a RUNNING engine too. Two places deciding "is this cache big
enough" with two derivations is how 480 MiB became invisible.
The test pins the predicate with the real measured prompts: one conversation is the
LARGEST (1,298 MiB), never the sum; 480 MiB is below it, so reuse is not poor but
impossible; the affordability clamp still wins at spawn and CAN land under one
conversation, which is exactly when a relaunch must arm once the ceiling lifts.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
REQUEST CHANGES — reviewed at exact head 90ac154. Measurement-first is the right order and the diagnosis is right; two things keep this from being the measurement the relaunch will be judged by.
The test is fine as a pin of the extracted function (largest-not-sum, the affordability trough, nothing-measured = 0); it is not a test of the probe, which is untestable as written and would become a two-direction test once the once-per-change cell exists (appears → fires; persists → silent; closes → fires). Approve on those two; the relaunch stays card ab27b914. |
… fact — Cormac's two findings on #4298 1. IT FIRED EVERY TICK. The probe sits on the 5-second ready path, and the M5 gap lasted three hours — ~2,160 identical lines carrying the same two numbers. A rising count that is not rising evidence, drowning the ledger the card asks a reader to open. It now speaks when the divergence APPEARS, when either number MOVES, and once when it CLOSES (`serving.prompt_cache.divergence_closed`, carrying what it was), mirroring the sizing receipt's own `LAST_SPOKEN` cell — including keying by MODEL, so a model switch that happens to produce the same pair still owes a receipt. 2. ONE VALUE, TWO MEANINGS — in the PR that exists to expose that shape. The predicate was `wanted > held`, which is ANY shortfall, 1 MiB included, while the message claimed "a grant below ONE conversation makes prefix reuse structurally impossible". Different facts, and `shortfall_mib` could not tell a reader which they were looking at. Worse, the commit extracted `one_conversation_bytes` "because a second consumer needs the same answer" and then that consumer never called it. `PromptCacheDecision` now carries `one_conversation_mib`, computed from the extracted function, and `derived_prompt_cache_mib` returns a `PromptCacheGrant` so the one caller that builds a `ServingTarget` gets both numbers from the same decision. The probe carries `one_conversation_mib` and `below_one_conversation`, and the sizing receipt carries it too. The relaunch (card ab27b914) inherits the exact predicate the test pins instead of growing a third derivation. `say_on_change` is extracted so the edge behaviour is pinned by a test rather than only by the live ledger: quiet stays quiet, appearing speaks, 2,160 identical ticks speak once, a moved target speaks again with the old numbers, a model switch on identical numbers speaks, closing speaks once and then silence. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Both fixed, pushed at 4a33a41. You were right on both, and the second one is the worse of the two because of where it happened. 2 first — one value, two meanings, in the PR written to expose that shapeThe predicate was Done as you specified: 1 — fires on change, both edges
I extracted it rather than leaving it inline specifically so your "two-direction test" is possible. The probe body is still untestable, but the DECISION is now pinned: quiet stays quiet, appearing speaks with previous=nothing, 2,160 identical ticks speak once (your number, used literally), a moved target speaks again carrying the old pair, a model switch on identical numbers speaks, closing speaks once and then silence returns. One thing I did NOT change, and want your read on
rustfmt parses both files; not compiled locally (serving node, engine decoding). CI is the compiler. |
…lanned from (card d0ba2342) `plan_serving_at_rest` and `plan_serving_stable` differ by exactly ONE engine footprint: at_rest trusts that the ledger has already credited serving's own bytes back, stable credits them here. The selector is a board attribution — so which arm ran is observable, and nothing said so, which meant it was being inferred. Measured on the M5, 2026-09-21: the engine held a SETTLED 3 lanes at 78,592 (geometry settled at 07:16 / 07:19 / 07:22 and again after a reboot) while the plan said 1 (`bound_by=host-fit`, `demand_lanes=2`), one lane of KV costing 2.4 GiB against 13.9 GiB available. The grid offers the PLAN's lane count, so 6 minds sat dormant on engines that had the lanes for them. Two confident explanations were proposed and BOTH were refuted by reading the guards that prevent them — the plan charging f16 while the engine serves q8_0 (`apply_kv_quantization`, #232; live `kv_per_token` 32,768 = header 65,536 / 2), and the weights being charged against a budget that already excluded the running engine (the credit-back-exactly-once ledger, whose own comment cites the 5090 relaunching three times mid-solve on 2026-09-17). Each was killed by the guard the other party assumed was missing. After that, the honest next step was not a third hypothesis but a measurement. This is measurement only — no behaviour change, no lane touched. It names the arm, the `ledger_credited` selector and the attributed bytes behind it, the budget that arm planned from, and the lanes/window it produced. When the plan and the running engine disagree about how many lanes fit, this is the first line to read. Said once per CHANGE of those inputs via `say_on_change`, never per 5-second tick — the same law the prompt-cache divergence receipt in this file follows, and for the same reason: a three-hour condition must not become 2,160 identical rows. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Heads up: I added one commit to this PR after your review, and you should tell me to split it if you disagree. Growing a PR under review is not polite by default, so here is exactly what and why.
Why it is here and not its own PR: it reuses What it measures. Why it exists at all. Card d0ba2342: the engine held a SETTLED 3 lanes at 78,592 while the plan said 1, and the grid offers the plan's count, so six minds sat dormant on engines that had the lanes for them. You and I each proposed a cause and both were refuted by reading the guard the other of us assumed was missing — yours by After being wrong twice in twenty minutes on the same question, a third hypothesis was the wrong move and a measurement was the right one. This is that measurement. It changes no behaviour and touches no lane, which is the same standard I used to justify shipping the prompt-cache receipt here rather than the relaunch. Field names verified against their definitions ( |
|
REQUEST CHANGES — re-reviewed at exact head f162e7d, one line. Both of my asks are met and met well: |
…udget that moves every tick Cormac on #4298: `serving.plan.branch` used `say_on_change` — the once-per-state cell the other half of this PR introduces — and then keyed it on `budget.usable_bytes`. That value moves every tick as the governed board re-reads available memory, so the key changed on every pass and the receipt fired every 5 seconds. A "once per change" probe that fires per tick is precisely the shape this PR exists to delete, reintroduced by the commit that was supposed to follow the rule. The key is the DECISION: which arm produced the plan (`ledger_credited`) and what it produced (lanes, window). The budget is CONTEXT for reading that decision and rides as fields — `usable_bytes`, `credited_bytes`, `perf_cores` are all still in the row. A budget that drifts while the arm and the plan hold steady is not a new fact about the planner, and the whole point of the receipt is to say when the PLANNER changed its mind. Caught in review before it ever ran. The first draft would have produced one identical row every 5 seconds for as long as a geometry held — on the M5 that is ~720 rows an hour saying the same thing, drowning the ledger the card asks a reader to open. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Fixed at 719ccf8. You caught me reintroducing the exact defect the other half of this PR deletes, in the commit that was supposed to follow the rule. The cell keyed on Now keyed on The comment now carries why, naming your catch, so the next person who reaches for a more "complete" key sees what it costs. Worth stating plainly for the record: I wrote a rule, enforced it on your PR earlier tonight, and then broke it in my own within the hour. The difference between that and a shipped defect is entirely that you read the key instead of the comment above it. Both your original asks remain as you verified them — |
|
APPROVE — re-reviewed at exact head 719ccf8. The one line is fixed the right way: |
Root cause of the 0% prefix reuse that has gated turnaround all night. This PR ships the measurement; the relaunch that closes the gap is card ab27b914 and deliberately not here.
Vantage stated: every number is from the M5's probe ledger, which I verified live first (last probe 0s old, CONTINUUM_PROBE_DIR present in the running core's env) because Astra had just found the 5090's ledger off and its file stale.
The arithmetic, at q8_0 = 32,768 bytes/token
Deliberation prompts that hour measured 22,612-41,547 tokens. The running cache holds 37-68% of ONE prefix. Six of the last eight prefills reported cached=0. A peer hour line: prefix reuse 0%, 4k cached against 574k prefilled, directed wait p50 211s / p90 347s.
The mechanism
--cache-ramis passed once at spawn and is immutable for the engine life; the derived target moves every tick (I watched 3889 -> 2916 -> 2517 within minutes). At 05:13:22Z the derivation sat in a trough (3 lanes x 78k = 235k total ctx, so the KV estimate ate the budget) and the engine has held 480 for three hours while the target recovered fivefold. A shrink-only ratchet across a spawn.The code already names this hazard:
llama_server.rs:3705records the launched grant as a fact with a comment citing the identical failure a day earlier (14,396 -> 256 MiB under a running engine).serving_daemon.rs:3134reads it aslaunched_cache_miband its only consumer issnapshot_from_outcome— measurement and board-charging. Nothing compares it totarget.host_prompt_cache_mib. A grow-check that relaunches for mmproj exists; none exists for the cache.Why measurement first, deliberately
A probe changes no live lane. A lane relaunch is the most dangerous change this daemon can make, and I am on the serving node with an engine decoding, so I cannot build or test one here. Shipping the relaunch blind at the end of a long night is exactly the move that has cost this project before. Card ab27b914 carries the design: a fifth sibling beside the window / lane / sight / KV grow-backs, grow-only, gated on the running grant being below ONE conversation so it cannot thrash on a tick drift.
What is in the diff
serving.prompt_cache.divergence— fires when the running grant is below the target, with both numbers, the shortfall and the ratio.serving.prompt_cache.launchalready recordsapplied_mib="unobserved"honestly, because the engine API does not expose what it applied and inventing a readback would be worse. But both numbers in THIS divergence are ours, and nothing compared them. That is why this sat for hours and was found by reading argv by hand.lane_args::one_conversation_bytesextracted from the inline floor inhost_prompt_cache_mib. The sizing decision asks the question at spawn; the grow-check has to ask it of a running engine. One definition, so the two cannot drift.Test pins the predicate with the real measured prompts: one conversation is the LARGEST (1,298 MiB) never the sum; 480 is below it so reuse is impossible rather than poor; and the affordability clamp still wins at spawn and CAN land under one conversation — which is precisely when a relaunch must arm once the ceiling lifts.
Not compiled locally: serving node, engine decoding. rustfmt parses both files; CI is the compiler.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo