Skip to content

fix(rust-server): Drain recv_from_rpc in rust-server mode - #33516

Closed
MortalHappiness wants to merge 2 commits into
sgl-project:mainfrom
MortalHappiness:fix/recv-from-rpc-never-drained-rust-server-mode
Closed

MortalHappiness wants to merge 2 commits into
sgl-project:mainfrom
MortalHappiness:fix/recv-from-rpc-never-drained-rust-server-mode

Conversation

@MortalHappiness

@MortalHappiness MortalHappiness commented Aug 4, 2026 •

Copy link
Copy Markdown

Motivation

Closes the "recv_from_rpc is never drained in rust-server mode" TODO item from #29799.

Rank 0's scheduler drains two input channels per event-loop iteration: the tokenizer channel (zmq PULL, scheduler_input_ipc_name) and the rpc channel (zmq DEALER, rpc_ipc_name, used only by the offline sgl.Engine's collective_rpc). SGLANG_RUST_SERVER replaces the first with an in-process ring and has no rpc equivalent, so the second has to keep working in both modes.

The rust branch was added at the top of _pull_raw_reqs and ends in return, which exits the whole function: it bypasses the tokenizer drain (intended) and the rpc drain below it (not intended). The socket is still created and wired into the receiver, but nothing reads it. The reply direction has the mirror problem: process_input_requests tested self.rust_server is not None before isinstance(output, RpcReqOutput), so the zmq reply branch was unreachable, and the Rust egress path it took instead asserts on a rust-minted rid that an rpc request arriving over zmq does not carry.

Modifications

In scheduler_components/request_receiver.py, the early return becomes an if/else, so rust mode bypasses only the tokenizer drain. The rpc loop body is unchanged.

In scheduler.py, process_input_requests now tests isinstance(output, RpcReqOutput) before the rust_server branch, so an rpc reply goes back down the DEALER pair instead of into the Rust egress ring. This is behaviour-preserving in zmq mode: there rust_server is None, so that branch was already reached.

The two are one fix: draining without the reorder would make the first rpc request in rust mode hit the rid assert and take the scheduler down, turning a silent hang into a crash.

Deliberately not changed

  • Idle wake-up. In rust mode the idle loop parks on the ring alone, so an rpc frame arriving at an idle scheduler waits out the 1s park timeout. No unified wait exists, since flume exposes no fd and zmq.Poller cannot watch the ring. The delay is bounded and documented in a comment at the drain, and it is negligible for the checkpoint exports that are its only in-tree callers.

Accuracy Tests

N/A

Speed Tests and Profiling

N/A

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #30952583076
Latest PR Test (Extra): ❌ Run #30952582600

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.


# The rpc channel is a bidirectional zmq DEALER pair with the

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.

Is this AI-generated code? Too many comments...

@MortalHappiness MortalHappiness Aug 4, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I'll shorter the comments and make the code more self-explantory. Thanks!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@hnyls2002 comments trimmed. Thanks.

Signed-off-by: Chi-Sheng Liu <chishengliu@chishengliu.com>
@rainj-me

rainj-me commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

@MortalHappiness , Let's review the scenarios that has to send request via rpc, and double check whether we can migrate to rust.

@MortalHappiness
MortalHappiness marked this pull request as draft August 5, 2026 00:47
@github-actions

Copy link
Copy Markdown
Contributor

Thanks @MortalHappiness. Closing this because it is still a draft and has not been updated in 52 days.

Reopen it if the work is still relevant.

Some directories moved recently, so an older branch may need retargeting:
sgl-kernel/ -> python/sglang/kernels/aot/, python/sglang/jit_kernel/
-> python/sglang/kernels/jit/, docs/ -> docs/docs/ (.mdx),
bench_serving.py -> benchmark/serving.py, test/srt/ -> test/registered/.

@github-actions github-actions Bot closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants