A request moves through six states
Once accepted, every request moves through a fixed set of states.
| From | Event | To |
|---|---|---|
| queued | a worker takes a lease | running |
| running | the result is written | succeeded |
| running | the lease lapses: attempt + 1 | queued |
| running | invalid, or failed for good | errored |
| queued | the batch is canceled before a worker took it | canceled |
| queued | the window closed before a worker took it | expired |
A request is in exactly one state at a time:
- queued: stored, and its batch passed the envelope checks.
- running: a worker holds a live lease on it.
- succeeded, errored, canceled and expired are final. A request never leaves them.
A running request whose lease lapses goes back to queued, with its attempt count raised by one.
One queue per model, with a sub-queue per tenant
A worker can serve only the model whose weights it has loaded, and loading a large model takes minutes. So queues are per model.
OpenAI builds the same limit into its API: each input file may hold requests for one model only.
Inside each model's queue, keep a sub-queue per tenant. Part 4, on fairness, shows why.
MOVES in the editor is the table of states, written as (state, event) to the next state. Write replay(events): start queued at attempt 1, apply each event the table allows from the current state, skip the rest, and raise the attempt by one on every lapse.