Prompt longer than the whole KV cache blocks the queue and crashes with assert scheduled_seqs
Description
When a prompt needs more KV cache blocks than the cache has in total, it can never be admitted. The prefill loop in Scheduler.schedule() only looks at the head of waiting (scheduler.py#L30-L38), so this request also blocks every request queued behind it, including ones that would fit. Once nothing else is running, the decode loop has nothing to schedule and schedule() fails on assert scheduled_seqs (scheduler.py#L71). The whole generate() call fails, and results of requests that already finished are lost.
This ends at the same assert as #274, but through a different path. #274 is a running sequence that outgrows the cache during decode. Here the sequence is never admitted, and self-preemption is never involved.
Reproduce
Scheduler only, no model weights or GPU work needed (it still imports nano-vllm's dependencies):
from types import SimpleNamespace
from nanovllm.engine.scheduler import Scheduler
from nanovllm.engine.sequence import Sequence
from nanovllm.sampling_params import SamplingParams
# KV cache of 4 blocks x 256 tokens = 1024 tokens
cfg = SimpleNamespace(max_num_seqs=512, max_num_batched_tokens=16384, eos=-1,
kvcache_block_size=256, num_kvcache_blocks=4)
sch = Scheduler(cfg)
for n in (10, 1100, 10): # A fits; P (1100 tokens) is larger than the whole cache; C fits
sch.add(Sequence([100] * n, SamplingParams(max_tokens=20, ignore_eos=True)))
step = 0
while not sch.is_finished():
step += 1
print(f"step {step}: waiting={len(sch.waiting)} running={len(sch.running)}")
seqs, is_prefill = sch.schedule()
sch.postprocess(seqs, [1] * len(seqs), is_prefill)Output on bb823b3:
step 1: waiting=3 running=0
step 2: waiting=2 running=1
...
step 20: waiting=2 running=1
step 21: waiting=2 running=0
AssertionError (scheduler.py, line 71: assert scheduled_seqs)A runs and finishes after 20 steps. C needs one block and three are free the whole time, but it sits behind P and never runs.
The real engine behaves the same. On an RTX 4060 Laptop with Qwen3-0.6B and gpu_memory_utilization=0.36 (5 KV blocks = 1280 tokens), llm.generate() on three prompts of 20, 1281 and 20 tokens fails with AssertionError, and none of the three results is returned.
Expected
A prompt that can never fit should not block other requests or crash the engine. For example, it could be rejected when it is added, with the other requests finishing normally.
Source: GeeeekExplorer/nano-vllm