[PR #1331] [CLOSED] On-disk conversations and the system prompt: spill tier, prefill cache, layer-split plumbing - tested against v0.1.41 #3391

Closed
opened 2026-11-07 14:41:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1331
Author: @shahrokhzargarpour
Created: 10/7/2026
Status: ❌ Closed

Base: main ← Head: aporte/disk-mirror-y-sesiones-agnosticas


📝 Commits (10+)

  • 22fd120 serve: keep evicted conversations on disk across restarts
  • 740fa33 serve: restore a session file without holding its K/V in RAM
  • eb960cc layer-split: the disk conversation tier works with a stage split, and the scan never deletes
  • 38ed3d9 disk tier: --conversation-cache-spill-when-full (evict-oldest|reject) and --conversation-cache-spill-max-age-days (0 = off)
  • 34e1c5f system-prompt prefill cache (--system-prompt-cache*): persist the prompt-cache root as a session file
  • efb34de system-prompt prefill cache works with --layer-split (one session file per stage) and with host-RAM K/V
  • 7d00c02 session identity: --kv-resident no longer enters it (a file restores under any residency)
  • 9756640 setup, serve: the installer and Settings expose the on-disk layer (off by default)
  • 30d1f59 docs: the system-prompt cache works under a layer split too
  • fcadcb4 disk tier: --conversation-cache-spill-on park (a mirror at the park), compaction and cancellation

📊 Changes

34 files changed (+5823 additions, -181 deletions)

View changed files

📝 CMakeLists.txt (+13 -1)
📝 README.md (+11 -0)
📝 docs/BATCHING.md (+31 -8)
📝 docs/DETAILS.md (+74 -4)
➕ docs/FLAGS.md (+119 -0)
📝 docs/MULTI_GPU.md (+27 -2)
➕ docs/SPILL_AND_PROMPT_CACHE.md (+290 -0)
📝 include/strata/core/conversation_cache.hpp (+145 -15)
📝 include/strata/core/conversation_file.hpp (+33 -1)
➕ include/strata/core/conversation_prompt_cache.hpp (+138 -0)
📝 include/strata/core/conversation_snapshot.hpp (+36 -0)
➕ include/strata/core/conversation_spill.hpp (+377 -0)
📝 include/strata/core/mtp.hpp (+4 -0)
➕ include/strata/core/stage_plan.hpp (+159 -0)
📝 serve/runconfig.py (+81 -5)
📝 serve/server.py (+180 -7)
📝 serve/test_monitor.py (+36 -0)
📝 serve/test_parallel.py (+29 -2)
📝 serve/test_runconfig.py (+37 -0)
📝 setup.py (+304 -2)

...and 14 more files

📄 Description

Title

On-disk conversations and the system prompt: spill tier, prefill cache, layer-split plumbing - tested against v0.1.41

Issue: Resolves #

Summary

An opt-in on-disk layer for long conversations: a disk tier that parks a conversation's K/V image when the RAM cache fills and restores it on a later request, a system-prompt prefill cache, both working across a layer split, plus --head-device card placement and acceptance reporting for --batch-mtp.

This is the same on-disk layer as the previous version of this PR, rebased and re-verified against upstream v0.1.41 (fb58e0d) - and, since that version, run live against it. Every statement below is about that base.

What changed

  • The whole series is rebased onto v0.1.41 - 17 commits, original authorship preserved, including the #1271/#1269 cherry-picks.
  • The make_room conflict is resolved semantically, not textually: the spill hook now lives in evict_oldest(), which gained a template<class Spill> overload. The zero-argument overload stays, so with the layer's flags off the code is upstream's byte for byte, and the hook sees the real eviction victim (which can be evicted from the middle of the deque) instead of a fixed entries_.front().
  • The put() re-reservation hole is closed: put() re-reserves with the real post-capture image.bytes(), which typically exceeds the estimate make_room() balanced against - so eviction at put() is the normal path of a large insert, not an edge case. put() gained a spill-callback overload and the park path propagates it. (drop_superseded() is deliberately left without a hook, and documented as considered-and-declined.)
  • Docs: docs/FLAGS.md (every flag, its scope, its non-claim, and a section on the upstream mechanisms this layer lives beside without fusing with - pin=N, --peer-device, STRATA_KV_GROW_HOLD), docs/SPILL_AND_PROMPT_CACHE.md (how it works, its limits, what was verified and what was not, now including the live run), a README section, and the host-only tests for the pure classes.
  • One known limitation ships declared rather than fixed - the divergence-discard path can name a sibling conversation's copy under a chat template that puts few-shot turns inside the system prompt. It is stated in docs/SPILL_AND_PROMPT_CACHE.md and in Extra Notes below; the fix is the next stacked PR on this branch.

Extra Notes

Evidence - static, against v0.1.41

CUDA build exit 0 - the strata.exe verified here is sha256 C1D54A4F5A405F076A0D5F1EB0384DECB5A5E422C3A109A7AD6CD7B86A26FB99; its --help lists all 17 flags of the layer; an unknown flag is fatal (unknown argument, exit 2); the host-only test battery passes 12/12 (ctest exit 0); the layer's anchor/flag verifier (39 anchors, 17 flags) exits 0.

Evidence - live, against v0.1.41

That same binary served 127.0.0.1:5012 on the verification machine on a clone of the production serve config (production stays on 5011 and was not touched) and reported /props build_info='Strata 0.1.41', n_ctx=196608, model qwen3.8-flash-next-unsloth-ud-iq4_xs, ready in 156.6 s in both runs. A four-test battery (smoke, streamed throughput, repeated system prompt, two conversations that spill) ran twice, with a server restart between runs and the tier's folders left in place. The second run passed all four tests (OVERALL: PASS); the first reported OVERALL: FAIL for one reason only - its harness (v1.0.0) could not compute a throughput figure at max_tokens=256.

  • Cold prefill against a restore after a restart. Two ~8k-token conversations (prompt_tokens=8016) took 29.76 s and 30.10 s in the first run (a fresh process, nothing on disk for them) and 1.98 s each in the second (a new process, both already on disk), with the engine counting restores=4 in that second run against restores=0 in the first. The 33,409-character system-prompt test has the same shape: 30.296 s for its first call in the first run (nothing reused) against 2.298 s for the same call in the second.
  • The tier's counters, read from the running engine: disk: enabled=True spills=2 bytes=2153775104 restores=4 over a folder of 19 files / 2,154,484,304 bytes, and sysprompt: enabled=True variants=3 hits=1 misses=0 bytes=719323136.
  • What the build serves (a property of the build, not of the layer): with no output cap and a natural stop, three reps produced 472 / 480 / 458 tokens (finish=stop) at a median TTFT of 0.452 s, at 28.11 tok/s decoding (27.39 tok/s end to end).

What the live numbers are not. Both runs used the same binary with the layer on, so what is measured is cold prefill against a restore from disk after a process restart - nothing more. It is not a comparison against upstream, not a speedup ratio for the layer, and not a throughput claim about it. restores=4 and hits=1 are one run each: a working signal, not a rate. The conversations=0 on that same counter line is what the engine reports and is not interpreted here. The system-prompt test of the second run (TTFT 1.096 s then 1.52 s, with reused=7920/7925 already warm) is one sample of a warm prefix, not a regression - and the -92.6 % of the first run is a cold-prefill KV-reuse figure (that run read sysprompt hits=0), so it is not a property of the system-prompt cache either.

What this PR does not claim

The previous version of this PR said "not tested live against v0.1.41". That non-claim is withdrawn - the runs above happened. What is still not claimed:

  • No layer-versus-no-layer run. Both live runs had the layer on, so nothing here is a measured speedup over upstream, and no performance number anywhere in the diff is one.
  • Two runs of one harness on one machine. One restores=4, one hits=1, one median TTFT, one conversation length. Both runs read tokens_saved=0, so there is no hit rate and no tokens-saved total.
  • Not every flag was reached. The battery did not exercise --head-device card order, a layer split, --batch-mtp, a cancelled request, the GC's age and budget levers, or the compaction path (when a rewrite happens is the harness's decision, and this delivery carries no archive tier). That the layer is inert with the flags off under load is likewise still unshown.
  • The host-only tests cover the pure classes (cache, spill, file, prompt cache, stage plan); the live battery covers the --serve loop for those four scenarios and nothing beyond them.

Known limitation: the divergence discard can name a sibling's copy

discard_diverged_impl (src/core/conversation_spill.cpp) decides which stored copy a rewritten tail belongs to from the end of the stored conversation's header - conversation_header_length, the start of its first assistant turn - and keeps a copy whose shared prefix reaches past that marker (header == 0 || common < header skips it). Few-shot turns inside the system prompt move that marker into the root the conversations share, so a sibling conversation (same system prompt, a different first exchange) also satisfies the guard, and its copy is the one removed - discarded from disk, not archived, in this version.

The fix is a property guard: only the copy sharing the longest prefix with the prompt is a rewrite candidate, a tie between copies that disagree discards nothing, and a trace line names the conversation_key of the copy removed. It is written and tested on a sibling branch and arrives as the next stacked PR against this branch; this delta ships without it. Being straight about the scope of the evidence: the reproducing test was written against the sibling base v0.1.40.1, not against v0.1.41, and has not been re-run here. The live battery above does not reach that path.

Collaboration

This overlaps in territory with #1529 (a disk tier for parked conversations) - it looks like the two efforts are complementary rather than competing, and I'm glad to align on naming or split the series so both can land; the put() re-reservation fix here is made against v0.1.41 and may be useful to that effort too. It also sits beside the supersession fix in konijiwa110/Strata#1; this series does not depend on its outcome. I haven't verified either PR's contents beyond their threads, so I won't claim more than "same area, happy to coordinate" - whatever split the maintainers prefer works for me.

Credits

This layer is authored and directed by Shahrokh Zargarpour. It was written and verified with the Grok TUI Build coding agent - first on DeepSeek Flash, currently on Qwen3.8 flash-next UD iq4_xs, the local inference runtime the layer was developed and verified against.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/1331 **Author:** [@shahrokhzargarpour](https://github.com/shahrokhzargarpour) **Created:** 10/7/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `aporte/disk-mirror-y-sesiones-agnosticas` --- ### 📝 Commits (10+) - [`22fd120`](https://github.com/Niko1221/Strata/commit/22fd120e4a4c81c647642a62804c1a37926d07ce) serve: keep evicted conversations on disk across restarts - [`740fa33`](https://github.com/Niko1221/Strata/commit/740fa3392dea42c08c8baec1ea8f1bb2ab08820c) serve: restore a session file without holding its K/V in RAM - [`eb960cc`](https://github.com/Niko1221/Strata/commit/eb960cca6a6d566c2171467bd4a96309bf7adc72) layer-split: the disk conversation tier works with a stage split, and the scan never deletes - [`38ed3d9`](https://github.com/Niko1221/Strata/commit/38ed3d997446f7eebb2f64de5b6939f5f428ae03) disk tier: --conversation-cache-spill-when-full (evict-oldest|reject) and --conversation-cache-spill-max-age-days (0 = off) - [`34e1c5f`](https://github.com/Niko1221/Strata/commit/34e1c5f6018a3ddcd5db34640f93801eb3ed3531) system-prompt prefill cache (--system-prompt-cache*): persist the prompt-cache root as a session file - [`efb34de`](https://github.com/Niko1221/Strata/commit/efb34de5e4a092a46519f990961cba45ebb5d85f) system-prompt prefill cache works with --layer-split (one session file per stage) and with host-RAM K/V - [`7d00c02`](https://github.com/Niko1221/Strata/commit/7d00c0270cea334cfa754a9690e44cf80b00d953) session identity: --kv-resident no longer enters it (a file restores under any residency) - [`9756640`](https://github.com/Niko1221/Strata/commit/9756640378f1324a4ac09cb48a30e0da111f4f99) setup, serve: the installer and Settings expose the on-disk layer (off by default) - [`30d1f59`](https://github.com/Niko1221/Strata/commit/30d1f597fff404b1f47a69958b1c877c38ea0859) docs: the system-prompt cache works under a layer split too - [`fcadcb4`](https://github.com/Niko1221/Strata/commit/fcadcb47896c188e4337f8d711ea72a77851d49c) disk tier: --conversation-cache-spill-on park (a mirror at the park), compaction and cancellation ### 📊 Changes **34 files changed** (+5823 additions, -181 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+13 -1) 📝 `README.md` (+11 -0) 📝 `docs/BATCHING.md` (+31 -8) 📝 `docs/DETAILS.md` (+74 -4) ➕ `docs/FLAGS.md` (+119 -0) 📝 `docs/MULTI_GPU.md` (+27 -2) ➕ `docs/SPILL_AND_PROMPT_CACHE.md` (+290 -0) 📝 `include/strata/core/conversation_cache.hpp` (+145 -15) 📝 `include/strata/core/conversation_file.hpp` (+33 -1) ➕ `include/strata/core/conversation_prompt_cache.hpp` (+138 -0) 📝 `include/strata/core/conversation_snapshot.hpp` (+36 -0) ➕ `include/strata/core/conversation_spill.hpp` (+377 -0) 📝 `include/strata/core/mtp.hpp` (+4 -0) ➕ `include/strata/core/stage_plan.hpp` (+159 -0) 📝 `serve/runconfig.py` (+81 -5) 📝 `serve/server.py` (+180 -7) 📝 `serve/test_monitor.py` (+36 -0) 📝 `serve/test_parallel.py` (+29 -2) 📝 `serve/test_runconfig.py` (+37 -0) 📝 `setup.py` (+304 -2) _...and 14 more files_ </details> ### 📄 Description ## Title On-disk conversations and the system prompt: spill tier, prefill cache, layer-split plumbing - tested against `v0.1.41` Issue: Resolves # ## Summary An opt-in **on-disk layer** for long conversations: a disk tier that parks a conversation's K/V image when the RAM cache fills and restores it on a later request, a **system-prompt prefill cache**, both working across a **layer split**, plus `--head-device` card placement and acceptance reporting for `--batch-mtp`. This is the same on-disk layer as the previous version of this PR, **rebased and re-verified against upstream `v0.1.41` (`fb58e0d`)** - and, since that version, **run live against it**. Every statement below is about that base. ## What changed - **The whole series is rebased onto `v0.1.41`** - 17 commits, original authorship preserved, including the #1271/#1269 cherry-picks. - **The `make_room` conflict is resolved semantically, not textually**: the spill hook now lives in `evict_oldest()`, which gained a `template<class Spill>` overload. The zero-argument overload stays, so **with the layer's flags off the code is upstream's byte for byte**, and the hook sees the real eviction victim (which can be evicted from the middle of the deque) instead of a fixed `entries_.front()`. - **The `put()` re-reservation hole is closed**: `put()` re-reserves with the real post-capture `image.bytes()`, which typically exceeds the estimate `make_room()` balanced against - so eviction at `put()` is the **normal** path of a large insert, not an edge case. `put()` gained a spill-callback overload and the park path propagates it. (`drop_superseded()` is deliberately left without a hook, and documented as considered-and-declined.) - **Docs**: `docs/FLAGS.md` (every flag, its scope, its non-claim, and a section on the upstream mechanisms this layer lives beside without fusing with - `pin=N`, `--peer-device`, `STRATA_KV_GROW_HOLD`), `docs/SPILL_AND_PROMPT_CACHE.md` (how it works, its limits, what was verified and what was not, now including the live run), a README section, and the host-only tests for the pure classes. - **One known limitation ships declared rather than fixed** - the divergence-discard path can name a sibling conversation's copy under a chat template that puts few-shot turns inside the system prompt. It is stated in `docs/SPILL_AND_PROMPT_CACHE.md` and in Extra Notes below; the fix is the next stacked PR on this branch. ## Extra Notes ### Evidence - static, against `v0.1.41` CUDA build exit 0 - the `strata.exe` verified here is sha256 `C1D54A4F5A405F076A0D5F1EB0384DECB5A5E422C3A109A7AD6CD7B86A26FB99`; its `--help` lists all 17 flags of the layer; an unknown flag is fatal (`unknown argument`, exit 2); the host-only test battery passes **12/12** (`ctest` exit 0); the layer's anchor/flag verifier (39 anchors, 17 flags) exits 0. ### Evidence - live, against `v0.1.41` That same binary served `127.0.0.1:5012` on the verification machine on a clone of the production serve config (production stays on 5011 and was not touched) and reported `/props` `build_info='Strata 0.1.41'`, `n_ctx=196608`, model `qwen3.8-flash-next-unsloth-ud-iq4_xs`, ready in **156.6 s** in both runs. A four-test battery (smoke, streamed throughput, repeated system prompt, two conversations that spill) ran **twice**, with a server restart between runs and the tier's folders left in place. The second run passed all four tests (`OVERALL: PASS`); the first reported `OVERALL: FAIL` for one reason only - its harness (v1.0.0) could not compute a throughput figure at `max_tokens=256`. - **Cold prefill against a restore after a restart.** Two ~8k-token conversations (`prompt_tokens=8016`) took **29.76 s** and **30.10 s** in the first run (a fresh process, nothing on disk for them) and **1.98 s** each in the second (a new process, both already on disk), with the engine counting `restores=4` in that second run against `restores=0` in the first. The 33,409-character system-prompt test has the same shape: **30.296 s** for its first call in the first run (nothing reused) against **2.298 s** for the same call in the second. - **The tier's counters, read from the running engine:** `disk: enabled=True spills=2 bytes=2153775104 restores=4` over a folder of 19 files / 2,154,484,304 bytes, and `sysprompt: enabled=True variants=3 hits=1 misses=0 bytes=719323136`. - **What the build serves** (a property of the build, not of the layer): with no output cap and a natural stop, three reps produced 472 / 480 / 458 tokens (`finish=stop`) at a median TTFT of **0.452 s**, at **28.11 tok/s** decoding (27.39 tok/s end to end). **What the live numbers are not.** Both runs used the same binary with the layer **on**, so what is measured is **cold prefill against a restore from disk after a process restart** - nothing more. It is not a comparison against upstream, not a speedup ratio for the layer, and not a throughput claim about it. `restores=4` and `hits=1` are **one run each**: a working signal, not a rate. The `conversations=0` on that same counter line is what the engine reports and is not interpreted here. The system-prompt test of the second run (TTFT 1.096 s then 1.52 s, with `reused=7920/7925` already warm) is one sample of a warm prefix, not a regression - and the **-92.6 %** of the first run is a cold-prefill KV-reuse figure (that run read `sysprompt hits=0`), so it is not a property of the system-prompt cache either. ### What this PR does not claim The previous version of this PR said "not tested live against `v0.1.41`". That non-claim is **withdrawn** - the runs above happened. What is still not claimed: - **No layer-versus-no-layer run.** Both live runs had the layer on, so nothing here is a measured speedup over upstream, and no performance number anywhere in the diff is one. - **Two runs of one harness on one machine.** One `restores=4`, one `hits=1`, one median TTFT, one conversation length. Both runs read `tokens_saved=0`, so there is no hit rate and no tokens-saved total. - **Not every flag was reached.** The battery did not exercise `--head-device` card order, a layer split, `--batch-mtp`, a cancelled request, the GC's age and budget levers, or the compaction path (when a rewrite happens is the harness's decision, and this delivery carries no archive tier). That the layer is inert with the flags off under load is likewise still unshown. - The host-only tests cover the pure classes (cache, spill, file, prompt cache, stage plan); the live battery covers the `--serve` loop for those four scenarios and nothing beyond them. ### Known limitation: the divergence discard can name a sibling's copy `discard_diverged_impl` (`src/core/conversation_spill.cpp`) decides which stored copy a rewritten tail belongs to from the end of the stored conversation's header - `conversation_header_length`, the start of its first assistant turn - and keeps a copy whose shared prefix reaches past that marker (`header == 0 || common < header` skips it). **Few-shot turns inside the system prompt** move that marker into the root the conversations share, so a **sibling** conversation (same system prompt, a different first exchange) also satisfies the guard, and its copy is the one removed - **discarded from disk, not archived**, in this version. The fix is a property guard: only the copy sharing the **longest prefix** with the prompt is a rewrite candidate, a tie between copies that disagree discards nothing, and a trace line names the `conversation_key` of the copy removed. It is written and tested on a sibling branch and arrives as the **next stacked PR against this branch**; this delta ships without it. Being straight about the scope of the evidence: the reproducing test was written against the sibling base `v0.1.40.1`, **not** against `v0.1.41`, and has not been re-run here. The live battery above does not reach that path. ### Collaboration This overlaps in territory with **#1529** (a disk tier for parked conversations) - it looks like the two efforts are complementary rather than competing, and I'm glad to align on naming or split the series so both can land; the `put()` re-reservation fix here is made against `v0.1.41` and may be useful to that effort too. It also sits beside the supersession fix in **konijiwa110/Strata#1**; this series does not depend on its outcome. I haven't verified either PR's contents beyond their threads, so I won't claim more than "same area, happy to coordinate" - whatever split the maintainers prefer works for me. ### Credits This layer is authored and directed by **Shahrokh Zargarpour**. It was written and verified with the **Grok TUI Build** coding agent - first on **DeepSeek Flash**, currently on **Qwen3.8 flash-next UD iq4_xs**, the local inference runtime the layer was developed and verified against. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 14:41:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#3391
No description provided.