Skip to content
All articles

LLM inference · Lifecycle

After the request ends, it must own nothing

A fast kernel cannot repair an inference lifecycle that leaks state after cancellation. Trace one request, r17, and check the invariant that nothing it held survives its final event.

· 3 min read

The lifecycle of request r17 in an inference engine. It is validated, queued as an interactive request with a 2,048 token prompt, admitted with a 4,096 token budget and KV blocks reserved, then prefill and decode for steps 1 to 63. The client cancels after token 23, and the request reaches FINAL as cancelled. While running it holds a queue slot, KV blocks, an adapter reference, a stream buffer and a billable reservation. After FINAL it owns none of them. Force every exit, from completion to disconnect, and check the same invariant. A fast kernel cannot repair a lifecycle that leaks state after cancellation.

Inference discussions tend to start with kernels. The course's view of the engine starts one level up: scheduling and memory ownership decide whether optimized kernels stay useful.

What the engine is made of

The request processor validates and tokenizes work. A scheduler selects prefills, decodes, preemptions and admissions under token and sequence budgets. A block manager allocates KV state. Model executors run kernels across local or distributed workers. Sampling and output processors turn logits into events, and metrics and health surfaces expose the lifecycle. Some engines combine these roles in one process, and production platforms may separate routers and worker pools.

One request, from start to finish

The course traces a request called r17:

request r17: VALIDATED -> QUEUED(class=interactive, prompt=2,048)
scheduler:   ADMITTED(token_budget=4,096, kv_blocks=reserved)
executor:    PREFILL -> DECODE(step=1..63)
client:      CANCELLED(after token 23)
engine:      STOP_SCHEDULING -> RELEASE_KV -> FINAL(cancelled)

Invariant: after FINAL, r17 owns no queue slot, KV block, adapter
reference, stream buffer, or billable generation reservation.

The client leaves after token 23. From that moment the engine has to stop scheduling the request and release its KV blocks, and only then reach its final state.

Mental Model

Every request borrows state from the engine: a queue slot, KV blocks, an adapter reference, a stream buffer and a billable reservation. A terminal event is the moment the loan must be repaid in full.

Test the exits, not only the happy path

A fast kernel cannot repair a lifecycle that leaks state after cancellation. So during evaluation, force every terminal path: completion, validation failure, timeout, worker loss and disconnect. For each one, verify the same ownership invariant.

The course also says to evaluate an engine on more than speed: supported models and hardware, correctness, scheduling policy, memory behavior, distributed execution, structured output, observability, upgrade stability and operational fit. Benchmark defaults are not architecture, and engine configuration should be pinned and treated as a release artifact, because scheduler or kernel changes can alter quality, latency and memory behavior.

Get one diagram a week

A short article built around one engineering diagram, from the same library as these courses.

One diagram-led article a week on AI and systems engineering. We email you once to confirm, and every newsletter has an unsubscribe link. Privacy policy