← All writing

Case study

When an agent restarts, who authorised the retry?

I compared four recovery policies across 120 synthetic failure cases, then tested competing processes and real SIGKILL webhook recovery. The result separates duplicate prevention, permission and justified completion.

Agent recoveryVerificationAI engineering

I was trying to answer a practical question: if an agent restarts after an external action, what gives it permission to try again?

My original October experiment made a £1 Stripe test payment, interrupted the agent before its tool returned, and inspected the outcome after recovery. That was useful, but it established a narrow boundary: Pi did not automatically replay the unsafe tool in those two recorded cases. It did not prove that a real workflow would always make the right next decision.

I returned to that boundary on 12 November with a deterministic recovery-contract experiment. The experiment compares four decisions under deliberately different failure conditions. The central result is not an algorithm; it is an executable demonstration of why duplicate prevention, current authority and justified knowledge of the outcome are separate requirements.

Four policies that sound similar until something breaks#

Imagine an external provider has accepted a write, but its response was lost. A recovering controller may try one of four approaches:

Policy Recovery decision Risk
A: fresh key Start another attempt under a new identifier The original action may already have succeeded
B: stable key Retry using the original idempotency key Deduplication has a defined scope; cancellation still matters
C: authority + evidence Preserve the original intent, enforce its frozen payload and current authority, reconcile provider evidence May have to report uncertainty if readback or provider cooperation is unavailable
D: hold Never retry while uncertain Avoids new effects, but can abandon legitimately recoverable work

I implemented a small synthetic provider with a durable SQLite effect ledger, separate from the recovering controller's SQLite database. Each test used new storage. The harness could commit an external effect, hide its response, interrupt work, withdraw permissions, change a payload or simulate an expired deduplication key.

This was a simulation, not a Stripe outage. The provider supports authoritative lookup and a cooperating idempotency cache by design. The expiry case uses a synthetic logical clock. No real Stripe key was observed being pruned.

What the tests actually counted#

The experiment ran ten failure cases for each policy, with three repetitions: 120 isolated scenarios. The scorer reopened the provider's own ledger to count effects rather than trusting the controller's last message.

Policy Safety violations in 30 simulated cases Duplicate effects Confirmed-progress cases Unresolved claims
Fresh key 24 21 6 0
Stable key 9 3 18 3
Authority + evidence 0 0 18 3
Hold 0 0 3 27

These numbers are fixture outcomes, not failure probabilities. Repeating the same deterministic conditions three times checks repeatability; it does not sample production behaviour.

The two policies with zero observed violations also behaved very differently. The authority-aware policy could confirm 18 legitimate outcomes in the modelled cases, while holding the remaining uncertain or unauthorised work. The blanket hold could confirm only the three clean controls. Simply reporting zero duplicates would conceal that difference.

The stable-key policy avoided many duplicates, but it could still dispatch after cancellation. It also created a second effect in the intentionally simulated retention-expiry case. Stripe documents finite API v1 key retention and parameter-consistency checks; a reusable key is not permanent business authorisation.

I tested processes, not just decision functions#

I then used two separate Node processes to compete for the same controller ledger. Across nine runs, the fresh-key policy accepted six writes and produced six provider effects, three of them duplicates. The stable-key policy accepted six requests but the cooperating provider recorded three effects. The authority-aware admission ledger accepted only three requests, yielding three effects.

That is evidence for this local transactional admission implementation. It is not proof of multi-region worker exclusion or safe concurrency with an arbitrary provider.

The downstream webhook test went further than my October marker-only exercise. It used a durable inbox and a separate receiver database, then killed the worker process at two dangerous moments: just before the receiver effect, and just after the effect but before acknowledgement. A new process recovered the pending event and delivered it again. Across 15 normal, crash and rejection cases, the receiver recorded exactly one measurable effect per event.

The essential condition was the receiver's unique event identity. Without cooperating deduplication, a crashed sender cannot always determine whether an external action already happened. I also tested fifteen scripted changes of amount, recipient, operation identity and authority epoch: the admission boundary rejected every unauthorised proposal. No live language model was used.

What real Stripe still confirms#

To keep the new study anchored to what actually happened in October, I performed fresh GET-only Stripe test-account readback. Both original £1 PaymentIntents still reported succeeded with the expected test metadata. A complete read-only creation-window query found zero payments for the separately attempted November hosted test, which stopped before its payment operation.

That readback does not turn the new synthetic fault matrix into a real-provider benchmark. Nor does it repair the original hosted assertion failure or prove that the corrected hosted runner passed on a fresh payment. I preserve those limits because they change what a reader can legitimately conclude.

What I would carry into production#

For a consequential tool call, I would require a stable business intent, a frozen request payload, an explicit current permission to dispatch, a durable record created before the external action, and a way to reconcile against provider evidence. I would give uncertainty its own visible state rather than treating a timeout as either confirmed success or confirmed absence.

I would also distinguish an in-flight write that commits after cancellation from a new write incorrectly dispatched after cancellation. The former can remain possible even when the application correctly refuses the latter.

That is a design direction supported by these limited tests, not a claim that I have deployed this complete policy to Post-Once, Stripe, or another customer's system.

13 November update: a real hosted Pi 1.4 interruption#

I followed the local fixture with a separate hosted Cloudflare Durable Object experiment on Agents 0.30.1 and Pi Durable 1.4.0. The worker was bearer-protected, restricted to two inert operation IDs, and had no Stripe binding or paid model inference.

In the completed path, two deliberately induced Durable Object terminations produced new instance identifiers. The operation reached parked, then an explicit release/retry completed it as done with an empty pending list. The tool-entry counter reached three; these were not three external business effects.

One surprising detail deserves preserving: a crash marker written immediately before terminating the object did not survive. It would be incorrect to claim that the expected marker persisted simply because the object was interrupted. Separately, the abort-path operation started but did not produce a verified terminal abort receipt. This is an incomplete experiment, not a 2/2 successful hosted comparison.

The temporary worker and secret were deleted. Its public endpoint returned HTTP 404, and its local bearer-token file was removed. The source, redacted readbacks and exact evidence verifier are published separately from the original October study.

This new observation strengthens the hosted lifecycle evidence. It does not resolve real Stripe response loss, genuinely expired idempotency keys, credential-revocation races, unattended alarm-only recovery or general exactly-once guarantees.

Prior work and the remaining research question#

A further literature check identified LIMBO, RetryBench, From Evidence to Effect and Permission to Retry. These already address duplicate side effects, durable authority, retry permissions and evidence-led recovery. My 120-case comparison therefore remains a reproducible engineering replication, not a claim of an original recovery theorem.

A future original study would need a clearly pinned implementation claim, a counterexample not already covered by those baselines, actual provider-grounded effects and a comparison against their strongest applicable policy.

Reproduce or challenge the result#

The signed source commit contains the standalone experiment, methods and limitations, and redacted numerical evidence.

The four offline suites need Node 24 and no paid model, external API, Stripe account or Cloudflare deployment. I also repeated them from a clean copy of the source. An owner-held 864-file evidence bundle passed integrity checks and rejected a deliberately corrupted copy; its hash is published with the summary. The evidence has not been independently reproduced or audited by an outside researcher.

The next research step is not simply to add more simulated faults. It is to identify a specific current recovery guarantee that these existing methods cannot explain, then test a minimal counterexample against a real provider, including changing permissions and retention guarantees. Until that evidence exists, this work is an inspectable engineering replication, not a new general recovery theorem.

My earlier Pi 1.3/Stripe case study and Pi 1.4 lifecycle experiment remain separate historical records.

Experiment design, implementation, execution support, analysis and drafting were AI-assisted. The recorded results and their limitations remain my responsibility.

Original publication: pinned GitHub article ↗

Continue reading