Skip to content

[sgl-router] Serve chat completions through the policies_reorg resolver - #40279

Closed
sherlockwu wants to merge 1 commit into
router/policies-reorg-5-cachefrom
router/policies-reorg-6-switch
Closed

sherlockwu wants to merge 1 commit into
router/policies-reorg-5-cachefrom
router/policies-reorg-6-switch

Conversation

@sherlockwu

@sherlockwu sherlockwu commented Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

Sixth PR of the engine-selection redesign, on top of #40277. The server now routes every chat completion through the new resolver. The legacy policies module stays in the tree (its Policy trait, factory and helpers still compile) so this PR is only the switch; the removal and the _reorg rename follow.

Modifications

  • server/app_context.rs: AppContext::with_engine_state(config, tokenizers, proxy, registry, active_load, kv_index, prefix_index) builds Dependencies (affinity store with its sweeper, prefix source from the remote indexer or the local KV index, metrics) and BucketResolver from build_pools. AppContext::new is the four-argument convenience without engine state. The legacy policies, bucket_selector, prefix_index and radix_tree_prefix_provider fields are gone.
  • server/routes/chat.rs: classifies the deployment through PdPoolResolver to choose the first stage, builds one PickRequest with a shared LoadView and PrefixMemo, picks prefill then decode through ctx.buckets, and maps PickError onto the existing API errors and selection-failure metrics. Unknown models are 404 before tokenization.
  • main.rs no longer builds the legacy policy registry.
  • buckets_reorg::Pools carries needs_request_tokens and needs_dispatch_timestamps; Bucket keeps its pending-prefill budget so the affinity group applies each engine's own bucket budget (PendingPrefill is a per-engine map).
  • Metrics: AffinityPolicy records sgl_router_sticky_total outcomes for sticky; CacheAwarePolicy records cache admission evaluations and rejections and the cache-aware decision. Decision reasons use the legacy labels (assigned, remap, session_primary, sticky_hit, cache_candidate, no_cache_candidate).
  • Removed: policies/selection.rs, policies/decode.rs, their component test, tests/proxy/shared_prefill_admission.rs (it drove the legacy proposal and backup contract directly), the two indexer unit tests in chat.rs, and the CacheCandidatesExhausted failure reason.

Behavior change worth a look: with buckets, an engine that the affinity group rejected is evaluated again by its own size bucket, so sgl_router_cache_admission_rejected_total can count one request twice; the pending-prefill proxy test now asserts at least one rejection.

Checklist

  • cargo clippy --locked --workspace --all-targets -- -D warnings clean
  • cargo test --locked --workspace -- --skip parity_matrix passes (965 tests)

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): 🚫 Run #35411243786
Latest PR Test (Extra): 🚫 Run #35411243644
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

AppContext builds BucketResolver from ModelConfig over the shared state
(affinity store, load table, local or remote prefix source) and the chat
handler picks the prefill or plain engine, then the decode engine, through
it. The legacy selection ladder (policies/selection.rs, decode.rs) is
removed with its tests; the rest of the legacy module stays until the
removal PR. Sticky, session and cache metrics keep their legacy names.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions github-actions Bot added the npu label Sep 19, 2026
@sherlockwu

Copy link
Copy Markdown
Collaborator Author

Closing: the series stops at the power-of-two PR (#40271) for now.

@sherlockwu sherlockwu closed this Sep 19, 2026
@sherlockwu
sherlockwu deleted the router/policies-reorg-6-switch branch September 19, 2026 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant