Skip to main content

CancellationManager

Workspace API


Workspace API / services/executors/CancellationManager

services/executors/CancellationManager

Classes

CancellationManager

Defined in: services/executors/CancellationManager.ts:57

Cancellation Manager

Manages cancellation state for skill executions:

  • Tracks AbortControllers per run
  • Persists cancellation requests to database
  • Provides polling interface for executors
  • Handles timeout-based cancellation

Constructors

Constructor

new CancellationManager(pollIntervalMs): CancellationManager

Defined in: services/executors/CancellationManager.ts:61

Parameters
pollIntervalMs

number = 1000

Returns

CancellationManager

Methods

register()

register(runId, maxRuntimeMs?): AbortSignal

Defined in: services/executors/CancellationManager.ts:72

Register a new run for cancellation tracking

Parameters
runId

string

The VoltAgent run ID (UUID)

maxRuntimeMs?

number

Optional maximum runtime before automatic cancellation

Returns

AbortSignal

AbortSignal for the run

cancel()

cancel(runId, requestedBy, reason?): Promise<CancellationRequest>

Defined in: services/executors/CancellationManager.ts:98

Request cancellation for a run

Parameters
runId

string

The VoltAgent run ID (UUID) - used for internal tracking

requestedBy

string

User ID requesting cancellation (UUID or 'system' for timeouts)

reason?

string

Optional reason for cancellation

Returns

Promise<CancellationRequest>

The cancellation request

cancelByWorkflowRunId()

cancelByWorkflowRunId(workflowRunId, requestedBy, reason?): Promise<CancellationRequest[]>

Defined in: services/executors/CancellationManager.ts:190

Request cancellation for a run by workflow_run_id

This is the API-facing method that accepts the workflow run UUID and finds the associated VoltAgent run(s) to cancel.

Parameters
workflowRunId

string

The workflow run ID (UUID) from the API

requestedBy

string

User ID requesting cancellation

reason?

string

Optional reason for cancellation

Returns

Promise<CancellationRequest[]>

The cancellation request(s)

isCancelled()

isCancelled(runId): boolean

Defined in: services/executors/CancellationManager.ts:258

Check if a run has been cancelled

Executors should call this periodically (every 1s) and before tool calls.

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

boolean

true if cancelled

getSignal()

getSignal(runId): AbortSignal | undefined

Defined in: services/executors/CancellationManager.ts:269

Get the AbortSignal for a run

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

AbortSignal | undefined

AbortSignal or undefined if not registered

getCancellationRequest()

getCancellationRequest(runId): CancellationRequest | undefined

Defined in: services/executors/CancellationManager.ts:279

Get the cancellation request for a run

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

CancellationRequest | undefined

CancellationRequest or undefined

acknowledge()

acknowledge(runId): Promise<void>

Defined in: services/executors/CancellationManager.ts:288

Acknowledge cancellation (called by executor when it stops)

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

Promise<void>

unregister()

unregister(runId): void

Defined in: services/executors/CancellationManager.ts:316

Unregister a run (cleanup)

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

void

checkDatabaseForCancellation()

checkDatabaseForCancellation(runId): Promise<boolean>

Defined in: services/executors/CancellationManager.ts:338

Check database for pending cancellation requests

Used for recovery after service restart.

Parameters
runId

string

The VoltAgent run ID (UUID)

Returns

Promise<boolean>

true if there's a pending cancellation

withTimeout()

withTimeout<T>(promise, timeoutMs, runId?): Promise<T>

Defined in: services/executors/CancellationManager.ts:363

Create a timeout wrapper for async operations

Type Parameters
T

T

Parameters
promise

Promise<T>

The promise to wrap

timeoutMs

number

Timeout in milliseconds

runId?

string

Optional run ID for cancellation checking

Returns

Promise<T>

The result or throws on timeout/cancellation

getPollIntervalMs()

getPollIntervalMs(): number

Defined in: services/executors/CancellationManager.ts:391

Get poll interval for cancellation checking

Returns

number


TimeoutError

Defined in: services/executors/CancellationManager.ts:399

Custom error for timeout

Extends

  • Error

Constructors

Constructor

new TimeoutError(message): TimeoutError

Defined in: services/executors/CancellationManager.ts:400

Parameters
message

string

Returns

TimeoutError

Overrides

Error.constructor


CancellationError

Defined in: services/executors/CancellationManager.ts:409

Custom error for cancellation

Extends

  • Error

Constructors

Constructor

new CancellationError(message): CancellationError

Defined in: services/executors/CancellationManager.ts:410

Parameters
message

string

Returns

CancellationError

Overrides

Error.constructor

Interfaces

CancellationRequest

Defined in: services/executors/CancellationManager.ts:17

Cancellation request record

Properties

id

id: string

Defined in: services/executors/CancellationManager.ts:19

Cancellation request ID

runId

runId: string

Defined in: services/executors/CancellationManager.ts:21

VoltAgent run ID (UUID) - internal tracking

workflowRunId?

optional workflowRunId: string

Defined in: services/executors/CancellationManager.ts:23

Workflow run ID (UUID) - from API

requestedBy

requestedBy: string

Defined in: services/executors/CancellationManager.ts:25

User who requested cancellation (UUID or 'system' for timeouts)

reason?

optional reason: string

Defined in: services/executors/CancellationManager.ts:27

Reason for cancellation

requestedAt

requestedAt: Date

Defined in: services/executors/CancellationManager.ts:29

When the request was made

processedAt?

optional processedAt: Date

Defined in: services/executors/CancellationManager.ts:31

When the request was processed

acknowledged

acknowledged: boolean

Defined in: services/executors/CancellationManager.ts:33

Whether the executor acknowledged the cancellation

Functions

getCancellationManager()

getCancellationManager(): CancellationManager

Defined in: services/executors/CancellationManager.ts:424

Get the cancellation manager instance

Returns

CancellationManager


shouldCancel()

shouldCancel(runId): boolean

Defined in: services/executors/CancellationManager.ts:434

Check if a run should be cancelled (convenience function)

Parameters

runId

string

Returns

boolean