Language

TaskContext<TInput> Class

Definition

The handler-facing context for a single task turn. Exposes the typed input, identity, entry mode, retry/steering signals, the crash-recovery count, and cooperative cancellation, matching Python's TaskContext. The protected constructor supports mocking; the engine populates instances internally.

public class TaskContext<TInput>
type TaskContext<'Input> = class
Public Class TaskContext(Of TInput)

Type Parameters

TInput

The task input type.

Inheritance
TaskContext<TInput>

Constructors

Name Description
TaskContext<TInput>()

Initializes a new instance of the TaskContext<TInput> class for mocking.

Properties

Name Description
Cancellation

A token signaled for any cancellation cause (timeout, steering-cancel, shutdown).

CancelRequested

Whether cancellation was requested by an explicit cancel cause.

EntryMode

How the handler was entered for this turn.

Input

The typed input for this turn.

InputId

The input id for this turn.

IsSteeredTurn

Whether the current turn was triggered by a steering input.

PendingInputCount

The number of pending (queued) steering inputs.

RecoveryCount

The crash-recovery count for this task (spec §22): 0 on a fresh run, incremented each time the task's lease is re-acquired under a new process instance (a crash/takeover recovery). Mirrors the persisted lease generation.

RetryAttempt

The zero-based retry attempt for the current turn (0 on the first try).

Shutdown

A token signaled when the host is shutting down.

Stream

Writes events to the stream associated with this task input.

TaskId

The task id.

TimeoutExceeded

Whether the per-task execution timeout was exceeded.

Methods

Name Description
ExitForRecoveryAsync(CancellationToken)

Exits the current turn for later recovery: releases the lease without a terminal status and signals the engine to park the task in_progress so it can be resumed elsewhere. This does not throw — after calling it the handler should return (any returned value is ignored). Only valid while Shutdown is signaled; calling it otherwise throws InvalidOperationException.

Applies to