Skip to content

feat(mocker): publish native KV events from SGLang gRPC servers - #14744

Merged
jthomson04 merged 3 commits into
mainfrom
jthomson04/sglang-mocker-kv-events
Oct 2, 2026
Merged

jthomson04 merged 3 commits into
mainfrom
jthomson04/sglang-mocker-kv-events

Conversation

@jthomson04

@jthomson04 jthomson04 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The SGLang mock gRPC server does not advertise or publish KV events, so requests through its sidecar cannot update Dynamo's KV router. Connect the existing ZMQ sink to LiveEngineConfig and advertise the bound endpoint through GetServerInfo.kv_events. The real SGLang sidecar then relays stored and removed blocks through the shared event path.

Publish when prefix caching is enabled and the wire role is not decode. Bind an automatic port by default, honor explicit event and replay ports, and retain regular-mocker error-and-continue behavior on publisher bind failure. Construction remains synchronous and uses the active Tokio runtime. Normalize engine arguments before the server's role and single-rank checks. Share the existing vLLM store/eviction test helper with SGLang, retain default prefix caching in the existing SGLang tests, and document discovery, IPv4 binding, token payloads, and disabled-publisher behavior.

This PR uses the published dependency pins from main: Rust aisimulate-core=0.13.0-dev.202609300000000061 and Python aisimulate==0.13.0.dev202609300000000061. No dependency overrides or compatibility patches are required. The parent vLLM change (#14737) and AISimulate compatibility update (#14541) are merged.

Related Issues

  • Confirmed — no related issue.

Validation

Local validation for 4012dd74437efe25b41dc94415efa37216f28885, with builds and execution outside the sandbox:

  • cargo test --locked -p dynamo-sglang-mocker -p dynamo-vllm-mocker -p dynamo-sidecar-testkit --no-fail-fast: 42 passed (33 mock-server tests and 9 testkit tests). Includes default-prefix-caching generation, cancellation and handoff, both sidecar store/eviction tests, publication gates, and bind failure.
  • The one added regression test failed before the fix with single-rank create_engine does not support attention DP; use create_grouped_scheduler, then passed after normalization moved before the server checks. It now receives Mocker dp_size must be 1 for Rust-built arguments with canonical attention_dp=2; no model download or performance database was needed.
  • Rebuilt the SGLang mock-server binary with --locked. Reused the unchanged frontend bindings and sidecar binaries from the prior validation.
  • SGLang HTTP smoke: 2 cases, 34 successful completion requests, covering automatic and explicit event ports. Both cases observed router cache-hit rates 0% -> 100% -> 0% before caching, after caching, and after eviction. Native events contained both prompt blocks and a complete generated-token block; removal events contained both prompt hashes.
  • cargo fmt --all -- --check, pre-commit checks for the four changed files, and git diff --check: passed.

The HTTP smoke used one worker per case, a local tokenizer, speedup_ratio=1000, direct ZMQ events, and isolated etcd/NATS state in memory. These are CPU-only local results, not full repository CI, GPU validation, or a performance comparison.

Summary by CodeRabbit

  • New Features
    • The mock SGLang server can publish KV cache events when prefix caching is enabled, except in decode mode. Event details are shared through server discovery, and the sidecar can relay stored and evicted block events.
    • Event publishing can use an automatically selected or configured port, and can be disabled by turning off prefix caching.
  • Documentation
    • Added setup guidance for configuring event and replay ports, exposing ports, and handling cases where event publishing cannot start.

@github-actions github-actions Bot added feat documentation Improvements or additions to documentation labels Sep 11, 2026
@jthomson04
jthomson04 force-pushed the jthomson04/sglang-mocker-kv-events branch from 9add2a6 to 02a912d Compare September 11, 2026 23:28
Base automatically changed from jthomson04/mocker-grpc-kv-events to main September 16, 2026 15:55
@jthomson04
jthomson04 force-pushed the jthomson04/sglang-mocker-kv-events branch from 02a912d to f4e87cf Compare October 1, 2026 20:08
@pull-request-size pull-request-size Bot added size/L and removed size/XL labels Oct 1, 2026
@jthomson04
jthomson04 marked this pull request as ready for review October 1, 2026 20:09
@jthomson04
jthomson04 requested review from a team as code owners October 1, 2026 20:09
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: ai-dynamo/dynamo/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9361c7fb-82bd-4fa6-b999-3d98e03127c4

📥 Commits

Reviewing files that changed from the base of the PR and between 006e5f3 and f4e87cf.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • lib/mocker/servers/sglang/Cargo.toml
  • lib/mocker/servers/sglang/README.md
  • lib/mocker/servers/sglang/src/main.rs
  • lib/mocker/servers/sglang/src/server.rs
  • lib/mocker/servers/sglang/src/server_tests.rs
  • lib/mocker/servers/sglang/tests/sidecar.rs
  • lib/mocker/servers/tests/common/mod.rs
  • lib/mocker/servers/vllm/tests/sidecar.rs

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


Walkthrough

The SGLang mocker can publish ZMQ KV cache events when prefix caching is enabled in supported server modes. The server includes publisher metadata in discovery. Tests cover publisher bind failure and sidecar event relay for SGLang and vLLM.

Changes

KV event publishing

Layer / File(s) Summary
Publisher setup and discovery
lib/mocker/servers/sglang/Cargo.toml, lib/mocker/servers/sglang/src/main.rs, lib/mocker/servers/sglang/src/server.rs, lib/mocker/servers/sglang/README.md
The SGLang service binds a ZMQ KV event sink when applicable and passes it to LiveEngine::start_with_config. Discovery includes optional publisher metadata. Engine argument normalization now follows the existing configuration checks. The README documents event configuration and endpoint behavior.
Event behavior tests
lib/mocker/servers/sglang/src/server_tests.rs, lib/mocker/servers/sglang/tests/sidecar.rs, lib/mocker/servers/tests/common/mod.rs, lib/mocker/servers/vllm/tests/sidecar.rs
Tests check discovery across server modes and prefix-caching settings, confirm generation continues when publisher binding fails, and exercise sidecar event relay for SGLang and vLLM.

Priority: ⬇️ Low

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

Merge Risk: ⚪ Minimal · up to f4e87

The change adds KV event publication and discovery for supported SGLang modes while preserving serving when publisher setup fails. No merge-blocking issue is identified; merge after normal checks pass.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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 clearly and concisely describes the main change: publishing native KV events from SGLang gRPC mock servers.
Description check ✅ Passed The description explains the motivation, implementation, validation, and related-issue status. It does not use the template's Overview, Details, or reviewer-start headings, but it provides the require…
Full details: Docstring Coverage

Explanation

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

  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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

@jthomson04 jthomson04 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review notes on f4e87cf03d (static review; nothing was built or run):

  • Validation-order regression: with normalized() moved after the dp_size guard, AIS attention_dp > 1 configs now fail late with a misleading error.
  • KV publishing on by default: every SGLang mock server now binds an unauthenticated ZMQ PUB socket on 0.0.0.0 that streams prompt token IDs, and pays the token-ID encoding cost on the scheduler hot path even with no subscriber.
  • Smaller items: expect panics in a fallible constructor, IPv6 wildcard mismatch, explicit ports silently ignored, test coverage drift, and duplication with the vLLM server.

Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
Comment thread lib/mocker/servers/sglang/src/server.rs Resolved
@jthomson04
jthomson04 marked this pull request as draft October 1, 2026 21:07
@jthomson04
jthomson04 marked this pull request as ready for review October 1, 2026 21:14
@devin-ai-integration

devin-ai-integration Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Dynamo PR CI passed — run 36926942220 (attempt 2) on 4012dd7443

Gate checks: ✅ backend-status-check · ✅ deploy-status-check · ✅ dynamo-status-check

Posted automatically by Devin for run 36926942220. Updated on every full-CI run of this PR.

@dmitry-tokarev-nv dmitry-tokarev-nv 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.

Approve at 4012dd74437efe25b41dc94415efa37216f28885. I found no P0, P1, or P2 defect. One P3 is open.

[P3] The README does not say that the mock encodes KV events differently from SGLang. lib/mocker/servers/sglang/README.md:46. SGLang 0.5.19's own decoder rejects the mock's events, but Dynamo's router decodes both encodings. Please add one sentence about this to the KV events section.

Event encoding, measured with the SGLang 0.5.19 image and this head.

I sent live mock events to SGLang's own KVEventBatch decoder. As a control, the same decoder accepts an event that SGLang encodes.

Source Encoded BlockStored event SGLang typed decode
SGLang 0.5.19 ['BlockStored', [1, 2], None, [0, ..., 7], 4, None, None] OK
Mock at this head {'type': 'BlockStored', 'block_hashes': [...], 'parent_block_hash': None, 'token_ids': [600, ..., 607], 'block_size': 4, 'group_idx': 0} ValidationError Expected `array`, got `object` - at `$[1][0]`

The frames (topic, sequence, payload), the batch envelope ([ts, events, dp_rank]), and the descriptor keys match. The mock omits only the optional load-publisher keys. The mock sink uses named fields on purpose (see the test comment in lib/mocker/src/services/zmq_events.rs). Thus I do not ask for a new encoding. The new end-to-end test covers Dynamo's map decoder, not the positional path that real SGLang uses.

What I measured at this head, with base and merge controls.

All runs are on a GPU box with Rust 1.96.1 and cargo test --locked --all-targets for dynamo-sglang-mocker, dynamo-vllm-mocker, dynamo-trtllm-mocker, and dynamo-sidecar-testkit.

Tree Passed Failed
Merge base 006e5f340e 88 0
This head 92 0
This head merged into main e54dbaba29 92 0
This head merged into main 0a6f58b95d 92 0

The 4 extra tests are the new SGLang tests. The counts match the Pre Merge job.

  • Event path: sidecar_relays_stored_and_evicted_blocks passed 20 of 20 runs. A probe printed the relayed events. The stored event carries the router's own hashes of both prompt blocks, so the token IDs arrive. A later removed event names the same two block hashes. The sidecar replaces 0.0.0.0 with the --grpc-endpoint host.
  • Gates, with the server binary: decode mode and "enable_prefix_caching":false bind no publisher and leave the explicit port free. Prefill mode publishes. The server binds explicit event and replay ports.
  • Bind failure: the server logs ZMQ PUB bind to tcp://0.0.0.0:37605 failed: Zmq error: Address already in use and serves without KV events.
  • Automatic ports: two servers on one host got ports 37605 and 41331, each held by its own process. A collision needs an explicit port that another server already holds. That server then logs the error above and runs without events.
  • Arguments: 11 cases give the same result through the base and head binaries, except "block_size":4294967296. Head now rejects it at startup in aggregated and decode mode. A second normalized() call does not change deserialized arguments (5 cases). Thus the removed call in main.rs has no effect.
  • Mutations: I broke the decode gate, the prefix-caching gate, the advertised port, host, block size, and descriptor, and I moved or removed normalized(). Each of the 9 mutants fails at least one test. A wrong advertised port fails only the end-to-end test, after a 10 s timeout. Normalization after the checks gives single-rank create_engine does not support attention DP; use create_grouped_scheduler, as the PR body says.
  • Cargo.lock: both sides list the same 1052 packages. The 3 new entries are workspace crates. The --locked builds pass on every tree above.

Deferred by the author and documented in the README, so I did not reopen them: publishing on by default, the unauthenticated IPv4 0.0.0.0 bind, token-ID work without subscribers, and IPv4-only events. These match the merged vLLM mock server.

@jthomson04
jthomson04 merged commit 46d5fab into main Oct 2, 2026
211 of 214 checks passed
@jthomson04
jthomson04 deleted the jthomson04/sglang-mocker-kv-events branch October 2, 2026 17:28
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 feat size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants