From f7102ba8262a69d5346350ea1f0b8d2802f13dc2 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Wed, 4 Feb 2026 13:19:48 -0800 Subject: [PATCH] runner: discard compute results if sequence replaced mid-batch (#14072) If a sequence is replaced in s.seqs while a batch is computing, the old logits can be decoded into the new sequence. This change rechecks the sequence pointer after compute and skips decoding for replaced entries, preventing stale results from being applied. --- runner/ollamarunner/runner.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/runner/ollamarunner/runner.go b/runner/ollamarunner/runner.go index 2aa89208..048facde 100644 --- a/runner/ollamarunner/runner.go +++ b/runner/ollamarunner/runner.go @@ -740,7 +740,11 @@ func (s *Server) computeBatch(activeBatch batchState) { if seq == nil || nextBatchTokens[i] == nil { continue } - + // If the sequence was replaced while this batch was computing, discard results. + if activeBatch.seqs[i] != seq { + logutil.Trace("computeBatch: sequence replaced, discarding its results", "batchID", activeBatch.id, "seqIdx", i) + continue + } seq.lastUpdatedAt = t if seq.numPredicted == 1 { seq.processingDuration = seq.lastUpdatedAt.Sub(seq.startedAt)