[PR #2443] [Engine] evict redundant holders while preserving pinned prefixes #4048

Open
opened 2026-11-07 15:32:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2443
Author: @KeyanHu-git
Created: 10/14/2026
Status: 🔄 Open

Base: main ← Head: fix/2255-pinned-eviction


📝 Commits (10+)

  • 3a28942 conversation cache: evict redundant holders without losing pinned prefixes
  • 6af3620 docs: describe pinned-prefix retention across conversation holders
  • 64a2275 conversation cache: align reclaimable bytes with pinned eviction
  • af1e09d merge current main and align pinned-prefix reclamation documentation
  • 9a08edc Validate pinned-prefix reclamation through session saving and model replay
  • 2d3cf51 Merge current main and retain pinned-prefix eviction documentation
  • da63fde Merge v0.2.7 and preserve pending snapshot ownership during eviction
  • daf1c41 Record v0.2.7 cache ownership and model validation
  • 8de521a Include sanitizer test receipts referenced by validation report
  • 2f4701c Keep cache PR focused and preserve validation at immutable revision

📊 Changes

9 files changed (+603 additions, -77 deletions)

View changed files

📝 docs/DETAILS.md (+5 -4)
📝 include/strata/core/conversation_cache.hpp (+136 -24)
📝 include/strata/core/session_save_reclaim.hpp (+1 -1)
📝 src/core/conversation_cache_test.cpp (+332 -2)
📝 src/core/conversation_file_test.cpp (+4 -4)
📝 src/core/conversation_snapshot_test.cpp (+28 -11)
📝 src/core/conversation_validation_test.cpp (+34 -22)
📝 src/core/session_save_reclaim_test.cpp (+41 -0)
📝 sycl/src/core/conversation_snapshot_test.cpp (+22 -9)

📄 Description

Problem and result

Pinning the same system prompt on every request fills the conversation cache with branches of one prefix. Upstream protects every branch, so later conversations cannot be saved even when the byte budget has room.

This change evicts redundant branches while keeping at least one holder of every pinned prefix. The same 15-request replay against v0.2.7, repeated on this ownership revision, gives:

Result v0.2.7 This PR This PR, async flags set
Parking refusals 8 0 0
Restored conversations 0 6 6
Input tokens processed on six revisits 1,778 90 90
Output sequences differing from v0.2.7 — 0 0

Fixes #2255. Related admission paths: #2253 and #2082.

Approach

flowchart LR
    A[Old branch A] --> P[Shared pinned prefix]
    B[Branch B] --> P
    C[Branch C] --> P
    A --> E[Evict A and save the new branch]
    B --> K[Prefix remains recoverable]
    C --> K

Evict unpinned entries first, then the oldest entry whose pinned prefixes all have another holder. Prefix identity includes token IDs, image identities and steering mode. A borrowed donor stays protected and counts as a surviving holder.

evictable_bytes() simulates the same removals, so admission and session-save reclamation agree with eviction about what can be released. Retained active K/V is accounted separately.

Snapshots are move-only resource owners. SavedConversation, ConversationKv and the retained-K/V package reject copying at compile time; moving transfers the buffers and their pending-copy tokens together. Replacement retires the complete old owner, joining its copies before releasing storage. Cache erasure, capture publication and file-load publication use the same type-level rule.

The cache itself is noncopyable and nonmovable because its serials, guards and accounting identify one service instance. Restore and file writing borrow snapshots through the existing completion checks. Ordinary checkpoint values remain copyable for prefix borrowing. Tests reconstruct independent fixtures instead of copying asynchronous owners; no new clone or shared-storage API is introduced.

Validation

Production revision: ce957e14, based on v0.2.7 5e8a4cca. The current diff keeps the fix, regression tests and user documentation. Experimental records are preserved at the immutable revision below, outside the merge diff. Recorded requests, outputs, settings, source hashes and reproduction steps.

Passed:

  • RX 7900 XTX / HIP: full engine build; cache, session-save, file, validation and device snapshot tests. Three 15-request Coder IQ1_M replays match the original output IDs. The successful retry batch took 200 seconds, including its incremental build and tests.
  • Apple Clang ASan/UBSan: 45,257 cache checks, 198 file checks and 161 session-save checks. Coverage includes pending old/new owners, self-move, both deque shift directions, nested stages, donor protection and reclamation accounting.
  • Eight compile probes reject copy construction/assignment of the four owning types. Full CUDA, HIP, Metal and SYCL engine builds passed. CUDA CPU ctest passed 5/5; CUDA and SYCL snapshot test targets also compile.

The initial CUDA/SYCL builds found a remaining copy in each malformed-payload test. Those tests now capture independent fixtures; the production implementation is unchanged. Historical lifetime counterexamples and earlier validation are retained separately.

HIP disables both STRATA_PARK_ASYNC and STRATA_CKPT_ASYNC in the implementation. The flag-set arm therefore validates HIP's fallback, not CUDA background copies. Pending-copy lifetime is tested with sanitizer-checked completion tokens. CUDA asynchronous device execution and CUDA/SYCL/Metal model execution were not run in this batch.

Limits

Explicit constructors make the snapshot types non-aggregate; current repository consumers pass all four backend builds. Data-member layout and session-file format are unchanged. Snapshot-owner copies are now rejected by the compiler; data readiness for borrowed reads continues to use the existing synchronization paths.

The eviction search depends on the number of entries, checkpoints and prefix length. Logical freed bytes are used for accounting; physical-memory admission still resamples available memory. The model replay establishes cache reuse and matching outputs on this workload, with diagnostics enabled, rather than a throughput claim.


🔄 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/2443 **Author:** [@KeyanHu-git](https://github.com/KeyanHu-git) **Created:** 10/14/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/2255-pinned-eviction` --- ### 📝 Commits (10+) - [`3a28942`](https://github.com/Niko1221/Strata/commit/3a289421ba741b91d6a84af983b8fef79352beac) conversation cache: evict redundant holders without losing pinned prefixes - [`6af3620`](https://github.com/Niko1221/Strata/commit/6af3620eb56561fa9ba1706e4b3705a430362696) docs: describe pinned-prefix retention across conversation holders - [`64a2275`](https://github.com/Niko1221/Strata/commit/64a227571fd9b1f888ab4f586c4c4c07c13c25aa) conversation cache: align reclaimable bytes with pinned eviction - [`af1e09d`](https://github.com/Niko1221/Strata/commit/af1e09ddc32e0415641a7976237451d9e092679a) merge current main and align pinned-prefix reclamation documentation - [`9a08edc`](https://github.com/Niko1221/Strata/commit/9a08edcac953dbc8e52d6267049cd2b5b5273c8b) Validate pinned-prefix reclamation through session saving and model replay - [`2d3cf51`](https://github.com/Niko1221/Strata/commit/2d3cf51189d0283f46a8b17ac34b0315dec8d24f) Merge current main and retain pinned-prefix eviction documentation - [`da63fde`](https://github.com/Niko1221/Strata/commit/da63fde09a7f83692cf9de5c05bf4001a46d7bed) Merge v0.2.7 and preserve pending snapshot ownership during eviction - [`daf1c41`](https://github.com/Niko1221/Strata/commit/daf1c41cbc9c7d334adfc00233125bfbad972630) Record v0.2.7 cache ownership and model validation - [`8de521a`](https://github.com/Niko1221/Strata/commit/8de521a99ecc249df71da945a8baad40acb7f85b) Include sanitizer test receipts referenced by validation report - [`2f4701c`](https://github.com/Niko1221/Strata/commit/2f4701cba620624e44ab65e30cf7de88fc3abd88) Keep cache PR focused and preserve validation at immutable revision ### 📊 Changes **9 files changed** (+603 additions, -77 deletions) <details> <summary>View changed files</summary> 📝 `docs/DETAILS.md` (+5 -4) 📝 `include/strata/core/conversation_cache.hpp` (+136 -24) 📝 `include/strata/core/session_save_reclaim.hpp` (+1 -1) 📝 `src/core/conversation_cache_test.cpp` (+332 -2) 📝 `src/core/conversation_file_test.cpp` (+4 -4) 📝 `src/core/conversation_snapshot_test.cpp` (+28 -11) 📝 `src/core/conversation_validation_test.cpp` (+34 -22) 📝 `src/core/session_save_reclaim_test.cpp` (+41 -0) 📝 `sycl/src/core/conversation_snapshot_test.cpp` (+22 -9) </details> ### 📄 Description ## Problem and result Pinning the same system prompt on every request fills the conversation cache with branches of one prefix. Upstream protects every branch, so later conversations cannot be saved even when the byte budget has room. This change evicts redundant branches while keeping at least one holder of every pinned prefix. The same 15-request replay against v0.2.7, repeated on this ownership revision, gives: | Result | v0.2.7 | This PR | This PR, async flags set | |---|---:|---:|---:| | Parking refusals | 8 | 0 | 0 | | Restored conversations | 0 | 6 | 6 | | Input tokens processed on six revisits | 1,778 | 90 | 90 | | Output sequences differing from v0.2.7 | — | 0 | 0 | ## Related discussion Fixes #2255. Related admission paths: #2253 and #2082. ## Approach ```mermaid flowchart LR A[Old branch A] --> P[Shared pinned prefix] B[Branch B] --> P C[Branch C] --> P A --> E[Evict A and save the new branch] B --> K[Prefix remains recoverable] C --> K ``` Evict unpinned entries first, then the oldest entry whose pinned prefixes all have another holder. Prefix identity includes token IDs, image identities and steering mode. A borrowed donor stays protected and counts as a surviving holder. `evictable_bytes()` simulates the same removals, so admission and session-save reclamation agree with eviction about what can be released. Retained active K/V is accounted separately. Snapshots are move-only resource owners. `SavedConversation`, `ConversationKv` and the retained-K/V package reject copying at compile time; moving transfers the buffers and their pending-copy tokens together. Replacement retires the complete old owner, joining its copies before releasing storage. Cache erasure, capture publication and file-load publication use the same type-level rule. The cache itself is noncopyable and nonmovable because its serials, guards and accounting identify one service instance. Restore and file writing borrow snapshots through the existing completion checks. Ordinary checkpoint values remain copyable for prefix borrowing. Tests reconstruct independent fixtures instead of copying asynchronous owners; no new clone or shared-storage API is introduced. ## Validation Production revision: `ce957e14`, based on v0.2.7 `5e8a4cca`. The current diff keeps the fix, regression tests and user documentation. Experimental records are preserved at the immutable revision below, outside the merge diff. [Recorded requests, outputs, settings, source hashes and reproduction steps](https://github.com/KeyanHu-git/Strata/tree/89fe461d9a3cb4efeaa6cde0b510239423b562a1). **Passed:** - RX 7900 XTX / HIP: full engine build; cache, session-save, file, validation and device snapshot tests. Three 15-request Coder IQ1_M replays match the original output IDs. The successful retry batch took 200 seconds, including its incremental build and tests. - Apple Clang ASan/UBSan: 45,257 cache checks, 198 file checks and 161 session-save checks. Coverage includes pending old/new owners, self-move, both deque shift directions, nested stages, donor protection and reclamation accounting. - Eight compile probes reject copy construction/assignment of the four owning types. Full CUDA, HIP, Metal and SYCL engine builds passed. CUDA CPU ctest passed 5/5; CUDA and SYCL snapshot test targets also compile. The initial CUDA/SYCL builds found a remaining copy in each malformed-payload test. Those tests now capture independent fixtures; the production implementation is unchanged. Historical lifetime counterexamples and earlier validation are retained separately. HIP disables both `STRATA_PARK_ASYNC` and `STRATA_CKPT_ASYNC` in the implementation. The flag-set arm therefore validates HIP's fallback, not CUDA background copies. Pending-copy lifetime is tested with sanitizer-checked completion tokens. CUDA asynchronous device execution and CUDA/SYCL/Metal model execution were not run in this batch. ## Limits Explicit constructors make the snapshot types non-aggregate; current repository consumers pass all four backend builds. Data-member layout and session-file format are unchanged. Snapshot-owner copies are now rejected by the compiler; data readiness for borrowed reads continues to use the existing synchronization paths. The eviction search depends on the number of entries, checkpoints and prefix length. Logical freed bytes are used for accounting; physical-memory admission still resamples available memory. The model replay establishes cache reuse and matching outputs on this workload, with diagnostics enabled, rather than a throughput claim. --- <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#4048
No description provided.