Beyond retries and checkpoints: engineering and testing transaction-aware recovery for tool-using AI agents.
The fulfillment service had committed a synthetic shipment record when its worker was terminated. The replacement could restart the workflow. It still needed evidence that the shipment record already existed or a service guarantee that repeating the request would preserve the original effect. Recovering an AI agent's execution state is not the same as recovering its business transaction.
The most useful result from 192 application attempts and 64 actual worker-termination trials was that the appropriate recovery policy depended on the service. Under the qualified durable idempotency contract, ordinary bounded retry matched the two durable worker policies on measured outcomes. It completed 24 of 24 application attempts and 8 of 8 process trials, with zero observed critical violations. Without downstream deduplication, ordinary retry duplicated shipment records after response loss, including with durable checkpoints. The transaction-aware policy recorded fewer critical violations in both trial types under that contract. Audited benchmark results
In Your AI Agent Works in a Demo. But Can You Trust It in Production?, I used a synthetic accounts-payable workflow to examine scoped access, deterministic policy, action-bound approval, and evidence-grounded explanations. This follow-up asks what happens after a permitted write leaves the worker. Authorization answers whether the worker may act. Recovery needs to establish what the service actually applied and what the replacement can safely do. The studies use different workflows and model setups. Previous article
What to take into a design review
Ask the downstream owner whether the same authorized request can be replayed with the same key, how long that guarantee lasts, and what evidence is available when replay is unsafe. The experiments below show how those answers change the recovery policy.
The shipment record survives the worker
Imagine the service inserts a shipment record and commits its transaction. The worker receives no response. Its checkpoint still describes the operation as pending. Restarting the worker restores a place to resume, but the shipment record belongs to a separate database with a different commit boundary. The previous attempt could have failed before commit, or the effect could already exist.
A retry policy that treats both histories alike can create a second record. A checkpoint can narrow the list of uncertain operations and retain attempt budgets, but it cannot supply a receipt the service never delivered. Three responsibilities follow from that separation:
- Execution recovery restores the workflow position and local progress.
- Transaction recovery resolves the status of a specific business operation or determines whether replay is safe.
- Evidence verification checks the actual effects, authorization and final claim independently of the worker that made the decision.
Ambiguous remote writes are an established distributed-systems problem. Durable execution engines, idempotent APIs and compensation patterns all address parts of it. Related agent work already explores phase-aware recovery, process faults and independent business-state evaluation. AgentResilience Lab assembles these concerns in a local, inspectable test harness with a controlled service, an owned process supervisor and a read-only business verifier. It is a focused research prototype for transaction recovery. Research landscape · Framework capability audit · Version 2 qualification
Temporal documents the same lost-completion window for Activities: an Activity can finish its work, lose the record of completion, and be invoked again. Its guidance assigns idempotency enforcement to the called service. The UndoBench preprint separately examines phase-dependent recovery in tool-using agents and reports the importance of verification and server-side deduplication after commit and before acknowledgment. This study isolates deterministic workflow execution and varies the downstream contract in a local order fixture. Its outcome counts belong to that design. Temporal Activity Definition · UndoBench preprint, sections 2 and 5–6
Transaction-aware agents also have direct precedent. SagaLLM applies saga-style compensation and validation to multi-agent planning, Cordon proposes staged semantic transactions for tool-using agents, and the Agentic Transaction preprint argues for ACID-style guarantees in agent systems. AgentChaos and ReliabilityBench inject model, tool and API faults into agents and score the results, and Exercised, Rarely Recovered surveys what public reports say about recovery across 50 agent harnesses and runtimes. This study does not propose a new transaction model. It measures how four conventional recovery policies behave at two real commit boundaries under two explicit downstream contracts, with business state checked independently. SagaLLM (PVLDB 18) · Cordon · Agentic Transaction · AgentChaos · ReliabilityBench · Exercised, Rarely Recovered
Where the model belongs
The benchmark reference worker is deterministic Python. It reserves inventory, creates a synthetic shipment record and records a notification through a local service. It makes no LLM or provider calls. The four arms vary recovery policy and keep the business rules, authorization, input and downstream behavior constant within a matched case.
A separate, optional LangGraph example uses a deterministic structured model stub to propose the next operation. The proposal cannot change the scoped payload, dispatch a new write around a pending operation, or claim completion independently. The same deterministic transaction gateway controls persistence, lookup, retry and stop decisions. That integration demonstrates an orchestration boundary for tool-using agents. It supplies no evidence about live-model reasoning or reliability, and its demo is excluded from the 256 attempts. Architecture · Deterministic LangGraph example
The candidate journal and business store have different roles. The service checks the synthetic principal, operation and payload scope, approval and business prerequisites before a mutation. It records the effect and its audit correlation together. The observer reads business state through a separate read-only connection. The child process and scoped service configuration are trusted local fixtures, so this design does not provide a sandbox for arbitrary code or authentication for production services. Threat model · Business service
Make the receipt prove something
The first version of the client exposed a useful review finding. For a shipment lookup, a synthetic stub returned HTTP 200 with a receipt body for notification. The client treated the response as confirmation. The status code alone carried no evidence that the intended operation had committed.
Version 2 distinguishes the stable logical operation key, the canonical payload fingerprint, and the per-dispatch ID. The operation key groups repeated attempts for the same tenant, order and operation. The payload fingerprint also binds customer and quantity. A direct response must correlate to the request, even if it describes an effect created by an earlier dispatch. A lookup must report authoritative committed evidence for the scoped operation and identify its effect. Wrong-scope, malformed or inconclusive evidence leaves the transaction unknown. The authority label is meaningful within the trusted local service contract. It is not remote cryptographic authentication. Review probe · Typed evidence contract
The fixture permits one logical instance of each operation per order. A production split shipment needs a stable shipment-instruction or action-instance ID allocated before dispatch. Each legitimate shipment gets its own identity, while retries for that shipment reuse its original identity. Bind the canonical payload per action instance. A fresh identity on every retry would defeat deduplication, and reusing the order-level identity for a second legitimate shipment would turn it into a conflict. Operation key implementation
After parsing the typed response, receipt validation checks the expected write and its request binding:
if ( evidence.operation != operation or evidence.scope != expected or evidence.logical_key != operation_key(operation, expected) or evidence.payload_sha256 != fingerprint(expected) or evidence.request_dispatch_id != dispatch_id ): return None The durable candidate records dispatching state before making the request. The excerpt below also shows the pre-dispatch test hook. Durable arms have a candidate state connection, while stateless arms do not persist the local save.
attempts += 1 dispatch_id = uuid4().hex save(state, operation, payload, "dispatching", attempts, metrics, dispatch_id) if before_dispatch is not None: await before_dispatch(operation) An authoritative receipt can resolve a pending operation. A definitive rejection permits a bounded retry when the trusted fixture has recorded and fenced the original dispatch. Sending that exact rejected dispatch later returns the recorded rejection and cannot mutate the store. A generic server error, timeout or empty lookup cannot provide the same assurance. A delayed original request might still commit after an empty read. Workflow · Receipt validation
On restart, A3 checks the pending operation before it can enter the dispatch loop:
if variant == "A3" and status == "dispatching": code = await reconcile(client, operation, expected, metrics) if code != 200 and (variant != "A3" or status != "dispatching" or durable_replay): while attempts < limit: What downstream idempotency changes
Both service profiles receive the same stable operation keys. In the no-deduplication profile, an ordinary retry sends a new dispatch ID and can create another business effect. In the durable profile, the service records the key, canonical payload hash and committed receipt transactionally with the effect. The same key and payload replay the original receipt within the retention horizon. A reused key with a different payload is rejected. Once the fixture observes expiry, it retains a tombstone and refuses replay. A late original using the same key cannot add a second effect under that contract.
The successful mutation and the idempotency insert below share the service's SQLite write transaction:
if evidence is None and code == 200: code, evidence = apply_mutation( db, operation, order, principal, fixture, dispatch_id, fail_before_shipment, ) if code == 200 and idempotency == "durable" and evidence is not None: db.execute( "INSERT INTO idempotencies VALUES (?, ?, ?, ?, 0)", (logical_key, payload_hash, evidence.model_dump_json(), clock() + retention_seconds), ) The default replay horizon is 3,600 seconds from the committed record. An observed expiry leaves a durable tombstone and returns HTTP 410 within the retained fixture lifetime. This policy refuses redispatch after expiry. For a production API, verify how long keys and tombstones survive independently of the client workflow. Idempotency implementation
This control lets ordinary retry be a fair baseline. A1 uses exactly the same logical key on its retry. When the original shipment record already exists, the service can return evidence of that record rather than insert another. A3 can still reconcile via an authoritative lookup, or redispatch the same key when the explicit durable replay contract applies and the attempt budget permits it. The fixture tests conflicts, delayed requests and expiry. It does not establish the same guarantees for a provider that drops keys or reuses them across payloads, or during failures outside the tested retention model. Compensation for a partially completed workflow is outside this study. Service and retention semantics · Negative tests
One worker behavior also changes with the contract. When the service advertises its durable replay contract, the reference worker skips its local stock pre-check and lets the service's authoritative reservation decide, so that a restarted worker can replay a reservation it already made. The durable comparison therefore varies the worker's pre-check as well as the service. This is why A0 and A1 can complete restarts in the scarce-stock group under durable idempotency but report failed restarts without it.
Separate response loss from process death
The application block used four profiles: clean execution, definitive rejection before shipment, loss of a committed shipment response with authoritative lookup, and the same loss with opaque lookup. Response suppression occurs at the in-process application transport boundary. It gives the worker an ambiguous result while the committed record remains observable.
The process block terminated actual project-owned Windows jobs at two barriers. Before dispatch, the process had reserved inventory but had sent no shipment request. The durable arms had saved the shipment as dispatching. After commit, the service signaled its committed shipment record and held the response. The supervisor independently checked the commit and original request correlation, killed the original worker's private job, and verified exit and drainage. It then released the response barrier and started a distinct replacement against the surviving service. These windows were applied across all four arms. The process block used authoritative lookup under both service contracts. Process design and verification
How the comparison was scored
| Arm | Recovery policy |
|---|---|
| A0 | One attempt per operation. After process death, restart without local progress. |
| A1 | Bounded ordinary retry. After process death, restart without local progress. |
| A2 | Bounded ordinary retry and durable progress. After process death, reopen the candidate journal. |
| A3 | Durable intent, typed evidence and scoped reconciliation. After process death, reopen unresolved operations and follow the evidence or qualified replay contract. |
The application matrix had three known fixture groups, four profiles, two service contracts, four arms and two deterministic repetitions. The process matrix had two groups, two crash windows, two contracts, four arms and two repetitions. Every planned slot was applicable and valid. The archive contains all 144 required application fault activations and 64 actual process activations. The remaining 48 slots were clean application controls.
The repetitions are deterministic: the same slot repeated reproduces the same decisions and is not an independent sample. Each application cell of 24 attempts covers 12 distinct conditions (three groups by four profiles), and each process cell of eight covers four (two groups by two windows). The counts are a conformance demonstration of the tested designs, not estimates of failure rates.
Strict completion required the authorized effect sequence with the expected counts, scope, quantities and stock balance, plus a truthful completion claim. A safe stop required an allowed partial state and an unknown claim. Failed restart remained distinct when a replacement could not resume but the business invariants held. Critical violations included duplicate effects and false claims of completion. The verifier inspected retained business rows independently of the candidate's account. Paired comparisons used the same group, profile, contract and repetition, then weighted fixture groups equally. Approved protocol · Raw and derived evidence
Application trials
Figure 1. Application outcomes. Each bar contains 24 valid attempts. The figure is generated directly from the frozen raw attempt ledger. The table in the results report provides a text alternative. Application outcome table
Without deduplication, A1 and A2 each completed 12 of 24 attempts and recorded 12 critical violations. In every one of those 24 violations, the worker claimed completion while the business store contained two synthetic shipment records. A3 completed 18 and stopped safely in six. Its six safe stops were the opaque response-loss cases, where it retained a reservation and one shipment record but did not record notification. A0 recorded zero observed violations and completed only six, with 18 safe stops. The difference between protection and completion is visible in that baseline.
With durable idempotency, A1, A2 and A3 each completed all 24 application attempts, with zero observed critical violations. A0's strict completion remained six because it did not retry after a failed or missing response. This finding is about the qualified service contract. It does not establish zero risk or show that a checkpoint itself prevents replay.
Real process trials
Figure 2. Outcomes after actual worker termination. Each bar contains eight valid attempts. The process trials are reported separately from simulated application response loss. Process outcome table
Without deduplication, A0 and A1 each recorded four failed restarts and four critical violations. The scarce-stock fixture could no longer reserve inventory when the stateless replacement restarted from the beginning. In the group with reservation headroom, the replacement could reserve again. The verifier detected those extra records. Headroom changed the observable failure mode while the restart policy stayed fixed.
A2 completed the four pre-dispatch attempts and duplicated the shipment record in all four post-commit attempts. A3 completed the four post-commit attempts by consulting the authoritative service. It stopped safely in the four pre-dispatch attempts because its persisted intent alone could not prove nonapplication. The supervisor knew no shipment request had reached the service. That information stayed on the observer side of the experiment and did not give the candidate permission to replay. The two variants had the same completion count, with different outcomes and different failure windows.
Figure 3. A2 and A3 had the same strict-completion count under no deduplication. The outcomes differed by crash window.
With durable idempotency, all four arms completed all eight process attempts per arm with zero observed critical violations. Even the stateless replacement could resubmit a prior logical operation and receive the existing effect under the fixture contract. That is a materially different recovery environment from the no-deduplication case. Audit and per-arm results
Paired differences and trade-offs
| Trial type | Service contract | Valid A2/A3 pairs | A3 minus A2 completion | A3 minus A2 critical violations |
|---|---|---|---|---|
| Application | No deduplication | 24 | +25 pp | −50 pp |
| Application | Durable idempotency | 24 | 0 pp | 0 pp |
| Process | No deduplication | 8 | 0 pp | −50 pp |
| Process | Durable idempotency | 8 | 0 pp | 0 pp |
These results change the order of the architecture decision. Start with what the service guarantees for an authorized logical write. If it durably binds the key to the payload and returns the original receipt, bounded replay may be sufficient for that operation. If the service cannot deduplicate but can return an authoritative receipt, persisted intent and scoped lookup can let the workflow continue after a committed response disappears. If neither guarantee is available, an explicit unknown result preserves the unresolved state for follow-up.
The process result makes the distinction concrete. Without deduplication, A2 and A3 each completed four of eight trials. Checkpoint-based retry completed the pre-dispatch trials and duplicated the shipment record after commit. Transaction-aware recovery completed the post-commit trials and stopped safely before dispatch when it could not prove nonapplication. A completion table alone would make these policies look equivalent in that block.
The durable path adds journal writes and can require an extra receipt query. In the matched durable application cell with opaque lookup, A1 and A3 each completed all six attempts and made 24 mutation dispatches, including the repeated shipment dispatches. A3 made six reconciliation calls and A1 made none. Candidate-time medians were 428 ms for A1 and 403 ms for A3 on this host. Six deterministic attempts per arm support describing those observations without drawing a speed conclusion. The archive records candidate time and process restart-plus-recovery separately. The study covers known synthetic fixture groups, two repetitions and a bundled A3 intervention. It provides no independent unseen holdout, stochastic model sample, isolated causal component estimate or general production performance guarantee. Timing and analysis records · Local results report
Choosing a recovery policy
| Downstream guarantee | Appropriate policy |
|---|---|
| Scoped, payload-bound replay is durable and the key is still within its qualified horizon | Use bounded retry with the same logical key. Add durable checkpoints when you need to resume a multi-step workflow without repeating known progress. |
| Replay is unsafe, but the service can establish the fate of the specific write | Persist intent, then reconcile through authoritative lookup. Continue on proven commit. Retry only after definitive nonapplication and fencing of an outstanding original request. |
| Neither safe replay nor authoritative resolution is available, or the replay contract has expired | Keep the operation pending, stop further dependent effects, and escalate with the evidence and open question. |
For production escalation, give the operator the logical action, payload fingerprint, dispatch IDs, observed receipts and the pending downstream effect. An operator should resolve the state from the system of record and record the evidence and authorization for any follow-up. If the business needs compensation, treat it as a separate authorized and idempotent action with its own audit, recovery semantics and potential failure. The prototype retains the unknown outcome. It has no operator queue or compensation workflow. Recovery correctness review
A practitioner checklist
- Define the logical write. Bind tenant, business entity, operation and canonical payload. Keep a per-dispatch correlation ID alongside any stable replay key.
- Decide where replay safety lives. Check whether the downstream service atomically records the effect and key, what it returns on payload conflict, and what happens when retention ends.
- Persist uncertainty before dispatch. A durable intent and attempt record should exist before an external write can leave the worker.
- Treat receipts as evidence. Require scope, effect identity and an authoritative contract. A missing or inconclusive receipt should leave an explicit unknown when replay safety is unproven.
- Exercise distinct faults. Test definitive pre-commit rejection, lost response after commit, and actual owned-worker termination independently. Verify the intended fault activated.
- Verify the business outcome. Read the system of record through an independent observer and check authorization, stock, effect counts, and whether the workflow reported completion truthfully.
The practical question for a workflow review is what evidence the replacement has before it sends another business write. The answer should be visible in the service contract and independently testable.
Reproduce the figures and review the evidence
The figure generator reads the archived ledger, verifies the raw digest and frozen slot order, and counts outcomes without executing a trial. From the repository root:
uv run --no-project --with matplotlib==3.10.8 python blog/generate_benchmark_figures.py The exact source archive and schedule are recorded under the freeze manifest. The run plan and JSONL evidence are available in the repository. Earlier development exercises retain their original data and provenance. Their rows are excluded from these results. The current Windows Application Control restriction prevented the final static checker from loading on this host. The recorded regression suite, targeted gate checks and independent ledger audit have separate verification records. Frozen manifest · Run plan · Raw ledger · Verification log
When you review a tool-using workflow, ask the service owner what happens if the same authorized write arrives again after the worker loses its response. A durable replay contract may make a simpler policy sufficient. An authoritative lookup can resolve a committed effect. When both are unavailable, an evidence-backed stop preserves the unresolved operation for follow-up. The worker's ability to resume is only one input to that decision.





