Skip to content

[Fix] scheduler: Publish KV events on every decode step - #46258

Open
sohom-cs wants to merge 4 commits into
sgl-project:mainfrom
sohom-cs:fix/decode-kv-events-cadence
Open

sohom-cs wants to merge 4 commits into
sgl-project:mainfrom
sohom-cs:fix/decode-kv-events-cadence

Conversation

@sohom-cs

@sohom-cs sohom-cs commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

With --kv-events-config, a KV-aware router (sgl-router, or Dynamo) builds its view of each worker's cache from the BlockStored / BlockRemoved stream. During decode, the scheduler publishes that stream only every decode_log_interval steps (40 by default). Blocks inserted when a request finishes, and blocks evicted to make room for decode, reach the router up to 40 steps late, and a follow-up turn that arrives in that window is routed on a stale view.

Prefill publishes after every batch, so mixed workers partly hide this. PD decode workers run only decode batches, so they always lag.

Modifications

report_decode_stats called publish_kv_events() after its periodic early return, so 39 of 40 decode steps skipped it. The call now runs before that return, so every decode step publishes, as every prefill batch already does. On ranks without a publisher it is a no-op, and a step with no events costs one take_events() call.

Accuracy Tests

New case in test/registered/unit/observability/test_forward_pass_metrics.py: a real SchedulerKvEventsPublisher behind the metrics reporter, one queued event, one decode step that is not a log step.

  • main: AssertionError: Lists differ: [] != [[<object ...>]] (nothing published)
  • this PR: passes (the file: 34 passed)

CPU only. I have not measured the effect on a live router.

Speed Tests and Profiling

Not applicable: one extra queue drain per decode step, on the publishing rank only.

Checklist

Related: #44516 (decode cache affinity reads these events).

Developed with AI assistance (Claude); every changed line was reviewed and the tests were run locally by me.


CI States

Latest PR Test (Base): 🚫 Run #41528985096
Latest PR Test (Extra): ❌ Run #41528984971
Latest PR Test (AMD ROCm 10): ❌ Run #41528984894

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

KV-aware routers build their view of each worker's cache from the
BlockStored/BlockRemoved stream. During decode, publish_kv_events ran
only after the decode_log_interval early return in report_decode_stats,
so blocks stored when a request finished and blocks evicted by decode
allocation reached the router up to 40 steps late. PD decode workers
never run prefill batches, so they always saw this lag.

Flush the queue before the periodic return, as prefill already does.

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-24T05:58:45.034143Z
We couldn’t complete this review. Comment @codex review to try again.
a3cd250 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[BBuf Review Agent] LGTM. Please wait for the related CI.

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Nov 1, 2026
@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

…cadence

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
@sohom-cs
sohom-cs requested a review from BBuf November 2, 2026 03:48
@BBuf

BBuf commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@github-actions

This comment has been minimized.

@BBuf

BBuf commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] @sohom-cs the required lint check failed on code this PR does not touch, and a re-run reuses the old merge commit. Could you merge the latest main into this branch so it runs again?

  • lint: error: Failed to parse test/registered/unit/disaggregation/test_decode_queue_cleanup.py:177:13: Duplicate keyword argument \"tree_cache\"". This deterministic syntax error is in a file untouched by th

…cadence

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
@sohom-cs

sohom-cs commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged the latest main, so CI now runs on a fresh merge commit. The lint failure came from main itself (a repeated tree_cache= argument in test_decode_queue_cleanup.py, fixed on main since). test_forward_pass_metrics.py passes on the merge and fails with the metrics_reporter.py change reverted.

@BBuf

BBuf commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] @sohom-cs Confirmed the duplicate tree_cache came from main and is gone at this head after the merge. That lint failure is unrelated to this PR.

This branch has not been deployed

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

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants