[PR #3973] [Engine] test: the byte-identity half of the reuse contract #4858

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3973
Author: @wannagoxuf
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: feature/reuse-identity-test


📝 Commits (1)

  • d604729 test: the byte-identity half of the reuse contract

📊 Changes

2 files changed (+227 additions, -0 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
➕ src/core/conversation_reuse_identity_test.cpp (+223 -0)

📄 Description

Problem

The snapshot API contract (include/strata/core/conversation_snapshot.hpp) says:

A nonzero unchanged_tokens is valid only for storage retained from an image actually restored into this
session, bounded by every subsequent rewrite. Equal token IDs alone do not establish that its K/V bytes
are unchanged.

The bookkeeping half of that - which bytes a capture claims are unchanged, and where the claim stops - is
covered in conversation_cache_test.cpp (retain / limit_reuse / take_reuse). The half that is not
covered is the byte half: whether the bytes really are unchanged.

That question is live in the two pull requests that touch the reuse path (#3711 and the harvest discussed in
#3321), and it is decidable in the shapes the cache actually produces.

Approach

A new test (src/core/conversation_reuse_identity_test.cpp, 21 checks) that covers:

  • a tail rewrite leaves the prefix bytes alone, and changes the tail bytes. This is what the
    unchanged_tokens claim rests on: the bytes before the first rewrite are still the ones the session holds.
  • a different prefix gives different bytes - the negative control. Without it the first case would prove
    nothing, since identical bytes could just mean the comparison is too coarse to see a difference.
  • the claim's bound: limit_reuse cuts it at the first rewrite, a rewrite from the start drops the whole
    donation, and a later continuation cannot widen a claim that was already cut.
  • the claim survives the capture: with a nonzero unchanged_tokens the capture keeps the donated prefix
    bytes and not the device's, and past the claimed prefix it takes the device's bytes.

The engine-level half - two independent computations of the same token prefix through different chunkings -
needs a real model and is not decided here. It is measured with STRATA_STATE_HASH=1 (the engine's
per-request fingerprint of the session's K/V) and the result is in #3321: on 4x4090 with
Qwen3.8-Flash-Next IQ3_XXS, the same prompt through --prefill 4096 and --prefill 1024 gives different
main-K/V fingerprints (2b0d5053ac251873 vs 42e1a97e3930a0fe), while the same chunking twice gives the
same fingerprint. So equal token IDs do not, in fact, establish equal bytes across a chunking boundary - the
contract's caution is observable, not theoretical.

Validation

Passed:

  • Build on origin/main (7dd5cf18): cmake -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON + cmake --build . -j 4 (CUDA 12.8, driver 580.178.04, 4x RTX 4090).
  • ctest -R conversation --output-on-failure -j 2: 8/8 passed, including the new
    conversation_reuse_identity_test (21 checks).
  • No production code is touched: the diff is one new test file and its add_test registration.

Not run:

  • The HIP and SYCL backends are not built here (no toolchain), so the test is not exercised on them. The
    test uses only conversation_kv_save / conversation_kv_verify / ConversationCache, none of which are
    backend-specific, but that is an argument, not a run.
  • The engine-level identity measurement (the STRATA_STATE_HASH=1 runs) is on the CUDA engine only.

Failed: nothing.

Limits

  • This test decides the bookkeeping and the byte-level properties of the shapes the cache produces. It does
    not decide whether two independent computations of the same prefix agree - that needs a model, and the
    answer there is no (see the measurement above).
  • The fixture writes the K/V bytes itself, so it can show that a rewrite leaves a prefix alone and that a
    different prefix differs; it cannot show that a real model's prefix bytes are stable across chunkings.
  • #3711 (the page-reuse part of the same series)
  • #3742 (the per-stage concurrent copies; no overlap with this test)
  • #3321 (the discussion this test comes out of)

🔄 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/3973 **Author:** [@wannagoxuf](https://github.com/wannagoxuf) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feature/reuse-identity-test` --- ### 📝 Commits (1) - [`d604729`](https://github.com/Niko1221/Strata/commit/d604729e04287b0859805a5e17eb57554ce17841) test: the byte-identity half of the reuse contract ### 📊 Changes **2 files changed** (+227 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) ➕ `src/core/conversation_reuse_identity_test.cpp` (+223 -0) </details> ### 📄 Description ## Problem The snapshot API contract (`include/strata/core/conversation_snapshot.hpp`) says: > A nonzero `unchanged_tokens` is valid only for storage retained from an image actually restored into this > session, bounded by every subsequent rewrite. Equal token IDs alone do not establish that its K/V bytes > are unchanged. The bookkeeping half of that - which bytes a capture claims are unchanged, and where the claim stops - is covered in `conversation_cache_test.cpp` (`retain` / `limit_reuse` / `take_reuse`). The half that is not covered is the byte half: whether the bytes really are unchanged. That question is live in the two pull requests that touch the reuse path (#3711 and the harvest discussed in #3321), and it is decidable in the shapes the cache actually produces. ## Approach A new test (`src/core/conversation_reuse_identity_test.cpp`, 21 checks) that covers: - **a tail rewrite leaves the prefix bytes alone**, and changes the tail bytes. This is what the `unchanged_tokens` claim rests on: the bytes before the first rewrite are still the ones the session holds. - **a different prefix gives different bytes** - the negative control. Without it the first case would prove nothing, since identical bytes could just mean the comparison is too coarse to see a difference. - **the claim's bound**: `limit_reuse` cuts it at the first rewrite, a rewrite from the start drops the whole donation, and a later continuation cannot widen a claim that was already cut. - **the claim survives the capture**: with a nonzero `unchanged_tokens` the capture keeps the donated prefix bytes and not the device's, and past the claimed prefix it takes the device's bytes. The engine-level half - two independent computations of the same token prefix through different chunkings - needs a real model and is not decided here. It is measured with `STRATA_STATE_HASH=1` (the engine's per-request fingerprint of the session's K/V) and the result is in #3321: on 4x4090 with Qwen3.8-Flash-Next IQ3_XXS, the same prompt through `--prefill 4096` and `--prefill 1024` gives different main-K/V fingerprints (`2b0d5053ac251873` vs `42e1a97e3930a0fe`), while the same chunking twice gives the same fingerprint. So equal token IDs do not, in fact, establish equal bytes across a chunking boundary - the contract's caution is observable, not theoretical. ## Validation **Passed:** - Build on `origin/main` (7dd5cf18): `cmake -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_CONVERSATION_TESTS=ON` + `cmake --build . -j 4` (CUDA 12.8, driver 580.178.04, 4x RTX 4090). - `ctest -R conversation --output-on-failure -j 2`: 8/8 passed, including the new `conversation_reuse_identity_test` (21 checks). - No production code is touched: the diff is one new test file and its `add_test` registration. **Not run:** - The HIP and SYCL backends are not built here (no toolchain), so the test is not exercised on them. The test uses only `conversation_kv_save` / `conversation_kv_verify` / `ConversationCache`, none of which are backend-specific, but that is an argument, not a run. - The engine-level identity measurement (the `STRATA_STATE_HASH=1` runs) is on the CUDA engine only. **Failed:** nothing. ## Limits - This test decides the bookkeeping and the byte-level properties of the shapes the cache produces. It does not decide whether two independent computations of the same prefix agree - that needs a model, and the answer there is no (see the measurement above). - The fixture writes the K/V bytes itself, so it can show that a rewrite leaves a prefix alone and that a different prefix differs; it cannot show that a real model's prefix bytes are stable across chunkings. ## Related - #3711 (the page-reuse part of the same series) - #3742 (the per-stage concurrent copies; no overlap with this test) - #3321 (the discussion this test comes out of) --- <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#4858
No description provided.