Skip to content

core: scaffold ds4-compatible disk KV cache - #4

Merged
hanzo-dev merged 1 commit into
mainfrom
zen5/disk-kv-cache
May 29, 2026
Merged

hanzo-dev merged 1 commit into
mainfrom
zen5/disk-kv-cache

Conversation

@hanzo-dev

Copy link
Copy Markdown
Member

Summary

Foundation for punch-list item #1 (SHA1-keyed rendered-prefix disk KV cache).

  • mistralrs-core/src/disk_kv_cache.rs (~270 LOC): KvcHeader (48 bytes, ds4-compatible), DiskKvCache with save / load / evict_to_budget, SHA1 keying via key_for(). Atomic writes via tmp+rename. LRU eviction by last_used_unix.
  • Added sha1 = "0.10" to mistralrs-core/dependencies and tempfile = "3" to dev-dependencies.

Format matches antirez/ds4 KVC so cache files are portable between hanzo-engine and zen5-server.

What this does NOT do (follow-up)

  • Wiring into the existing PrefixCacheManagerV2 (cold / continued / evict / shutdown save hooks + load-before-prefill). That's a separate, larger change that touches the engine main loop.
  • --kv-disk-dir DIR / --kv-disk-space-mb N CLI flags. Will land alongside the wiring.
  • Optional KTM tool-id replay map tail section (punch-list item port ds4 613e9b2: default min-p filtering at 0.05 #3). The header already reserves a bit for it.

Tests

cargo test -p mistralrs-core --no-default-features --lib disk_kv_cache

5 tests cover header round-trip, SHA1 stability, save/load round-trip, missing-key returns None, and LRU eviction.

🤖 Generated with Claude Code

KVC file format (48-byte header) + SHA1-keyed rendered-prefix storage
with save / load / LRU eviction. Foundation only; wiring into the
existing PrefixCacheManagerV2 (cold / continued / evict / shutdown save
hooks + load-before-prefill) lands in a follow-up.

Format matches antirez/ds4 KVC so cache files are portable between
hanzo-engine and zen5-server.

5 unit tests cover header round-trip, SHA1 stability, save/load
round-trip, missing-key None, and LRU eviction.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@hanzo-dev
hanzo-dev merged commit 0cd1d48 into main May 29, 2026
@hanzo-dev
hanzo-dev deleted the zen5/disk-kv-cache branch May 29, 2026 19:52
@github-actions

Copy link
Copy Markdown
Code Metrics Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Language              Files        Lines         Code     Comments       Blanks
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 C Header                  5          305          210           52           43
 CSS                       5         1462         1288           39          135
 CUDA                     60        20622        16570         1656         2396
 Dockerfile                1           38           21            8            9
 JavaScript               19         3972         3089          488          395
 Jinja2                    7          694          656            5           33
 JSON                     27         9400         9397            0            3
 Makefile                  1            6            5            0            1
 MDX                       1          147            0          132           15
 Metal Shading Lan|       34        13466        10542         1117         1807
 PowerShell                1          300          227           30           43
 Python                  131        10161         8357          462         1342
 Shell                     4          948          765          106           77
 Plain Text                3         3723            0         2413         1310
 TOML                     30         1427         1237           46          144
 TypeScript               11         1607         1371           66          170
 YAML                      4           41           39            2            0
─────────────────────────────────────────────────────────────────────────────────
 HTML                      4          782          695           38           49
 |- CSS                    1          578          544           14           20
 |- JavaScript             1           24           23            0            1
 (Total)                             1384         1262           52           70
─────────────────────────────────────────────────────────────────────────────────
 Jupyter Notebooks         3          122           83           23           16
 |- Markdown               1           60           30           22            8
 |- Python                 1          122          113            1            8
 (Total)                              304          226           46           32
─────────────────────────────────────────────────────────────────────────────────
 Markdown                210        19178            0        13456         5722
 |- BASH                 123         1399         1090          190          119
 |- Dockerfile             3            6            6            0            0
 |- JSON                  35         1175         1175            0            0
 |- PowerShell             5            7            7            0            0
 |- Python                45         1717         1459           65          193
 |- Rust                  64         2423         2048           56          319
 |- TOML                  16          318          250            4           64
 |- YAML                   3           18           17            1            0
 (Total)                            26241         6052        13772         6417
─────────────────────────────────────────────────────────────────────────────────
 Rust                    602       259959       229293         6654        24012
 |- Markdown             400         9599          454         7977         1168
 (Total)                           269558       229747        14631        25180
─────────────────────────────────────────────────────────────────────────────────
 Svelte                   18         1831         1696           50           85
 |- CSS                    1            4            4            0            0
 |- JavaScript            18          876          727           24          125
 (Total)                             2711         2427           74          210
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 Total                  1181       368517       293488        35197        39832
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

zeekay pushed a commit that referenced this pull request Jul 26, 2026
core: scaffold ds4-compatible disk KV cache
hanzo-dev added a commit that referenced this pull request Jul 27, 2026
core: scaffold ds4-compatible disk KV cache
zeekay added a commit that referenced this pull request Sep 15, 2026
core: scaffold ds4-compatible disk KV cache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants