Interruptions are messages sent to an agent while it is already working. For a coding agent, this is essential: you notice the agent going off in the wrong direction, and you want to add missing context to get it back on track without waiting for the current task to finish. Restate lets you implement interruptions with cancellation signals. Cancelling a running invocation causes it to terminally fail and raise an error at the next durable step, while still letting the handler run further durable actions such as cleanup and notifying the agent orchestrator. Cancellation automatically propagates through sub-invocations, giving you something similar to stack unwinding with exceptions, just distributed.Documentation Index
Fetch the complete documentation index at: https://docs.restate.dev/llms.txt
Use this file to discover all available pages before exploring further.
How it works
The pattern uses two services:CodingAgent— a Virtual Object, one per agent session. It holds the conversation history and the invocation ID of any running task.CodingTask— a long-running Service that performs the actual work (a lengthy LLM call, or a chain of them).
- The agent’s
messagehandler loads the conversation history from the Virtual Object state. - If a task is already running, it cancels that invocation and waits for the cleanup to finish.
- It sends a new task to the
CodingTaskservice and persists the new invocation ID. - Inside
CodingTask, the cancellation surfaces as a terminal error at the next Restate await. The task catches it, notifies the orchestrator for durable cleanup, and re-raises so Restate records the invocation ascancelled.
How does Restate help?
- Durable cancellation signals: Cancellation is a first-class, durable signal that propagates through nested invocations automatically.
- Cleanup always runs: Terminal errors surface at the next Restate await, giving the handler a chance to run durable cleanup steps before finishing.
- Concurrency control per session: Virtual Objects queue concurrent requests per key, so interruptions are processed one at a time without races.
- Observability: The Restate UI shows the cancelled invocation side-by-side with the one that replaced it.