Enforce the byte cap: unlink oldest-mtime entries until under it.
Best USABLE stored entry for prompt in ns: the longest common
prefix (capped at prompt.length−1 — at least one token must forward).
An entry LONGER than the matched prefix is returned only when it can
actually seed the prompt: the divergent tail must be trimmable after
restore. Untrimmable entries (ring post-wrap, SSM) that would need a
trim are SKIPPED here — before this gate, the big [prompt+gen] file
always outranked the usable boundary snapshot, got restored, and was
thrown away by take()'s backstop (the 2026-07-06 restart-0 + wasted
84 s restore-then-re-prefill path). Pure index lookup; no I/O.
Exact checkpoint selection for a known session, independent of residency.
Longest durable in-flight generation for an identical request. The checkpoint namespace is separate from the ordinary prompt-cache tier, so incomplete assistant output can never seed an unrelated prefill.
True when the SSD index can seed every token in this prefix. A longer trimmable descendant is equivalent to an exact boundary snapshot.
Restore an entry via packages/inference/src/state/persistence.ts's STREAMED COPY (bounded host transient — live entry + one tensor; no mapping survives the call, the caches own their bytes). Bumps LRU mtime. On ANY failure the file is dropped and null returned.
Read on the dedicated CPU queue, then let the model codec adopt state.
Startup recovery: rebuild the in-memory index from disk. Corrupt
headers are unlinked; .tmp orphans reaped; a file whose header names
another model/tokenizer/fingerprint is left in place and not indexed.
Only OUR fingerprint dir is touched. Returns entries indexed.
Persist an entry. Synchronous (the tier calls it on the idle serial lane between requests); atomic via packages/inference/src/state/persistence.ts's tmp+fsync+rename. An entry bigger than the cap is refused; disk/write failure is a warn-once soft-fail — serving never stalls on the cold tier. Existing entries in the same ns whose tokens are a PREFIX of the new entry are superseded (the agent-conversation pattern: one growing entry, not N generations of it). Returns true if stored.
Optionalattachments: CheckpointAttachment[]Non-blocking store (the write-behind persistence path): same file,
index, and supersede semantics as store(), but the tensor flush
yields the event loop between tensors so serving interleaves.
Caller passes zero-copy CLONES it owns (a consistent snapshot no
matter what the live entry does meanwhile) and disposes them after.
runStep optionally wraps owner-thread snapshot preparation. Hashing,
packing and disk writes execute on the CPU worker.
OptionalrunStep: <T>(step: () => T) => Promise<T>Optionalattachments: CheckpointAttachment[]Persist one in-flight generation atomically. A completed newer checkpoint supersedes older checkpoints for the same request only after its rename succeeds, so a crash during a write leaves the prior point.
Actual sampler seed, including a server-generated default. Required to continue the random stream exactly after a restart.
True when seed was part of the client request rather than generated
by the server.
OptionalrunStep: <T>(step: () => T) => Promise<T>Header-only provenance for the serving tokenizer; no tensor restore.
Longest token prefix whose atomic cache file is present in the index.