Skip to content

fix(serving): a fresh core's first cache sizing reads the saved pages on disk (card 37eb1925) - #5060

Merged
joelteply merged 7 commits into
canaryfrom
37eb1925/launch-time-cache-ram-below-one-saved-st
Oct 15, 2026
Merged

joelteply merged 7 commits into
canaryfrom
37eb1925/launch-time-cache-ram-below-one-saved-st

Conversation

@joelteply

@joelteply joelteply commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

The state samples that size the host prompt cache were seeded from the pages
on disk only in note_page_dir, at the spawn. The sizing for that spawn runs
first, so every freshly started core sized its first lane from the KV
estimate, which misses the recurrent state and checkpoints a hybrid model
saves. #5056's re-home then relaunched the lane minutes later.

Kimi's node, 2026-10-15, engine 5b8500ee2 (root's receipts
20261015-core-start-cache-sizing.json, -cache-launch-derivation.jsonl,
-cache-rehome-generations.jsonl):

  • the core started 12:15:15Z;
  • the derivation ran about 20 s later: reason=resident_demand_kv_estimate,
    2 x 1,616 = 3,232 MiB, against 30,227 MiB affordable;
  • the launch used --cache-ram 3232, then cache_holds_no_state fired, then a
    relaunch at 9,477 MiB. That's two lane starts, about 7.5 min to settled.

Seeding moves to the read path. The first measured_state_bytes for a dir
reads its newest pages once, a dir with no pages is remembered empty (one
read, not one per tick), a live sample still outranks the disk's, and the
answer is read under the lock that seeded it. note_page_dir keeps its
registration and seeds through the same function.

Measured

  • Before (the defect): root's receipts above, Kimi's node, core build 6226 / 66cfeb7, engine 5b8500ee2, 2026-10-15. The core started at 12:15:15Z. Its first derivation was 3,232 MiB from the KV estimate, and the lane started twice.
  • Source: the new slots.rs test the_first_sizing_after_a_restart_reads_the_pages_on_disk seeds the planned model's dir under a page store that also holds another model's dir and 10 newer dirs, with no spawn and no note_page_dir. Without the seed measured_state_bytes returns None there; that's the mutation this test catches. CI at this head is pending, and I don't compile the core on IntelMac.
  • After deploy (owner Cormac, deadline: the first core restart on Kimi's node after adoption): that restart's first serving cache derivation should carry a measured state (not resident_demand_kv_estimate) and a desired_mib that holds one state. There should be no cache_holds_no_state grow on that lane generation. Card 37eb1925 stays open until that receipt is posted.

Not changed: the sizing formula, the re-home rule (#5056), or reconcile_to_plan's synchronous contract (no deferred tick). Shape (head ce7371d, on eeb7a32, after root's reviews): launch_window() is the one owner of the launch geometry (sticky, wedge-heal, physical fit), and both the reconcile and the async tick call it. Before each reconcile, the tick seeds the EXACT dirs reconcile reads (the plan model at the launch window and at the live window); the adopt rail seeds its own. The sample cache is the readiness authority: a known dir is never re-read, an evicted dir is re-read alone, and a new geometry is a new dir. There is one shared in-flight read per dir; each asker waits at most REPORTER_TIMEOUT (100 ms, the guarded() budget #5058's registry uses); serving is never held by the disk. pages_in and newest_page_states return Result (missing dir = empty, a vanished entry skipped, anything else an error). Warm scan cost on IntelMac 13:21Z: 0.80 ms for 134 entries.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

@joelteply
joelteply force-pushed the 37eb1925/launch-time-cache-ram-below-one-saved-st branch from 7a58b05 to f07da10 Compare October 15, 2026 13:40
joelteply and others added 5 commits October 15, 2026 09:23
… on disk (card 37eb1925)

The state samples that size the host prompt cache were seeded from the pages
on disk only in note_page_dir, at the spawn. The sizing for that spawn runs
first, so every freshly started core sized its first lane from the KV
estimate, which misses the recurrent state and checkpoints a hybrid model
saves. #5056's re-home then relaunched the lane minutes later.

Kimi's node, 2026-10-15, engine 5b8500ee2 (root's receipts
20261015-core-start-cache-sizing.json, -cache-launch-derivation.jsonl,
-cache-rehome-generations.jsonl):
- the core started 12:15:15Z;
- the derivation ran about 20 s later: reason=resident_demand_kv_estimate,
  2 x 1,616 = 3,232 MiB, against 30,227 MiB affordable;
- the launch used --cache-ram 3232, then cache_holds_no_state fired, then a
  relaunch at 9,477 MiB. That's two lane starts, about 7.5 min to settled.

Seeding moves to the read path. The first measured_state_bytes for a dir
reads its newest pages once, a dir with no pages is remembered empty (one
read, not one per tick), a live sample still outranks the disk's, and the
answer is read under the lock that seeded it. note_page_dir keeps its
registration and seeds through the same function.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
… the first sizing (card 37eb1925)

Root's review of bcb2d96: measured_state_bytes ran a synchronous directory
scan from the reconcile tick and the adopt rail, and warm timings do not
bound a cold scan. measured_state_bytes is a pure lookup again. The disk
read happens in two awaited places, both on the blocking pool:

- the serving daemon's initialize awaits seed_page_store(kv_pages_root())
  before its boot reconcile: ONE spawn_blocking that reads the STATE_DIRS
  newest page dirs, so the first cache sizing finds measured states;
- the adopt rail (async ensure_model_serving_if_current) awaits
  seed_state_samples for the dir it checks, a no-op once known.

note_page_dir goes back to registration only. reconcile_to_plan's contract
is unchanged: no tick is deferred, so every launch-on-first-reconcile test
keeps its meaning. A failed blocking read leaves the dir unmeasured (probe
inference.kv_page.seed_failed), never recorded empty, so it never triggers
a relaunch.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…le, bounded (card 37eb1925)

Root's review of 7a58b05: the boot read covered only the 8 newest dirs,
so a planned model outside them, or a later model switch, still sized from
the KV estimate; and an awaited unbounded read could hold serving's startup
on an unavailable disk.

seed_model_pages(model) replaces both reads. It reads every geometry dir of
that model (kv_page_dir_prefix is now the one owner of the dir naming), once
per model per process, as a shared in-flight future, so a slow disk never
grows a second stuck thread. The read runs on the blocking pool, and each
asker waits at most the disk reporters' REPORTER_TIMEOUT (the same
guarded() budget #5058's cargo-root registry uses). On timeout the read
stays in flight, this sizing uses the estimate (probe
inference.kv_page.seed_pending), the next tick uses the pages, and serving
is never held. A failed read is forgotten so the next ask reads again.

The serving daemon awaits it for the plan's base model before the boot
reconcile and before each tick's reconcile; the adopt rail awaits it for
its target. reconcile_to_plan itself is unchanged and stays synchronous.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…keeps custody, re-reads evicted dirs, fails loud (card 37eb1925)

f07da10 cut slots.rs from the seed's doc to state_dir_known_in, deleting
STATE_DIRS, STATE_SAMPLES, RECENT_STATE_BYTES, PAGE_SIDECARS, pages_in,
newest_page_states, note_state_bytes, page_sidecar_bytes and
trim_page_store_after_save while their callers remained. CI failed to
compile, and root's review caught it. This rebuilds the file from bae8b9f
and replaces only the seeding span.

Root's other findings on f07da10, each addressed in the one owner:
- Pending custody: a model's in-flight read (ModelSeed::Reading) is never
  dropped, so its blocking worker is never orphaned and never duplicated.
  Only completed entries beyond STATE_DIRS are dropped.
- Completed lifecycle: a completed seed remembers the dirs it filled. If any
  of them has since been evicted from the samples, the model is read again.
- Exact geometry: every one of the model's dirs is read, not the first 8, so
  the planned geometry is measured whenever it has pages. A geometry with no
  dir has no saved state, and the estimate is the honest answer there.
- Read failure: model_page_dirs returns Result. A missing store is empty;
  any other failure to read the root or one of the model's dirs is an error,
  probed as inference.kv_page.seed_failed and forgotten, so the next ask reads
  again. It is never cached as an empty store.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…w owns the launch geometry; page reads fail loud (card 37eb1925)

Root's blockers on 84634e8 (b7dc1416, 5b01d3fe): a model census
overflowed the 8-dir sample cache, so "held" was never true and every
reconcile rescanned; a completed seed with no dirs was held forever and
never saw a later geometry; and the read_dir preflight did not make the
later reads honest, because pages_in and newest_page_states still
swallowed errors.

- One owner of the launch geometry: launch_window(desired, plan_window,
  lanes) is reconcile's sticky (#175), wedge-heal (#363) and physical-fit
  derivation, extracted without side effects. reconcile probes each step
  that moved the window, as before; the async tick calls the same function.
- Seed the exact dir: before each reconcile, seed_reconcile_pages seeds the
  plan model's dir at the launch window (what the cache sizing reads) and at
  the live window (what the cache-holds-no-state check reads), and the
  adopt rail seeds its own dir. The sample cache (RECENT_STATE_BYTES) is the
  readiness authority: a known dir is never read again, an evicted dir is
  unknown and read again alone, and a new geometry is a new dir. Each dir
  has one shared in-flight read (SEEDING); an entry leaves only when its
  read lands, and each asker waits at most REPORTER_TIMEOUT.
- pages_in and newest_page_states return Result: a missing dir is empty, an
  entry that vanishes mid-scan is skipped, anything else is an error. The
  seed probes it and leaves the dir unknown; trim_page_store trims nothing
  on an unreadable store (probe inference.kv_page.store_unreadable).

Tests: >8 same-model geometries with the desired one first, a repeat ask
that does not read again, a geometry created after an earlier seed, an
evicted dir read again alone, and a file used as a page dir as an error,
not an empty store.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply force-pushed the 37eb1925/launch-time-cache-ram-below-one-saved-st branch from 84634e8 to ce7371d Compare October 15, 2026 14:24
@github-actions github-actions Bot added size: L and removed size: M labels Oct 15, 2026
joelteply and others added 2 commits October 15, 2026 09:52
…nder a dead volume, released unwatched (card 37eb1925)

Root's findings on ce7371d (7a3915a9, d2685005):

- Bound. SEEDING held one shared read per distinct dir, so on a volume that
  stopped answering every new plan geometry started another stuck
  spawn_blocking. Now ONE read is in flight: every page dir is under one
  store on one volume, so a second concurrent read only adds a second stuck
  thread. While it runs, any other dir stays unknown; its sizing uses the
  estimate (probe inference.kv_page.seed_busy) and the next ask reads it.
- Release. The read lived in a Shared future that only an asker's poll
  drove. After a timeout, a live save could make the dir known, the fast
  path returned early, and nobody ever polled it again, so the slot was
  held forever. The read is now its own tokio task: it lands its samples (a
  live sample still outranks them) and clears the slot whether or not anyone
  is waiting. Askers wait on its completion, bounded by REPORTER_TIMEOUT. A
  panicked task's slot is released by the next waiter.
- The doc no longer promises a new geometry is read unconditionally: it is
  read when the slot is free, and stays truthfully unknown until then.

Test one_stuck_read_holds_one_slot_and_releases_it_unwatched drives it with
a gated reader: the asker times out, a second dir starts no worker, a live
save lands, the reader is released, the slot clears with nobody waiting,
the live sample stands, and the dir had exactly one read.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply merged commit 2f5f48d into canary Oct 15, 2026
7 checks passed
@joelteply
joelteply deleted the 37eb1925/launch-time-cache-ram-below-one-saved-st branch October 15, 2026 15:43
joelteply added a commit that referenced this pull request Oct 20, 2026
…state sized it (card 37eb1925)

serving.prompt_cache.derived hard-coded serialized_state_bytes = "unobserved"
and kept reason = resident_demand_kv_estimate even when with_measured_state
had raised a demand to the measured saved state. One reason with two
meanings: on Kimi's node, 8eaed76's first post-boot sizing was measured
(one_conversation 4,816 MiB from a 5,050,734,260-byte page; estimated_kv_bytes
10,101,522,432 = 2 x the page rounded up to 32,768-byte tokens, exactly), yet
the probe read as the very defect #5060 fixed. Proving the fix took a
hand-built arithmetic receipt (helper, 9173c5a9).

- serialized_state_bytes now carries the measured state the sizing read
  (None when nothing was measured).
- sized_by(): a KV-estimate sizing whose demands a measured state raised
  reports reason resident_demand_measured_state. Priors are never relabeled.

The sizing itself is unchanged. The test pins all three cases with the
node's page size.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
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