Skip to content

[Fix] scheduler: Publish KV events while the engine is paused - #46334

Merged
BBuf merged 2 commits into
sgl-project:mainfrom
sohom-cs:fix/publish-kv-events-while-paused
Nov 2, 2026
Merged

BBuf merged 2 commits into
sgl-project:mainfrom
sohom-cs:fix/publish-kv-events-while-paused

Conversation

@sohom-cs

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

Copy link
Copy Markdown
Contributor

Motivation

An RL weight sync runs pause_generation in retract mode, then update_weights_* with flush_cache=True, then continue_generation. The flush queues AllBlocksCleared, but a paused scheduler never publishes KV events, so a KV-event router (sgl-router, or Dynamo) keeps that worker's whole pre-flush cache view for the entire sync and scores requests against blocks that no longer exist. The clear reaches the router only after resume.

#24003 added a publish at pause entry. It covers what was queued up to the pause, not what happens during it, such as the weight update's flush.

Found while following #24003's pause-time flush through a weight update.

Modifications

Every pausable event loop (normal, overlap, PD prefill, PD decode, MLX) calls _record_scheduler_state_for_paused_engine() on each paused iteration and skips on_idle. This adds one publish_kv_events() call to that helper, which covers the flush and anything else recorded while paused. The call does nothing on ranks without a publisher, and on an idle paused loop it only drains an empty queue.

Accuracy Tests

In test/registered/unit/managers/test_scheduler_pause_generation.py:

  • New case with a real RadixCache and publisher: pause (retract), flush_cache, one paused iteration, then AllBlocksCleared must have been published.

Results:

  • main: Lists differ: [] != ['AllBlocksCleared']
  • this PR: the file passes (29 passed)

CPU only, stub scheduler, Python tree core. I have not run it against a live router or an RL job.

Speed Tests and Profiling

N/A

Checklist

Related: #46258 (every decode step publishes; this PR covers the paused loop). #46307 edits the same paused-loop branch for a different reason; the two changes are independent.

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 #41272361376
Latest PR Test (Extra): ❌ Run #41272361479
Latest PR Test (AMD ROCm 10): ✅ Run #41272361313

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

The paused branch of every scheduler event loop skips on_idle, so events recorded while paused were only published after continue_generation. In the RL weight-update sequence (pause in retract mode, update weights with flush_cache, continue), the AllBlocksCleared from the flush therefore reached KV-event routers only after resume, and they kept routing against the old tree for the whole update. Publish from _record_scheduler_state_for_paused_engine, which every pausable loop calls on each paused iteration.

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-24T21:49:24.086303Z
We couldn’t complete this review. Comment @codex review to try again.
0cae88e 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.

@tejachavali tejachavali left a comment

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 fixes a real gap. A paused scheduler loop never reaches on_idle, so KV events recorded during the pause, like the AllBlocksCleared from a weight update flush, were held until resume while routers kept scoring against stale blocks. Adding the publish to _record_scheduler_state_for_paused_engine is the right place, since every paused loop already calls that helper. The new test is a genuine one: without the fix nothing drains the flushed event before the assertion.

One thing to confirm before merge: the PR test runs currently show as failed. Are those failures unrelated to this change? Otherwise I have no objections.

@sohom-cs

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Yes, they're unrelated: the PR has no run-ci label yet, so pr-gate fails by design and the *-finish jobs only report that; none of the test suites has run. Locally the new test fails on main and passes with the fix.

@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. Let's wait for the related CPU CI.

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

[BBuf Review Agent] Could you rebase this onto the latest main? It conflicts with main now.

@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

/tag-and-rerun-ci

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

sohom-cs commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Done: merged current main into the branch rather than rebasing, so the reviewed commit stays as it was. The only conflict was an import pair in test_scheduler_pause_generation.py. That file passes on the merge (30 passed); with the scheduler.py change reverted, test_cache_flush_while_paused_is_published_before_resume fails.

The CI run for this push may stop at pr-gate on my 120-minute author cooldown; I'll rerun it once that clears.

@sohom-cs

sohom-cs commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@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.

@BBuf

BBuf commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@sohom-cs
sohom-cs requested a review from BBuf November 2, 2026 03:48
@BBuf
BBuf merged commit acd6f55 into sgl-project:main Nov 2, 2026
346 of 376 checks passed
Yuxingwang-intel pushed a commit to Yuxingwang-intel/sglang that referenced this pull request Nov 6, 2026
…oject#46334)

Signed-off-by: Sohom Chakraborty <16609933+sohom-cs@users.noreply.github.com>
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.

3 participants