[PR #4224] [Engine] Add opt-in parked cache deduplication #4958

Open
opened 2026-11-07 16:31:37 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4224
Author: @4f1sh3r
Created: 10/26/2026
Status: 🔄 Open

Base: main ← Head: parked-cache-dedup


📝 Commits (1)

  • 57d6238 [Engine] Add opt-in parked cache deduplication

📊 Changes

16 files changed (+852 additions, -45 deletions)

View changed files

📝 CMakeLists.txt (+5 -0)
➕ docs/PARKED_CACHE_DEDUP.md (+114 -0)
📝 include/strata/core/conversation_buffer.hpp (+33 -5)
📝 include/strata/core/conversation_cache.hpp (+160 -18)
📝 include/strata/core/conversation_snapshot.hpp (+6 -2)
➕ include/strata/core/conversation_storage.hpp (+247 -0)
📝 include/strata/core/session_save_reclaim.hpp (+2 -0)
📝 serve/server.py (+4 -0)
📝 src/core/conversation_copy.hpp (+12 -0)
📝 src/core/conversation_file.cpp (+3 -2)
📝 src/core/conversation_snapshot.cpp (+16 -7)
📝 src/core/conversation_snapshot_test.cpp (+17 -6)
📝 src/core/conversation_state.cpp (+8 -2)
📝 src/core/conversation_validation_test.cpp (+4 -1)
📝 src/program/generate.cpp (+37 -2)
➕ tests/core/conversation_storage_test.cpp (+184 -0)

📄 Description

Problem and result

With the conversation cache enabled, every parked conversation keeps its own full copy of the conversation bytes, so shared prefixes and repeated turns are charged against the cache budget several times.

On a RAM-constrained host the cache then evicts or refuses parked histories while identical bytes already sit in RAM. Measured on a 192 GiB host with a 40 GiB cache budget, the unpatched engine retained 41 conversations at 92.7 GiB RSS where dedup keeps 64 at 73.2 GiB.

With STRATA_PARKED_DEDUP=1, identical parked payloads are stored once and shared. In three days of production (single RTX 3090, 64 slots, 40 GiB budget) the engine reports 33.7 GB logical against 25.3 GB physical parked bytes (~8.5 GB saved, ~25%), 7000+ dedup hits and zero budget evictions. Unset, behaviour is unchanged.

none

Approach

A content-addressed immutable parked storage layer (include/strata/core/conversation_storage.hpp): snapshots reference shared payloads, copy-on-write on divergence, and budget/RAM admission plus eviction planning now account physical (shared) bytes plus a metadata bound instead of logical bytes.

Opt-in via one environment variable; mode 0 keeps the pre-patch code paths, fingerprint-compared against the unpatched engine. A refused put() keeps superseded copies until the image fits, and the RAM gate trims the heap before evicting, because freed 1 MiB blocks can otherwise stay in the heap and not show up in MemAvailable. Diagnostics: a conversation_cache.dedup block in /metrics and one stats line per park. Design notes in docs PARKED_CACHE_DEDUP.md. No defaults changed, no unrelated cleanup.

Validation

Passed:

  • New tests/core/conversation_storage_test.cpp, wired into CMake and run with:

    cmake -S . -B build -DSTRATA_BUILD_CONVERSATION_TESTS=ON
    cmake --build build --target conversation_storage_test conversation_cache_test
    ctest --test-dir build -R "conversation_storage|conversation_cache"
    

    at 7ddc17a3 (v0.2.3.1) and at this revision on 4b9e05a2 (v0.2.6): 519
    checks with dedup disabled, 608 enabled, 608 with forced hash collisions.

  • Existing engine unit suites on the CUDA build host, in both dedup modes:
    snapshot 4041, validation 972, transfer and failure injection 1548,
    serialization 201, memory 31, split allocation failures 8/12/16, cache policy
    4772 (disabled), memory guard 156. Storage fixture also green under
    ASan+UBSan.

  • Controlled full-model probes (31 requests each, one output token,
    STRATA_PREFILL_CPU_SHARE=0): unpatched, patched-off and patched-on produced
    identical outputs and identical GDN/PLE/tail/index/KV state fingerprints.

  • Budget-bound synthetic A/B (89 requests, 10240 MiB budget, 64 slots, 64
    conversations sharing a 24576-token prefix): no regression in retained
    histories, evictions or decode speed against the off arm.

  • Applied unchanged and re-validated on 4b9e05a2 (engine 0.1.51): unit suites
    green, running in production since 2026-10-25, including a service restart on
    2026-10-26.

    Environment: Linux x86-64 (Threadripper 5965WX, 192 GiB RAM), single RTX 3090,
    CUDA 13.2, Release build.

Failed:

none observed

Not run:

  • HIP/SYCL/Metal builds (no hardware available); CUDA only on the single RTX
    3090 host.
  • Multi-GPU, staged or batched serving: startup refuses this combination, and
    only the refusal itself was exercised.
  • No maximum-context rerun and no long soak; the RAM-gate trim-before-evict path
    is covered by review and allocator reasoning, not by a live OOM test.

Limits

  • Opt-in only; requires single-GPU serial serving. Startup exits with a clear
    message when combined with stages or batch.
  • Failed parking is still not transactional at serving level — pre-existing
    upstream behaviour, unchanged here.
  • Session-save reclaim accounting is unchanged.

🔄 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/4224 **Author:** [@4f1sh3r](https://github.com/4f1sh3r) **Created:** 10/26/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `parked-cache-dedup` --- ### 📝 Commits (1) - [`57d6238`](https://github.com/Niko1221/Strata/commit/57d6238365f2b5760d822862f8e83c0a43c8f9be) [Engine] Add opt-in parked cache deduplication ### 📊 Changes **16 files changed** (+852 additions, -45 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+5 -0) ➕ `docs/PARKED_CACHE_DEDUP.md` (+114 -0) 📝 `include/strata/core/conversation_buffer.hpp` (+33 -5) 📝 `include/strata/core/conversation_cache.hpp` (+160 -18) 📝 `include/strata/core/conversation_snapshot.hpp` (+6 -2) ➕ `include/strata/core/conversation_storage.hpp` (+247 -0) 📝 `include/strata/core/session_save_reclaim.hpp` (+2 -0) 📝 `serve/server.py` (+4 -0) 📝 `src/core/conversation_copy.hpp` (+12 -0) 📝 `src/core/conversation_file.cpp` (+3 -2) 📝 `src/core/conversation_snapshot.cpp` (+16 -7) 📝 `src/core/conversation_snapshot_test.cpp` (+17 -6) 📝 `src/core/conversation_state.cpp` (+8 -2) 📝 `src/core/conversation_validation_test.cpp` (+4 -1) 📝 `src/program/generate.cpp` (+37 -2) ➕ `tests/core/conversation_storage_test.cpp` (+184 -0) </details> ### 📄 Description ## Problem and result With the conversation cache enabled, every parked conversation keeps its own full copy of the conversation bytes, so shared prefixes and repeated turns are charged against the cache budget several times. On a RAM-constrained host the cache then evicts or refuses parked histories while identical bytes already sit in RAM. Measured on a 192 GiB host with a 40 GiB cache budget, the unpatched engine retained 41 conversations at 92.7 GiB RSS where dedup keeps 64 at 73.2 GiB. With `STRATA_PARKED_DEDUP=1`, identical parked payloads are stored once and shared. In three days of production (single RTX 3090, 64 slots, 40 GiB budget) the engine reports 33.7 GB logical against 25.3 GB physical parked bytes (~8.5 GB saved, ~25%), 7000+ dedup hits and zero budget evictions. Unset, behaviour is unchanged. ## Related discussion none ## Approach A content-addressed immutable parked storage layer (`include/strata/core/conversation_storage.hpp`): snapshots reference shared payloads, copy-on-write on divergence, and budget/RAM admission plus eviction planning now account physical (shared) bytes plus a metadata bound instead of logical bytes. Opt-in via one environment variable; mode 0 keeps the pre-patch code paths, fingerprint-compared against the unpatched engine. A refused `put()` keeps superseded copies until the image fits, and the RAM gate trims the heap before evicting, because freed 1 MiB blocks can otherwise stay in the heap and not show up in `MemAvailable`. Diagnostics: a `conversation_cache.dedup` block in `/metrics` and one stats line per park. Design notes in `docs PARKED_CACHE_DEDUP.md`. No defaults changed, no unrelated cleanup. ## Validation **Passed:** - New `tests/core/conversation_storage_test.cpp`, wired into CMake and run with: ```sh cmake -S . -B build -DSTRATA_BUILD_CONVERSATION_TESTS=ON cmake --build build --target conversation_storage_test conversation_cache_test ctest --test-dir build -R "conversation_storage|conversation_cache" ``` at `7ddc17a3` (v0.2.3.1) and at this revision on `4b9e05a2` (v0.2.6): 519 checks with dedup disabled, 608 enabled, 608 with forced hash collisions. - Existing engine unit suites on the CUDA build host, in both dedup modes: snapshot 4041, validation 972, transfer and failure injection 1548, serialization 201, memory 31, split allocation failures 8/12/16, cache policy 4772 (disabled), memory guard 156. Storage fixture also green under ASan+UBSan. - Controlled full-model probes (31 requests each, one output token, `STRATA_PREFILL_CPU_SHARE=0`): unpatched, patched-off and patched-on produced identical outputs and identical GDN/PLE/tail/index/KV state fingerprints. - Budget-bound synthetic A/B (89 requests, 10240 MiB budget, 64 slots, 64 conversations sharing a 24576-token prefix): no regression in retained histories, evictions or decode speed against the off arm. - Applied unchanged and re-validated on `4b9e05a2` (engine 0.1.51): unit suites green, running in production since 2026-10-25, including a service restart on 2026-10-26. Environment: Linux x86-64 (Threadripper 5965WX, 192 GiB RAM), single RTX 3090, CUDA 13.2, Release build. **Failed:** none observed **Not run:** - HIP/SYCL/Metal builds (no hardware available); CUDA only on the single RTX 3090 host. - Multi-GPU, staged or batched serving: startup refuses this combination, and only the refusal itself was exercised. - No maximum-context rerun and no long soak; the RAM-gate trim-before-evict path is covered by review and allocator reasoning, not by a live OOM test. ## Limits - Opt-in only; requires single-GPU serial serving. Startup exits with a clear message when combined with stages or batch. - Failed parking is still not transactional at serving level — pre-existing upstream behaviour, unchanged here. - Session-save reclaim accounting is unchanged. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#4958
No description provided.