Skip to content

core: a two-session KV isolation test across spill, offload and a retired page - #3840

Merged
ashhart merged 2 commits into
mainfrom
lead/kv-isolation-test
Nov 19, 2026
Merged

ashhart merged 2 commits into
mainfrom
lead/kv-isolation-test

Conversation

@ashhart

@ashhart ashhart commented Nov 18, 2026

Copy link
Copy Markdown
Owner

A regression test that pins prefix-cache isolation across spill, offload and page reuse: a kept state is only ever matched by its tokens, never by position, size or slot.

Sessions A and B have disjoint prompts of the same length and keep states at the same positions, so a lookup that went by position alone would hand one the other's rows. On the rows fake and the snapshot fake, the test checks:

  1. A's state is spilled to disk and dropped from RAM, then B is admitted. B's first turn prefills, its next turn resumes its own state (equal to a fresh pass of B's tokens), and A's spilled file is never read for B.
  2. A's next turn resumes A's spilled state from disk, equal to a fresh pass of A's own tokens.
  3. After a page is retired and reused (A's spilled state and blocks removed and another session's written, or A's dropped RAM storage taken by B's save), a lookup for A's prefix matches nothing, restores nothing, and A prefills its own tokens.

All three pass on main. The tests catch the leak they guard against: with the token comparison removed from Rows.matches, tests 1, 2 and the disk half of 3 fail; removed from the store's lookup, all three fail.

Tests only, no engine change. A recent advisory in another engine (a request decoding against an unrelated request's prefix under cascade attention with CPU KV offload) prompted it; TensorFold already keys states by tokens, and this keeps it that way.

Checked on this head: zig build test-rows-host, zig build check-release-paths, zig fmt --check, and the lean check (no new problems).

  • Synthena

…ired page

Sessions A and B have disjoint prompts of the same length and keep states at the same positions, so a lookup that
went by position alone would hand one the other's rows. On the rows fake (rows_fake.zig) and the snapshot fake
(prompt_cache_fake.zig), the test checks:

1. A's state is spilled to disk and dropped from RAM, then B is admitted: B's first turn prefills, its next turn
   resumes its own RAM state equal to a fresh pass of B's tokens, and A's spilled file is never read for B.
2. A's next turn then resumes A's spilled state from disk, equal to a fresh pass of A's own tokens.
3. After a page is retired and reused (A's spilled state and its blocks removed and another session's written; or
   A's dropped RAM storage left spare and taken by B's save), a lookup for A's prefix matches nothing, restores
   nothing and A prefills its own tokens.

All three pass on main. With the token comparison removed from Rows.matches, the spill test (1, 2) and the disk
retire test (3) fail; removed from the store's find, all three tests fail, the RAM page test (3) too. Tests only: no engine code changes.
@ashhart
ashhart force-pushed the lead/kv-isolation-test branch from b005584 to 6c73f08 Compare November 19, 2026 09:56
@ashhart
ashhart merged commit d74be31 into main Nov 19, 2026
2 of 11 checks passed
@ashhart
ashhart deleted the lead/kv-isolation-test branch November 19, 2026 09:57
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.

1 participant