KV Cache Reuse Consistency Design for Hybrid Attention Models
Paged KV caching enables prefix reuse in LLM inference, but prefix-hash hits do not guarantee correct state in hybrid attention architectures. This article explains why, introduces five distinct cache object types (compressed KV, uncompressed tail, SWA window, indexer state, on-disk prefix), presents an allocator state machine with a four-layer validation pipeline, and provides four consistency checks plus practical engineering guidance to ensure that cache reuse never compromises generation correctness.
1. Background: Paged Caching Enables Prefix Reuse, but Not State Correctness
In large language model inference, the KV cache is a critical structure that determines throughput, GPU memory usage, and time-to-first-token. Paged KV cache management partitions token history into fixed-size physical blocks and maps logical positions to physical blocks through a page table. This allows requests sharing the same prefix to reuse existing KV blocks and avoid redundant computation. For a long time, this approach worked well for conventional attention models because “identical prefix” usually implied “the KV state at the corresponding positions can be read directly and computation can continue.”
However, this inference holds only when cached objects have a uniform shape, a consistent lifecycle, and a clear recovery path. Hybrid attention architectures break that assumption. Different layers may mix full-history compression, sliding-window attention, sparse routing, and other mechanisms. Each layer retains historical information differently, so the same token prefix may exist in multiple forms in the cache: some compressed, some still in an uncompressed tail, some limited to a sliding window, some dependent on indexer routing state, and some already swapped out to external storage.
In this situation, a prefix-hash hit only proves the token sequences are identical — it says nothing about whether the required state is complete and available. Prefix cache hit rate is not a correctness metric. If the uncompressed tail, the sliding window, or the indexer state is missing after a hit, the generated output can still be wrong. Inference frameworks must therefore upgrade from “finding blocks by hash” to “tracking polymorphic cache objects by token range and validating recoverability.”
2. Three Trigger Conditions Introduced by Hybrid Attention
Hybrid attention complicates cache state. Three classes of inputs typically push the system beyond what a single rule can cover:
- Different attention mechanisms across layers. Full-history compression layers need compressed KV, sliding-window layers need the recent window, and sparse-routing layers need indexer state. The cache for a single request is no longer a homogeneous set of blocks but a composition of multiple object types.
- Ultra-long contexts exceeding single-GPU memory. Part of the prefix may be swapped out to external storage, forming an on-disk prefix. Recovery requires asynchronous migration back, and the data cannot participate in computation until migration completes.
- Cross-request reuse. Multiple requests may share the same prefix but have different tails, windows, and index states. Identical prefixes do not imply identically recoverable states.
Together, these conditions require the cache manager to explicitly model object state instead of merely maintaining a free list of physical blocks.
3. Five Cache Object Types: Different Lifecycles and Recovery Conditions
3.1 Compressed KV
Compressed KV consists of blocks produced by compressing historical tokens. It typically has a long lifecycle and serves as the primary vehicle for cross-request reuse. Its recovery conditions include: the compressed blocks exist, the version matches, and the compression boundary aligns with the requested token range. If the compression version is stale or the compressed blocks cover only part of the history, computation cannot continue directly.
3.2 Uncompressed Tail
The uncompressed tail holds the KV of the most recent tokens that have not yet been compressed. It usually shares a boundary with the compressed KV. Recovery must confirm that the tail blocks are complete and that the tail start is contiguous with the end of the compressed blocks. Without the tail, even a prefix-hash hit cannot resume from the compression boundary — the tail must be recomputed.
3.3 SWA Window
Sliding-window attention depends only on the most recent window, and its cache object is the SWA window. Its lifecycle is short and highly dynamic: as generation advances, the window keeps moving and old windows may be evicted. The recovery condition is not “some window block exists” but “the window covers the range required by the current request, and the tokens inside the window are contiguous.” When the window does not match, it must be rebuilt or the relevant layers recomputed.
3.4 Indexer State
Sparse routing or indexer state determines which historical blocks will be accessed. It may include routing tables, block indexes, and version information. Recovery conditions include: the indexer state is synchronized with the KV block version, token position mappings are correct, and routing results are reproducible. If the indexer state is missing or stale, the correct positions may be unreadable even when the KV blocks exist.
3.5 On-Disk Prefix
A prefix swapped out to external storage forms an on-disk prefix. Its lifecycle spans four stages: swap-out, storage, migration back, and binding. Its recovery conditions are the strictest: migration must be complete, data verification must pass, and the migrated blocks must be bound to the current request’s address space. Before migration finishes, the system can only wait or fall back to recomputation.
The five object types differ in lifecycle, recovery conditions, and hit determination. The cache manager cannot treat them as the same kind of block.
4. The Allocator State Machine: From “Finding Free Blocks” to “Recording Shape”
A traditional allocator’s main job is to find free GPU memory blocks and write new tokens into them. Under hybrid attention, the allocator must also record the current form of each token segment and its state transitions. Otherwise, downstream prefix matching reports a hash hit while the actual read lacks the tail, the SWA window, or the indexer routing — and generation still fails.
The cache object state can be expressed in pseudocode as follows:
struct CacheObjectState {token_range: [start, end]compressed_kv: BlockRef?uncompressed_tail: BlockRef?swa_window: WindowRef?indexer_state: IndexerRef?on_disk_prefix: DiskRef?version: uint64state: {READY, PENDING_RESTORE, PARTIAL, INVALID}}function can_resume(prefix_hash, request_range):obj = lookup_cache(prefix_hash)if obj is null:return false, "NO_CACHE"if not covers(obj.compressed_kv, request_range):return false, "MISS_COMPRESSED_KV"if not covers(obj.uncompressed_tail, request_range.tail):return false, "MISS_TAIL"if not covers(obj.swa_window, request_range.window):return false, "MISS_SWA_WINDOW"if not synced(obj.indexer_state, obj.version):return false, "STALE_INDEXER"if obj.on_disk_prefix is not null and not migrated(obj.on_disk_prefix):return false, "PENDING_DISK_PREFIX"return true, "RESUMABLE"
The key point: the allocator state machine must ensure that every “reusable” decision passes the dispatch validation of all five object types, and that state transitions are atomic. Otherwise, a race condition arises where the state is usable at check time but invalid at use time.
5. Hit Determination: A Hash Hit Does Not Mean Computation Can Resume
Prefix matching is typically based on token sequences or block hashes. A hash hit only means “the prefix content is identical,” not “the cache state is complete.” Correct hit determination should include four layers of validation:
- Block alignment check: whether the token range is aligned to whole blocks at the least common multiple, and whether compression boundaries fall at legal positions.
- Kernel ABI check: whether the cache block layout, version, and operator calling conventions match, preventing new kernels from misreading old layouts.
- Multi-cache-group state intersection check: all five state types — compressed KV, tail, SWA window, indexer state, and on-disk prefix — must simultaneously satisfy the intersection required by the current request.
- Byte-level hardware alignment check: whether physical addresses, block sizes, and device-side access granularity meet alignment requirements.
Only when all four checks pass can a prefix hit be converted into a resumable computation. Otherwise, the system should enter a degradation path: recompute the tail, rebuild the window, refresh the indexer, or wait for the on-disk prefix to migrate back.
6. Four Consistency Checks: Rules the State Machine Must Not Violate
In engineering practice, the following four checks should be enforced as hard constraints of the allocator state machine:
- Admission cap: limit the number of cache objects a single request can occupy and the concurrency of migrations, preventing state explosion.
- Five-way state dispatch: every allocation, release, and reuse action must be dispatched and handled according to the five object types: compressed KV, tail, SWA window, indexer state, and on-disk prefix.
- TOCTOU and state_data_ptrs consistency: no state drift may occur between check and use; state pointers and data pointers must be updated in pairs.
- Static graph capture topology stability: if static graph capture is used, the cache object topology and address bindings must remain stable, preventing state changes after capture from causing read errors.
7. Practical Engineering Recommendations
First, model cache objects as a combination of “token range + polymorphic state + version number” rather than a single block. Second, make the recovery flow transactional: lock the state first, validate the four layers of conditions, then commit the resume or degrade. Third, build observability metrics covering hash hit rate, state recoverability rate, tail recomputation rate, window rebuild rate, index refresh rate, and disk migration wait time. Finally, design degradation strategies: recompute the tail when it is missing, rebuild the window when it is missing, refresh the index when it is stale, and wait or recompute when the disk prefix has not migrated back.
Hybrid attention improves long-context modeling capability, but it also transforms KV cache reuse from a “block matching problem” into a “polymorphic state consistency problem.” Only by measuring hit rate and correctness separately, and by bringing all five cache object types into a unified state machine, can we guarantee correct generation results while reusing prefixes.
