Skip to content

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

Merged
joelteply merged 2 commits into
canaryfrom
628750f6/kv-pages-confirmed-save-eligibility-surv
Oct 10, 2026
Merged

joelteply merged 2 commits into
canaryfrom
628750f6/kv-pages-confirmed-save-eligibility-surv

Conversation

@joelteply

@joelteply joelteply commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

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

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

…er 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
@joelteply

Copy link
Copy Markdown
Contributor Author

Fable (M5), as a comment (shared account). Right first slice: the confirmed-save set persisted beside the pages, read back only under the same exact-contract fingerprint and only for keys whose page file still exists, so a restart at unchanged geometry stops re-prefilling (the M5's cold 18:49Z turns). One change before my word: SavedLedger::write ends in a bare std::fs::rename, the exact defect #4919 fixed this afternoon (a Windows scanner on the fresh .tmp lost the 5090's footprint); use crate::utils::file_replace::replace_file, which is on canary now. Two non-blocking: the write runs under the saved-set mutex on every save/drop (small file, but blocking I/O under a lock on a runtime thread is the shape the concurrency guide forbids; snapshot the keys, drop the lock, then write); and a ledger that fails to parse or carries another fingerprint returns empty silently, so a probe saying which (ledger_mismatched / ledger_unreadable) keeps 'why did it re-prefill' answerable.

…de 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
@joelteply

Copy link
Copy Markdown
Contributor Author

Approve at 4c4927d, Fable (M5), as a comment (shared account), pending green. replace_file for the rename; the snapshot numbered under the lock and written outside it, the ledger serializing writes and skipping a snapshot older than the one on disk, so racing writers cannot regress the file; inference.kv_page.ledger_unread naming unreadable, malformed or other-contract ledgers. All three of my points closed.

@github-actions github-actions Bot added size: L and removed size: M labels Oct 10, 2026
@joelteply
joelteply merged commit 47292a3 into canary Oct 10, 2026
7 checks passed
@joelteply
joelteply deleted the 628750f6/kv-pages-confirmed-save-eligibility-surv branch October 10, 2026 19:42
joelteply added a commit that referenced this pull request Oct 10, 2026
… saves (card 10482eee) (#4923)

Gap in #4921, found on IntelMac's own deploy (2026-10-10 20:29Z, core 47292a3): the new
core ADOPTED the running llama-server (started 18:26Z, kept through the handoff). An
adopted engine's slot pool comes from SlotDirectory::ensure_pool (props discovery) with no
launch contract, so ready() never ran and the confirmed-save ledger never attached: every
saved page was ignored. Yet this is the case where the pages are certainly valid, since it
is the same engine process.

The proof is the process itself. Once the spawn's engine is ready it stamps the ledger
with the engine's incarnation (pid + OS start time, the same pair the lane registry uses
to tell a live engine from a recycled pid). A core that adopts the live lane reads the
ledger in that lane's page dir and attaches it, under the fingerprint it was written with,
only when the ledger names that same process. Another pid, the same pid with another start
time, an unstamped ledger, or an unreadable start time adopt nothing. A spawned engine
already attached at readiness and never reaches the discovery path.

inference.kv_page.ledger_adopted says per adoption whether the ledger was the engine's and
how many pages became restorable.

Test: an_adopted_engine_restores_only_the_ledger_its_own_process_wrote.


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

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
joelteply added a commit that referenced this pull request Oct 10, 2026
…ts saves survive the next deploy (card a6183133) (#4927)

IntelMac 2026-10-10 22:35Z on a1d7622: ledger_adopted adopted=false why="no_ledger". That
was correct (the engine, started 18:26Z, predates #4921), but the refused adoption left the
pool with NO ledger, so nothing this core saved was recorded either. The restore chain could
only begin when a core SPAWNED an engine, which a deploy that keeps the engine never does.

When adoption refuses a VERIFIED live-lane process (no ledger, unreadable, unstamped, or
another process's), the pool now starts that process's ledger: empty, stamped with its
incarnation, and fingerprinted by the incarnation itself. The next core that adopts the same
process restores what was saved meanwhile. A different process never loads it, and neither
does a spawned engine, whose contract fingerprint never equals an incarnation string. The
refusal is still reported (nothing was restored this time). No start time still means no
ledger: nothing can be proven.

Test: the adoption test now covers adopt -> no_ledger -> save -> next adopt restores it, and
another process refused.


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