[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
+72 -1
View File
@@ -146,7 +146,53 @@ SITE_QSA_ROPE_POS = 9
# The skip itself is the earlier behaviour; the count is the instrument
# for the v2.2 ring-row reconciliation. Telemetry only: warn.
SITE_QSA_RING_SKIP = 10
NUM_SITES = 11
# The pre-indexer found a historical raw-key ring row whose tag is
# not `logical_position + 1` -- a row this request never committed for that
# position (claim residue, a skipped suffix commit, a stale mapping). The
# group's pooled load, its RoPE-tail read and its compressed-slot store are all
# MASKED, so the compressed slot is left unwritten: durable damage, fatal.
# Unlike the other sites the three slots form ONE coherent record, claimed
# first-offender-wins with atomic_cas: slot 0 = rows flagged (all offenders),
# slot 1 = packed (layer + 1, batch request row, source logical position) of
# the first offender, slot 2 = the tag that offender's row actually held.
# Decode slot 1 with decode_ring_record().
SITE_QSA_RING_UNCOMMITTED = 11
NUM_SITES = 12
# Bit layout of the SITE_QSA_RING_UNCOMMITTED record (before GUARD_BIAS).
RING_RECORD_POS_BITS = 32
RING_RECORD_REQ_BITS = 16
RING_RECORD_LAYER_BITS = 14
def encode_ring_record(layer_id: int, request_row: int, position: int) -> int:
"""Python twin of the kernel's packing (tests; the kernel inlines it)."""
layer = (int(layer_id) + 1) & ((1 << RING_RECORD_LAYER_BITS) - 1)
row = int(request_row) & ((1 << RING_RECORD_REQ_BITS) - 1)
pos = int(position) & ((1 << RING_RECORD_POS_BITS) - 1)
return (
(layer << (RING_RECORD_REQ_BITS + RING_RECORD_POS_BITS))
| (row << RING_RECORD_POS_BITS)
| pos
)
def decode_ring_record(biased: int) -> dict[str, int] | None:
"""Unpack slot 1 of SITE_QSA_RING_UNCOMMITTED. ``layer`` is -1 when the
launcher was not given one. None = nothing recorded (or not yet visible)."""
value = decode_slot(biased)
if value is None:
return None
pos_mask = (1 << RING_RECORD_POS_BITS) - 1
req_mask = (1 << RING_RECORD_REQ_BITS) - 1
layer_mask = (1 << RING_RECORD_LAYER_BITS) - 1
return {
"layer": ((value >> (RING_RECORD_REQ_BITS + RING_RECORD_POS_BITS)) & layer_mask)
- 1,
"request_row": (value >> RING_RECORD_POS_BITS) & req_mask,
"source_position": value & pos_mask,
}
SITE_NAMES = {
SITE_MAMBA_COPY: "_copy_mamba_state_block (block-table row/column)",
@@ -165,6 +211,10 @@ SITE_NAMES = {
SITE_QSA_RING_SKIP: "_qsa_pre_indexer_kernel suffix commit SKIPPED "
"(state slot < 0 or >= ring capacity; slot 1 = token index, "
"slot 2 = state slot value)",
SITE_QSA_RING_UNCOMMITTED: "_qsa_pre_indexer_kernel historical ring row "
"UNCOMMITTED (tag != logical_position + 1; group load, RoPE tail and "
"compressed-slot store masked; slot 1 = packed first-offender record, "
"slot 2 = the tag its row held)",
}
@@ -373,6 +423,14 @@ _ALWAYS_FATAL_SITES: set[int] = set()
# whatever VLLM_E2_GUARD_MODE says. (bounds-guard instrumentation, rope site)
_ALWAYS_FATAL_SITES.add(SITE_QSA_ROPE_POS)
# An uncommitted ring row leaves the group's compressed slot
# UNWRITTEN (the store is masked, there is no correct value to store), and the
# selection kernels will read that slot on every later step. That is durable
# damage by the same argument as the rope site, so it stops the rank under
# warn too. The failure boundary is the rank, not the request: per-request
# containment (discard + quarantine + TP/PP coordination) is not implemented.
_ALWAYS_FATAL_SITES.add(SITE_QSA_RING_UNCOMMITTED)
def _normalize(device: torch.device) -> torch.device:
"""torch.device("cuda") and torch.device("cuda:0") are different dict keys.
@@ -479,6 +537,19 @@ def _report_rows(device: torch.device, rows: list[list[int]]) -> None:
_seen[(device, site)] = n_masked
row = decode_slot(biased_row)
val = decode_slot(biased_val)
if site == SITE_QSA_RING_UNCOMMITTED:
# One coherent first-offender record, not independent maxima.
record = decode_ring_record(biased_row)
msg = (
f"ring-row tag guard masked {n_masked} uncommitted historical "
f"ring row(s) in {SITE_NAMES[site]} on {device}; first "
f"offender {record}, its row held tag {val} (expected "
f"source_position + 1). The group was not pooled and its "
f"compressed slot was NOT written."
)
logger.warning("%s", msg)
_arm(msg)
continue
msg = (
f"bounds guard masked {n_masked} out-of-range access(es) "
f"in {SITE_NAMES.get(site, site)} on {device} "