From d7e3c2a58ac02515342700636d8bf851749c9b70 Mon Sep 17 00:00:00 2001 From: fl0l0u Date: Sun, 15 Nov 2026 17:20:52 +0000 Subject: [PATCH] sched: an anchor row with no anchor is row zero, not row minus one LiLiCorr's correlator gathers each sequence's context state by the row the advance pass wrote into h_arow (RadBatch::anchor_rows), and the gather validates the index plane in shape, not values: an index of -1 reaches one int32 before the context buffer and reads off the end of a device allocation. The reset that opens a build filled the plane with -1 -- honest for a host reader, poison for an index -- so a row that reached the query pass without advancing, in any path that skips the advance, gathered out of bounds instead of gathering a wrong row. The sentinel becomes row 0: always in range, and a row that really did skip its advance reads an anchor that fails acceptance and is discarded, which is the same outcome with no fault and no neighbour's state read. --- core/sched/batch.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/sched/batch.cpp b/core/sched/batch.cpp index 22ec51a0..1aa261b7 100644 --- a/core/sched/batch.cpp +++ b/core/sched/batch.cpp @@ -1132,7 +1132,12 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv, s.h_q[i] = e.n_tokens; s.h_ctx[i] = e.ctx_len; s.h_acc[i] = e.n_accepted; - s.h_arow[i] = -1; + /* Row 0, not -1: the query pass gathers the context state by these values, and the + * gather's index plane is validated in shape only -- a row that reaches the correlator + * without having advanced would gather one row BEFORE the context buffer (device OOB). + * Row 0 is always in range; a row that skipped its advance reads a wrong anchor, which + * the acceptance path discards, instead of faulting or reading a neighbour's state. */ + s.h_arow[i] = 0; if (e.is_prefill) { if (e.n_tokens > max_q_pf) max_q_pf = e.n_tokens; } else { if (e.n_tokens > max_q_dec) max_q_dec = e.n_tokens; } }