Skip to main content
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.

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).
When a new user message arrives:
  1. The agent’s message handler loads the conversation history from the Virtual Object state.
  2. If a task is already running, it cancels that invocation and waits for the cleanup to finish.
  3. It sends a new task to the CodingTask service and persists the new invocation ID.
  4. 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 as cancelled.

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.

Example

This pattern is implementable with any of our SDKs and any AI SDK. If you need help with a specific SDK, please reach out to us via Discord or Slack.