Repository navigation
Avoid implicit field-based side channel in Scheduler planning - #29408
Conversation
…h slots abort_request's "method 3" (aborting already-running requests) scanned only self.running_batch plus a stale self.cur_batch. Under pipeline parallelism the scheduler keeps per-microbatch-slot state in running_mbs[] / mbs[], and at abort time self.running_batch is aliased to just the current slot while self.cur_batch holds the previous step's batch. So an abort (or abort_all) only reached requests in the current slot and the previous one; requests decoding in any other slot's running_mbs (or still in flight in mbs) were never marked FINISH_ABORT and kept running to completion. This only manifests with more than two microbatch slots, since with two the current and previous slots already cover both. Fix: under PP, scan every running_mbs and mbs slot (id-deduped); the non-PP path keeps scanning running_batch + cur_batch as before. Add a scripted-runtime regression test (pp_size=4, pp_max_micro_batch_size=1) that forces one decode request into each microbatch slot and asserts abort_all releases all of them.
Two independent cur_batch reads are dropped/replaced, both behavior-preserving:
1. is_fully_idle: the `self.cur_batch is None or self.cur_batch.is_empty()` term
never changes the result.
- Under PP it is a subset of self._pp_microbatches_drained() (which scans every
running_mbs and mbs slot), so it is already covered.
- Without PP, every is_fully_idle caller runs at the top of the event loop
(flush, health check, weight update, pause), where self.cur_batch and
self.last_batch both hold the previous iteration's batch and are therefore
equal -- so the adjacent last_batch term already covers it.
Drop the redundant term.
2. abort_request: the non-PP branch reads self.last_batch instead of
self.cur_batch. abort runs at the top of the loop before the next batch is
assigned, so cur_batch still holds the previous iteration's batch and equals
last_batch -- the two reads are identical here.
…state `self.cur_batch` was a scheduler-wide attribute written by every event loop (normal, overlap, PP, disagg prefill/decode, MLX) but its only cross-thread reader is the watchdog, which uses it purely as a debugging signal (`is_active` / `dump_info`). All in-loop consumers can read the batch from a local instead. Rename the field to `cur_batch_for_debug` to make the watchdog its sole legitimate user, and stop every other site from depending on it: - `launch_batch_sample_if_needed` now takes the current batch as a parameter instead of reading `self.cur_batch`; all three callers pass their local `batch`. - The PP loops bind a local `cur_batch` and only mirror it into `cur_batch_for_debug` for the watchdog; `_pp_launch_batch` takes that local `cur_batch` as a parameter instead of reading `self.mbs[mb_id]`. Tests that poke the attribute directly are updated to the new name.
…thods First step of removing the hidden self.*_batch in/out channel from the scheduling decision tree: get_next_batch_to_run, is_disable_overlap_for_batch, process_prefill_chunk, and get_next_disagg_prefill_batch_to_run no longer read self.last_batch. Each takes last_batch as an explicit parameter, and every caller passes it (the event loops pass self.last_batch; PP passes the value it already loaded from its microbatch slot). The field stays on self for its other readers (pause, observers, invariant checker). Behavior-preserving.
Continue removing the hidden self.running_batch in/out channel, starting from the leaves of the decision tree: - get_new_batch_prefill / _get_new_batch_prefill_raw take running_batch and return (new_batch, running_batch); the MIXED-chunk reset now rebinds the local and is returned to the caller instead of overwriting self.running_batch. - _abort_on_running_timeout and get_new_prebuilt_batch take running_batch as a read-only parameter. Every caller (the decision-tree roots, the PP / disagg / pd-mux event loops, and the direct-call unit tests) passes self.running_batch and stores the returned value back. The roots still touch self.running_batch for their own logic; that is removed in the following commits. The dllm subtree (get_new_batch_dllm and its helpers) is experimental and not exercisable on the current hardware, so it is left intact behind a single running_batch sync at get_new_batch_dllm's entry rather than threaded through. Behavior-preserving.
…lf.running_batch get_next_batch_to_run now takes running_batch and last_batch as explicit parameters and returns a NextBatchPlan(batch_to_run, running_batch) struct; its body no longer reads or writes self.running_batch / self.last_batch. The MIXED chunked-prefill running reset and the decode update now flow out through the returned plan. Every caller (event_loop_normal, event_loop_overlap, the PP loop, the MLX overlap loop, and the direct-call unit tests) passes self.running_batch and stores plan.running_batch back to the field it owns (running_mbs[mb_id] for PP). The PP load/store of self.running_batch is kept so process_input_requests (e.g. pause) still sees the current microbatch's batch. NextBatchPlan is a msgspec.Struct defined in schedule_batch.py. Behavior-preserving.
…turn Black reformatting of the lines touched while threading running_batch, plus the test mock for get_new_batch_prefill now returns (None, running_batch) to match the method's new tuple return.
get_next_disagg_prefill_batch_to_run now takes running_batch and returns a NextBatchPlan; process_prefill_chunk takes running_batch. Neither reads self.running_batch anymore. The non-PP disagg prefill event loops store plan.running_batch back; the PP disagg prefill loop passes its microbatch-slot running batch into process_prefill_chunk and get_new_batch_prefill. Behavior-preserving.
get_next_disagg_decode_batch_to_run now takes running_batch and returns a NextBatchPlan; its body no longer reads or rebinds self.running_batch (the prebuilt-merge takeover and the decode update flow out through the plan). The non-PP disagg decode event loops and the PP disagg decode loop pass self.running_batch and store plan.running_batch back. Behavior-preserving.
…it params inspect the source of every batch decision method (get_next_batch_to_run, the prefill/decode roots, and their running/last-batch leaves) and assert it never references self.running_batch / self.last_batch / self.cur_batch, locking in the explicit-parameter contract. The dllm subtree and update_running_batch are intentionally out of scope and excluded from the list.
The other batch-decision methods (get_next_batch_to_run and the disagg analogues) already return a NextBatchPlan. get_new_batch_prefill returned a bare (batch, running_batch) tuple, forcing every caller to positionally unpack two values. Return the same NextBatchPlan struct so all decision methods share one interface and callers read named fields.
There was a problem hiding this comment.
Code Review
This pull request refactors the scheduler's batch decision-making methods to eliminate implicit state access via self by explicitly passing running_batch and last_batch as parameters and returning updates via a new NextBatchPlan struct. A guard test is also added to prevent future regressions. The review feedback points out that get_new_batch_dllm still assigns self.running_batch = running_batch, thereby re-introducing the implicit side-channel. The reviewer recommends refactoring this method to return a NextBatchPlan, updating its call site, and adding it to the guard test's list of checked methods.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| def get_new_batch_dllm( | ||
| self: Scheduler, running_batch: ScheduleBatch | ||
| ) -> Optional[ScheduleBatch]: | ||
| """Generate a new batch for DLLM (Diffusion LLM) scheduling.""" | ||
| self.running_batch = running_batch | ||
| if self.enable_priority_preemption: | ||
| self.running_batch.batch_is_full = False |
There was a problem hiding this comment.
The assignment self.running_batch = running_batch re-introduces the implicit field-based side channel on self that this PR aims to eliminate.
To maintain consistency with the rest of the scheduler refactoring:
- Refactor
get_new_batch_dllmto acceptrunning_batchand return aNextBatchPlaninstead ofOptional[ScheduleBatch](remember to importNextBatchPlanfromsglang.srt.managers.schedule_batch). - Replace all internal references to
self.running_batchwithrunning_batchwithin this method. - Add
get_new_batch_dllmtoDECISION_METHODSintest_scheduler_decision_batch_params.pyto ensure it is covered by the guard test.
| def get_new_batch_dllm( | |
| self: Scheduler, running_batch: ScheduleBatch | |
| ) -> Optional[ScheduleBatch]: | |
| """Generate a new batch for DLLM (Diffusion LLM) scheduling.""" | |
| self.running_batch = running_batch | |
| if self.enable_priority_preemption: | |
| self.running_batch.batch_is_full = False | |
| def get_new_batch_dllm( | |
| self: Scheduler, running_batch: ScheduleBatch | |
| ) -> NextBatchPlan: | |
| """Generate a new batch for DLLM (Diffusion LLM) scheduling.""" | |
| if self.enable_priority_preemption: | |
| running_batch.batch_is_full = False |
| if self.dllm_config is not None: | ||
| new_batch = self.get_new_batch_dllm() | ||
| new_batch = self.get_new_batch_dllm(running_batch) |
There was a problem hiding this comment.
Since get_new_batch_dllm should be refactored to return a NextBatchPlan (to avoid implicit side-channels and keep consistency with get_new_batch_prefill), we should update the call site here to unpack the plan and update running_batch explicitly.
| if self.dllm_config is not None: | |
| new_batch = self.get_new_batch_dllm() | |
| new_batch = self.get_new_batch_dllm(running_batch) | |
| if self.dllm_config is not None: | |
| dllm_plan = self.get_new_batch_dllm(running_batch) | |
| new_batch = dllm_plan.batch_to_run | |
| running_batch = dllm_plan.running_batch |
| SchedulerDisaggregationDecodeMixin.get_new_prebuilt_batch, | ||
| SchedulerDisaggregationDecodeMixin.get_next_disagg_decode_batch_to_run, |
There was a problem hiding this comment.
Once get_new_batch_dllm is refactored to remove references to self.running_batch, add it to DECISION_METHODS so that the guard test can enforce the "no hidden channel" invariant for the DLLM path as well.
SchedulerDisaggregationDecodeMixin.get_new_prebuilt_batch,
SchedulerDisaggregationDecodeMixin.get_next_disagg_decode_batch_to_run,
Scheduler.get_new_batch_dllm,|
/tag-and-rerun-ci |
|
/tag-and-rerun-ci extra |
The batch result processor already holds the failing `req`, yet it built a
synthetic `AbortReq(rid=req.rid)` and re-dispatched through the full rid-based
`abort_request` machinery, which scans every queue/batch only to relocate the
req in hand and finally set `to_finish` (abort "method 3"). Set
`req.to_finish = FINISH_ABORT()` directly, matching the idiomatic in-hand
termination used by the running-timeout abort.
For a single request this reproduces the exact net effect (only method 3 can
apply to an in-flight req). For `n > 1` parallel sampling, where rids are
`f"{rid}_{i}"`, it also avoids the `startswith` rid-prefix aliasing that could
over-abort sibling samples (e.g. aborting `R_3` would match `R_30`).
This removes the only mid-iteration caller of `Scheduler.abort_request`, which
now runs solely from the top-of-loop input path.
|
| # | Where | Code under test | Result | Link |
|---|---|---|---|---|
| 1 | This PR (op5) extra-a-test-1-gpu-large (1), attempt 3 |
op5 branch | FAIL — same ClientPayloadError, no coredump |
https://github.com/sgl-project/sglang/actions/runs/28936293209/job/86012773225 |
| 2 | Isolated single-test probe | upstream/main @ 2b3d9ad375 |
FAIL — Server process exited with code -7 (SIGBUS), 3 relaunches all SIGBUS |
https://github.com/sgl-project/sglang/actions/runs/28997593004 |
| 3 | Isolated single-test probe (repeat) | upstream/main @ 1c9eb6bb0b |
running — result will be posted as a reply | https://github.com/sgl-project/sglang/actions/runs/28998279442 |
Probes #2/#3 run only test_vlm_offline_throughput on the real 1-gpu-h100 runner (the 1-gpu-large mapping), so there is no 600s file-timeout or sibling-test confound.
Aggregate observed so far: 0 pass / 6 fail across the op5 branch (4) and clean main (2).
Why retry is not a fix here
The test framework already retries the whole server launch to its maximum, and every relaunch dies with SIGBUS. Adding a CI-level retry would burn more GPU time and still end red. This is a real, deterministic server crash that needs a code fix.
Suspected area (not yet bisected)
SIGBUS on the multimodal shared-memory path. The most suspicious recent main commits touching /dev/shm / SHM helpers:
- [CI] Reclaim leaked /dev/shm segments on server startup #28089 —
[CI] Reclaim leaked /dev/shm segments on server startup - Replace hasattr with isinstance in SHM feature helpers #29549 —
Replace hasattr with isinstance in SHM feature helpers
Happy to bisect main with the same ~4-minute single-test GPU probes to pin the exact introducing PR if that is wanted.
Probe #3 result: FAIL — Same failure family (VLM server dies → all client requests fail → Updated tally: 0 pass / 7 fail — op5 branch (4) + clean |
|
| # | Scope | Code under test | Result | Link |
|---|---|---|---|---|
| 1 | This PR (op5), extra-a-test-1-gpu-large (1) attempt 3 |
op5 branch | FAIL — ClientPayloadError, no coredump |
https://github.com/sgl-project/sglang/actions/runs/28936293209/job/86012773225 |
| 2 | Isolated single-test probe A | upstream/main @ 2b3d9ad375 |
FAIL — Server process exited with code -7 (SIGBUS), 3 relaunches all died |
https://github.com/sgl-project/sglang/actions/runs/28997593004 |
| 3 | Isolated single-test probe B | upstream/main @ 1c9eb6bb0b |
FAIL — server dies mid-benchmark, leaked SHM 93→118 | https://github.com/sgl-project/sglang/actions/runs/28998279442 |
Auditable count: 3 linked runs, 0 pass / 3 fail — of which 2 are on clean main (probes A & B), both FAIL. Probes A/B run only this test on the real runner, so there is no 600s file-timeout and no sibling-test confound.
Non-auditable additional observations (same fingerprint, but I did not retain individual run links): 3 more failing runs on the op5 branch and 1 earlier main probe. I mention these for context only — they are not part of the auditable count above.
Why "retry" is not a fix
The test framework already retries the whole server launch to its maximum, and every relaunch crashes. A CI-level retry would burn more GPU time and still end red. This is a real, deterministic server crash that needs a code fix.
Suspected area (not yet bisected)
SIGBUS on the multimodal shared-memory path. Most suspicious recent main commits touching /dev/shm / SHM helpers:
- [CI] Reclaim leaked /dev/shm segments on server startup #28089 —
[CI] Reclaim leaked /dev/shm segments on server startup - Replace hasattr with isinstance in SHM feature helpers #29549 —
Replace hasattr with isinstance in SHM feature helpers
Can bisect main with the same ~4-minute single-test GPU probes to pin the exact introducing PR on request.
Prior comments in this thread: #29408 (comment) · #29408 (comment)
|
cc @yhyang201 - that test is temp disabled |
The Qwen2.5-VL server dies with SIGBUS (exit code -7) shortly after startup, deterministically, on plain upstream/main — unrelated to this refactor chain. No CUDA coredump is produced (host-side shared-memory fault on the multimodal /dev/shm path). The harness already retries the server launch to its max and every relaunch crashes, so a retry cannot green it. Skip until the underlying main crash is fixed.
|
all tests passed |
# Conflicts: # python/sglang/srt/disaggregation/decode.py
…ler-batch-field/op5
# Conflicts: # python/sglang/srt/disaggregation/decode.py
# Conflicts: # python/sglang/srt/managers/schedule_batch.py # python/sglang/srt/managers/scheduler.py # test/registered/unit/managers/test_scheduler_pause_generation.py
# Conflicts: # python/sglang/srt/managers/scheduler.py # test/registered/unit/managers/test_scheduler_pause_generation.py
# Conflicts: # python/sglang/srt/managers/scheduler.py # test/registered/unit/managers/test_scheduler_pause_generation.py
…fill has not returned Three boots of forensics land on one invariant. A request that has never produced an output token has nothing to decode from, and decoding it anyway is what has been killing this window's boots on their first short prompt. The chain, measured end to end: get_next_batch_to_run makes a freshly built PREFILL batch the running batch in the same breath. Upstream that holds -- without PP the prefill runs in the same round, so output_ids is non-empty by the time update_running_batch sees it. The seam is stock, every commit touching it is an upstream PR (sgl-project#29408, sgl-project#22131, sgl-project#20343, sgl-project#14320, sgl-project#17484, sgl-project#14883), none of ours, so there is nothing to revert. PP=3 widens it: the result comes back several passes later while membership was granted immediately, and with one short request and no other traffic the next round has nothing else to do and decodes it first. prepare_for_decode then leaves the prefill input_ids in place -- there is no last token to embed -- and the batch travels on labelled DECODE while carrying extend tokens. Boot 67 read every link: rid e463acc5, prefix_lens=0 fill_lens=3 out_lens=0, one ADMIT, no retraction, and no void at all (797_void=0, 798_void=0, so the void explanation is excluded). It surfaced first as forward_mode=2 with batch_size=1 and input_ids=3 through the sgl-project#1007 probe, then as "causal_conv1d_update: conv_state_indices has 1 entr(ies) for a batch of 3". Every short prompt does this, health checks included; long chunked prompts under continuous load never reach the state, which is exactly why it stayed latent behind every other defect this window. So the hold sits where decode eligibility is decided, not on a consumer. The requests are neither dropped nor reset: they stay in the running batch and become eligible the moment their prefill result lands, and filter_batch's keep_indices keeps the parallel tensors consistent rather than reseating reqs by hand. The counter is cumulative on purpose (INDIKATOR-GESETZ): a held_total that never grows means the class no longer occurs, one that grows without bound means results are not landing at all. Those are different diagnoses and a per-call line could not tell them apart. Evidence: desk, executed. py_compile; the condition sits inside update_running_batch ahead of prepare_for_decode, and the counter is written once and read twice. Belegstufe: DESK-BEWIESEN -- BOOT-BEWIESEN only once the 3-token probe returns tokens.
get_next_batch_to_runand its callee tree (plus the disaggregation analoguesget_next_disagg_prefill_batch_to_run/get_next_disagg_decode_batch_to_runand their trees) usedself.cur_batch/self.last_batch/self.running_batchas an implicit in/out side channel. This PR makes those reads and writes explicit: the batch state is passed in as parameters and returned out via aNextBatchPlanstruct. The fields stay onself(they have legitimate readers elsewhere), but the planning methods no longer touch them.get_next_batch_to_run(running_batch, last_batch) -> NextBatchPlan; callers storeplan.running_batchback and runplan.batch_to_run.get_new_batch_prefill, the disagg roots) threadrunning_batchin and out the same way;get_new_batch_prefillreturns aNextBatchPlanlike the others.test_scheduler_decision_batch_params.py) asserts viainspect.getsourcethat these methods take the batches as explicit parameters and contain noself.running_batch/self.last_batch/self.cur_batchtoken — turning "no hidden channel" into an executable invariant.Mental model: the scheduler's core will eventually be split out (e.g. a stateless
SchedulerPlanner); this removes the hidden coupling that would make such a split leakself.*access.No behavior change: the event loops still own the fields and update them every iteration from the returned plan.
Equivalence audit
Verified behavior-preserving by an independent read-only Codex audit (verdict: PROVEN). It confirmed that for every changed signature the caller passes the same value previously read from
self.*and writes the returnedrunning_batchback to the same field at the same point in the loop — including the PPrunning_mbs[mb_id]slots, the disagg prefill/decode trees, and the MLX/pd-mux paths — and that no returned plan is dropped.Known residual (not a behavior change): the DLLM prefill helpers (
dllm/mixin/scheduler.py) still readself.running_batchinternally after assigning it, so that branch is outside the guard test's scope. Codex confirmed it mutates the sameScheduleBatchobject without rebinding, so behavior is unchanged; fully threading it is a follow-up.CI States
Latest PR Test (Base): 🚫 Run #29061151142
Latest PR Test (Extra): 🚫 Run #29061150984