Skip to main content

TaskStore

Trait TaskStore 

Source
pub trait TaskStore:
    Send
    + Sync
    + 'static {
Show 13 methods // Required methods fn create_task<'life0, 'life1, 'async_trait>( &'life0 self, tool_name: &'life1 str, arguments: Value, ttl: Option<u64>, owner: TaskOwner, ) -> Pin<Box<dyn Future<Output = Result<(String, CancellationToken)>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn task_owner<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskOwner>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskObject>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_task_result<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskSnapshot>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn wait_for_completion<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskSnapshot>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn list_tasks<'life0, 'async_trait>( &'life0 self, status_filter: Option<TaskStatus>, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskObject>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn require_input<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, requests: InputRequests, message: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait; fn outstanding_input_requests<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<InputRequests>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn apply_input_responses<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, responses: InputResponses, ) -> Pin<Box<dyn Future<Output = Result<Option<AppliedInputResponses>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn set_ttl<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn complete_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, result: CallToolResult, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn fail_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, error: JsonRpcError, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn cancel_task<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, reason: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskObject>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait;
}
Expand description

Storage backend for async task state.

Implementations persist task lifecycle state keyed by task ID. The default implementation is MemoryTaskStore; external stores (Redis, Postgres, etc.) typically live in separate crates.

§Semantics

  • Terminal states (TaskStatus::is_terminal) are immutable: once a task is completed, failed, or cancelled, further transitions must be rejected (Ok(false) from the transition methods).
  • An expired task is indistinguishable from an unknown one. Reads return None once ttlMs has elapsed since creation, whether or not the entry has actually been reclaimed, so callers cannot probe for the existence of a task whose retention window has closed.
  • cancel_task must signal the task’s CancellationToken even if the task is already terminal.
  • wait_for_completion blocks until the task reaches a terminal state; how an implementation waits (notification, polling, pub/sub) is an implementation detail and must not leak into the trait.

Required Methods§

Source

fn create_task<'life0, 'life1, 'async_trait>( &'life0 self, tool_name: &'life1 str, arguments: Value, ttl: Option<u64>, owner: TaskOwner, ) -> Pin<Box<dyn Future<Output = Result<(String, CancellationToken)>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Create and store a new task owned by owner.

Returns the task ID and a cancellation token for the spawned work. owner is the authenticated principal responsible for the task, or None when the request carried no authenticated context.

Source

fn task_owner<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskOwner>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read a task’s owner.

The outer Option distinguishes a known task from an unknown or expired one; the inner TaskOwner distinguishes an owned task from one created without an authenticated principal.

Source

fn get_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskObject>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get task object by ID. Returns None if unknown.

Source

fn get_task_result<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskSnapshot>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a task’s full snapshot (task object, result, error) by ID.

Source

fn wait_for_completion<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskSnapshot>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Wait for a task to reach a terminal state, then return its snapshot.

If the task is already terminal, returns immediately. Otherwise blocks until the task completes, fails, or is cancelled. Returns None if the task is unknown.

Source

fn list_tasks<'life0, 'async_trait>( &'life0 self, status_filter: Option<TaskStatus>, ) -> Pin<Box<dyn Future<Output = Result<Vec<TaskObject>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List all tasks, optionally filtered by status.

Source

fn require_input<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, requests: InputRequests, message: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Mark a task as requiring input, recording the requests to be answered.

requests replaces the outstanding set. Any key that was outstanding and is not re-issued becomes superseded; a re-issued key is a fresh question and becomes outstanding again even if previously answered.

Returns Ok(false) if the task is unknown, expired, or already terminal.

Source

fn outstanding_input_requests<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<InputRequests>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Read the requests a task is currently waiting on.

Returns an empty map when the task is not input_required, and None when the task is unknown or expired.

Source

fn apply_input_responses<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, responses: InputResponses, ) -> Pin<Box<dyn Future<Output = Result<Option<AppliedInputResponses>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Apply tasks/update.inputResponses to a task.

Consumes the keys that match an outstanding request and ignores the rest. When the last outstanding request is answered the task returns to TaskStatus::Working.

Returns None if the task is unknown, expired, or already terminal.

Source

fn set_ttl<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, ttl_ms: u64, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Update a task’s time-to-live, measured from creation.

SEP-2663 allows ttlMs to change over a task’s lifetime. Returns Ok(false) if the task is unknown or already expired.

Source

fn complete_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, result: CallToolResult, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a task as completed with a result.

A result carrying isError: true still completes the task: the tool ran and produced a domain error, which SEP-2663 distinguishes from an execution failure.

Returns Ok(false) if the task is unknown, expired, or already terminal.

Source

fn fail_task<'life0, 'life1, 'async_trait>( &'life0 self, task_id: &'life1 str, error: JsonRpcError, ) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Mark a task as failed with a structured execution error.

Returns Ok(false) if the task is unknown, expired, or already terminal.

Source

fn cancel_task<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, task_id: &'life1 str, reason: Option<&'life2 str>, ) -> Pin<Box<dyn Future<Output = Result<Option<TaskObject>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Cancel a task.

Signals the task’s CancellationToken and, if the task is not already terminal, marks it cancelled. Returns the updated task object, or None if the task is unknown.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§