Companion to the blog post "Making KVCache Transfer Abort-Safe: Solving a Family of Slot-Liveness Issues in PD Disaggregation", specifically its Making It Deterministic section. This gist contains everything needed to reproduce, on live GPUs over real RDMA, both the corruption (hold disabled) and the fix (hold enabled, the shipped default).
The race in one sentence: when a request is aborted while its prefill→decode KVCache transfer is in flight, writes already launched to the NIC cannot be cancelled; if decode frees the destination slots at abort time and the allocator reassigns them, the dead request's KV lands inside another request's cache and silently corrupts its output.
| Hardware | 1 node, 2×NVIDIA H200, RDMA NICs (Mooncake auto-discovers; same-host PD runs RDMA loopback) |
| Software | SGLang v0.5.21 (lmsysorg/sglang:latest), Mooncake transfer backend (Mooncake 0.3.13, the version bundled in that image) |
| Model | Qwen/Qwen3-0.6B (small on purpose: fast startup, high decode TPS) |
| Topology | 2 prefill engines (both on GPU 0) + 1 decode engine (GPU 1) |
Why two prefill engines: Mooncake's prefill-side transfer queues are sharded by destination session, so with a single prefill, the victim's transfer serializes behind the donor's in-flight chunk on the same worker thread and always lands after the donor's late write, scrubbing it cell by cell. Two prefill engines sharing one decode break that serialization and let the late landing arrive out of order, as it would across a real fleet.
patch_harness.py: patches the installed SGLang in place:- conn.py: an env-gated
sleepin the Mooncake transfer worker, placed after the per-chunk abort/status check and before the RDMA submit. Past that check, the chunk is "launched": an ABORT arriving during the sleep cannot stop the write below from landing.SGLANG_TEST_SEND_KV_DELAY_Ssets the hold;SGLANG_TEST_SEND_KV_DELAY_MIN_TOKENS=300makes only the long donor prompt trigger it. - decode.py: warning-level logs for every
PREALLOC(room, rid, slot range),FREE,HOLD(deferred release armed, required acks), andRESOLVE(drained vs timeout).
- conn.py: an env-gated
launch_pd2.sh red|green: launches the 2P1D stack.redexportsSGLANG_DISAGGREGATION_DEFERRED_DECODE_KV_RELEASE=false(the pre-fix behavior);greenleaves the hold on (the default since v0.5.21). Decode runs with--max-total-tokens 512 --num-reserved-decode-tokens 64so slot reuse is immediate. The script is written so that it reproduces on every run: it waits for the previous engines to exit and deletes the old logs (otherwise a still-exiting engine keeps writing into the truncated log at its old offset,exp3.pymisses the "held" line, andassert heldfails); it starts prefill-2 only after prefill-1 is healthy (otherwise prefill-2 can claim GPU 0 memory first and prefill-1 exits withRaise --mem-fraction-static above 0.265); it pins a distinct--nccl-portper engine (the default random pick can collide between engines starting at once,EADDRINUSE); it exits with an error as soon as any engine dies during startup (instead of polling/healthuntil a long timeout); and it returns only when all three engines answer/health.exp3.py baseline | race red | race green: the driver. It bypasses the router and sends the same payload to a prefill engine and the decode engine with injectedbootstrap_host/port/room(exactly what the PD load balancer does). This matters twice: a router may retry the aborted request, and the retry re-writes the freed slots with identical KV, masking the corruption; and the abort must be one-sided (posted to decode only) to model the race. It exits withERRORinstead of a verdict if a decode request fails, so a dead engine can never be mistaken for corruption, and also if the harness "held" line for A's own bootstrap room does not appear within 20 s (harness not applied, or engines not started bylaunch_pd2.sh).
Donor A: a 430-token prompt via prefill-1 (its single KV chunk exceeds the 300-token threshold, so its launched write is held 0.45 s before the RDMA submit). Victim B: a ~100-token prompt via prefill-2 asking the model to count from 1 to 150, temperature=0, max_new_tokens=400, ignore_eos (so it is still decoding when the late write lands). The driver watches the prefill-1 log for the harness "held" line (proof the chunk is past the cancellable stage), then posts /abort_request for A to decode only, then immediately sends B.
Three timing/topology traps will silently mask the race if ignored (each cost us one clean-but-wrong "no repro"):
- Router retry: the aborted request gets re-sent and re-writes the same slots with the same KV. Bypass the router.
- Per-dst-session queue serialization: on 1P1D the victim's transfer lands after the donor's late write and scrubs it. Use 2 prefill engines.
- Victim lifetime: corruption only affects cells the victim wrote before the late landing; if the victim finishes decoding first, nothing shows. Size the delay so the landing falls mid-decode.
Decode-side slot trace (from the instrumentation):
[HARNESS] PREALLOC room=8596337577093805153 rid=rA_red kv_slots=[1..430] n=430
Decode transfer failed for request ... rid='rA_red' ... KVTransferError(...): Aborted by AbortReq.
[HARNESS] FREE room=8596337577093805153 rid=rA_red: kv slots returned to allocator
[HARNESS] PREALLOC room=6931021827077952974 rid=vB_red kv_slots=[1..105] n=105 <-- inside A's freed range
Prefill-1 side, same seconds:
[HARNESS] room 8596337577093805153: launched write of 430 tokens held 0.45s before RDMA submit
[HARNESS] room 8596337577093805153: submitting held RDMA write now <-- lands in B's live slots
(On later races against the same engines the held write is 429 tokens, because prefill-1's prefix cache already holds A's prompt; that is still above the 300-token threshold and still lands in B's slots.)
Victim output vs the temperature-0 baseline (first divergence at character 301):
baseline: ..., 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, ...
race: ..., 78, 79, 80,
Okay, so I need to figure out the pattern here. Let me start by writing
the sequence one two three four five six seven eight nine ten one two ...
The victim was counting correctly until the late write landed, then derailed into the donor's prompt content ("one two three four five…" is request A's prompt). This is not generic garbage: it is the aborted request's KV being read back out of another request's generation, cross-request contamination made visible. Every component reported success; nothing raised.
Reproducibility. Verified from scratch on two different 2×H200 nodes, each time with a clean SGLang tree and the gist files fetched on the box: the How-to-run sequence, then 4 fresh launches × 10 races per mode. Across both nodes red mismatched the baseline in 80/80 races and green matched it byte for byte in 80/80 (every green abort resolved drained, none by timeout). The current scripts (with the fail-fast startup check and the per-room "held" match) were then re-run on a clean tree: the How-to-run sequence plus 2 launches × 10 races per mode, red 20/20 and green 20/20. In every race the victim was preallocated slots [1..105] inside the donor's [1..430]. The first divergence fell between characters 261 and 301. Every red run leaked the donor's one-to-ten cycle into the victim: usually A's exact words ("one two three four five…", sometimes after an "Okay, so I need to figure out the pattern" preamble), sometimes as digits ("1234567890…", "8 9 10 1 2 3…") or as the model reasoning about a sequence "repeating every 10 numbers".
Identical timing, identical one-sided abort. Decode now holds instead of freeing:
[HARNESS] PREALLOC room=5364971304770933278 rid=rA_green kv_slots=[1..430] n=430
Decode transfer failed for request ... rid='rA_green' ... Aborted by AbortReq.
[HARNESS] HOLD room=5364971304770933278 rid=rA_green: release deferred, required_acks=1
[HARNESS] RESOLVE room=5364971304770933278: releasing now, outcome=drained <-- ABORT_ACK after prefill drained
[HARNESS] FREE room=5364971304770933278 rid=rA_green: kv slots returned to allocator
[HARNESS] PREALLOC room=170924350370374013 rid=vB_green kv_slots=[1..105] n=105 <-- same slots, AFTER the landing
The victim waited out the hold (wall time 1.34 s vs 0.65 s baseline, and 1.05 to 1.11 s in the re-runs: the cost lands on the aborted path, not the steady state) and its output matched the baseline byte for byte. The slots were reused just the same; the only difference is when: after the positive drain signal, so the late write landed in quarantined memory that was never read.
# inside an sglang v0.5.21 container (lmsysorg/sglang:latest) with 2 GPUs
# if the default HF cache is read-only, point HF_HOME at a writable dir first
HF_HOME=/scratch/hf hf download Qwen/Qwen3-0.6B --local-dir /scratch/qwen3-0.6b
python3 patch_harness.py # needs an unpatched tree; to undo: git -C /sgl-workspace/sglang checkout -- python/sglang/srt/disaggregation
./launch_pd2.sh red # or: green
python3 exp3.py baseline
python3 exp3.py race red # expect MISMATCH_BASELINE + donor-content leak
./launch_pd2.sh green
python3 exp3.py baseline
python3 exp3.py race green # expect MATCH_BASELINE + HOLD/RESOLVE(drained) in decode logThe harness changes nothing about the protocol under test: the delay only widens the window that already exists, the abort is the stock /abort_request path, and the hold/ack/release behavior is the unmodified v0.5.21 mechanism toggled by its own environment variable.