server: persist the --cache-ram prompt cache to a dir with per-entry idle sync #1
Reference in New Issue
Block a user
Delete Branch "prompt-cache-persistence"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Reworks prompt-cache persistence from a single shutdown-written file into a directory of per-entry files with live idle-sync, replacing
--prompt-cache-filewith:--prompt-cache-dir PATH— one file per prompt-cache entry, named<content-hash>.bin(created if missing)--prompt-cache-sync-idle SEC— how long an entry must be unchanged before a sweep writes it (default 300)Design
PCD2, version, file size, model fingerprint (n_ctx/n_embd/n_layer/n_head/n_vocab/model path/build commit), then the KV blobs. The dir listing is the index — no manifest.--prompt-cache-sync-idle. Idle is per entry (time since finalized/mutated; LCP reads don't count). Shutdown/sleep-entry flushes become near-no-ops.-c) cannot wipe a good mirror..tmp+fsync+ rename), sokill -9can never yield a half-written entry.shared_ptr); the sync thread only copies finalized bytes and never touchesllama_context. Steal path erases instead of clearing in place.llama_state_seq_*against destroyed contexts (use-after-free, crash on SIGTERM-while-sleeping).Verification
Full battery on qwen2.5-0.5b (live sweep, restore + cache-hit warm eval 73 ms/tok vs 5.3 s cold, steal-prune, eviction-prune, byte-corruption reject, truncation reject, fingerprint reject, wipe-guard, flock, kill -9, sleep flush, sleep+SIGTERM): 6/6 scenarios green on the final build, incl.
(shutdown)flush writing the live conversation and clean.lockremoval while sleeping.Known (pre-existing, upstream)
SIGTERM landing during the sleep transition can self-deadlock: queue sleeping-state callbacks run while
mutex_tasksis held, and the signal handler'sterminate()takes the same mutex. Not introduced here — this commit only widens the window by ~25 ms of flush work.server: persist --cache-ram prompt cache to disk across restartsto server: persist the --cache-ram prompt cache to a dir with per-entry idle syncView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.