[QSA] Tag every raw-key ring row and validate it before pooling

The fused pre-indexer could read a stale or uncommitted raw-key ring row and
pass its int64 tail to RoPE as a position (illegal address). The writer now
tags each row with logical_position + 1; the reader checks the tag of every
source row and, on a mismatch, masks the pooled load, the RoPE-tail read and
the compressed-slot store. New guard site 11 (always fatal under warn). The
KV pool size is unchanged.

Co-Authored-By: Hinata <hinata@idihore.id>
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-09 20:01:26 +07:00
co-authored by Hinata
parent ad80cac06d
commit fba504d5bb
12 changed files with 463 additions and 16 deletions
+7
View File
@@ -301,6 +301,13 @@ class SchedulerOutput:
# preventing stale NaN/data from corrupting attention or SSM computation.
new_block_ids_to_zero: list[int] | None = None
# v2.2 ring-row tag fix: ring (CircularBufferSpec) blocks claimed during this
# scheduling step. Independent of new_block_ids_to_zero and of
# needs_kv_cache_zeroing: the worker clears only the rows' tag words, after
# the zeroer and before any copy or forward of this step, i.e. before the
# new owner's first read or write of the ring.
new_ring_block_ids_to_clear: list[int] | None = None
# CoW copies to apply after zeroing new blocks and before forward.
kv_cache_block_copies: list[KVCacheBlockCopy] | None = None
+24
View File
@@ -366,6 +366,11 @@ class Scheduler(SchedulerInterface):
# Bind after construction so connectors can access the cache manager.
if self.connector is not None:
self.connector.bind_kv_cache_manager(self.kv_cache_manager)
# Ring blocks an async KV load is about to fill. Their tag clear
# is skipped for the same reason as zeroing (it could land after the
# out-of-band write and wipe the producer's committed tags). Tracked
# whatever needs_kv_cache_zeroing says, like the clear itself.
self._skip_ring_clear_block_ids: set[int] = set()
self.use_pp = self.parallel_config.pipeline_parallel_size > 1
self.use_v2_model_runner = vllm_config.use_v2_model_runner
@@ -1333,6 +1338,12 @@ class Scheduler(SchedulerInterface):
request.num_computed_tokens = num_computed_tokens
self._inflight_prefills.add(request)
self._set_kv_fetch_stage(request, KV_FETCH_IN_PROGRESS)
# Same race for the ring's tag clear; the load
# brings the producer's rows and tags (or none, and the
# reader then fails closed on the missing history).
self._skip_ring_clear_block_ids.update(
self.kv_cache_manager.get_ring_block_ids(request.request_id)
)
skip_request(request_queue)
continue
@@ -1525,6 +1536,8 @@ class Scheduler(SchedulerInterface):
finished_req_ids=self.finished_req_ids,
free_encoder_mm_hashes=self.encoder_cache_manager.get_freed_mm_hashes(),
new_block_ids_to_zero=self._get_new_block_ids_to_zero(),
# Drained every step, never gated on KV zeroing.
new_ring_block_ids_to_clear=self._get_new_ring_block_ids_to_clear(),
has_sync_kv_loads=has_sync_kv_loads,
kv_cache_block_copies=pending_kv_cache_block_copies,
kv_connector_block_state=kv_connector_block_state,
@@ -1572,6 +1585,17 @@ class Scheduler(SchedulerInterface):
) -> KVConnectorMetadata:
return connector.build_connector_meta(scheduler_output)
def _get_new_ring_block_ids_to_clear(self) -> list[int] | None:
"""Ring claims of this step whose tag words the worker clears.
Unconditional (not under needs_kv_cache_zeroing); only blocks an async
KV load is about to write are left out."""
ids = self.kv_cache_manager.take_new_ring_block_ids()
if self._skip_ring_clear_block_ids:
skip = self._skip_ring_clear_block_ids
ids = [b for b in ids if b not in skip]
skip.clear()
return ids or None
def _get_new_block_ids_to_zero(self) -> list[int] | None:
# Drain new attention block ids every step so the manager-side list
# does not grow unbounded; only kv-cache zeroing consumes them.