Skip to content

Reset physical KV residency across verified engine restarts - #4367

Merged
joelteply merged 1 commit into
canaryfrom
fix/kv-engine-generation
Sep 23, 2026
Merged

joelteply merged 1 commit into
canaryfrom
fix/kv-engine-generation

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

A same-endpoint llama-server restart could leave the old physical KV-holder ledger in place, letting subsequent requests assume context was still resident. Requests and warm-ahead could also overlap engine transitions.

Keep endpoint admission across both inference paths, carry a generation identity with the owned child, and require observed predecessor exit before replacement. Publish a fresh physical ledger only after verified readiness. Preserve saved-page eligibility only for matching model, adapter, engine and slot geometry; failed transitions remain closed and late old exits cannot clear a new generation.

Validation: native restart/compatible-page fixture, pinned-slot contention fixture, and actual child-retirement fixture passed. Independent source review approved lifecycle ownership, lock ordering and failure closure. Full CI and source-hygiene gates remain required before merge. No runtime deployment or measured speedup is claimed; academy save/loan/restore remains separate.

@joelteply
joelteply marked this pull request as ready for review September 23, 2026 21:21
@joelteply
joelteply merged commit c413db9 into canary Sep 23, 2026
8 checks passed
@joelteply
joelteply deleted the fix/kv-engine-generation branch September 23, 2026 21:22
joelteply added a commit that referenced this pull request Oct 10, 2026
…er the same exact contract (card 628750f6) (#4921)

* fix(kv): a confirmed save stays restorable across a core restart, under the same exact contract (card 628750f6)

Saved KV pages were offered for restore only from KvSlotPool.saved, an in-memory set
that starts empty in every core process. So every deploy re-prefilled every mind while
its pages sat on disk: on the M5 at 18:49Z the first turns after the restart reused
nothing (turn_cached 0 of 31,811 and 27,250), at ~90 tok/s about 5 minutes each.

The set already is a confirmed-save ledger: note_page_lost runs before a save overwrites
a page and note_saved only after the engine confirms it. This persists that set beside
the pages (saved-ledger.json, tmp+rename, written under the lock that changed it, so the
file's writes follow the set's changes), and reads it back at engine ready ONLY when the
stored fingerprint equals the live KvPageContract's. The exact-contract rule of #4367 is
unchanged: the fingerprint covers every field, context and slots included, and is None
exactly where in-process carry-over is refused. In-process carry-over stays the fresher
record; the disk is read only when nothing was carried. A key loads only if its page file
is still there.

Measured on the pinned engine before choosing the contract (IntelMac, throwaway
llama-server, 1.5B): a page restores across a CONTEXT change at the same --parallel
(cache_n 3489 of 3489, same logprob delta as the same-geometry control) but is refused
across a --parallel change. Splitting context out of the contract is a separate PR.

Test: confirmed_saves_survive_a_restart_only_under_the_same_contract (a restarted pool
restores a confirmed save; a missing page file, a save lost before confirmation, and one
more slot restore nothing; unknown revisions never persist).

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

* fix(kv): the ledger replaces its file with replace_file, writes outside the set's lock, and says when it restores nothing (Fable on #4921)

- replace_file (#4919) for the rename: a bare rename on Windows loses the write to a
  sharing violation, as the 5090 lost a footprint at 15:28Z.
- The write happens outside KvSlotPool.saved's lock, since replace_file may retry for ~1.6 s
  and a turn's paging must not wait on it. Each change is numbered under the lock, and
  the ledger serializes writes and drops a snapshot older than the one on disk, so the
  file is still the newest set when writers race.
- inference.kv_page.ledger_unread when a ledger exists but is unreadable, malformed, or
  written under another contract (absent stays silent: nothing was ever saved there).

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