﻿# Executor cancellation: queued futures and running preprocessing need separate budgets

A practical investigation of executor cancellation: queued futures and running preprocessing need separate budgets, with explicit observations, control cases and evidence limits.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/field-security-executor-cancel-pending-running-work/
Language: en

## The operational scenario

A request is cancelled while its preprocessing callable is already decoding synthetic input in a thread pool. The service calls shutdown with cancel_futures enabled and immediately reports released capacity. That conclusion can be wrong even when every queued job disappears. The relevant security question is whether an abandoned request can keep consuming a protected worker slot or retaining an input handle.

## The trust-boundary mechanism

Python documents that cancel_futures cancels futures the executor has not started. Running and completed futures are unaffected. Waiting for shutdown changes when the method returns; it does not transform cancellation into forced interruption. A successful cancellation of another queued item therefore provides no evidence that the running decoder stopped. The running-state boundary must be observed before interpreting the result.

## Define the control contract

Define separate limits for queued work, already running work and final resource cleanup. For cooperative code, a stop event can communicate abandonment, but the worker must check it at meaningful boundaries. State what happens during a blocking library call that cannot observe the event. If the design requires hard termination, a thread-pool cancellation flag is not evidence for that stronger guarantee.

## A step-by-step verification

First use a harmless callable that announces entry and waits at a controlled checkpoint. Submit additional bounded queued work, then request cancellation after observing entry. Record which futures cancel and which remain running. Next release the running callable through a stop event and verify its cleanup path. Repeat with cancellation before entry to demonstrate that queue cancellation and running-task completion genuinely follow different transitions.

## Evidence required for acceptance

Preserve submission, worker-entry, cancellation-request, stop-observation and cleanup-completion events. Link resource-release evidence to the actual task identity rather than the cancelled client response. Acceptance requires a documented bound or explicit unresolved state for each running path. Count a future as cancelled only when its API state supports that classification; a timed-out wait should remain distinguishable from successful cancellation.

## Failure cases and limits

Cooperative stopping cannot guarantee interruption of arbitrary native decoding, blocked I/O or unrelated child work. An event flag is communication, not rollback of files already written. Publishing partial output needs its own admission rule. The proposed review establishes whether shutdown accounting respects the executor contract; it does not claim the Python process can exit immediately while outstanding thread work continues.

## Primary references and related reading

Cancelling pending futures does not stop running work; shutdown needs an explicit cooperative stopping contract. [Python Executor submission and result buffering](https://docs.python.org/3/library/concurrent.futures.html); [Python cooperative thread signaling](https://docs.python.org/3/library/threading.html).

The proposed investigation of executor cancel pending running work is a proposed control review; no live security test was executed. Related reading: [Google CancelOperation is a best-effort request](/journal/guide-google-canceloperation-best-effort/); [Request cancellation: testing the full client-to-engine chain](/journal/provider-client-disconnect-cancellation-chain/).
