TaskRun Class

Handle to a running or completed resilient task.

Returned by start. Provides external observation and control of the task lifecycle.

Constructor

TaskRun(task_id: str, *, provider: Any = None, result_future: Future[Any], cancel_event: Event | None = None, status: Any = None, terminate_event: Event | None = None, execution_task: Task[Any] | None = None, terminate_reason_ref: list[str | None] | None = None, lease_expiry_count: int = 0, cancel_ctx_ref: Any = None, input_id: str | None = None, queued_cancel_callback: Any = None)

Parameters

Name Description
task_id
Required
str

The task identifier.

provider
Required
<xref:TaskProvider>

Storage provider for refresh/delete operations.

result_future
Required
Future[<xref:Output>]

Future that resolves with the task output.

cancel_event
Required

Event to signal cancellation.

status
Required
<xref:TaskStatus>

Initial task status.

Keyword-Only Parameters

Name Description
provider
Default value: None
result_future
Required
cancel_event
Default value: None
status
Default value: None
terminate_event
Default value: None
execution_task
Default value: None
terminate_reason_ref
Default value: None
lease_expiry_count
Default value: 0
cancel_ctx_ref
Default value: None
input_id
Default value: None
queued_cancel_callback
Default value: None

Methods

cancel

Signal cancellation to the running task.

: sets ctx.cancel_requested = True BEFORE setting ctx.cancel, so a handler observing ctx.cancel.is_set() == True is guaranteed to see at least one cause boolean already True.

The handler should check ctx.cancel.is_set() (and optionally branch on which cause boolean is set) to wind down cleanly.

For a queued (not-yet-promoted) steering input, cancel() removes the queued slot from the chain's pending-inputs queue and resolves result with TaskCancelled. The active turn (if any) is not affected.

result

Await task completion and return the raw output value.

: returns Output directly (not a wrapper). Failures, cancellation, deferral are raised as exceptions.

return: The task's output value.

rtype: Output

raises TaskFailed: If the function raised an exception (one-shot).

raises TaskCancelled: If the task was cancelled.

raises TaskDeferred: If the task called ctx.exit_for_recovery().

cancel

Signal cancellation to the running task.

: sets ctx.cancel_requested = True BEFORE setting ctx.cancel, so a handler observing ctx.cancel.is_set() == True is guaranteed to see at least one cause boolean already True.

The handler should check ctx.cancel.is_set() (and optionally branch on which cause boolean is set) to wind down cleanly.

For a queued (not-yet-promoted) steering input, cancel() removes the queued slot from the chain's pending-inputs queue and resolves result with TaskCancelled. The active turn (if any) is not affected.

async cancel() -> None

result

Await task completion and return the raw output value.

: returns Output directly (not a wrapper). Failures, cancellation, deferral are raised as exceptions.

return: The task's output value.

rtype: Output

raises TaskFailed: If the function raised an exception (one-shot).

raises TaskCancelled: If the task was cancelled.

raises TaskDeferred: If the task called ctx.exit_for_recovery().

async result() -> Output

Attributes

input_id

input_id: str

is_queued

Whether this handle represents a queued steering input.

True when this TaskRun is a queued (not-yet-promoted) steering input on a steerable chain — i.e. the request landed while a turn was already in flight and is awaiting drain — and False for a freshly-started or active run. A queued run's cancel removes the queued slot and resolves result with TaskCancelled without affecting the active turn.

This is the supported, public way to distinguish a queued steering handle from a freshly-started one.

Returns

Type Description

True if this handle is a queued steering input.

task_id