Never hold finished results for the stragglers
A batch can also end early, by a cancel or by its deadline.
| State | Cancel at 10:00 | The window closes |
|---|---|---|
| queued | canceled | expired |
| running | finish, or stop after a short bound | finish, and count |
| succeeded | kept, delivered | kept, delivered |
Partial results. Never hold finished results hostage to stragglers. When the window closes, what succeeded is delivered and what never started is expired.
Cancellation. Set the batch to canceling. The dispatcher stops granting its leases, and queued requests become canceled. In-flight ones finish, or are stopped after a short bound, and written results stay.
OpenAI keeps a batch in cancelling until its in-flight requests are complete, for up to 10 minutes. Make cancel idempotent, and don't delete the input while an in-flight request may still read its prompt.
Expiry. Store expires_at as the creation time plus 24 hours. The dispatcher refuses leases for expired batches, and a sweeper marks what's still queued as expired.
Anthropic draws the line at dispatch: a request expires if the deadline passed before it was sent to the model. So requests already running at the deadline finish and count.
In the editor, write close(states, why): each request's state after the batch closes, where why is cancel or expire. Queued requests become canceled or expired, running ones keep running, and final states stay as they are.