Redesigning State Caching for Hybrid Architectures: 3x Higher Prefill Throughput

    This article explains why hybrid architectures that combine full attention with linear layers such as Kimi Delta Attention, Gated DeltaNet, and Mamba-2 make caching significantly more complex, introducing a second cache dimension alongside the KV cache. It breaks down the three core challenges of hybrid state caching—inconsistent granularity, inconsistent lifecycles, and inconsistent transfer and placement—and presents a dual-track caching design that unifies KV blocks and state snapshots under a shared position-and-version coordinate system. Readers will learn the four key mechanisms behind this approach: unified addressing, tiered placement, prefill parallelization, and cross-node reuse. The article also includes an engineering checklist, the sources of the reported gains, and the workload conditions under which the optimization holds.

    1. Hybrid Architectures Are Going Mainstream: Faster Decoding, Heavier Caching

    In open-source LLM design over the past two years, linear attention and state space layers have moved from experimental components to common building blocks. Linear sequence modeling structures represented by Kimi Delta Attention, Gated DeltaNet, and Mamba-2 are typically stacked alternately with a small number of full attention layers, forming a hybrid architecture of “full attention plus linear layers.” The motivation is straightforward: the memory footprint of full attention layers grows quadratically with sequence length, while the inference cost of linear layers grows roughly linearly with length. Hybrid stacking therefore preserves long-context modeling capability while substantially reducing decoding-stage overhead.

    From a systems engineering perspective, however, a hybrid architecture turns caching from a single-dimension problem into a two-dimension one. Pure Transformer inference only needs to manage the KV cache: every token produces a set of key-value pairs at each layer, and the cache can be appended to, truncated, and reused at token granularity. A hybrid architecture introduces an additional “state cache”: linear layers maintain a fixed-size recurrent state that is a compressed representation of the historical sequence and has no semantics for token-level slicing. As a result, prefix reuse is no longer just a matter of finding matching KV for an identical prefix; it also requires the state and the KV to be strictly aligned at the same position.

    2. Why Coding Agent Workloads Amplify the Caching Problem

    Coding agent workloads have several distinct characteristics: very long system prompts and repository context, continuous appends from multi-turn tool calls, repeated rollbacks to earlier versions within the same session, and multiple branches sharing large common prefixes. These characteristics make the prefix cache hit rate the decisive performance variable, and they also amplify the cost of caching mistakes.

    With a pure Transformer, a prefix cache miss usually affects only speed. Under a hybrid architecture, if the state cache and the KV cache are out of version sync, the “compressed history” the model sees is misaligned with the actual token sequence, output quality drops noticeably, and such degradation is often hard to pinpoint from logs. The design goals for a hybrid state cache can therefore be summarized as three points: a correctness-first alignment mechanism, the highest achievable prefix hit rate, and scalability across layers and nodes.

    3. Three Core Challenges of Hybrid State Caching

    The first is inconsistent granularity. The KV cache grows naturally per token, while the state cache is fixed in size per layer. When a request is truncated or rolled back in the middle of a sequence, KV can be rolled back precisely to a given token position, whereas the state must be rolled back to “the version of the state snapshot corresponding to that position”; otherwise the compressed representation will contain content that has been undone.

    The second is inconsistent lifecycle. In multi-turn conversations, the KV of a common prefix can be shared by many requests, but state snapshots are usually bound to a specific session. Caching only KV while ignoring state causes reuse to “break the chain” at the first incremental decoding step; if state and KV use entirely different eviction policies, a half-hit state also appears, where one side hits and the other misses.

    The third is inconsistent transfer and placement. KV blocks are small and numerous, which suits fine-grained paging; state snapshots are fixed in size, one per layer, which suits whole-object movement. Putting both under the same transfer and placement policy easily leads to wasted bandwidth or queueing jitter.

    4. Redesign Approach: Orchestrating KV and State as a Dual-Track Cache

    An approach validated in real agent trajectory replays is to abstract KV and state as two tracks that share the same “position-and-version” coordinate system, with a unified scheduler deciding hits, rollbacks, and migrations. The core mechanism breaks down into four layers.

    4.1 Unified Addressing: Binding Both Tracks to a Position Anchor

    Maintain a logical identifier for each prefix position, with both KV blocks and state snapshots attached to that identifier. When a request hits a prefix, the scheduler fetches the corresponding KV blocks and state snapshot at the same time and verifies that their version numbers match; if they do not, it falls back to the most recent consistent point. Illustrative logic:

    1. on_prefix_hit(pos):
    2. kv = kv_store.get(pos)
    3. st = state_store.get(pos)
    4. if kv.version != st.version:
    5. pos = last_consistent(pos)
    6. kv, st = load(pos)
    7. return kv, st

    4.2 Tiered Placement: Hot Data in GPU Memory, Warm Data in Host Memory, Cold Data Remotely

    GPU memory holds only the KV pages and state snapshots of currently active sessions; host memory carries medium-hot prefixes; a larger-capacity remote cache or object storage carries cold prefixes. Because a state snapshot is a fixed-size whole object, it is best accessed as a whole using “session plus position” as the key, avoiding the metadata bloat caused by fine-grained splitting.

    4.3 Prefill Parallelization: Overlapping State Reconstruction with Chunked Prefill

    The main cost of the prefill stage is recomputing long prefixes. After the redesign, the scheduler splits a long prefix into chunks, computes KV in parallel within each chunk, and advances the state in dependency order at the same time; already-hit prefixes skip computation entirely and only undergo dual-track loading and verification. This compresses the critical path of “waiting for the state to be ready” to a minimum, significantly raising prefill throughput and reducing the long tail of time to first token.

    4.4 Cross-Node Reuse: State Snapshots as First-Class Citizens in Migration

    In distributed deployments, node failures or scaling events trigger session migration. Migrating only KV forces the receiving node to recompute the state; including state snapshots in the migration set, and allowing common prefix state to be shared across nodes in read-only mode, keeps time to first token stable during scale-out and canary releases.

    5. Engineering Implementation Checklist

    • Versioned metadata: record the version, layer count, and creation time of both KV and state for each prefix position, as the basis for consistency checks.
    • Rollback policy: define an upper bound on the rollback depth to the “most recent consistent point,” preventing degradation into full recomputation in extreme cases.
    • Capacity planning: estimate GPU memory KV usage by “number of active sessions × average context length,” and state cache usage by “number of sessions × number of layers × state size,” setting a separate watermark for each.
    • Observability: monitor KV hit rate, state hit rate, the number of dual-track inconsistency rollbacks, and prefill queueing time separately, in order to locate the sources of the long tail.
    • Integration with general cloud capabilities: container platforms can host inference services, object storage can hold cold prefixes, message queues can decouple migration events, and monitoring and alerting can track long-tail latency, forming a scalable tiered caching system.

    6. Sources of Gains and Applicability Boundaries

    In public replays of real multi-turn long-context workloads, the dual-track cache orchestration approach raised prefill throughput to more than three times the baseline, and reduced long-tail time to first token by more than eighty percent; the gains still held after attaching host memory caching on the order of hundreds of GiB. It should be emphasized that the gains depend heavily on the proportion of shared prefixes in the workload: if requests share almost no common prefix, a lower hit rate will weaken the optimization. Before going live, sample trajectories first to quantify prefix sharing and session rollback frequency, then decide the cache tiers and capacity allocation.