Skip to content

fix(serving): the adopt rail honours the daemon's cache re-home: --cache-ram is launch geometry (card d7294f0b) - #5056

Merged
joelteply merged 2 commits into
canaryfrom
d7294f0b/after-adoption-re-home-fires-on-cache-ho
Oct 15, 2026
Merged

joelteply merged 2 commits into
canaryfrom
d7294f0b/after-adoption-re-home-fires-on-cache-ho

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Kimi's node, 2026-10-15 07:37 and 07:39Z: the daemon found her adopted lane's 3,248 MiB
--cache-ram grant held no measured saved state (so every switch between minds re-prefilled)
and decided "re-homing" twice, charging a cooldown each time. The actuation,
ensure_model_serving_if_current, relaunches only for genes, window or lanes grow, sight or the
KV type; cache size was never one, so it answered AlreadyServing and nothing changed.

  • LaunchKv now carries the running lane's --cache-ram (cache_ram_mib_in, previously used only
    by its test), read off the engine's own argv like the KV type, so adopted lanes have it.
  • ensure gains cache_ok from the SAME rule the daemon uses: relaunch only when the running
    grant holds no measured state and the target's grant would. Unknown grant, nothing measured,
    or a target that would hold no state either is never a relaunch.
  • A cache grow is a grow: the closed memory gate refuses it like a wider window or more lanes.
  • launched_cache_holds_no_state / cache_relaunch_needed move from serving_daemon to lane_args
    (the --cache-ram owner) with their test; the daemon and the rail both call them there.

Co-Authored-By: Claude Opus 5.5 (1M context) [email protected]
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…che-ram is launch geometry (card d7294f0b)

Kimi's node, 2026-10-15 07:37 and 07:39Z: the daemon found her adopted lane's 3,248 MiB
--cache-ram grant held no measured saved state (so every switch between minds re-prefilled)
and decided "re-homing" twice, charging a cooldown each time. The actuation,
ensure_model_serving_if_current, relaunches only for genes, window or lanes grow, sight or the
KV type; cache size was never one, so it answered AlreadyServing and nothing changed.

- LaunchKv now carries the running lane's --cache-ram (cache_ram_mib_in, previously used only
  by its test), read off the engine's own argv like the KV type, so adopted lanes have it.
- ensure gains cache_ok from the SAME rule the daemon uses: relaunch only when the running
  grant holds no measured state and the target's grant would. Unknown grant, nothing measured,
  or a target that would hold no state either is never a relaunch.
- A cache grow is a grow: the closed memory gate refuses it like a wider window or more lanes.
- launched_cache_holds_no_state / cache_relaunch_needed move from serving_daemon to lane_args
  (the --cache-ram owner) with their test; the daemon and the rail both call them there.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…ds no measured state (card d7294f0b)

Codex geometry helper's review of #5056: the parser, predicate and gate tests each pass but do
not prove the wiring that failed. This drives ensure_model_serving through FakeControl: a 3,800 MiB
measured state recorded for the lane's page dir, a running --cache-ram of 3,248 MiB and a target of
4,096 MiB relaunches (Spawned, one serve); an unknown grant (no argv) and a target whose grant
would hold no state either (3,500 MiB) still adopt (AlreadyServing, no serve).
note_state_bytes becomes pub(crate) so the test records the state the way a save does.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
@joelteply
joelteply merged commit 66cfeb7 into canary Oct 15, 2026
7 checks passed
@joelteply
joelteply deleted the d7294f0b/after-adoption-re-home-fires-on-cache-ho branch October 15, 2026 09:19
joelteply added a commit that referenced this pull request Oct 15, 2026
… 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
joelteply added a commit that referenced this pull request Oct 15, 2026
… 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
joelteply added a commit that referenced this pull request Oct 15, 2026
… on disk (card 37eb1925) (#5060)

* fix(serving): a fresh core's first cache sizing reads the saved pages 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

* fix(serving): seed state samples off the worker: one boot read before 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

* fix(serving): seed the planned model's page dirs before every reconcile, 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

* fix(serving): restore the slots.rs definitions f07da10 deleted; seed 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

* fix(serving): seed the EXACT page dir each sizing reads; launch_window 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

* fix(serving): one page read in flight, run as its own task: bounded under 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

* docs(slots): an outer-task panic's slot release is waiter-dependent; say so, not that one panic cannot hold reads out (root on #5060)

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

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[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