Skip to content

fix(serving): the prompt cache the daemon granted is not KV — the footprint subtracts its own --cache-ram, an unattributable sample retires the record, and the grant leaves co-consumer headroom - #4216

Merged
joelteply merged 2 commits into
canaryfrom
fix/the-prompt-cache-is-not-kv
Sep 19, 2026

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

The M5, 2026-09-19 03:25–04:30Z, build 1d2ae5f: the lane ran --parallel 2 -c 134680 --cache-ram 19519 while the health line said "lanes 1 @ 67k — STARVED: 5 minds on 1
lanes" and the hour delivered 6 acts, 0 writes. The plan said one lane; the process ran
two. Three reads in one line:

  1. lane_footprint::per_token_from divides the process's whole anonymous footprint by
    lanes × window. The host prompt cache (--cache-ram, a grant the daemon itself made)
    fills that same footprint over the serve's life: 16.7 → 20.4 GB across the hour, and
    the reading went 105,919 → 133,720 B/token against a 32,768 estimate. corrects()
    fired, the plan's kv/token became ~107k, two lanes at 67k no longer fit usable 26–34 GB,
    and the planner starved the seat it was still running two lanes on.
    Fix: subtract the granted cache before dividing. The reading becomes a LOWER bound on
    the KV-attributable bytes — the only direction a footprint may correct an estimate.

  2. The record is persisted (state/lane-footprint.json) and fresh for an hour. When the
    new process's sample reads "nothing beyond the cache", observe returned None without
    touching the record — the stale 133,720 would have ruled the plan from disk through the
    relaunch that was supposed to fix it. Fix: an unattributable sample RETIRES the record
    (apply_sample, pure over the map, tested).

  3. prompt_cache_decision granted everything above the OS floor: afford 20,468 MiB →
    --cache-ram 19519. A cache fills to its grant by design, so that is a grant to end the
    serve at the floor with nothing left for the co-consumers the planner reserves for
    (the core's growth, a sidecar, the eye): the box sat 6 GB into swap with 25 GB in the
    compressor, and a 37,020-token prompt prefilled in 367 s with 0 cached. Fix: the grant
    leaves CO_CONSUMER_HEADROOM — the planner's own constant, one place, both decisions.

Probe serving.footprint.measured now carries host_cache_bytes so the subtraction is
readable on the wire. No change to the lifetime-peak read (#4165) — with the grant
subtracted, the peak's cache component is bounded by the number we subtract.

Card 1c0b60a9 (settles inflated). Related: #4165, #4202, #4207.

Test plan

  • CI: cargo test -p continuum-core --lib lane_footprint (new: the_prompt_cache_the_daemon_granted_is_not_kv_and_an_unattributable_sample_retires_the_record) + serving_daemon (afford assertion updated)
  • On the M5 after deploy: serving.footprint.measured carries host_cache_bytes and per_token_measured reads 0 (unattributable) or ≤ ~40k; serving.plan returns to lanes 2; state/lane-footprint.json no longer holds the 133,720 row; the next launch's serving.prompt_cache.derived shows afford_mib below available − floor.
  • Receipt that matters: the next [health] line says lanes 2 @ 67k, no STARVED.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

…sured lane footprint subtracts its own `--cache-ram` before attributing bytes to tokens, an unattributable sample retires the record, and the cache grant leaves the planner's co-consumer headroom

The M5, 2026-09-19 03:25–04:30Z, build 1d2ae5f: the lane ran `--parallel 2 -c 134680
--cache-ram 19519` while the health line said "lanes 1 @ 67k — STARVED: 5 minds on 1
lanes" and the hour delivered 6 acts, 0 writes. The plan said one lane; the process ran
two. Three reads in one line:

1. `lane_footprint::per_token_from` divides the process's whole anonymous footprint by
   lanes × window. The host prompt cache (`--cache-ram`, a grant the daemon itself made)
   fills that same footprint over the serve's life: 16.7 → 20.4 GB across the hour, and
   the reading went 105,919 → 133,720 B/token against a 32,768 estimate. `corrects()`
   fired, the plan's kv/token became ~107k, two lanes at 67k no longer fit usable 26–34 GB,
   and the planner starved the seat it was still running two lanes on.
   Fix: subtract the granted cache before dividing. The reading becomes a LOWER bound on
   the KV-attributable bytes — the only direction a footprint may correct an estimate.

2. The record is persisted (`state/lane-footprint.json`) and fresh for an hour. When the
   new process's sample reads "nothing beyond the cache", `observe` returned None without
   touching the record — the stale 133,720 would have ruled the plan from disk through the
   relaunch that was supposed to fix it. Fix: an unattributable sample RETIRES the record
   (`apply_sample`, pure over the map, tested).

3. `prompt_cache_decision` granted everything above the OS floor: afford 20,468 MiB →
   `--cache-ram 19519`. A cache fills to its grant by design, so that is a grant to end the
   serve at the floor with nothing left for the co-consumers the planner reserves for
   (the core's growth, a sidecar, the eye): the box sat 6 GB into swap with 25 GB in the
   compressor, and a 37,020-token prompt prefilled in 367 s with 0 cached. Fix: the grant
   leaves `CO_CONSUMER_HEADROOM` — the planner's own constant, one place, both decisions.

Probe `serving.footprint.measured` now carries `host_cache_bytes` so the subtraction is
readable on the wire. No change to the lifetime-peak read (#4165) — with the grant
subtracted, the peak's cache component is bounded by the number we subtract.

Card 1c0b60a9 (settles inflated). Related: #4165, #4202, #4207.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
…r share — a cache fills to its grant, so no arm is promised everything above the floor

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
@joelteply

Copy link
Copy Markdown
Contributor Author

APPROVE — reviewed at exact head abf0676; merge on the re-run lib test.

Checked, not read:

  • host_cache_bytes is the RUNNING process's grant: served_prompt_cache_mib is written at :2783 when the ServingTarget is built for the launch, not from a later desire. Right number for the subtraction.
  • CO_CONSUMER_HEADROOM is pub const 0.15 in serving_plan.rs and already applied at the three window-sizing sites; the cache grant now takes the same share, one constant. The tests assert affordable_bytes == above_floor × (1 − h) exactly, so a double application would fail, not pass.
  • The direction is right: subtracting the WHOLE grant (not the filled part, which nothing reports) makes the reading a lower bound, and corrects() is upward-only, so a lower bound can only remove false corrections — the M5's 133,720 B/token was exactly a false one. The retire arm closes the other hole (a stale record ruling from disk for FRESH_MS after the process it measured is gone).

One consequence, stated so nobody reads it as a regression: on a node whose cache is empty the reading is None for the whole early serve. IntelMac now: anon 1.65 GB under an 18 GB grant (--cache-ram 17236) — after this lands, per_token_measured is absent here until anon exceeds ~18.5 GB. Plan unchanged (its old reading of 42,129 was BELOW the estimate and never corrected anything), observability narrowed on purpose. My registered second-tier test of your mechanism will read anon_bytes climbing with the cache fill instead of per_token.

Not asked, not a condition: the 6 GB of swap on the M5 is the OTHER half — the 15% share fixes the grant going forward; a box already in the compressor needs the relaunch to take it. The receipt is serving.footprint.measured host_cache_bytes > 0 with per_token_measured absent on the M5's next serve, and lanes back to 2.

@joelteply
joelteply enabled auto-merge (squash) September 19, 2026 04:16
@joelteply
joelteply merged commit 91f2743 into canary Sep 19, 2026
6 checks passed
@joelteply
joelteply deleted the fix/the-prompt-cache-is-not-kv branch September 19, 2026 04:31
joelteply added a commit that referenced this pull request Sep 19, 2026
…the grant leaves ECO_EXIT_BYTES free after it fills, so a full cache cannot step the serving mode down and cut its own lanes (#4222)

Measured 2026-09-19 on the M5 (build 2491308): the prompt cache was granted 17,021 MiB
from 29.6 GB available. It filled; available fell to 7 GiB; the live budget's pressure
mode stepped Comfort → Eco (serving fraction 0.80 → 0.55); the plan cut to one lane; at
12:19Z the reconcile RELAUNCHED the lane at `--parallel 1` — five coders on one lane,
"STARVED: the planner owes lanes" — and the relaunch derived the same 17 GB grant again
from the RAM the dead engine had just freed. The box crossed Comfort ↔ Eco five times
in the morning (available 7 ↔ 12 GiB). Two hours earlier the same seat had read HEALTHY
at three lanes @ 67k with writes 2.

The daemon's own cache was driving the daemon's own pressure mode. Fix at the grant
(one clause in `prompt_cache_decision`, beside #4216's co-consumer share): the grant is
capped at `available − ECO_EXIT_BYTES` before the share is taken, so what remains after
the cache fills stays above the Eco EXIT band and a full cache can never enter Eco by
itself. No new constant: ECO_EXIT_BYTES is the pressure law's own number. The unknown-
availability arm is unchanged.

Test: for available readings of 13 / 20 / 29 / 46 GiB the post-fill remainder stays above
the exit band, the grant is monotone in room, and with 46 GiB free the cache is still a
real cache (> 8 GiB). The existing "bounded by what the box can give now" pin takes the
new bound. Card 1c0b60a9 (grant half; the plan-side term stays with Kimi).


Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

Co-authored-by: Claude Fable 5.1 <[email protected]>
joelteply added a commit that referenced this pull request Sep 19, 2026
…budget; a roster short of warm slots is re-home evidence (the M5 could never reach two lanes) (#4230)

* fix(serving): one headroom, not three — the plan sizes to the budget the mode hands it; and a roster short of warm slots is re-home evidence whatever the token-space says (the M5 could never reach two lanes)

Measured 2026-09-19 15:4xZ on the M5 (64 GB, Comfort) on 1d994a7, right after #4226
landed the header KV rate (per_token_estimate 32,768): the board hands serving a 37 GB
budget after 18.7 GB of other holders; the plan then kept 0.80 (the mode) × 0.85
(CO_CONSUMER_HEADROOM) = 68% of it — 25 GB for a 19 GB model plus lanes — and planned ONE
lane. Physically 2 × 67,340 lanes are 27.4 GB, inside the 37 GB budget with 26% to spare.

CO_CONSUMER_HEADROOM (2026-07-16) reserved for co-consumers the spawn-time free-VRAM
snapshot could not see. Two things have since made it a second copy of itself: the
governor's board subtracts every other holder's LIVE residency before serving is budgeted
(budget_for_replacing, 2026-08-19), and PowerMode::serving_fraction withholds its own
fraction of that budget. The mode IS the headroom policy, one place. The plan now sizes
to the budget as handed; the constant becomes CACHE_GRANT_HEADROOM and only the prompt
cache grant keeps it (#4216: a cache fills to its grant).

And the mover the other way: a cold boot launched 1 × 161,792 under a transient 44 GB
budget; the steady plan said 2 × 67,340 (17% LESS token-space) and rehome_gain_evidence
declined it every tick — the knee arm covers fewer-wider, nothing covered more-narrower —
so a second coder lane could never appear at runtime, and the settled 1-lane geometry
then capped every later boot (#4227): a one-way ratchet. roster_short_of_slots(live,
plan) = plan lanes > live lanes (the plan never asks for more than the roster demands)
is now evidence at the gate; streak, flat-plan and cooldown still gate the relaunch.

Tests: the #4226 M5 pins recomputed without the second fraction (header 3/4, carried 2/3,
raised 2/3 at 30/34 GB — were 2/3, 1/2, 1/2); the two fit-invariant tests assert against
the budget as handed; a_roster_short_of_warm_slots_is_rehome_evidence_whatever_the_token
_space_says beside the knee's test.

Receipt on the M5: serving.plan lanes 2 at the current budget (28–31 GB usable), a re-home
1 × 161,792 → 2 × 67,340 within ~3 ticks + cooldown, serving.geometry.settled with lanes 2,
and the next [health] line with 2 lanes @ 67k.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* fix(serving): no production budget hands the plan 1.0 — Performance keeps the serving process's own overhead (BigMama's condition), and the five pins measured under the old 15% reserve keep their budgets

The plan's only headroom is now the mode's fraction, and Performance was 1.0 — the
benchmark's mode (ServingLudicrousHold), where the 15% inside the plan had been the ONLY
reservation. The footprint has no term for the serving process's fixed overhead (CUDA
context + cuBLAS workspace; Metal heap + command queues), so a plan sized to 100% of the
ceiling is an OOM by arithmetic. Performance.serving_fraction() = 0.96 (measured for scale
on the 5090: 2.3 GB of slack on a 32.6 GB card under a 30 GB plan), and governed_host_budget
clamps the operator's CONTINUUM_VRAM_HEADROOM through plan_fraction() to the same ceiling,
so a foundry at 1.0 still keeps it. Tests: the monotonic-fraction test asserts < 1.0 and
≥ 0.95; a_foundry_headroom_of_one_still_keeps_the_process_overhead.

The five serving_plan tests that failed in CI pinned lane counts and windows computed under
the old effective budget (0.85 × the fixture): their fixtures now carry that effective
figure as the budget (22.1 GB for the 26 GB cases, 51.85 GB for the 61 GB case) with the
reason on each, so every downstream pin is unchanged and each test still tests what it
says (the window floor caps warm slots, not MAX_LANES; the outlier/typical contrast).

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

* docs(serving): the Performance fraction is 0.96 in the two comments that said 1.0

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo

---------

Co-authored-by: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant