Skip to content

[sgl-router] refactor - move policy-required states under src/state - #40272

Merged
sherlockwu merged 7 commits into
mainfrom
router/policies-reorg-0-state-move
Sep 20, 2026
Merged

sherlockwu merged 7 commits into
mainfrom
router/policies-reorg-0-state-move

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Move the routing state required by policies to make routing decisions into src/state/. This includes load monitoring, KV events, and affinity stores such as session state.

Stack: main → #40272 (shared state) → #40241 (bucket routing and power-of-two) → #40379 (session-aware) → #40366 (cache-aware) → #40271 (admission) → #40292 (SLO ordering).

Changes

  • Move the KV-event index to state::kv_events and load monitoring to state::load_monitor.
  • Distinguish engine-published measurements (engine_reported_load) from router-local request accounting (router_inflight_load).
  • Extract worker-ID bindings, idle expiry, and concurrent binding updates into AffinityStore. Sticky routing reuses eligible bindings during concurrent first touches; session-aware routing retains its final-selection commit behavior.
  • Sticky routing now identifies workers by discovery WorkerId instead of URL. Static discovery uses the URL as the ID, so nothing changes there; on Kubernetes the ID is the pod UID, so a replaced pod at the same address is remapped instead of reused, since the new pod has no warm cache.

Validation after rebase

Rebased the stack onto main (95521da18d) after #39867 merged. All 31 commit patches and each PR's router tree are unchanged. Formatting and diff checks pass after this rebase. Clippy and workspace tests passed on the identical router tree in the previous rebase: 1,100 passed, with two Hugging Face cache-dependent parity tests excluded.

PR-specific validation from the unchanged router trees:

  • cargo +nightly fmt --all -- --check
  • cargo +1.92 clippy --locked --workspace --all-targets -- -D warnings
  • cargo +1.92 test --locked --workspace -- --skip parity_matrix: 1,037 tests passed. Two Hugging Face cache-dependent parity tests excluded.

CI States

Latest PR Test (Base): ✅ Run #35541557061
Latest PR Test (Extra): ❌ Run #35541556949
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

@github-actions github-actions Bot added the npu label Sep 19, 2026
@sherlockwu
sherlockwu force-pushed the router/policies-reorg-0-state-move branch from 399af99 to 85c6702 Compare September 19, 2026 01:06
@sherlockwu
sherlockwu added this pull request to stack #40280 September 19, 2026 01:09
@sherlockwu sherlockwu changed the title [sgl-router] Move shared selection state into src/state [sgl-router] refactor - move states for policy decisions into src/state Sep 19, 2026
@sherlockwu
sherlockwu removed this pull request from stack #40280 September 19, 2026 17:34
@sherlockwu
sherlockwu added this pull request to stack #40368 September 19, 2026 17:34
@sherlockwu sherlockwu changed the title [sgl-router] refactor - move states for policy decisions into src/state [sgl-router] refactor - group policy-required states under src/state Sep 19, 2026
@sherlockwu
sherlockwu removed this pull request from stack #40368 September 19, 2026 20:40
@sherlockwu
sherlockwu added this pull request to stack #40380 September 19, 2026 20:40
@sherlockwu
sherlockwu marked this pull request as ready for review September 19, 2026 22:49
@sherlockwu
sherlockwu force-pushed the router/policies-reorg-0-state-move branch from dfe320f to a889213 Compare September 19, 2026 22:53
@sherlockwu sherlockwu changed the title [sgl-router] refactor - group policy-required states under src/state [sgl-router] refactor - move policy-required states under src/state Sep 19, 2026
@sherlockwu
sherlockwu force-pushed the router/policies-reorg-0-state-move branch from a889213 to 5ccb03e Compare September 20, 2026 00:04
An error occurred while trying to automatically change base from codex/refactor-router-config to main September 20, 2026 11:40

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

Safe and correct, only need a rebase.

@github-actions github-actions Bot added documentation Improvements or additions to documentation quant LLM Quantization dependencies Pull requests that update a dependency file deepseek blackwell SM100/SM120 diffusion SGLang Diffusion labels Sep 20, 2026
@sherlockwu
sherlockwu removed this pull request from stack #40380 September 20, 2026 17:28
@sherlockwu
sherlockwu changed the base branch from codex/refactor-router-config to main September 20, 2026 17:28
@sherlockwu
sherlockwu added this pull request to stack #40484 September 20, 2026 17:28
sherlockwu and others added 7 commits September 20, 2026 22:23
Pure relocation: kv_events/ becomes state/kv_events/, and engine_load.rs
and active_load.rs become state/load_monitor/{engine_load,active_load}.rs.
Every import path follows; no code changes. This gives the legacy policies
and the upcoming policies_reorg one home for the signals they both read.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…policies

Both policies kept the same private state: a map of key to assigned worker
with a last-seen instant, a clock, an idle window and a sweep. That state
becomes state::AffinityStore, keyed by WorkerId, and both policies hold an
Arc to it. Two small semantic tightenings: sticky pins by worker id rather
than URL, and a racing first touch for one key converges on the binding
that is still a candidate instead of last-writer-wins.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Rename engine-published measurements to engine_reported_load and
router-local request accounting to router_inflight_load. Make
AffinityStore::sweep_expired return the number of entries it removed
instead of a length delta, which under-counted when requests inserted
keys during the sweep.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sherlockwu
sherlockwu force-pushed the router/policies-reorg-0-state-move branch from f8aed5b to dbb8cd6 Compare September 20, 2026 22:23
@sherlockwu
sherlockwu merged commit 4a9dc5c into main Sep 20, 2026
98 of 103 checks passed
@sherlockwu
sherlockwu deleted the router/policies-reorg-0-state-move branch September 20, 2026 23:49
ighutake-debug added a commit to ighutake-debug/sglang that referenced this pull request Sep 28, 2026
…ection path

Fixes sgl-project#32752: the counter was defined, rendered, documented, and unit
tested, but no production route ever called record_decode_affinity, so
live PD deployments never reported decode-affinity outcomes.

- select_decode_with_affinity now returns the branch taken alongside
  the worker (same_host_picked / fallback_breaker /
  fallback_load_imbalance / new fallback_no_same_host for pools with no
  co-located peer)
- LegacyHostAffinityDecodePolicy tags its SelectionProposal with the
  outcome; select_decode_peer records it once per successful selection
  via a metrics handle on DecodeSelectionInputs (None in tests, the
  shared registry in the chat route)
- a capacity-fallback override of the affinity pick records
  fallback_load_imbalance, since the affinity was not honored
- plain-mode requests and failed selections record nothing, per the
  issue's expected behavior

Rebuilt on current main after the sgl-router state/bucket refactors
(sgl-project#40241, sgl-project#40272) — the previous branch auto-merged cleanly but produced
unparsable code in the merge tree, which is what lint caught.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 deepseek dependencies Pull requests that update a dependency file diffusion SGLang Diffusion documentation Improvements or additions to documentation npu quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants