Repository navigation
[HiCache]: Fix host lock ownership across radix splits - #38480
Conversation
|
/tag-and-rerun-ci |
| if node.parent is not None: | ||
| # A later split inserts nodes between this anchor and its current | ||
| # parent. Remember that boundary so release also unlocks those | ||
| # fragments without touching pre-existing ancestors. | ||
| result.skip_lock_node_ids.setdefault(ct, set()).add(node.parent.id) |
There was a problem hiding this comment.
CC @xiezhq-hermann who is trying to removing skip_lock_node_ids in #36848
There was a problem hiding this comment.
I had a quick LLM chat, the bug I'm addressing here (split node not being accounted host_lock_ref) seems currently present in #36848 too. Maybe host_lock_ref should also become a segment lock?
|
please resolve the conflicts |
7a05ee7 to
94855cf
Compare
|
Rebased after merge, can confirm the bug is still present after #36848 Implementation changed quite a bit:
Testing:
|
94855cf to
01d2f97
Compare
|
rebased |
There was a problem hiding this comment.
Trying to explain the motivation of this PR with my own words to confirm my understanding.
"""
Originally, a Full host lock pinned only its anchor node, and host_lock_ref wasn’t propagated during splits. This PR copies the refcount to the new prefix, preserving protection for all original buffers. It also moves the UUID boundary to that prefix, so unlock releases exactly the chain of fragments covered by the original lock—preventing leaked host references.
"""
| /// Mint the next component lock-segment uuid. | ||
| pub(crate) fn next_component_uuid_(&mut self) -> i64 { | ||
| self.component_uuid_counter += 1; | ||
| self.component_uuid_counter |
There was a problem hiding this comment.
Let's introduce separate counters per component type? (As the counter is on tree core layer, the memory overhead should be negaligible).
There was a problem hiding this comment.
I'll add this. Although maybe for debugging it would be easier to have disjoint ID spaces
There was a problem hiding this comment.
Yeah, good point. Currently, we have multiple monotonic growth counters which are all starts from 0. I think a proper way out is to
- still using separate i64 counters for different use case
- use different and fixed initial offset to achieve disjointness
- with that being built, it's also easier for the
debuggerto tell what does these belongs to.
There was a problem hiding this comment.
Sure, I can add this. n * (1B = 1,000,000,000) as start offsets?
There was a problem hiding this comment.
Sure, I can add this.
n * (1B = 1,000,000,000)as start offsets?
Maybe prepare for the worse case, counter got bump every 1ns, and the server live for a week. With that, 1E14 is able to cover all ns changes for a week.
(n+1)*1E14 should be safe.
01d2f97 to
d6550c7
Compare
Jialin
left a comment
There was a problem hiding this comment.
Overall LGTM. For easier long term maintainance, let's further enhance the test coverage.
For example, ensure there's no leakage with E2E test (e.g. acuiqre, split and then release)
|
Great, I'll think about extending the testcases too |
d6550c7 to
87eacfd
Compare
|
Ok, l think the test coverage of the hicache looking mechanism is already quite good. I added in the last push: |
87eacfd to
fade7b9
Compare
|
/rerun-failed-ci |
|
@lluki could you resolve the conflict? |
492fdb3 to
232a3ee
Compare
|
Rebased onto upstream’s generic lock API and updated the tests. |
232a3ee to
d0f7fbf
Compare
Signed-off-by: Lukas Humbel <[email protected]>
d0f7fbf to
103d7fb
Compare
|
In my opinion the CI is green enough, the hicache tests are green for both python and Rust, the remaining ones are skipped runs or infrastructure failures. But that is some maintainers call @xiezhq-hermann @alphabetc1 |
|
/rerun-failed-ci |
…receipt test test_host_lock_refs_round_trip (from upstream sgl-project#41276) asserted the SWA leaf's host-lock receipt holds only an SWA entry. sgl-project#38480 makes the Full component record its host-lock boundary uuid in the same receipt, so the exact-dict assertion failed for both SWA cases on a freshly built extension (also on the sgl-project#38480 head itself). Assert the SWA leg is still windowless and the Full leg is present instead. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Brings in 699 upstream commits up to 87845cd (sgl-project#43301, 2026-10-09). Conflict resolutions (67 files): - multimodal_gen quality tiers: adopt upstream exact/lossless/high migration (old lossless=bit-exact -> new "exact"; fusion moves into "lossless", which is now the DEFAULT). Migrated the stack's teacache guard (minimax_h3) to the "exact" tier and ltx_2 mask-skip to quality_allows(q, "lossless"). - video saving: take upstream's one-pass _save_video_ffmpeg (plugin-free), superseding the stack's PyAV/ffmpeg-pipe two-pass path (c16d89e/1b66dcb374); video_api generate_audio re-expressed over their request_extra_value. - teacache: union API -- keep our get_thresh/get_skip_boundaries/is_step_boundary alongside their get_skip_step_range (wanvideo/longcat/minimax + tests use all). - orchestrator.py: kept OURS wholesale (their refactor targets classic dispatchers our DAG sgl-project#139 removed); glm_distributed NotImplementedError lives in scheduler_mixin. - schedule_batch: retained our grammar_needs_sync field. - pool_host / mamba naming: took theirs. - unified_radix_cache: took their prefix-hit API, re-porting our bounded-evict logic into allocate_storage_hit. - hybrid_cache_controller: kept sgl-project#39830 degrade-to-miss guard over their changes. - hybrid_pool_assembler: took theirs (sgl-project#39893 absorbed our earlier patch). - qwen4_exp: rebuilt stage-boundary logic + re-applied PLE deltas. - qsa_sparse_attn_backend: integrated upstream CP / breakable-graphs / verify-fusion over our SM120 triton-decode and FP8-descale paths. - sgl-project#38480 + sgl-project#39862 arrived via upstream (stack dupes dropped). - tests: upstream deleted test_scheduler_decision_batch_params; ported that coverage to test_scheduler_grammar_mixed_tail_sync.py. - quantization import test (merge fallout): upstream renamed kitchen_int8 -> convrot_int8 and dropped the package-level config-class __getattr__ shim, so test_quantization_imports now asserts get_quantization_config dispatch against the concrete modules (canonical convrot names) plus an explicit kitchen_int8->convrot alias check. Deferred: GPU end-to-end verification owed (all 4 GPUs are running production servers; this battery was CPU-forced). Stack fixes land live only after the next diffusion/AR server restarts. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Motivation
HiCache can corrupt a value being written to L3 storage when a radix-tree node is split while its write-back SET is still in flight.
The SET reads directly from host KV-cache blocks. A split creates a new prefix node for the shared tokens, but that fragment does not inherit the parent's full host lock. Duplicate-host reclamation may therefore free and reuse the prefix blocks before the storage backend has finished reading them, this causes wrong data to be written to storage. The backend behaves correctly: it stores exactly what is in those buffers when its SET runs. The stale write is caused by SGLang changing ownership of the buffers too early.
Modifications
This keeps every zero-copy SET source block owned by the SET until the backend call has returned, even if the radix node is split in the meantime.
Accuracy Tests
I tested this with both unit tests (in this PR) an end2end reproducer (not in this PR).
The e2e verifier runs SGLang with hicache nixl backend and slows down the
batch_set_*artificially to reliably trigger the bug:The second request reports a 768-token storage hit, proving that it exercised L3. On buggy upstream code its answer changes from ZEBRA4821 to repeated Answer: tokens. This is visible entirely through the completion API.
I ran this validation and testsuite with both python and rust cores.
Speed Tests and Profiling
N/A
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #36804765986
Latest PR Test (Extra): ✅ Run #36804765970
Latest PR Test (AMD ROCm 10): ❌ Run #36804765995