Skip to content

fix(kv-router): decode SGLang BlockStored metadata in positional KV events - #14530

Closed
ishandhanani wants to merge 1 commit into
mainfrom
idhanani/dyn-sglang-blockstored-metadata-decode
Closed

ishandhanani wants to merge 1 commit into
mainfrom
idhanani/dyn-sglang-blockstored-metadata-decode

Conversation

@ishandhanani

@ishandhanani ishandhanani commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • SGLang >= 0.5.18 emits BlockStoredWithMetadata (feat: add cache salt support to KV cache events sgl-project/sglang#30827): the vLLM-compatible positional prefix plus a BlockStoredMetadata map at position 7 whenever the stored node carries a cache_salt. feat(agent sessions): attribute stored KV cache blocks to sessions sgl-project/sglang#37482 adds session_id to the same map.
  • Dynamo's positional decoder read position 7 as vLLM's lora_name: Option<String>. Every such event failed with invalid type: map, expected a string, and apply_live_batch in services/indexer/listener.rs dropped the whole ZMQ batch. Co-batched unsalted events were lost too, so the router index silently diverged from the engine. No error reached the client.
  • This change accepts either a string or a map at position 7, maps cache_salt to the cache namespace like the named-map path already does, and ignores keys the raw event does not model yet (session_id), so the event and its batch decode.
  • Not triggered in shipped configurations today: neither the Rust SGLang sidecar nor the Python dynamo.sglang worker forwards cache_salt. It becomes live with sglang#37482 plus session-id forwarding (feat(sglang): support session-attributed KV events #14144), or with any cache_salt support for SGLang. Backport candidate for release/1.5.0, which has the same decoder and pins SGLang 0.5.18.
  • Updates lib/kv-router/src/zmq_wire/README.md with the SGLang shape.

Validation

  • cargo test -p dynamo-kv-router --lib zmq_wire: 62 passed, including 4 new tests (metadata map decode, unknown keys plus empty salt, lora_name string unchanged, whole-batch decode).
  • cargo clippy -p dynamo-kv-router --tests -- -D warnings and cargo fmt --all -- --check: clean.
  • Reproduced the failure first with the same fixture against main: invalid type: map, expected a string for both the cache_salt-only map and the session_id map; the legacy shape decoded.
  • Observed end to end on an 8xH100 SGLang + Dynamo stack (SGLang at sglang#37482, session ids forwarded through the sidecar): every session-attributed batch logged Failed to decode KvEventBatch and the KV index stayed empty (0 cached tokens on every turn) until this change.

Summary by CodeRabbit

  • New Features

    • Added support for processing SGLang positional cache metadata, including cache salts and optional session information.
    • Continued support for vLLM adapter names in positional events.
    • Unknown metadata fields and empty cache-salt values are handled safely.
  • Documentation

    • Updated positional-event documentation to describe vLLM and SGLang formats and producer behavior.
  • Tests

    • Added coverage for SGLang metadata decoding, fallback behavior, and mixed event batches.

…vents

SGLang >= 0.5.18 emits BlockStoredWithMetadata (sgl-project/sglang#30827):
the vLLM-compatible positional prefix plus a BlockStoredMetadata map at
position 7 whenever the stored node carries a cache_salt. The positional
decoder read that slot as vLLM's lora_name string, so every such event
failed with "invalid type: map, expected a string" and the listener dropped
the whole ZMQ batch, including co-batched unsalted events. The router index
then silently diverged from the engine.

Accept either a string or a map at position 7, map cache_salt to the cache
namespace like the named-map path does, and ignore keys the raw event does
not model yet (sgl-project/sglang#37482 adds session_id). Document the shape
in the wire README.

Signed-off-by: Ishan Dhanani <[email protected]>
@ishandhanani
ishandhanani requested a review from a team as a code owner September 9, 2026 07:17
@copy-pr-bot

copy-pr-bot Bot commented Sep 9, 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 github-actions Bot added fix documentation Improvements or additions to documentation labels Sep 9, 2026
@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 5263b8d5-9a97-44bb-957a-71a0d12330d2

📥 Commits

Reviewing files that changed from the base of the PR and between 10ecc28 and 1b9a751.

📒 Files selected for processing (3)
  • lib/kv-router/src/zmq_wire/README.md
  • lib/kv-router/src/zmq_wire/deserialize.rs
  • lib/kv-router/src/zmq_wire/tests.rs

Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review.


Walkthrough

The ZMQ wire deserializer now accepts SGLang BlockStoredMetadata maps at positional field 7, preserves vLLM lora_name support, and uses non-empty cache_salt values for cache namespace resolution. Documentation and regression tests cover the behavior.

Changes

ZMQ wire SGLang metadata support

Layer / File(s) Summary
Decode metadata and resolve cache namespace
lib/kv-router/src/zmq_wire/deserialize.rs
Positional BlockStored field 7 accepts either a vLLM lora_name string or an SGLang metadata map. Non-empty cache_salt values take precedence over legacy namespace derivation.
Document and test metadata compatibility
lib/kv-router/src/zmq_wire/README.md, lib/kv-router/src/zmq_wire/tests.rs
Documentation describes SGLang metadata fields and compatibility rules. Tests cover cache-salt extraction, ignored keys and empty values, vLLM strings, and salted event batches.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 1b9a7

KV-router now accepts SGLang metadata-map events while retaining vLLM compatibility and routes non-empty cache salts into cache namespaces. The covered decoding and namespace behavior presents no remaining merge-blocking risk.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the problem, implementation, impact, and validation results, but it does not use the required template sections and omits the required Related Issues declaration and the Where… Add the required Overview, Details, Where should the reviewer start, and Related Issues sections. In Related Issues, either provide the issue reference or check the confirmation that no related issue exists.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: decoding SGLang BlockStored metadata in positional KV events.
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.
Full details: Description check

Explanation

The description explains the problem, implementation, impact, and validation results, but it does not use the required template sections and omits the required Related Issues declaration and the Where should the reviewer start section.

Full details: Docstring Coverage

Explanation

Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 2 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

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

}
}

/// The listener decodes a whole `EventBatch` at once, so one salted SGLang event

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This batch-level case is redundant with the added positional SGLang metadata decoder test: decode_event_batch is only rmp_serde::from_slice, so the salted event failure is distinguished by test_deserialize_sglang_positional_block_stored_metadata_map and the batch envelope is already exercised by an existing selected decode_event_batch test. Removing this case still leaves the SGLang metadata map contract and the EventBatch decoding boundary protected.

🤖 AI Fix

Remove test_decode_event_batch_with_sglang_metadata_event and rely on the direct SGLang metadata deserialization test plus the existing batch decode coverage.

}
}

/// SGLang's typed `BlockStoredMetadata` map. Since SGLang 0.5.18 a positional

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This repeats the version and issue history already recorded in the adjacent wire-format README. Retain only the lasting forward-compatibility constraint: this metadata preserves cache_salt and ignores unmodeled keys.

🤖 AI Fix

Condense this doc comment to the metadata's cache_salt and unknown-key compatibility behavior.

}
}

/// SGLang >= 0.5.18 appends its `BlockStoredMetadata` map at position 7 when the

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The test name, positional fixture, and assertions already document this compatibility case; the version and issue reference add implementation history without a lasting constraint.

🤖 AI Fix

Remove this test doc comment.

}
}

/// Keys the raw event does not model yet (sgl-project/sglang#37482 adds

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This merely narrates the unknown-key and empty-value fixture that the test name and assertions make explicit.

🤖 AI Fix

Remove this test doc comment.

}
}

/// The vLLM `lora_name` string at position 7 still decodes as before.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This restates the test name and its single lora_name assertion.

🤖 AI Fix

Remove this test doc comment.

}
}

/// The listener decodes a whole `EventBatch` at once, so one salted SGLang event

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The decode_event_batch call and test name establish the batch-level coverage; "used to drop" is bug history rather than a lasting constraint.

🤖 AI Fix

Remove this test doc comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation fix size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant