The three acts
The Resilient Agent runs eight checks in three acts.
This page takes them one at a time: what each sets up, what it asserts, what
it asserts does not happen, and the numbers from the run the example's
README records. Each act's output is quoted verbatim from that README, which
captured it with A2A_TEST_POSTGRES_URL set; task ids and the store-lag
figure vary between runs.
Act 1 — Durability
src/durability.rs. The database is a per-run temp directory, removed on
every exit path so a later run cannot pass on a row an earlier one left.
[ok] SQLite: a completed task survives a handler restart task 887e9cce-d969-402b-b024-0fe6da1dffbc: Completed, 1 history message(s), 1 artifact(s) with 2 part(s) — 5 frames streamed, 4 push delivery(ies) received, 0 persistence errors, store Completed 14.185899ms after the stream ended; read back byte-identical by a fresh handler, push config intact
[ok] SQLite: a task cut off mid-stream is persisted as far as it got task 896067a2-0389-4526-b555-ad966c313e54: 3 frames seen before the cut; the new handler reads Working, 1 history message(s), 1 artifact(s) with 1 part(s) — chunk one persisted, chunk two never written; still Working after 500ms: the SDK does NOT resume an executor after a restart
Completed before the restart. Handler A (SqliteTaskStore::with_migrations,
SqlitePushConfigStore::new, an HttpPushSender so push configs are
accepted, and a recording Metrics) streams a task carrying an inline push
config to completion: Working, artifact chunk one, chunk two appended,
Completed. Every Arc to A is dropped. Handler B is opened over the same
file with new pools. GetTask on B must equal A's read as a whole JSON value
(status, history, artifacts, timestamps), and
ListTaskPushNotificationConfigs on B must list exactly the webhook.
Two things this act measured rather than assumed:
- The stream ends before the store is written. The streaming reader and
the persister are separate subscribers to the event queue, so the client
sees
Completeda few milliseconds beforeGetTaskdoes — 11-14 ms on the machine the README was recorded on. The first version of this check read the task straight after the stream and found itWorking; the check now polls and prints the lag. A client that restarts an agent the instant its stream ends can lose the terminal write.Metrics::on_persistence_erroris the SDK's only report of a write that failed outright, and the act asserts it stayed at zero. - A task cut off mid-stream is persisted as far as it got and is not
resumed. The executor emits chunk one and then parks forever — a process
death from the store's point of view. B reads the task
Workingwith exactly chunk one, and it is stillWorking500 ms later on the new handler. Nothing in the SDK reconciles or re-drives an in-flight task after a restart; a deployment needs its own sweep (for example, mark staleWorkingtasksFailed) or an idempotent re-send from the client.
Act 2 — Failure injection
src/failure.rs, with the injectors in src/support/injectors.rs. Every
fault is on a real socket or in a real executor, in front of a real agent, so
the success path is a genuine agent reply.
[ok] Executor failing its first N attempts: the SDK does not retry it N=2: sends 1..=2 -> Failed, send 3 -> Completed; executor invoked 3x for 3 sends with a 5-retry client policy (a Failed task is a successful RPC); a follow-up on the Failed task is refused. The Failed task's status message carries the error text ("[-32603] injected failure on attempt 1"), GetTask returns the same, and the streamed status event still carries it as metadata.error ("[-32603] injected failure on attempt 1")
[ok] Push webhook refusing its first M deliveries: what Metrics reports M=2, 4 events: sender with 1 attempt -> delivered=2, failed=2 (webhook refused 2, accepted 2); sender with 3 attempts -> delivered=4 (webhook refused 2, accepted 4, 4 delivered after in-sender retries). A `failed` delivery is not re-queued. Defaults: HttpPushSender::new() schedules 98s per delivery against push_delivery_timeout=5s, so its retries are cut short (`timeout_truncated`)
[ok] Client RetryPolicy: transport faults retried only where a re-send is safe K=2: GetTask over dropped connections -> ok (proxy faulted 2, forwarded 1); SendMessage over dropped connections -> error to caller (faulted 1, forwarded 0: not retried, ambiguous); SendMessage over 503s -> ok (faulted 2, forwarded 1); executor ran 2x
Executor failing its first N attempts (FlakyExecutor, N=2). Each send
is a new task; the first N come back Failed, the third Completed. The
executor's invocation counter equals the number of sends, with a 5-retry
client policy on the calls, because a Failed task is a successful RPC and
nothing in RetryTransport or the handler re-runs it. A follow-up on the
failed task's id is refused: terminal tasks accept no new messages, so
"retry" means "new task". The executor's error text is the Failed task's
status message — an agent-role Message with one text part, which the sync
collector copies onto the task and the store persists — so a blocking caller,
and a GetTask after the fact, both read why. The act builds its handler with
expose_internal_errors(): by default an internal error's text is withheld
from callers, who are given a reference to it in the log instead. The act streams a second
failing send to show the event still carries metadata.error for streaming
callers.
Webhook refusing its first M deliveries (webhook_sink, M=2, answering
503). A recording Metrics collects on_push_delivery outcomes; the sink
tallies refusals and acceptances. Four events per task (Working, two
chunks, Completed), one delivery each:
| Sender | Metrics outcomes | Webhook saw |
|---|---|---|
PushRetryPolicy 1 attempt | delivered=2, failed=2 | refused 2, accepted 2 |
| 3 attempts, 10 ms backoff | delivered=4 | refused 2, accepted 4 |
The only retry is the sender's own attempt schedule inside one delivery; a
failed outcome is not re-queued. That schedule is bounded by the handler's
push_delivery_timeout: HttpPushSender::new().max_delivery_duration() is
98 s against a 5 s default, which the SDK itself labels timeout_truncated.
The act computes that arithmetic rather than waiting five seconds to watch it.
Proxy faulting its first K requests (faulting_proxy, K=2), twice: once
dropping the accepted connection unanswered, once answering 503.
RetryPolicy classes both as retryable, but re-sends a non-idempotent method
only when the failure proves the server never processed it (429 and
503):
| Call | Fault | Proxy | Result |
|---|---|---|---|
GetTask | Dropped connection | faulted 2, forwarded 1 | ok |
SendMessage | Dropped connection | faulted 1, forwarded 0 | error surfaced to the caller |
SendMessage | 503 | faulted 2, forwarded 1 | ok |
The executor ran twice in total (the seed task and the 503 case), so no
dropped-connection SendMessage reached it behind the caller's back. A note
for anyone writing their own injector: a 503 fault has to be decided per
request, because hyper's client keeps a 503'd connection alive and sends
the retry down it.
Act 3 — Horizontal scaling
src/scaling.rs. A replica is a handler with its own executor, queues and
port.
[ok] In-memory stores: a task created on replica A is not on replica B task d81e584b-320a-4af2-9043-9fa6033e296c: GetTask on A -> found; GetTask on B -> TaskNotFound — the default store is per-process, so a balancer in front of two replicas needs a shared store
[ok] PostgreSQL shared store: B reads A's task; B's subscriber sees the end only task 4f07b014-82a7-4a06-8d40-cd66180050e8: GetTask on B -> Completed, 2 artifact part(s), identical to A's; A's stream carried 2 artifact frame(s), B's subscription saw 0 and ended with Completed — the store is shared, the event queues are not
[ok] PostgreSQL shared rate-limit counter: one limit across two replicas limit 5/300s per caller, 12 sends alternating A/B: independent limiters admitted 10 (A 5, B 5); limiters sharing PostgresRateLimitCounter admitted 5 (A 3, B 2)
In-memory stores. A creates a task; GetTask on B is
ErrorCode::TaskNotFound, asserted on the code, not just "an error". The
default store is per-process.
Shared PostgresTaskStore. Two handlers, two pools, one database. A
streams a task; from its first frame B subscribes (SubscribeToTask) while
the executor is still running on A. B's subscription ends with Completed
— the reattach hook polls the store for a terminal state — but sees 0 of the
2 artifact frames A's stream carried, because event queues live in process
memory. GetTask on B then equals GetTask on A as a JSON value. This is the
same pair of properties crates/a2a-protocol-server/tests/multi_replica.rs
pins; here they are shown over a socket with the numbers side by side.
Shared rate-limit counter. Two handlers each with a RateLimitInterceptor
at 5 requests per 300 s window, a fixed per-run caller identity (so the
counter table, which outlives the process, cannot carry a previous run's count
into this one), and 12 sends alternating A/B:
| Limiters | Admitted |
|---|---|
| Independent (the default) | 10 (A 5, B 5) |
Each with its own PostgresRateLimitCounter::new(url) over the same table | 5 (A 3, B 2) |
Each replica gets its own counter instance and pool, as separate processes
would; what is shared is the a2a_rate_limit table and its atomic
INSERT … ON CONFLICT DO UPDATE … RETURNING.
Layout
| File | What it holds |
|---|---|
src/main.rs | Check/Outcome, the runner, the report and exit codes |
src/durability.rs | Act 1 |
src/failure.rs | Act 2 |
src/scaling.rs | Act 3 |
src/support/mod.rs | Serving on a loopback port, messages, the per-run caller identity |
src/support/executors.rs | StreamingExecutor (can die after its first chunk), FlakyExecutor |
src/support/injectors.rs | The refusing webhook and the faulting proxy |
src/support/metrics.rs | The recording Metrics |
src/tests.rs | Each act as a test, and the injectors on their own |
No dependency outside what the workspace already uses.
Where next
- Resilient Agent: how to run it, and the exit codes.
- Running More Than One Replica: Act 3 as deployment guidance.
- Idempotent Sends: the client side of a re-send that is safe.