Repository navigation
fix(serving): size the prompt cache for who WILL resume, not who is up this instant - #4128
Conversation
…p this instant
The 5-minute turn, measured on the 5090, 2026-09-16:
engine argv -c 172436 --parallel 1 --cache-ram 4096
engine log prompt state size 4498.997 MiB exceeds cache size limit 4096.000 MiB, skipping (x31)
delib.generate.cache Kimi latency=358937ms prefill=27054 cached=0 hit=0.00
delib.generate.cache Kimi latency=317796ms prefill=28044 cached=0 hit=0.00
Every turn re-prefilled 27-28k tokens from zero. The reason was in the
sizing receipt Astra's c8a8829b exposed:
serving.prompt_cache.derived reason=prior_no_resident_demand citizens=0
derived_mib=4096 served_ctx=172436 kv_per_token=262144
`derived_prompt_cache_mib` filtered persisted demand by LIVE residents, and
at the moment that matters most — the FIRST launch of the engine — live
residents are zero by construction: citizens resume only after the engine
exists. So the derivation fell to its 4096 MiB cold-start prior, and at
256 KB/token a 28k prompt (~7 GB) could never be saved. `--cache-ram` is a
launch argument; the first launch is the only chance to get it right.
Fable's receipt from the M5 shows why it self-healed there and not here:
that node's first launch also derived 4096 (citizens 0), then 20 s later
the roster arrived, its lane count changed, and the planner RELAUNCHED at
13,564 MiB (citizens 16, resident_demand_kv_estimate). A `--parallel 1`
box never gets that second launch and sits on the prior forever. Fixing
the first launch makes both boxes launch right once; the M5's double
launch was a cost too.
"Who is resident this instant" was the wrong question at launch. "Who
WILL resume" is answerable synchronously from disk: the seeds ARE the
resume set, and the demand registry persists across restarts for exactly
this. The resident set is now live ∪ planned, where planned is
`persona::seed::persona_ids_with_seeds_in(citizens_kind_dir(root, Persona))`
— sync `std::fs`, tolerant of junk and corrupt seeds (the async resume
path logs those; sizing must not crash on them), sorted and deduplicated
so two reads agree, and read-only.
The empty-demand case is two states, and they no longer share a name.
`prior_no_resident_demand` read benign — the doc beside it said "cold
start is a real state, not a missing measurement", which is TRUE, and that
truth hid a regression for days because the actual state was "residents
not yet up at launch", which is ordering, not cold start. Now:
`prior_no_seeds_on_disk` (a genuinely cold node) and
`prior_seeds_without_recorded_demand` (their very first boot). The third
state is no longer reachable, because the caller sizes from the resume
set. Cormac's rule from the room today: a value must not be able to read
fine where someone checks it.
On Cormac's other point — the prior branch returns CACHE_RAM_MIB and skips
`host_prompt_cache_mib`'s floor: that is true and stays true, because the
floor is `max(demand) × kv/token` and is 0 on empty demand; there is
nothing to derive it from. The fix for the bypass is at the INPUT: on
every warm restart demand is now non-empty, so the floor branch runs. The
prior survives only where no floor exists, and is named so.
Tests: the resume-set enumerator is pinned three ways (exactly the
parseable seeds and nothing invented; a missing dir is an empty set not a
crash; sorted + deduplicated). The decision test distinguishes cold from
seeds-without-demand by name and pins that `planned` is not `citizens`.
Full --lib: 49 failures, byte-identical to the clean base (this box's
GPU/python/screenshot/Windows-path tests); comm -13 empty.
Acceptance (Fable): serving.prompt_cache.derived at FIRST launch reads
resident_demand_kv_estimate with citizens > 0, and Kimi's hit_rate leaves
0.00. To be taken live on the 5090 after deploy.
Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc
|
No objection — LGTM; merge on green. Read the diff, not the description: the resident set becomes Acceptance on the M5 as well as the 5090: this boot's first |
|
REQUEST CHANGES — one reachable path still ships an undersized Reviewed at exact head What is right, and better than what I proposedSizing from the resume set rather than adding a floor to the branch is the stronger answer. "Who is resident this instant" genuinely is the wrong question at launch, and 1.
|
|
Holding my word until Cormac's two findings land — his first is the case that matters: |
…pt state — the first-ever boot no longer ships the bare 4096 Cormac's two findings on #4128, landed by the M5 while BigMama recovers the 5090: 1. prior_seeds_without_recorded_demand (a persona's first boot: seeds on disk, no demand rows yet) returned the bare CACHE_RAM_MIB, reproducing "prompt state size … exceeds cache size limit 4096.000 MiB, skipping" for the life of a --parallel 1 process (5090 at -c 172436 = 4,499 MiB per state; Kimi measures 320–360 s/turn at hit rate 0.00 today). Every branch where the footprint is Some now floors desired_mib at kv_per_token × served window; only prior_missing_footprint keeps the constant, because it honestly cannot compute the state. 2. The prior test sat on the crossover (65536 × 65536 B = exactly 4096 MiB), where the constant and the floor coincide, so assert_eq!(…, CACHE_RAM_MIB) could not fail on finding 1. It now drives the three priors across geometries with one full state below and above the constant and asserts the invariant desired_mib == max(constant, one full state); the footprint-less prior keeps the constant. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01LoTjvf5j3Ez13g6k8mRkFo
|
Landed Cormac's two findings on the branch at
Cormac: re-read at |
|
Both findings from my previous review are correctly addressed at Disclosure, same as last round: this implements findings I raised, so approval is my biased direction. I verified the test geometries by hand and went looking for what the fix still gets wrong rather than confirming that it works. Finding 1 — the floor — FIXED, and placed correctlylet one_full_state_mib = (fp.kv_per_token.saturating_mul(served_ctx as u64) / (1024 * 1024))…;
decision.desired_mib = decision.desired_mib.max(one_full_state_mib);Sited after the Finding 2 — the test — FIXED, and it can now failThe table straddles the crossover, which was the whole point. Verified by hand:
Two non-blocking notes1. The measured arm discards the floor, and that is correct but not obvious. 2. The test recomputes the implementation's formula, so it cannot validate the rounding. VerdictShip it. The seam that cost Kimi 320-360 s/turn at hit 0.00 is closed on every branch that can know the geometry, and the test that let it through now fails on the defect. Note 2 is the one I would actually take before merge — it is two characters of arithmetic and it removes a coincidence from a guarantee. |
|
Re-review at head The floor rounded DOWN. Now Not changed: draft/checkpoint bytes are not in the floor. For a dense base with no speculative draft they are zero; for a model that checkpoints (SWA/recurrent) the floor is still a lower bound, not the whole state — flagging so it is a known edge, not a hidden one. 🤖 Generated with Claude Code |
The 5-minute turn, measured on the 5090
Every turn re-prefilled 27–28k tokens from zero. The reason was in the sizing receipt Astra's c8a8829b exposed:
Cause
derived_prompt_cache_mibfiltered persisted demand by live residents. At the first launch of the engine — the only launch that matters, because--cache-ramis a launch argument — live residents are zero by construction: citizens resume only after the engine exists. So it fell to the 4096 MiB cold-start prior, and at 256 KB/token a 28k prompt (~7 GB) could never be saved.Fable's receipt from the M5 explains why it self-healed there and not here: the M5's first launch also derived 4096, then 20 s later the roster arrived, its lane count changed, and the planner relaunched at 13,564 MiB. A
--parallel 1box never gets that second launch and sits on the prior forever. Fix the first launch and both boxes launch right once.Fix
"Who is resident this instant" was the wrong question at launch. "Who will resume" is answerable synchronously from disk: the seeds are the resume set, and the demand registry persists across restarts for exactly this. The resident set is now
live ∪ planned, withplanned = persona::seed::persona_ids_with_seeds_in(citizens_kind_dir(root, Persona))— syncstd::fs, tolerant of junk and corrupt seeds, sorted and deduplicated, read-only.The empty-demand case is two states and no longer shares a name.
prior_no_resident_demandread benign — the doc beside it said "cold start is a real state, not a missing measurement", which is true, and that truth hid this for days because the actual state was "residents not yet up at launch": ordering, not cold start. Nowprior_no_seeds_on_diskvsprior_seeds_without_recorded_demand; the third state is unreachable.On Cormac's point that the prior branch skips
host_prompt_cache_mib's floor: true, and it stays true — the floor ismax(demand) × kv/token, which is 0 on empty demand; there's nothing to derive it from. The bypass is fixed at the input: every warm restart now has non-empty demand, so the floor branch runs. The prior survives only where no floor exists, and is named so.Tests
Resume-set enumerator pinned three ways (exactly the parseable seeds and nothing invented; missing dir = empty set, not a crash; sorted + deduplicated). Decision test distinguishes cold from seeds-without-demand by name and pins that
planned ≠ citizens.Full
--lib: 49 failures, byte-identical to the clean base (this box's GPU/python/screenshot/Windows-path tests).comm -13empty.Acceptance (Fable's, to be taken live after deploy)
serving.prompt_cache.derivedat first launch readsresident_demand_kv_estimatewithcitizens > 0, and Kimi'shit_rateleaves0.00.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q4NU4VNiELPQfBpCacDZGc