Before you start: words you need#
| Word | Plain meaning |
|---|---|
| Synchronous request | The client opens a connection and waits on it until the answer is complete. |
| Async job | The client submits work, gets an ID back immediately, and checks later (polling) or is told when it is done. |
| Background mode | OpenAI’s Responses API option (background: true) that runs a response as an async job. |
| Resumable stream | A stream the client can reconnect to after a drop, continuing from the last event it saw. |
| Checkpoint | Saved progress from which a job can continue after a failure instead of starting again. |
| Durable execution | A workflow engine (Temporal is a common one) that records each step’s result so a crashed workflow resumes where it stopped. |
| Idempotent | Safe to repeat: doing it twice has the same effect as doing it once. |
| Cancellation | Stopping work the client no longer wants, so it stops consuming GPU time and KV memory. |
1. What is it?#
Some model work no longer fits in one HTTP request:
- a high-effort reasoning answer that thinks for ten minutes (27.a);
- a “deep research” or coding agent that runs for an hour across a hundred turns (27.b);
- an agent that waits for a human approval, a CI run or a long tool in the middle.
The serving stack has to turn these into jobs: submitted, tracked, resumable after a failure, cancellable, and billed. The building blocks exist at every layer:
| Layer | Building block |
|---|---|
| Provider API | OpenAI Responses background: true: poll with GET, cancel with POST .../cancel, and resume a stream with starting_after a sequence_number. Anthropic recommends batch processing for thinking budgets above 32k tokens “to avoid networking issues” |
| Self-hosted engine | vLLM v0.32.0’s Responses API accepts background: true and serves GET /v1/responses/{id} and POST /v1/responses/{id}/cancel, but only with VLLM_ENABLE_RESPONSES_API_STORE=1, and it keeps responses in process memory |
| Orchestration | Durable workflow engines, job queues, and agent runtimes that persist conversation state between turns |
Facts checked on 13 November 2026. The API shapes for chat, Responses and streaming are in 20.b; timeouts and retries in 20.e. This lesson is about jobs that outlive any single connection.
2. Why does it matter?#
Because long jobs fail by default. Every link in the path has a reason to break a connection: proxies with idle timeouts (20.e), load balancers draining during deploys, replicas restarting, spot instances being reclaimed, laptops going to sleep. Section 4 shows that with one interruption every two hours on average, a 4-hour job that must restart from zero takes almost 13 hours on average; the same job with per-turn checkpoints takes 4 hours and 1 minute.
And long jobs cost real money while they run: a session holding 20 GiB of KV (27.b) for an hour, or a reasoning stream occupying a decode slot for ten minutes. A job nobody is waiting for any more, but which keeps running because cancellation did not propagate, is pure waste.
3. Simple analogy#
Sending a large parcel abroad.
- Synchronous: you drive it there yourself and do not stop until it arrives. If the car breaks down at hour seven, you start again from home.
- Async job: you hand it to a courier and get a tracking number. You check the tracking page (polling) or get a text when it arrives (notification).
- Checkpoints: the courier scans the parcel at every depot. If a truck breaks down, the parcel continues from the last depot, not from your house.
- Cancellation: if you change your mind, the courier stops at the next depot, rather than delivering to an address nobody lives at.
4. Tiny example: restart or resume#
One interruption every 120 minutes on average (deploys, dropped connections, preemption). A checkpoint after every minute of work (about one agent turn). Resuming costs 0.2 minutes of re-prefill.
job length P(no interruption) from scratch with checkpoints
1 min 99.2% 1.0 min 1.0 min
10 min 92.0% 10.4 min 10.1 min
60 min 60.7% 77.8 min 60.4 min
240 min 13.5% 766.7 min 241.4 min
480 min 1.8% 6431.8 min 482.8 minShort requests do not need any of this. Past an hour, restarting from zero is not a slower version of the same design; it is a design that almost never finishes.
5. Technical explanation#
From connection to job#
SYNCHRONOUS ASYNC JOB
client ──open──► server client ──submit──► job API ──► queue ──► workers ──► engine
◄───stream (minutes)── ◄──── job id ──── │ │
connection must live state store ◄────────┴── progress, results ──┘
for the whole job client polls / reconnects / is notifiedA job API needs five things:
- A durable job record: ID, owner, status (
queued,in_progress, a terminal state), inputs, and output so far. - An event log per job, so a client that reconnects can resume a stream from the last event it
saw. OpenAI’s background mode does this with
sequence_numberandstarting_after. - Cancellation that reaches the engine: aborting the engine request frees its KV blocks and decode slot immediately. OpenAI’s cancel is idempotent; repeating it returns the final object.
- Retention rules: how long results are kept. OpenAI keeps background responses in some
data-retention configurations only about 10 minutes unless
store=true. - Notifications or polling guidance, so a million clients polling every second do not become the load.
The self-hosted trap: in-memory “background”#
vLLM v0.32.0 accepts background: true on /v1/responses, but only when the server runs with
VLLM_ENABLE_RESPONSES_API_STORE=1. The store is a dictionary inside the API-server process. Its
own log message warns that enabling it “may cause a memory leak since we never remove responses
from the store”. If the process restarts, every stored and running response is gone. That is
useful for development and short jobs; production job semantics need a durable store and an
orchestration layer in front of the engine.
Checkpoints for agents come almost for free#
An agent’s state between turns is its conversation history plus the state of its tools (files, sandbox). If the orchestrator saves the history after each turn, recovery after a crash is: reload the history, send the next model call. The serving cost of resuming is one prefill of the history, often a cache hit if the KV is still in a shared tier (27.b). That is why agent runtimes persist messages per turn and treat each model call and tool call as a recorded step.
Durable execution engines formalise this: the workflow code is replayed after a crash, and completed steps return their recorded results instead of running again. Two rules make it work:
- Model and tool calls must be idempotent or recorded. Re-running a tool that sent an email or merged a pull request is not safe; record its result and never repeat it.
- Model calls are not deterministic. Replaying a model call gives a different answer; the recorded output must be reused, not recomputed.
Mid-generation failure#
If a replica dies in the middle of a 20,000-token reasoning stream, there are three options:
| Option | Cost | Caveat |
|---|---|---|
| Restart the turn from its prompt | All tokens generated so far | Simple; fine for short turns |
Continue: send prompt + partial output and ask the model to continue the assistant message (vLLM’s chat API has continue_final_message) | One prefill of the partial output | Hidden reasoning must be available to the orchestrator; some providers return it encrypted or not at all |
| Fail the turn and let the agent decide | The turn | The agent loop must handle it |
For self-hosted engines the continuation route is usually best for long reasoning turns: prefill is far cheaper than regenerating the same number of tokens by decode (12.c).
Scheduling and admission for long jobs#
- Admit by concurrent work, not request rate. One long job can hold a decode slot and tens of GiB of KV for an hour. Quotas in concurrent jobs or token-seconds (23.j) reflect cost better than requests per minute.
- Separate priority classes. Interactive turns of a long agent job are latency-sensitive; its background sub-tasks are not. Use engine priorities (17.c) and separate queues.
- Drain with care. A deploy that kills replicas with a 30-second grace period interrupts every long job on them. Drain long jobs by stopping new admissions and letting turns finish, or rely on checkpoints and accept the resume cost (23.g).
- Park idle sessions. A job waiting for a human for hours should hold no GPU memory; its KV moves to a cheaper tier or is dropped and recomputed on return (24.h).
6. Under the hood: the restart model#
// longjob.go — why long agent jobs need checkpoints, not one long connection.
package main
import (
"fmt"
"math"
)
func main() {
const (
mtbfMin = 120.0 // one interruption every 2 h on average: deploys, drops, preemption
checkpoint = 1.0 // minutes of work between checkpoints (about one agent turn)
resumeMin = 0.2 // re-prefilling the saved context after an interruption
)
lambda := 1 / mtbfMin
// Expected wall time to finish w minutes of work that restarts from zero on failure.
restart := func(w float64) float64 { return (math.Exp(lambda*w) - 1) / lambda }
fmt.Println("job length P(no interruption) from scratch with checkpoints")
for _, t := range []float64{1, 10, 60, 240, 480} {
scratch := restart(t)
segments := t / checkpoint
failures := segments * (math.Exp(lambda*checkpoint) - 1) // expected interruptions
ckpt := segments*restart(checkpoint) + failures*resumeMin
fmt.Printf("%6.0f min %17.1f%% %8.1f min %12.1f min\n",
t, 100*math.Exp(-lambda*t), scratch, ckpt)
}
}Output:
job length P(no interruption) from scratch with checkpoints
1 min 99.2% 1.0 min 1.0 min
10 min 92.0% 10.4 min 10.1 min
60 min 60.7% 77.8 min 60.4 min
240 min 13.5% 766.7 min 241.4 min
480 min 1.8% 6431.8 min 482.8 minThe formula (e^{λw} − 1)/λ is the expected time to complete w minutes of work when interruptions arrive at rate λ and each one sends you back to the start. It grows exponentially with w, which is why the “from scratch” column explodes. Checkpointing splits the job into short segments, each of which is cheap to repeat.
7. Performance implications#
- Long jobs hold memory. KV·time (27.a) is the right unit for their cost; park them when idle.
- Polling is load. A million clients polling every second is a million requests per second on the job API; use backoff, long polling or notifications.
- Resume costs prefill. Every recovery re-prefills the history; with a shared KV tier and sticky placement much of it is a cache hit.
- Cancellation saves GPU time only if it reaches the engine; measure the time from a client’s cancel to the engine’s abort.
8. Production implications#
- Offer two APIs: synchronous streaming for short work, and a job API for anything that may exceed a few minutes. Route by expected duration (effort level, agent type).
- Persist per turn: history, tool results and recorded model outputs, in a durable store, not the engine process.
- Make tools idempotent or record their side effects; never repeat a non-idempotent tool on replay.
- Set end-to-end deadlines per job and per turn, and cancel downstream work when a deadline passes.
- Bill and quota in token-seconds or concurrent jobs, not requests.
- Test failure: kill replicas, drop connections and redeploy during long jobs in staging, and measure completion rate and resume cost (23.e).
9. Common mistakes#
- Running hour-long agent tasks over one streaming HTTP connection.
- Using vLLM’s in-memory Responses store as a production job store.
- Retrying a whole job after a failure in its last turn.
- Replaying tool calls with side effects during recovery.
- Letting cancelled jobs keep generating because the abort never reached the engine.
- Holding GPU KV memory for sessions that are waiting on a human.
- Rate-limiting long jobs by requests per minute.
10. Hands-on exercise#
A. Background mode locally. Start vLLM with VLLM_ENABLE_RESPONSES_API_STORE=1, submit a
long background: true response, poll it, then cancel it. Watch the engine’s running-request count
fall. Restart the server and check what happened to the stored response.
B. Resume a stream. With a provider that supports it, start a background streamed response,
drop the connection mid-way, and resume with starting_after the last sequence_number. Check
that no events were lost or duplicated.
C. Continuation. Interrupt a long generation on vLLM after 5,000 tokens; resend the prompt plus
the partial assistant message with continue_final_message. Compare the time to finish with a full
restart.
D. Your MTBF. Measure interruptions per hour for long streams in your environment (deploys,
proxy timeouts, preemptions). Put the number into longjob.go. Above what job length must you
checkpoint?
11. Interview questions#
- Why does a 4-hour job that restarts from zero take so much longer than 4 hours on average?
- What does a job API need that a streaming chat API does not?
- How would you recover a coding agent after the replica serving it dies mid-turn?
- Why are model calls a problem for durable-execution replay, and how do you handle it?
- How should quotas and admission work for long-running jobs?
- What is wrong with an in-memory store for background responses?
12. Further reading#
Checked on 13 November 2026.
- OpenAI — Background mode
- Anthropic — Extended thinking (batch for budgets above 32k)
- Anthropic — Managed Agents overview
- Temporal — Workflows and durable execution
- vLLM v0.32.0 — OpenAI-compatible server
- APIs and streaming: 20.b. Timeouts, retries and idle timeouts: 20.e. Fault tolerance: 23.e.