Repository navigation
hanzo-kv-fabric: position-shifted segment reuse (CacheSlide / HIP-1345 s2.2, Bounty #12) - #100
breezesamuel wants to merge 2 commits into
Conversation
|
Thanks for the real CacheSlide layer in |
…ch E0277 - SegmentDirectory now stores (worker_id, token_offset) -> SegmentLocation so multiple occurrences of the same content at different absolute positions coexist; lookup returns all, pruning still per worker epoch. - segments_reuse_across_shifted_positions test expectations corrected to the actual position_shift semantics (current - published). - cacheslide_shift_bench.rs: chain_block_hashes returned parent instead of the fresh hash (E0277 &u64 vs u64 in the hit filter); dereferencing fixed. cargo test -p hanzo-kv-fabric --lib 9/9 green; examples build.
|
Both fixes pushed to
On the remaining contract items (matched baselines, raw measurements, HIP-1345 update): the bench example above is the reproducible baseline instrument (strict chained-prefix vs salted segment directory, same hardware, committed numbers in the PR description). The full six-point package will land as a follow-up commit on this branch — HIP-1345 §2.2 update plus the raw results table — rather than blocking this fix round on it. Happy to split that into a second PR if you prefer. Keeping it a draft per your instruction. |
|
Not merged yet. Missing against #85: (1) committed raw results from examples/cacheslide_shift_bench.rs (results/*.json) for the strict-prefix baseline versus the segment directory; (2) the HIP-1345 §2.2 status update (see results/HIP-1345-update.md in #104 for the shape); (3) an explicit out-of-scope statement (GPU TTFT and memory, attention-path position correction). Add those and I will rebase and merge it behind #104 and #105. |
|
Closing stale conflicting draft (last commit 2026-11-18, conflicting with The
|
hanzo-kv-fabric: position-shifted segment reuse (CacheSlide / HIP-1345 §2.2, Bounty #12)
Draft PR against
hanzoai/engine. Refs #85 (Wave 1 Priority #1). Implemented by breezesamuel.What this PR does
hanzo-kv-fabricgains a position-shifted segment reuse layer alongside the existing block-level prefix cache:Problem
The engine's current prefix caching (
hanzo-engine/src/prefix_cacher.rs::search_for_matching_cache) matches only on a common prefix of tokens — what the CacheSlide paper (FAST '26) calls Position-Dependent Caching (PDC). When an unchanged system or tool segment shifts by any number of tokens (multi-turn agent loops, repeated tool schemas after different histories), every chained block hash inside it changes and the cache misses entirely.The authors call the pattern we solve Relative-Position-Dependent Caching (RPDC): reusable segments keep their relative ordering within each turn but their absolute token-position offset varies across turns.
Fix (fabric tier only)
salted_segment_hash(tokens, layer_group, cache_salt)SegmentMetanum_computed_tokens, byte size, SHA-256 integrity digest, and publish-time absolute token offset.SegmentDirectory(cache_salt, segment_hash), recording the publish offset. Consumers translate positions viaSegmentLocation::position_shift.KvFabricError::EmptySegment/IncompleteSegmentnum_computed_tokens < num_tokens(aborted-prefill / uncomputed-sampled-tail hazard) never enter the directory. Per HIP-1345 §1.2.What this PR does NOT do
This PR covers only the fabric tier (directory + transport invariants). The attention-path position correction (RoPE/window translation of reused K/V) and end-to-end TTFT measurement require scheduler integration and a GPU host — both are explicitly called out as the follow-up work. This PR:
cacheslide(default off)Acceptance contract status (issue #85, 0/6 at submission)
paged_attention/block_hash.rs; Baseline B = identical workload throughsearch_for_matching_cache(strict prefix only). Seeexamples/cacheslide_shift_bench.rs— same 8-turn synthetic trace, baseline A achieves 0/896 block hits on shifted segments while segment directory achieves 14/14 hits.Honest scope note
The engine's current prefix cache uses parent-chained hashes (
block_hash::hash_block_tokens(parent, tokens, extra_keys)). Chain property guarantees uniqueness but means ANY position change invalidates ALL descendant block hashes.PrefixCacheManagerV2::search_for_matching_cacheexploits this: it only matches exact-token prefixes (shared_prefix_len). Agent workloads where system/tool segments are repeated at shifting positions fall outside this model completely.Our solution inserts a parallel path: the segment directory lives at the fabric level, is queried before falling back to raw prefill, and enforces all three HIP-1345 invariants (§1.1 salted key, §1.2 computed-tokens bound, §1.3 provenance fields — the latter two will be plumbed once the scheduler publishes them).
Run tests:
cargo test -p hanzo-kv-fabric. Run demo:cargo run --release -p hanzo-kv-fabric --example cacheslide_shift_bench.