Repository navigation
refactor(mesh): move tree path hashing out of mesh into kv-index - #1535
Conversation
`hash_node_path`, `hash_token_path`, and `GLOBAL_EVICTION_HASH` are tree-node identification helpers — they hash a string prefix or token sequence to identify a radix-tree node in the TreeSync wire format. They lived in the mesh crate as leftovers from the v1 cleanup (the v2 spec says "the mesh crate should have ZERO knowledge of trees, workers, policies, or routing"). Move them to `kv-index`, the crate that owns the radix-tree implementations they identify. Only consumer that actually computes hashes is `CacheAwarePolicy` in the gateway; it already imports `kv-index` for `Tree`, `TokenTree`, and friends, so the move adds no new dependency edges. The mesh-side TreeSync adapter never computed hashes — it just forwards the already-computed `node_hash` field on `TreeDelta` — so the mesh crate's public surface shrinks by three symbols with no functional change. Mesh crate keeps `blake3` as a workspace dependency for the unrelated replica_id derivation in `kv.rs`. Signed-off-by: Chang Su <8605658+CatherineSue@users.noreply.github.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThis PR migrates three hashing utilities ( ChangesHash Function Relocation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Clean refactoring — moves path hashing from mesh into kv_index where it logically belongs. File rename is 100% identical, all call sites updated, no stale references remain. blake3 dependency correctly added to kv_index/Cargo.toml. Doc comment in tree_sync.rs updated to reference the new location. LGTM.
There was a problem hiding this comment.
Code Review
This pull request relocates hashing utilities, specifically hash_node_path, hash_token_path, and the GLOBAL_EVICTION_HASH constant, from the mesh crate to the kv_index crate. The changes include adding the blake3 dependency to kv_index, creating the path_hash module, and updating all call sites within the model_gateway and mesh crates to point to the new location. I have no feedback to provide.
Description
Problem
crates/mesh/src/hash.rsexports three tree-node identification helpers —hash_node_path,hash_token_path, andGLOBAL_EVICTION_HASH— that hash a string prefix or token sequence to identify a radix-tree node in the TreeSync wire format. They lived in the mesh crate as leftovers from the v1 cleanup.The mesh v2 spec (
.claude/docs/mesh/mesh-v2-generic-kv.md) says explicitly:Tree-prefix hash helpers are by definition tree-specific. The mesh-side TreeSync adapter doesn't even use them — it forwards already-computed
node_hashvalues onTreeDeltawithout ever computing one. The only caller that actually computes hashes isCacheAwarePolicyin the gateway, which already depends onkv-indexfor the radix tree types these hashes identify.Solution
Move the three symbols to
kv-indexas a newpath_hashmodule, re-exported at the crate root so existingkv_index::hash_node_path(...)/kv_index::hash_token_path(...)call shapes match the priorsmg_mesh::hash_node_path(...)shape. No behavior change.Changes
crates/kv_index/Cargo.toml— addblake3workspace dependency.crates/kv_index/src/path_hash.rs— new module (moved verbatim fromcrates/mesh/src/hash.rs).crates/kv_index/src/lib.rs— register the module and re-export the three symbols at the crate root.crates/mesh/src/hash.rs— deleted.crates/mesh/src/lib.rs— drop thehashmodule declaration and the three re-exports.model_gateway/src/policies/cache_aware.rs— switch 12 call sites fromsmg_mesh::hash_*tokv_index::hash_*.model_gateway/src/mesh/adapters/tree_sync.rs— update one stale doc comment (smg_mesh::tree_ops::GLOBAL_EVICTION_HASH→kv_index::GLOBAL_EVICTION_HASH).Mesh crate keeps
blake3as a workspace dependency for the unrelatedreplica_idderivation inkv.rs:536.Test Plan
cargo test -p kv-index --lib path_hash— all 4 hash tests pass in their new home.cargo test -p smg-mesh --lib— 146 pass (4 fewer than pre-move because the tests moved with the file).cargo build -p smg-mesh -p smg— clean.cargo clippy --workspace --all-targets --all-features -- -D warnings— clean.Checklist
cargo +nightly fmtpassescargo clippy --all-targets --all-features -- -D warningspassestree_sync.rsdoc reference)Summary by CodeRabbit