Skip to content

fix(data-gen): reuse shared KV hashing for Mooncake IDs - #10095

Merged
PeaBrane merged 11 commits into
ai-dynamo:mainfrom
RitwijParmar:codex/data-gen-kv-hashing-contract
Jun 9, 2026
Merged

PeaBrane merged 11 commits into
ai-dynamo:mainfrom
RitwijParmar:codex/data-gen-kv-hashing-contract

Conversation

@RitwijParmar

@RitwijParmar RitwijParmar commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Part of #8997.

This removes one small source of hash-contract drift from dynamo-data-gen: RollingHashIdMapper::hash_token_blocks no longer reimplements its own local block + parent-chain hashing. It now derives sequence-aware hashes through dynamo-kv-hashing::Request::sequence_hashes and only keeps the existing data-gen responsibility of compacting stable sequence hashes into Mooncake hash_ids.

What changed:

  • dynamo-data-gen depends on dynamo-kv-hashing instead of bytemuck + dynamo-tokens
  • hash_token_blocks now uses the shared KV-hashing contract before compacting IDs
  • added try_hash_token_blocks so invalid block sizes can be surfaced without panicking
  • added regression coverage that compares token-block hashing against explicit Request::sequence_hashes
  • added coverage for the universal contract's trailing partial-block behavior

One behavior note: trailing partial token blocks are no longer assigned Mooncake IDs by the token helper, matching dynamo-kv-hashing's current complete-block-only contract. This is intentional here, but I called it out because it changes the old local helper's behavior.

Checks run locally:

  • cargo test -p dynamo-data-gen
  • cargo test -p dynamo-kv-hashing
  • cargo fmt --check --package dynamo-data-gen
  • cargo clippy -p dynamo-kv-hashing -p dynamo-data-gen --all-targets -- -D warnings
  • git diff --check

I also tried the nearby consumer test:

  • cargo test -p dynamo-bench agent_trace --test agent_trace

That did not reach the test phase locally because etcd-client's build script requires protoc, which is not installed in this local environment.

AI disclosure: I used AI assistance while editing and reviewing this patch, then ran the checks above locally.

Summary by CodeRabbit

  • New Features

    • Introduced new fallible token block hashing API with explicit error handling and input validation. Existing APIs remain available and now delegate to the new error-handling implementation.
  • Tests

    • Enhanced test suite with comprehensive coverage for token block hashing, including edge case validation, block-size constraint enforcement, and result consistency verification.

Review Change Stack

@RitwijParmar
RitwijParmar requested a review from a team May 28, 2026 18:11
@copy-pr-bot

copy-pr-bot Bot commented May 28, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi RitwijParmar! Thank you for contributing to ai-dynamo/dynamo.

Just a reminder: The NVIDIA Test Github Validation CI runs an essential subset of the testing framework to quickly catch errors.Your PR reviewers may elect to test the changes comprehensively before approving your changes.

🚀

@github-actions github-actions Bot added the external-contribution Pull request is from an external contributor label May 28, 2026
@coderabbitai

coderabbitai Bot commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

Walkthrough

Token-block hash ID generation in the data-gen crate migrates from local in-module hashing to the Dynamo KV hashing library. A new fallible try_hash_token_blocks API validates input and propagates errors; existing non-fallible helpers now delegate to this path and panic on failure. Test coverage extends to verify KV-hashing contract equivalence and edge cases.

Changes

Dynamo KV hashing migration

Layer / File(s) Summary
Dependencies and imports
lib/data-gen/Cargo.toml, lib/data-gen/src/mooncake.rs
dynamo-kv-hashing workspace dependency is added; module imports replace local hashing dependencies with dynamo_kv_hashing::Request.
Fallible hash API and KV-hashing integration
lib/data-gen/src/mooncake.rs
New RollingHashIdMapper::try_hash_token_blocks method and free function validate positive block size and use dynamo_kv_hashing::Request to derive sequence hashes from tokens, then map to stable compact ids; hash_token_blocks now delegates to the fallible path and panics on error; tests validate KV-hashing contract equivalence, empty input, trailing blocks, and zero block size rejection.
Public API re-export
lib/data-gen/src/lib.rs
try_hash_token_blocks is exported via the mooncake module re-export list.

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description check ✅ Passed The description covers all required template sections: overview (Part of #8997, explains the core change), detailed changes (dependency updates, implementation approach), reviewer guidance (mentions key file mooncake.rs), and related issues (closes #8997 implied).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main change: refactoring Mooncake hash ID generation to reuse the shared KV hashing implementation from dynamo-kv-hashing instead of a local implementation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/data-gen/src/mooncake.rs`:
- Around line 397-432: Add round-trip wire-format tests that verify
alias-to-canonical field name conversion for Mooncake: create one test that
deserializes a Mooncake wire-format input using aliased field names into Request
(use Request::builder() shape to know expected fields), then reserialize and
assert the output uses the canonical field names and matches the canonical
serialization; add a second test that does the same for canonical input to
ensure identity round-trip. Use the library's (de)serialization helpers
(serde_json::from_str/to_string or the crate's helpers) and also assert that
relevant derived values (e.g., Request::sequence_hashes(...) and
RollingHashIdMapper behavior) remain the same after the round trip.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9509f49f-c6c0-4979-8505-162a7b63e667

📥 Commits

Reviewing files that changed from the base of the PR and between c226999 and f41249d.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • lib/data-gen/Cargo.toml
  • lib/data-gen/src/lib.rs
  • lib/data-gen/src/mooncake.rs

Comment thread lib/data-gen/src/mooncake.rs Resolved
@RitwijParmar RitwijParmar changed the title Reuse shared KV hashing for Mooncake hash IDs fix(data-gen): reuse shared KV hashing for Mooncake IDs May 28, 2026
@github-actions github-actions Bot added the fix label May 28, 2026
Comment thread lib/data-gen/src/mooncake.rs Resolved
@pull-request-size pull-request-size Bot added size/L and removed size/M labels Jun 2, 2026
@RitwijParmar

Copy link
Copy Markdown
Contributor Author

I added follow-up coverage in 3e944cd for the Mooncake wire format that this PR touches.

The new tests cover both upstream alias input (input_tokens, output_tokens, created_time, delay_ms) and canonical input, then verify serialization emits only canonical fields and that the derived hash_ids stay stable through the round trip. I kept this on MooncakeRow because dynamo_kv_hashing::Request itself is not a serde wire type in this branch.

Validated locally:
cargo test -p dynamo-data-gen mooncake --lib -> 21 passed

@RitwijParmar

Copy link
Copy Markdown
Contributor Author

Small update: I amended the follow-up commit with DCO sign-off and force-pushed it as d56c339. The code/test content is the same; this is just to clear the DCO check.

@RitwijParmar

Copy link
Copy Markdown
Contributor Author

Fixed the partial-block capacity issue in 2d49173049.\n\nThe Mooncake helper still uses Request::sequence_hashes for complete blocks, but now appends one stable mapped key for a trailing partial block. That keeps hash_ids.len() at ceil(input_length / block_size), so generated replay rows don’t lose capacity for non-multiple prompt lengths.\n\nI also updated the regression from the old floor-block expectation and added an exact-boundary test so full-block prompts don’t get an extra ID.\n\nValidated locally:\n- cargo fmt --check --manifest-path lib/data-gen/Cargo.toml\n- cargo test -p dynamo-data-gen mooncake --lib -> 22 passed

@hhzhang16

Copy link
Copy Markdown
Contributor

/ok to test 2d49173

@PeaBrane PeaBrane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion on keeping partial-block hashing aligned with the existing rolling hash contract.

Comment thread lib/data-gen/src/mooncake.rs Resolved

@PeaBrane PeaBrane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One performance suggestion to avoid the additional full-prompt clone introduced by the shared hashing path.

Comment thread lib/data-gen/src/mooncake.rs Resolved
@RitwijParmar

Copy link
Copy Markdown
Contributor Author

Thanks, good catch. I ran cargo fmt --all and pushed the rustfmt-only cleanup in cb89db2635.

I also rechecked the relevant local commands before pushing:

  • cargo fmt --all --check
  • cargo clippy -p dynamo-data-gen --lib --tests -- -D warnings
  • cargo clippy -p dynamo-kv-hashing --lib --tests -- -D warnings
  • cargo test -p dynamo-data-gen mooncake --lib
  • cargo test -p dynamo-kv-hashing consuming_sequence_hashes_match_borrowed_path --test request_hashing

Will watch the rerun from here.

@PeaBrane

PeaBrane commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

/ok to test cb89db2

@PeaBrane
PeaBrane enabled auto-merge (squash) June 8, 2026 19:13
auto-merge was automatically disabled June 8, 2026 19:24

Head branch was pushed to by a user without write access

@RitwijParmar

Copy link
Copy Markdown
Contributor Author

I checked the new failure from rust-tests (.). It was not in the KV hashing/data-gen path; the failing test was agents::trace::record::tests::test_emit_request_end_sanitizes_non_finite_metrics.

The test subscribes to the shared trace bus and was accepting the first RequestEnd event it saw. In the full test shard it picked up another request-end record, so the timestamp assertion compared against a live wall-clock timestamp instead of this test’s 1000 value.

I pushed d85fdaf6b2 to make the test wait for its own request_id before asserting. Local checks I could run:

  • cargo fmt --all --check
  • cargo test -p dynamo-data-gen mooncake --lib
  • cargo test -p dynamo-kv-hashing consuming_sequence_hashes_match_borrowed_path --test request_hashing

I also tried the exact dynamo-llm test locally, but this machine is missing protoc, so etcd-client fails during build before the test binary is produced. CI has that dependency, so I’ll watch the rerun there.

@PeaBrane

PeaBrane commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

/ok to test d85fdaf

@PeaBrane
PeaBrane enabled auto-merge (squash) June 9, 2026 00:11

@PeaBrane PeaBrane left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requested hashing-contract, dependency-boundary, and consuming-path changes are addressed. Pre-merge Rust tests and clippy are green.

@PeaBrane
PeaBrane merged commit 57a6582 into ai-dynamo:main Jun 9, 2026
103 checks passed
Broduker pushed a commit to Broduker/dynamo that referenced this pull request Jun 12, 2026

This branch was previously deployed

1 inactive deployment
GITLAB — d85fdaf6 Deployed Jun 9, 2026 by copy-pr-bot[bot] via Trigger CI Pipeline #30542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contribution Pull request is from an external contributor fix size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants