pub trait TaskStore:
Send
+ Sync
+ 'static {
Show 31 methods
// Required methods
fn save<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>;
fn get<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<Task>, A2aError>> + Send + 'a>>;
fn list<'a>(
&'a self,
params: &'a ListTasksParams,
) -> Pin<Box<dyn Future<Output = Result<TaskListResponse, A2aError>> + Send + 'a>>;
fn insert_if_absent<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>;
fn delete<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>;
// Provided methods
fn get_with_position<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<(Task, Option<u64>)>, A2aError>> + Send + 'a>> { ... }
fn count<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>> { ... }
fn health<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn isolates_tenants(&self) -> bool { ... }
fn supports_idempotency(&self) -> bool { ... }
fn database(&self) -> Option<StoreDatabase> { ... }
fn turn_claims(&self) -> Option<Arc<dyn TurnClaimStore>> { ... }
fn is_process_local(&self) -> bool { ... }
fn seals_content(&self) -> bool { ... }
fn claim_idempotency_key<'a>(
&'a self,
key: &'a str,
message_id: &'a MessageId,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<IdempotencyClaim, A2aError>> + Send + 'a>> { ... }
fn release_idempotency_key<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn idempotency_holder<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyHolder>, A2aError>> + Send + 'a>> { ... }
fn save_artifact_delta<'a>(
&'a self,
task: &'a Task,
delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn save_status_delta<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn try_save_artifact_delta<'a>(
&'a self,
_task: &'a Task,
_delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>> { ... }
fn try_save_status_delta<'a>(
&'a self,
_task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>> { ... }
fn save_appending_history<'a>(
&'a self,
task: &'a Task,
messages: &'a [Message],
limit: HistoryLimit,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn supports_event_log(&self) -> bool { ... }
fn append_event<'a>(
&'a self,
task_id: &'a TaskId,
seq: u64,
event: &'a StreamResponse,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>> { ... }
fn last_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>> { ... }
fn read_events<'a>(
&'a self,
task_id: &'a TaskId,
after_seq: u64,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RecordedEvent>, A2aError>> + Send + 'a>> { ... }
fn earliest_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>> { ... }
fn hold_events(&self, task_id: &TaskId, after: u64) -> Option<EventHold> { ... }
fn watch_event_log(
&self,
task_id: &TaskId,
) -> Option<Pin<Box<dyn Future<Output = LogWake> + Send>>> { ... }
fn event_log_covers<'a>(
&'a self,
task_id: &'a TaskId,
after_seq: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>> { ... }
fn trim_event_log<'a>(
&'a self,
task_id: &'a TaskId,
below: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>> { ... }
}Expand description
Trait for persisting and retrieving Task objects.
All methods return Pin<Box<dyn Future>> for object safety — this trait
is used as Box<dyn TaskStore>.
§Object safety
Do not add async fn methods; use the explicit Pin<Box<...>> form.
§Writes the handler makes again
When one of save, save_status_delta,
save_artifact_delta or
append_event fails with an error that says “not
now” (A2aError::is_unavailable), a turn’s event consumer makes the same
call again, for up to
HandlerLimits::store_write_retry.
The first call may have applied before its answer was lost, so each of
these must leave the store as one call would when called twice with the
same arguments: a save writes the same row, a delta that already applied
changes nothing or refuses as its compare-and-set would, and an append at
a position the log already holds does nothing. Answer “not now” only for a
failure a later call may get past (a lost connection, a timeout, a lock);
anything else is returned to the turn at once. The stores in this crate
keep this; tests/retried_statements.rs runs each of them twice.
§Example
use std::future::Future;
use std::pin::Pin;
use a2a_protocol_types::error::A2aResult;
use a2a_protocol_types::params::ListTasksParams;
use a2a_protocol_types::responses::TaskListResponse;
use a2a_protocol_types::task::{Task, TaskId};
use a2a_protocol_server::store::TaskStore;
/// A no-op store that rejects all operations (for illustration).
struct NullStore;
impl TaskStore for NullStore {
fn save<'a>(&'a self, _task: &'a Task)
-> Pin<Box<dyn Future<Output = A2aResult<()>> + Send + 'a>>
{
Box::pin(async { Ok(()) })
}
fn get<'a>(&'a self, _id: &'a TaskId)
-> Pin<Box<dyn Future<Output = A2aResult<Option<Task>>> + Send + 'a>>
{
Box::pin(async { Ok(None) })
}
fn list<'a>(&'a self, _params: &'a ListTasksParams)
-> Pin<Box<dyn Future<Output = A2aResult<TaskListResponse>> + Send + 'a>>
{
Box::pin(async { Ok(TaskListResponse::new(vec![])) })
}
fn insert_if_absent<'a>(&'a self, _task: &'a Task)
-> Pin<Box<dyn Future<Output = A2aResult<bool>> + Send + 'a>>
{
Box::pin(async { Ok(true) })
}
fn delete<'a>(&'a self, _id: &'a TaskId)
-> Pin<Box<dyn Future<Output = A2aResult<()>> + Send + 'a>>
{
Box::pin(async { Ok(()) })
}
}Required Methods§
Sourcefn save<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save<'a>( &'a self, task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Saves (creates or updates) a task.
§Terminal states are final
Every store shipped in this crate refuses a write — through this method
or any of the delta methods below — that would move a stored terminal
task to a different state, and does so atomically with the write. The
refusal is an UnsupportedOperation error that
TerminalStateConflict::from_error
recognises. See crate::store::terminal for why, and for what a
custom store has to do to give the same guarantee.
§Errors
Returns an A2aError if the store operation fails,
including the terminal-state refusal described above.
Sourcefn get<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<Task>, A2aError>> + Send + 'a>>
fn get<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<Task>, A2aError>> + Send + 'a>>
Sourcefn list<'a>(
&'a self,
params: &'a ListTasksParams,
) -> Pin<Box<dyn Future<Output = Result<TaskListResponse, A2aError>> + Send + 'a>>
fn list<'a>( &'a self, params: &'a ListTasksParams, ) -> Pin<Box<dyn Future<Output = Result<TaskListResponse, A2aError>> + Send + 'a>>
Lists tasks matching the given filter parameters.
A store may return each task with only the last history_length
messages of its history (none for 0), saving the copy of the rest;
the caller trims to the same length either way, so a store that
returns whole tasks is correct too. The in-memory stores do this
since 2026-10-18 (ADR 0017). include_artifacts is the caller’s to
apply.
§Errors
Returns an A2aError if the store operation fails.
Provided Methods§
Sourcefn get_with_position<'a>(
&'a self,
id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<(Task, Option<u64>)>, A2aError>> + Send + 'a>>
fn get_with_position<'a>( &'a self, id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<(Task, Option<u64>)>, A2aError>> + Send + 'a>>
Retrieves a task with the position in its event log that the stored record reflects: every logged event up to that position is folded into it, and none after.
A subscription on a replica with no live queue for the task starts its
stream from this record, and replays the log after this position. A
processor logs each event before it stores the state the event leads
to, so the log’s end can hold an event the record does not reflect
yet; without the position, that event was neither in the snapshot nor
replayed (audit register R69). See
AppliedPosition for how a store
learns the position of each write.
The default reads get and reports no position, which the
subscription treats as unknown: it falls back to reading the log’s end
and then the task.
§Errors
Returns an A2aError if the store operation fails.
Sourcefn health<'a>(
&'a self,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn health<'a>( &'a self, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Whether the store can take a turn’s writes now: what a readiness probe
asks (RequestHandler::task_store_health).
The default asks count. The SQL stores answer
with a statement that costs the same however many tasks they hold, and
the PostgreSQL stores refuse a standby, which takes no writes. Until
2026-10-29 the probe was count, a SELECT COUNT(*) over every task:
it slowed as the table grew, until every replica’s probe timed out at
once (audit A2, E-F5). A wrapper store forwards its inner store’s.
§Errors
Returns an A2aError when the
store cannot be reached or cannot take writes.
Sourcefn isolates_tenants(&self) -> bool
fn isolates_tenants(&self) -> bool
Whether this store partitions what it holds by tenant.
A store answering true reads
TenantContext::current
on every call and keeps each tenant’s records apart, so a task saved
under one tenant is not readable, listable or cancellable under
another. The TenantAware* stores do.
Defaults to false, and that default is load-bearing in the same way
supports_idempotency’s is: the
handler refuses any request that resolves to a non-empty tenant unless
both its task store and its push-config store answer true. A store
that ignores the tenant therefore produces a loud refusal, never one
tenant reading another’s tasks. Until this existed, the default store
accepted a tenant field and silently shared every record — measured
2026-10-02 as five of five cross-tenant probes succeeding
(docs/sdk-comparison-2026-10-02.md §5.1).
A wrapper that forwards to another store must forward this too.
Sourcefn supports_idempotency(&self) -> bool
fn supports_idempotency(&self) -> bool
Whether this store can back idempotency keys.
Defaults to false, and that default is load-bearing: a server
advertises the idempotency extension only where this is true, and
refuses a send carrying a key where it is not. A store that has not
implemented claim_idempotency_key
therefore produces a missing advertisement and a loud refusal, never a
send that quietly runs twice. Silent at-least-once is what the feature
exists to remove; it must not also be what forgetting to implement it
produces.
Sourcefn database(&self) -> Option<StoreDatabase>
fn database(&self) -> Option<StoreDatabase>
The database this store runs against, which the handler names in a
CLIENT span around each of the store’s operations and measures in
db.client.operation.duration (the OpenTelemetry database
conventions; crate::store::traced).
Defaults to None, which records neither: a store that keeps its
tasks in a database but does not override this gets no span and no
latency for any operation, so a slow or failing database shows up only
as slow or failing calls. The in-memory stores take the default, as
they run against no database. The bundled SQL stores answer
postgresql or sqlite.
A wrapper that forwards to another store must forward this too.
Sourcefn turn_claims(&self) -> Option<Arc<dyn TurnClaimStore>>
fn turn_claims(&self) -> Option<Arc<dyn TurnClaimStore>>
The turn claims of the database this store writes to, if it is one
several replicas can share (crate::store::claim).
With Some, the handler claims each task for the length of a turn,
so a send to a task another replica is running waits for that turn,
or is refused, exactly as it would on the replica running it; and
every write the turn makes must be fenced by the store with
current_fence, in the same
atomic step as the write, refusing it with
ClaimLost when the token no longer
holds a claim.
Defaults to None: no claim is taken, and a store several replicas
share is safe only when every turn of a task is routed to one of them
(session affinity). The in-memory stores take the default, as nothing
outside their process can write to them. The bundled SQL stores answer
Some, over their own database.
A wrapper that forwards to another store must forward this too.
Sourcefn is_process_local(&self) -> bool
fn is_process_local(&self) -> bool
Whether this store keeps its tasks in this process alone, so that they are gone when it stops and no other process can read them.
The default is false: a store this crate cannot see into (yours, over
Redis, say) is taken to be durable and shared, as the other store traits
take theirs. The in-memory stores answer true, and so do the SQLite
stores over sqlite::memory:.
Profile::DurableProduction
refuses a store that answers true.
A wrapper that forwards to another store must forward this too.
Sourcefn seals_content(&self) -> bool
fn seals_content(&self) -> bool
Whether this store seals the content of every task before it is written, so the database, its backups and its replicas hold no message or artifact in the clear.
The default is false. EncryptedTaskStore (feature encryption)
answers true. Profile::RegulatedData
requires it, or a declaration that the storage is encrypted another way
(ExternalControl::EncryptionAtRest).
A wrapper that forwards to another store must forward this too.
Sourcefn claim_idempotency_key<'a>(
&'a self,
key: &'a str,
message_id: &'a MessageId,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<IdempotencyClaim, A2aError>> + Send + 'a>>
fn claim_idempotency_key<'a>( &'a self, key: &'a str, message_id: &'a MessageId, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<IdempotencyClaim, A2aError>> + Send + 'a>>
Atomically claims key for task_id on behalf of message_id.
Concurrent claims of one key must resolve to exactly one
Claimed; every other caller observes
Replay or
Conflict. An implementation that is not
atomic here reintroduces the double execution this prevents.
§What counts as the same request
The message_id, not the message body. A genuine retry resends the
identical message — the caller kept it in order to resend it — so its
id is unchanged, while a distinct send carries a fresh one. This
compares message identity and deliberately does not hash content: a
caller reusing one MessageId for two bodies has already broken an
invariant the protocol cannot check on its behalf.
§Errors
The default implementation reports an unsupported operation; it is
never reached unless
supports_idempotency is true.
Implementations return an error if the store operation fails.
Sourcefn release_idempotency_key<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn release_idempotency_key<'a>( &'a self, key: &'a str, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Releases a key claimed by claim_idempotency_key,
so it can be claimed again.
§Why this exists
A claim is taken before the send’s remaining side effects — the queue lease, the task row, the inline push config — precisely so that two racing duplicates cannot both get past it. Any of those can still fail, and a claim left behind by a send that never created a task is worse than no claim at all: the caller’s legitimate retry would replay to a task id that never existed. Every failure path after the claim releases it, which is the same discipline the queue lease and cancellation token already follow.
Releasing a key that is not held is not an error; a failure path may run after another caller has already taken over.
§Errors
The default implementation reports an unsupported operation. It is
unreachable in practice: a release only follows a successful claim,
which only a store with
supports_idempotency can grant.
Sourcefn idempotency_holder<'a>(
&'a self,
key: &'a str,
) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyHolder>, A2aError>> + Send + 'a>>
fn idempotency_holder<'a>( &'a self, key: &'a str, ) -> Pin<Box<dyn Future<Output = Result<Option<IdempotencyHolder>, A2aError>> + Send + 'a>>
Reads who holds key, without claiming it: None when it is free.
§Why this exists
A send that has to wait for another replica’s turn must not hold its
idempotency key while it waits: a retry routed elsewhere would be
answered “accepted” by the key while the send it repeats could still
be refused when its wait ran out. So such a send takes the key only
once it holds the turn. A retry of a send that is running still has
to be told so at once, and that needs a read of the key that does not
take it; claim_idempotency_key
cannot be that read, because for a free key it claims.
Read once and not under a lock, so the answer can be stale by the time
it is used: the caller treats Some as “already accepted” and None
as “not yet”, and the claim itself, which is atomic, stays the
arbiter.
Defaults to None, which is right for a store whose handler takes no
turn claims (turn_claims is None): the
only caller is the wait for a turn another replica holds. A store that
returns claims and keeps keys must override it. A wrapper that
forwards to another store must forward this too.
§Errors
Implementations return an error if the store operation fails.
Sourcefn save_artifact_delta<'a>(
&'a self,
task: &'a Task,
delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_artifact_delta<'a>( &'a self, task: &'a Task, delta: ArtifactDelta, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Persists an artifact change that has already been applied to task.
§Why this exists
A streaming agent emits one artifact event per chunk, and the obvious
implementation persists each one with save — which
hands the store the whole task. The task grows with every chunk, so the
cost of one event is proportional to the number of events before it, and
the cost of a stream is quadratic in its length. Measured on the
backpressure/append_volume benchmark, a 502-event stream spent 43.4 ms
against the in-memory store versus 3.2 ms against a store that discards
everything: 13.5× of that stream was re-persisting artifacts already
persisted.
delta says exactly what changed, so a store that can update a record
in place does work proportional to the change rather than to the record.
§Implementing this
The default replaces the whole record via save, which is always
correct — every existing implementation keeps working unchanged, and a
store with no incremental update path should keep it. Overriding is
worthwhile for any store where applying a delta is cheaper than
rewriting the record.
All three stores shipped here override it, and what each one wins differs with its storage model:
| Store | Approach | Measured on a 500-chunk stream |
|---|---|---|
InMemoryTaskStore | Mutates the stored task in place | 43.4 ms to 2.5 ms |
SqliteTaskStore | json_set splices the tail into the document | 144.5 ms to 127.6 ms |
PostgresTaskStore | jsonb_set with || array concat | 798 ms to 500 ms |
The in-memory win is the largest because a full save there is a deep
clone and a delta is a Vec extend. The SQL stores keep one JSON
document per row, so they still rewrite the row internally; what the
delta removes is the Rust-side serialization of the whole task and its
transfer as a bind parameter. That is enough to flatten Postgres’s
per-event cost — 874, 1183, 1597 µs at 50, 250 and 500 chunks with
save, against 853, 840, 1000 µs with the delta — but not to make
either SQL store as cheap as memory. Only normalising artifacts into
their own table would do that, and the same measurements put the
per-event round trip well above the document-size term, so it would buy
the smaller half.
An override must leave the store holding exactly what save(task)
would have left it holding. delta describes a change already present
in task; if an implementation cannot apply it — the record is missing,
or its shape does not match — it must fall back to save(task) rather
than persist a divergent record.
§“What save would have left it holding” includes the bookkeeping
A delta is a cheaper way to perform a write, not a way to perform
fewer writes. Whatever per-write maintenance an implementation’s save
does — advancing an eviction or compaction counter, refreshing a
last-touched timestamp, updating a metric — an override has to do too,
or that maintenance silently stops happening in proportion to how often
the fast path is taken.
Both deltas shipped here got this wrong, and the failure is worth
stating because it is invisible to the obvious test. InMemoryTaskStore
paces its TTL sweep off a counter that every write advances, and neither
override advanced it. The reasoning in the artifact one was explicit and
wrong in an instructive way: an in-place delta adds no entry, so it
cannot push the store past its capacity bound. True — and irrelevant to
the other bound, because expiry is driven by elapsed time rather than
by growth, so a stream that only appends to tasks already stored still
ages every other task in the store. The better the fast path worked, the
more rarely anything was collected. Every functional test still passed:
the store held exactly the right bytes, just for ever.
§Errors
Returns an A2aError if the store operation fails.
Sourcefn save_status_delta<'a>(
&'a self,
task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_status_delta<'a>( &'a self, task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Persists a task whose status alone changed, without rewriting the rest of the record.
The same argument as TaskStore::save_artifact_delta, applied to the
other per-event write on the hot path. A Task carries its history,
which the send path grows by one message per turn up to an internal cap
of 1,024 messages (handler::messaging::MAX_TASK_HISTORY_MESSAGES,
which is crate-private and so not linkable from here),
so a turn emitting n status events through save on a channel
holding h messages does n * h work. Measured back to back on one
turn of 512 events, concurrency one, in-memory store, by
tests/swarm_scale::cost::a_turn_that_emits_many_events_on_an_aged_channel:
with save, 1,706µs / 18,609µs / 54,301µs at h of 1 / 200 / 600;
with this method, 1,044µs / 1,280µs / 2,248µs. The turn stops growing
with the channel’s age, which matters more than the 24x at h = 600.
It does not measurably change a turn that emits one event — four other
O(history) copies dominate that. docs/swarm-scale-findings.md has
both runs and the attribution.
§What an override must preserve
It must leave the store holding exactly what save(task) would
have, which for an ordered store includes the position: §3.1.4 orders
by status timestamp, so a status change moves the record and an
in-place edit still has to re-key its indexes. An implementation that
cannot apply the change — no such record — must fall back to
save(task) rather than drop the transition.
§Implementing this
The default replaces the whole record via save, which is always
correct. All three stores shipped here override it, and what each one
wins differs with its storage model. Measured on this box, 100 status
events on a channel holding 200 messages, medians of five runs:
| Store | Approach | save | this method |
|---|---|---|---|
InMemoryTaskStore | Edits the stored status, re-keys the indexes | 8,499µs | 639µs |
SqliteTaskStore | json_set on $.status, plus state/updated_at | 122,071µs | 37,216µs |
PostgresTaskStore | jsonb_set on ARRAY['status'], plus state/updated_at | 287,287µs | 120,104µs |
The in-memory win is the largest because a full save there is a deep
clone and the delta is a field assignment. The SQL stores keep one JSON
document per row and still rewrite the row internally; what the delta
removes is the Rust-side serialization of the whole task — history
included — and its transfer as a bind parameter.
Two columns are as much part of “what save would have left” as the
document is, and an override that misses either is wrong in a way no
round-trip test of get would show: the state column that list
filters on, and updated_at, which carries the §3.1.4 ordering key.
SqliteTaskStore additionally must not delete its artifact journal
here, though its save does. save deletes those rows because it has
just rewritten the document with every part in it; a status delta has
not, so the rows are still the only record of the appended parts and
deleting them would lose data.
Callers must use this only when the status is genuinely the only field
that moved; the background processor appends to history on an agent
Message event and calls save for exactly that reason.
§Errors
Returns an A2aError if the store operation fails.
Sourcefn try_save_artifact_delta<'a>(
&'a self,
_task: &'a Task,
_delta: ArtifactDelta,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn try_save_artifact_delta<'a>( &'a self, _task: &'a Task, _delta: ArtifactDelta, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
Applies an artifact delta in place if this store can, and writes
nothing if it cannot: Ok(true) when applied, Ok(false) when the
caller must write the task whole.
save_artifact_delta is this
followed by save on false. The split exists for a wrapper that
transforms parts before storing them —
EncryptedTaskStore (the encryption feature) seals each one — so that it can transform only what an in-place write
stores, and everything only when the write is whole.
§What an implementation may read from task
Only what the delta writes: the appended parts (the last count of
artifacts[index]) or the pushed artifact, that artifact’s id and
metadata, and the task’s status and metadata. Every other part may
be a placeholder that cannot be opened. An implementation that reads
more must return false instead.
§What not overriding it costs
The default writes nothing and returns false, which is always
correct: the caller writes the task whole. Behind
EncryptedTaskStore that means sealing every part of the task on
every artifact event, so a stream of n chunks costs about n²/2
seals instead of n (release audit F7). Override it with exactly the
in-place path of save_artifact_delta.
§Errors
The store’s error, and the terminal-state refusal save would report.
Sourcefn try_save_status_delta<'a>(
&'a self,
_task: &'a Task,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn try_save_status_delta<'a>( &'a self, _task: &'a Task, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
try_save_artifact_delta for
save_status_delta: writes the status
in place and returns true, or writes nothing and returns false.
An implementation may read only task.status (and the id). Not
overriding it costs what the artifact one does, per status event: behind
EncryptedTaskStore, every part of the task is sealed on every
status transition.
§Errors
The store’s error, and the terminal-state refusal save would report.
Sourcefn save_appending_history<'a>(
&'a self,
task: &'a Task,
messages: &'a [Message],
limit: HistoryLimit,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn save_appending_history<'a>( &'a self, task: &'a Task, messages: &'a [Message], limit: HistoryLimit, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Persists a task whose history grew by messages, without the caller
shipping the history it has already stored.
task.history is ignored. The appended messages come from
messages and nothing else. That is deliberate and is the whole point:
the caller does not have to hold, clone or transfer the conversation in
order to add one turn to it, so a send stops costing what the channel
has accumulated. Reusing task.history for the tail — the shape
TaskStore::save_artifact_delta uses — would have put the caller
back in possession of the whole thing.
Every other field of task is the new snapshot and replaces what is
stored, exactly as save would.
limit is what the merged history is trimmed to, oldest first, by
message count and by bytes (HistoryLimit::trim). It is a parameter
rather than a constant here because retention is the handler’s policy,
not the store’s; a store that invented its own cap would silently
disagree with the one the rest of the server enforces.
§Implementing this
The default reads the record, appends, trims and writes the whole thing
back through save, which is always correct and is what the send path
did before this method existed — so a store that does not override it
is no worse off than it was. Overriding is worthwhile for a store that
can append without rewriting: the in-memory one extends a Vec in
place.
The SQL stores take this default: a read and a write of the whole
document, so an append costs in proportion to the history kept, which
limit bounds. They do not splice the tail in the database, because a
JSON column is rewritten whole by any update: measured on PostgreSQL
16.15 with a task holding 1.04 MB of history (91 KB stored, TOAST
compressed), appending one message with jsonb_set in the database
wrote 200,712 bytes of WAL and replacing the whole document 190,448,
three runs alike (audit NEW-h-designs-6, ADR 0044). A splice would save
the read and the transfer of the history, not the write, and would have
to repeat the byte trim and the write rules of save in SQL. That trim
counts bytes of serde’s compact JSON, which a trim computed in SQL would
not agree with, and one computed in Rust needs the history it was meant
not to ship (ADR 0047).
An override must leave the store holding exactly what the default
would have left it holding, including the trim, and must fall back to
inserting task when no such record exists rather than dropping the
turn.
§Errors
Returns an A2aError if the store operation fails.
Sourcefn supports_event_log(&self) -> bool
fn supports_event_log(&self) -> bool
Whether this store keeps a per-task event log.
false by default. A server reads this before offering
resumption-from-offset, so a store without a log degrades to the
snapshot behaviour rather than promising replay it cannot deliver.
Sourcefn append_event<'a>(
&'a self,
task_id: &'a TaskId,
seq: u64,
event: &'a StreamResponse,
) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
fn append_event<'a>( &'a self, task_id: &'a TaskId, seq: u64, event: &'a StreamResponse, ) -> Pin<Box<dyn Future<Output = Result<(), A2aError>> + Send + 'a>>
Appends one event at seq in the task’s log.
seq is a position, not a counter: the same (task_id, seq)
written twice must leave one row, so replaying an append is
idempotent rather than duplicating an event. That is the property
sqlite_store::journal already relies on, and for the same reason —
it makes a retried or overlapping write safe without a read first.
§Errors
A2aError if the store fails,
or unsupported_operation
when the store keeps no log.
Sourcefn last_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn last_event_seq<'a>( &'a self, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
The highest seq this task’s log holds, or 0 when it is empty.
Needed because a task outlives any one executor invocation: a task
parked at input-required and then continued gets a second
processor, and a seq restarting at 1 would collide with positions
the first one already wrote. Since appends are idempotent by
position, those collisions would be silently dropped — the
continuation’s events would simply not be recorded. Resuming the
numbering from here is what stops that.
§Errors
A2aError if the store fails,
or unsupported_operation when the store keeps no log.
Sourcefn read_events<'a>(
&'a self,
task_id: &'a TaskId,
after_seq: u64,
limit: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<RecordedEvent>, A2aError>> + Send + 'a>>
fn read_events<'a>( &'a self, task_id: &'a TaskId, after_seq: u64, limit: usize, ) -> Pin<Box<dyn Future<Output = Result<Vec<RecordedEvent>, A2aError>> + Send + 'a>>
Reads a task’s events in order, starting after after_seq.
after_seq is exclusive, so a subscriber that has seen event n
asks for n and receives n+1 onward — which is exactly the
Last-Event-ID contract, and avoids the off-by-one that an
inclusive offset invites at every call site.
§Errors
A2aError if the store fails,
or unsupported_operation when the store keeps no log.
Sourcefn earliest_event_seq<'a>(
&'a self,
task_id: &'a TaskId,
) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
fn earliest_event_seq<'a>( &'a self, task_id: &'a TaskId, ) -> Pin<Box<dyn Future<Output = Result<Option<u64>, A2aError>> + Send + 'a>>
The lowest seq this task’s log still holds, or None when it holds
nothing — or when the store cannot say, which is the default.
§Why a store has to be able to say this
read_events filters seq > after_seq and
returns whatever survives. If the head of the log is gone — truncated
by TaskStoreConfig::max_events_per_task, or swept as an orphan on a
SQL backend — the first event replayed is not after_seq + 1, and
nothing in that answer says so. The subscriber cannot tell it apart
from the numbering gaps this design calls normal (an append that
failed skips a position), so it silently receives a stream with a hole
in it and believes it resumed.
§The default, and why it is Ok(None) rather than an error
The other event-log methods default to unsupported_operation, because
a store that forgot to implement them should report no log rather than
an empty one. This one cannot: it was added to a trait that out-of-tree
stores already implement, and defaulting it to an error would break a
working store that keeps a perfectly good log (STABILITY.md §4). It
therefore defaults to “cannot say”, which is what every caller already
assumed before this existed.
None is consequently not evidence that nothing is missing. Read
it through event_log_covers, which
spells that out in one place.
§Errors
A2aError if the store fails.
Sourcefn hold_events(&self, task_id: &TaskId, after: u64) -> Option<EventHold>
fn hold_events(&self, task_id: &TaskId, after: u64) -> Option<EventHold>
Holds this task’s log after after for a stream that still owes those
positions, until the hold is advanced or dropped (spec §3.5.2); see
EventHolds. Synchronous: a stream takes
it while it is built. A wrapper must forward it.
None by default, and what that costs: a bounded log drops events a
slow stream still owes, which then ends with streamLagged. A store
that keeps the whole log (the SQL ones) loses nothing by it.
Sourcefn watch_event_log(
&self,
task_id: &TaskId,
) -> Option<Pin<Box<dyn Future<Output = LogWake> + Send>>>
fn watch_event_log( &self, task_id: &TaskId, ) -> Option<Pin<Box<dyn Future<Output = LogWake> + Send>>>
A registered wait for this task’s event log to change, for a
SubscribeToTask stream that would otherwise read the store on a timer
(audit E-F25 (b), ADR 0057). None, the default, is a store that
cannot say.
A stream on a replica that does not run the task learns of its events
by reading the log, and waits between reads. With a watch it waits on
the watch as well as on its timer, and a store that learns of every
append (the PostgreSQL stores, through LISTEN/NOTIFY, when
PostgresTaskStore::with_log_notifications (feature postgres) is set)
wakes it at once instead of at the timer’s end.
The watch is registered when this method returns, not when the returned future is first polled: the stream creates it, reads the store, and then waits, and an append made in between must wake it. It resolves at most once, and its being dropped ends the interest. A wake is a hint to read the store, never an answer: the stream reads again and goes back to waiting if nothing it cares about changed. Called from within the request’s tenant scope, as the store’s other methods are, so a tenant-aware store watches the partition the stream reads.
Synchronous, as hold_events is, and for the same
reason: it takes no I/O. A wrapper must forward it.
§What the default costs
Nothing is lost, and nothing is gained: a stream on a store that returns
None waits on its timer alone, as every release before this method
did, so an event written by another replica reaches it at the next
poll (subscribe_reattach_interval, backing off while the task is idle
to subscribe_reattach_max_interval) rather than at once. A wrapper
that does not forward the method is such a store, whatever it wraps.
Sourcefn event_log_covers<'a>(
&'a self,
task_id: &'a TaskId,
after_seq: u64,
) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
fn event_log_covers<'a>( &'a self, task_id: &'a TaskId, after_seq: u64, ) -> Pin<Box<dyn Future<Output = Result<bool, A2aError>> + Send + 'a>>
Whether a replay starting after after_seq can be served in full.
false means the log no longer holds after_seq + 1: the caller asked
to resume from a position that has been dropped, and serving
read_events would hand it a gapped stream
it cannot detect. Answer such a subscriber with an error, or with a
fresh snapshot — anything but a silent partial replay.
true means “no gap can be proven”, which is the honest reading: a
store whose earliest_event_seq is
the default answers true always, exactly as callers behaved before
either method existed.
Provided rather than implemented per store, so the comparison — and the
off-by-one in it, after_seq being exclusive — lives once.
§Errors
A2aError if the store fails.
Sourcefn trim_event_log<'a>(
&'a self,
task_id: &'a TaskId,
below: u64,
) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
fn trim_event_log<'a>( &'a self, task_id: &'a TaskId, below: u64, ) -> Pin<Box<dyn Future<Output = Result<u64, A2aError>> + Send + 'a>>
Drops this task’s events at positions below below, and returns how
many it dropped: the compaction of a live task’s log (audit H13, ADR
0047, option C), which
RetentionPolicy::max_events_per_live_task
drives from the SQL stores’ purge_expired.
The store trims exactly what it is asked to. Choosing below is the
caller’s: never past the stored snapshot’s position plus one, so every
event dropped is one the snapshot already reflects. A reader that then
asks to resume from before below is told the log no longer covers it
(event_log_covers answers false) and
is answered with the snapshot, as a lagged reader is, never with a
silently gapped replay. That is why a store that implements this must
also implement earliest_event_seq.
§The default, and why it is an error
unsupported_operation, as the other log methods default: a sweep
that asks a store which cannot trim learns so, rather than reading
0 as “nothing needed trimming”. It is new on a trait out-of-tree
stores implement, and an error breaks none of them: nothing in the
handler calls it.
§Errors
A2aError if the store fails,
or unsupported_operation when it cannot trim its log.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".