Skip to content

[Disagg] Validate state strides before Mooncake transfers - #41607

Merged
ShangmingCai merged 1 commit into
sgl-project:mainfrom
aurickq:codex/pd-state-stride-validation
Oct 1, 2026
Merged

ShangmingCai merged 1 commit into
sgl-project:mainfrom
aurickq:codex/pd-state-stride-validation

Conversation

@aurickq

@aurickq aurickq commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Why is this change needed?

Mooncake receives destination entry sizes during registration, but its generic state-transfer path uses the prefill entry size for both destination addressing and copy length without checking the decode stride. A mismatch can therefore submit a successful transfer to the wrong slot. For example, with a 32-byte prefill entry and a 64-byte decode entry, destination slot 5 is addressed at offset 160 instead of 320, and only 32 bytes are copied.

Forward the existing destination-size metadata and validate mapped strides before submitting the state transfer. Reuse the existing layer-ID and pipeline-stage mapping, including grouped C4 state. Compatible layouts retain their existing transfer plan; the wire format is unchanged.

On a stride mismatch, log the precise cause and mark only the affected request KVPoll.Failed through conclude_failure. Stop its remaining state and auxiliary writes, then run the existing worker cleanup. The session is not blacklisted for this validation failure; actual transport failures retain their existing handling.

Related: #25036 describes speculative/non-speculative compressor-ring layouts differing between prefill and decode.

Test Plan

  • Red → green: the worker regression has four mismatch/cleanup cases that fail on unmodified upstream main and on the earlier exception-based guards. All six cases pass with request-only failure; the two transport-error controls pass in every version.
  • Full CPU wire-test module plus four related PP and Mooncake batching modules passed.
    PYTHONPATH=python python -m pytest -q \
      test/registered/unit/disaggregation/test_disaggregation_wire.py \
      test/registered/unit/disaggregation/test_pp_hybrid_kv_transfer.py \
      test/registered/unit/disaggregation/test_pp_mla_kv_transfer.py \
      test/registered/unit/disaggregation/test_mooncake_transfer_batching.py \
      test/registered/unit/disaggregation/test_mooncake_custom_mem_pool_batch.py
  • Rejection tests cover positional and layer-ID entries and assert that no transfer is submitted on a mismatch. Matching-layout tests cover ordinary PP slicing and grouped C4 slicing, checking the generated destination addresses.
  • Worker regression covers both positional and layer-ID mismatches, concurrent request cleanup, and actual transport errors. It checks failure notification, exact local diagnostics, no remaining writes for the rejected request, no session blacklist on mismatch, and progress on the next request.
  • Upstream pre-commit checks passed on both changed files.
  • Transport is mocked. No GPU inference or throughput benchmark was run. The checks inspect CPU metadata during state handoff and add no GPU operations or wire payload.

CI States

Latest PR Test (Base): ✅ Run #36791844810
Latest PR Test (Extra): ⚠️ Not enabled -- add run-ci-extra label to opt in.
Latest PR Test (AMD ROCm 10): ❌ Run #36791844758

@aurickq

aurickq commented Sep 29, 2026

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Sep 29, 2026
@aurickq
aurickq force-pushed the codex/pd-state-stride-validation branch from ca8703e to a63ef02 Compare September 30, 2026 22:38
@aurickq aurickq changed the title [Disagg] Validate state strides before NIXL and Mooncake transfers [Disagg] Validate state layouts without stopping Mooncake workers Sep 30, 2026
@aurickq
aurickq force-pushed the codex/pd-state-stride-validation branch from a63ef02 to ca8703e Compare September 30, 2026 22:43
@aurickq aurickq changed the title [Disagg] Validate state layouts without stopping Mooncake workers [Disagg] Validate state strides before NIXL and Mooncake transfers Sep 30, 2026
@aurickq
aurickq force-pushed the codex/pd-state-stride-validation branch 3 times, most recently from 1098ba7 to 28e790d Compare September 30, 2026 23:18
@aurickq aurickq changed the title [Disagg] Validate state strides before NIXL and Mooncake transfers [Disagg] Validate state strides before Mooncake transfers Sep 30, 2026
@aurickq
aurickq force-pushed the codex/pd-state-stride-validation branch from 28e790d to bf4ed94 Compare September 30, 2026 23:35

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

Looks good. We could merge this one first, I will try to make a following PR to see whether we could turn this from per-request level check to per-PD-pair level check.

@ShangmingCai ShangmingCai added the highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed label Oct 1, 2026
@ShangmingCai
ShangmingCai merged commit 1a0250c into sgl-project:main Oct 1, 2026
184 of 200 checks passed
LinyuanLi0046 added a commit to LinyuanLi0046/sglang that referenced this pull request Oct 19, 2026
Port existing community lifecycle code onto b85c644.
Fixed upstream source: 0dc6de2.

Keep generation-tagged ABORT/ACK state across sender cleanup, count dequeued
and in-flight transfers, drain running transfer futures, poison uncertain
native failures, and retain decode KV plus metadata until ACK or the
community device-destination timeout. Resolve held releases before decode
scheduling gates and account for them in scheduler idle checks. Complete
the existing cached-prefix event handoff through the worker. Use shared
terminal-status helpers and socket locks for failure fanout and to prevent
Success after cancellation.

Migrated upstream implementations and provenance:
- 97dedd1 (sgl-project#35049): device deferred
  release, ACK tracking, future draining and worker drain integration.
- adca19c (sgl-project#35360): common ACK helpers,
  unique prefill rank and dequeue-before-status accounting.
- 8ef6d31 (sgl-project#40645): preserve pending
  drain ACK targets across sender cleanup.
- cd11037 (sgl-project#41023): default-on setting
  and explicit backend capability gate.
- 14ab74e (sgl-project#41402): ACK endpoint fanout.
- 2a1c477 (sgl-project#41404): defer all eligible
  failure paths and force-arm partial metadata publication.
- 8293f9a (sgl-project#37077): shared ABORT/ACK
  types, generation filtering and common target/poison state.
- 4195980 (sgl-project#43719): suppress drained
  ACK after uncertain native KV/state/aux failure.
- f9df334 (sgl-project#44386): pending decode
  releases keep the scheduler non-idle.
- c683190 (sgl-project#41395): cached-prefix
  ready-event forwarding and worker-side synchronization.
- 2a46cf2 (sgl-project#36612): terminal/cleared
  room handling, first failure cause and shared failure/status fanout.
- abddb1c (sgl-project#32541): state-send return
  propagation and per-cached-socket send locking.
- 05c7ebf (sgl-project#30545): staging_counted
  and outstanding accounting across worker requeue/completion.
- 8ad7641 (sgl-project#36160): common wait_event
  job field used by the early-send handoff.
- 5b5d721 (sgl-project#40703): worker cleanup
  precedes outstanding-entry removal.
- 348689d (sgl-project#38959): sender poll wrapper
  holds Success while counted transfers remain.

- 1a0250c (sgl-project#41607): check Failed
  after state transfer before continuing to aux.
- 8bf780d (sgl-project#41128): retain deferred
  release start_time/deadline tuple shape without its new metrics API.
- 4dc9cda (sgl-project#37454): decode-side
  backend capability check before deferring a failed request.

Baseline compatibility adaptations:
- Insert selected snippets into existing server_args/configuration and
  worker/listener layout; retain local request timing and transfer batching.
- Omit absent deferred-allocation/bootstrap ownership, role-switch teardown,
  host-receive and PP-consensus branches; import no placeholder subsystems.
- Keep baseline 30-second socket timeout, optional sender-table guards and
  three-frame Mooncake status wire format; serialize existing manager sends
  with the imported endpoint locks.
- Use release_kv_cache(req, tree_cache, is_insert=False), the old failed
  request release API, and the existing scheduler invariant-check entrypoint.
- Omit unavailable new deferred-release metrics without importing the full
  metrics refactor; retain existing local metrics and diagnostics.

No WELM/NPU layerwise additions are included. Device timeout behavior and
backend capability defaults match the pinned community source.

Validation: 48 external CPU protocol/worker/decode cases; source AST
comparison for unadapted helpers; Python syntax, isort and configured Ruff
checks; git diff --check. CPU fixtures remain outside this repository.
No NPU/RDMA hardware execution was available for this commit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

highest-priority CI: all three control labels, plus never batch-cancelled or stale-closed run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants