﻿# Google CancelOperation is a best-effort request

Interpret Google CancelOperation through the operation record, distinguishing an accepted cancellation request, successful completion despite cancellation and deletion of the handle.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/guide-google-canceloperation-best-effort/
Language: en

## Separate the cancel request from the background outcome

The [Google operations interface](https://raw.githubusercontent.com/googleapis/googleapis/master/google/longrunning/operations.proto) defines CancelOperation as starting asynchronous cancellation with best effort. It explicitly allows the operation to finish despite the request. A proposed user-facing state should therefore distinguish cancellation requested from cancellation confirmed. A race between completion and cancellation is part of the contract, not automatically a client bug. Preserve the operation identity so the eventual outcome can still be read after the cancel attempt returns.

## Interpret the empty response at the correct level

The [Spanner cancellation reference](https://docs.cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.operations/cancel) gives a concrete REST mapping: a POST to the operation's cancel action with an empty body, followed by an empty JSON response on success. That response acknowledges the cancel method, rather than supplying the completed operation. A parser that treats an empty object as proof that all work stopped would lose the distinction. Record transport failure, unsupported cancellation and a successful acknowledgment separately before interpreting any later operation state.

## Look for cancellation in the retained operation record

The interface specifies that successful cancellation does not delete the operation. Instead, the record contains Operation.error with the CANCELLED status code. A proposed reconciler reads the same operation through the service's observation method and distinguishes that outcome from a normal successful response. It should also retain a still-running observation without inventing a deadline at which cancellation must already have taken effect. The generic interface does not provide that universal stopping bound.

## Do not substitute DeleteOperation for cancellation

The [Spanner deletion reference](https://docs.cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.operations/delete) explicitly says deleting an operation means the client is no longer interested in its result and does not cancel it. The two methods can both return empty responses while requesting different transitions. A proposed interface should keep their labels and audit events distinct. Removing the observation handle can also prevent straightforward later reconciliation, so deletion should not be used merely to make an unfinished job disappear from a dashboard.

## Verify final state rather than promising rollback

The cancellation contract alone does not specify reversal of every side effect of the original service operation. Any rollback guarantee needs that operation's own documentation. An editorial fixture can model completion winning the race, confirmed cancellation and an unsupported cancel method, then check the client's displayed state. [Cancellation-chain testing](/journal/provider-client-disconnect-cancellation-chain/) examines a different transport-to-engine boundary; [contract fixtures](/journal/provider-golden-contract-fixtures/) preserve these operation-level outcomes. This explanation performs no cancellation or deletion.
