What "Cancel" Means After an Agent Starts Work
TL;DR
When a user presses Cancel on an agent run, they are expressing a preference about future work. They are not receiving proof that a command already sent to a deployment API, payment provider, email service, or job queue has not taken effect.
Treat cancellation as a stateful operation. It should prevent work that has not started, signal work that can still cooperate, and leave a durable record of work whose outcome must be reconciled. A run is not safely terminal just because its UI says cancel requested.
Context
An agent is asked to roll back a service. It has already submitted this command to a deployment system:
deployments.create_rollback({ service: "checkout", version: "2026.10.15.3" })
The user immediately notices the version was wrong and cancels the agent run. The orchestrator marks the run cancelled, stops its next tool call, and closes the conversation.
That may be correct for the agent loop. It says almost nothing about the deployment. The remote API may have rejected the command, accepted it but not started it, started a rollout, or completed it just before the cancellation reached the orchestrator. Treating all four outcomes as “cancelled” converts an actionable operational question into a misleading terminal label.
This is not an obscure agent problem. gRPC describes cancellation as the client no longer being interested in an RPC result and says that server handlers must coordinate to stop their own processing. Its core documentation also warns that changes made before cancellation are not rolled back. gRPC cancellation guide gRPC core concepts
For an agent that can cause external effects, cancellation needs a result contract as carefully designed as execution.
Key Points
“Stop waiting” and “stop work” are different requests
A client can stop awaiting a response while the server continues. A server can receive a cancellation signal while a downstream provider has already accepted a request. A worker can notice a cancellation token after it has written an irreversible record.
The practical distinction is where the work sits when cancellation arrives:
| Stage | Useful cancellation behavior | What still needs to be known |
|---|---|---|
| Not yet dispatched | Remove or mark the task ineligible before a worker claims it. | Did a worker race and claim it first? |
| Running locally | Signal cooperative cancellation and wait for the handler to acknowledge it. | Which steps completed before the check? |
| Submitted to another service | Call that service's cancellation API if it has one. | Did it accept cancellation, and what had already happened? |
| Completed or unknown | Do not pretend cancellation reversed it. | What final state exists, and is compensation appropriate? |
The boundary between these states is not cosmetic. It determines whether the system can safely schedule another action, tell a user nothing happened, or must begin incident handling.
Give the operation an identity before trying to cancel it
An agent should not try to cancel a remote effect using only a local run ID. The service that received the work needs an operation identifier it can report on later.
type RollbackOperation = {
id: string;
idempotencyKey: string;
status:
| "queued"
| "running"
| "cancel_requested"
| "cancelled_before_start"
| "succeeded"
| "failed"
| "outcome_unknown";
startedAt?: string;
finishedAt?: string;
cancellationReason?: "user_request" | "deadline" | "policy_change";
};
async function cancelRollback(operationId: string) {
const operation = await rollbacks.requestCancellation(operationId);
if (operation.status === "cancelled_before_start") {
return { state: "stopped", operation };
}
return {
state: "reconcile",
operation,
message: "Cancellation was requested; inspect the final operation state.",
};
}
The names are illustrative. The important part is that cancel_requested is not collapsed into cancelled, and that a caller can retrieve the operation's final state with the same identity. This is the same reason an uncertain write needs an idempotency key and a reconciliation path: a disconnected caller cannot infer the remote outcome from its own timeout or cancellation event. A Tool Error Is an Instruction to Your Agent
Do not use a status lookup as an excuse to make cancellation synchronous forever. A cancellation endpoint may return quickly with cancel_requested; the agent runtime can then stop invoking new tools while a durable worker reaches a terminal state. The user needs a truthful distinction between “we stopped before dispatch” and “we asked the system to stop and are verifying the result.”
Cancellation has to cross ownership boundaries deliberately
Local cancellation primitives are useful, but they do not automatically cross every queue, process, or vendor API in a workflow.
For a long-running handler, propagate the signal into each operation that can honor it, and check it at safe boundaries:
async function runImport(job: ImportJob, signal: AbortSignal) {
for await (const page of source.pages({ signal })) {
signal.throwIfAborted();
const batch = normalize(page);
await destination.upsert(batch, {
idempotencyKey: `${job.id}:${page.cursor}`,
signal,
});
}
}
This code is intentionally not a claim that an AbortSignal undoes upsert. It merely gives work that has not begun—or a dependency that supports cancellation—a chance to stop. If the destination has already committed a batch, the operation record must say so. If the business requirement is to remove that batch, that is a separate compensating action with its own authorization, scope, and failure modes.
The same distinction exists in RPC systems. gRPC recommends that a server propagate cancellation to work it initiated, but its library cannot generally interrupt application handlers for the developer. The handler has to cooperate. gRPC cancellation guide
Never make compensation an accidental side effect of cancel
“Undo it” can be more dangerous than “stop.” A rollback request may have changed traffic, an email may have been delivered, and an external payment may already be captured. Automatically submitting a compensating action can create a second incident if the original action turns out not to have completed.
Keep three decisions separate:
- Cancellation: prevent work that has not yet happened.
- Reconciliation: establish what did happen using the operation identity, provider status, and durable local records.
- Compensation: perform a new, explicitly authorized action if the established result calls for it.
This sequencing is deliberately slower than a single “cancel and reverse” button. It is also more honest about distributed effects. For low-impact, fully local work, the three steps may finish in milliseconds and appear as one action. For deployments, account changes, and third-party writes, exposing the distinction prevents the system from inventing a success story it cannot prove.
Steps / Code
Review a cancellable agent operation with these cases:
- Cancel before dispatch, while a worker is racing to claim the job. Verify at most one actor can transition it into active work.
- Cancel during a local loop. Verify the loop stops at documented boundaries and records which batch was last committed.
- Cancel after the remote service accepts the request but before the agent receives its response. Verify the next step is an operation lookup, not a retry or an unsupported claim that nothing happened.
- Cancel a request that the provider cannot interrupt. Verify the UI and tool result say that cancellation only stops further orchestration.
- Cancel an operation that completed just before the request. Verify the terminal record remains
succeeded, with the cancellation attempt preserved as an audit event. - Require compensation after reconciliation. Verify it is a separately authorized operation—not a hidden behavior of the cancellation endpoint.
For agent runtimes, the minimum useful user-facing states are usually:
cancelled_before_start
cancel_requested
completed_before_cancel
outcome_unknown_needs_reconciliation
There is no universal vocabulary, but each state should lead to a specific next action. A vague red “Cancelled” badge is not a protocol.
Trade-offs
Durable operation records, cancellation propagation, and reconciliation endpoints add work. For a local calculation that owns no shared state, an AbortSignal and a single cancelled status may be enough.
The investment is justified as soon as an agent crosses a process boundary or triggers an externally visible effect. The uncomfortable cases are exactly the ones where a simple cancellation story is least trustworthy: a queue race, a lost response, a provider without a cancel API, or a write that cannot be rolled back.
Cancellation also needs retention and access rules. An operation lookup can disclose that a sensitive action was attempted, so it must be scoped to the correct tenant and principal. The status record is not merely debug data; it is part of the authorization surface.
References
- gRPC, Cancellation
- gRPC, Core concepts: RPC termination and cancellation
- This repository, A Tool Error Is an Instruction to Your Agent
- This repository, Retries Need an Identity Before They Need Backoff
Final Take
Cancellation is a request to stop the future, not evidence that the past has been undone.
Make the request durable, stop work at every boundary that can cooperate, and preserve a final operation record for the effects that outrun the request. That turns an agent's Cancel button from a comforting fiction into a reliable control.
Changelog
- 2026-10-15: Initial publication.