Inspiration

A payment timeout does not mean the payment failed.

That becomes dangerous when an AI agent is allowed to continue a commerce workflow autonomously. After a lost response, the agent may see only:

PAYMENT TIMEOUT / PAYMENT UNKNOWN / MERCHANT ORDER NOT CONFIRMED

Blindly retrying can create a duplicate financial effect. Blindly stopping can abandon a legitimate purchase. Looking only at the payment status is also not enough, because the correct recovery may depend on merchant reality such as inventory, order state, or fulfillment.

The question behind REVERSA became:

Can an AI agent recover a broken transaction safely by discovering what actually happened before it moves money again?

We wanted to test that question causally, not just build a polished demo around a happy path.

So we created blind worlds where the agent sees the same failure signal, while the underlying business reality changes.


What it does

REVERSA is a self-healing recovery layer for agentic commerce.

When checkout loses certainty, REVERSA:

  1. inspects the real PayPal payment state;
  2. obtains the business-state evidence required by that payment state;
  3. reconstructs the safe recovery transition;
  4. passes the proposed transition through deterministic policy;
  5. executes the allowed PayPal action;
  6. independently re-reads PayPal to verify the final financial outcome.

Depending on the evidence, the recovery outcome can be:

  • CAPTURE — complete an authorized purchase when fulfillment is still viable;
  • VOID — release an authorization when the purchase can no longer proceed;
  • RESTORE_ORDER — restore merchant-side state after a payment succeeded;
  • REFUND — reverse a completed payment when fulfillment is impossible;
  • DO_NOTHING — preserve an already healthy transaction;
  • ABSTAIN — refuse to move money when decisive evidence cannot be established safely.

The model never directly controls unrestricted financial APIs.

The Winning Moment

We tested REVERSA against three blind PayPal Sandbox worlds.

All three presented the same visible failure and began with the same PayPal state: a fresh authorization.

Only hidden inventory reality changed.

World A1

Payment timeout → PayPal authorization active → inventory available → CAPTURE → PayPal COMPLETED

World B

Payment timeout → PayPal authorization active → inventory unavailable → VOID → PayPal VOIDED

World A2

Payment timeout → PayPal authorization active → inventory available → CAPTURE → PayPal COMPLETED

Final result:

CAPTURE → VOID → CAPTURE

The final live gate produced:

aba_flip_pass                   true
all_independent_outcomes_pass   true
counterfactual_probe_paths_pass true
unsafe_executions               0
duplicate_financial_effects     0
no_leak                         true
result                          PASS

The model did not receive the blind-world label, expected action, hidden inventory truth, or test secret.

Same failure signal. Different reality. Different safe action.


How we built it

REVERSA deliberately separates reasoning, authorization, execution, and verification.

AI reasoning

We use the OpenAI Responses API with gpt-5.4-mini and Structured Outputs.

The model receives only model-visible transaction context and observations returned by allowed tools. Each reasoning step is constrained to a structured schema describing either an observation request or a recovery decision.

The reasoning layer cannot directly call arbitrary financial APIs.

Deterministic recovery policy

A protocol layer constrains which observation or financial transition is legal from the state already established by external evidence.

For example:

No PayPal truth yet
→ inspect PayPal

Active authorization + no capture
→ inspect inventory

Inventory available
→ CAPTURE

Inventory unavailable
→ VOID

This dependency graph does not contain the blind-world label or expected answer. It represents state-transition safety rules.

PayPal execution

The live proof uses the PayPal Sandbox developer platform.

We use PayPal Orders v2 to create and authorize AUTHORIZE checkout orders and PayPal Payments v2 to inspect and mutate payment state.

Real Sandbox actions used in the final proof include:

  • reading authorizations;
  • capturing authorized payments;
  • voiding authorizations;
  • reading captures after execution;
  • independently re-reading PayPal after each mutation.

Independent verification

REVERSA does not trust the AI model's statement that an action succeeded.

After a financial mutation, an independent verifier reads PayPal again and checks invariants such as:

  • expected action matches actual action;
  • amount and currency match;
  • authorization reached the expected final state;
  • capture reached COMPLETED when applicable;
  • no duplicate capture exists;
  • no unexpected refund exists.

Blind A→B→A harness

CAPTURE and VOID are irreversible, so the final experiment uses three separate real Sandbox authorizations.

The model-visible initial state remains the same, while the hidden merchant inventory world changes A → B → A.

That gives us a counterfactual test rather than a single successful example.

Judge-facing product

The public interface is a Next.js Recovery Console deployed on Vercel.

It includes:

  • animated recovery traces;
  • the blind A→B→A comparison;
  • independently verified outcomes;
  • real PayPal Sandbox identifiers;
  • safety metrics;
  • a SHA-256 Proof Lock.

The public hosted experience is read-only and uses the successful locked evidence. It does not expose PayPal or OpenAI credentials and cannot trigger new financial actions.


Challenges we ran into

A timeout is not an oracle

Our first challenge was preventing the system from interpreting a network timeout as either payment success or payment failure.

Recovery had to begin by establishing external truth instead of assuming what the timeout meant.

Safety versus over-abstention

An early version was safe but overly conservative. The model sometimes chose ABSTAIN even though another external observation could resolve the situation.

We addressed this with a deterministic probe dependency graph. If an active authorization exists and inventory has not yet been checked, for example, the system must obtain inventory evidence before it can stop or move money.

Structured model outputs

Prompting the model to "return JSON" was not strong enough for a financial recovery protocol. During an early live run, a malformed concatenated response broke parsing.

We replaced prompt-only JSON with Structured Outputs so the API constrains every reasoning turn to a validated schema.

Irreversible payment actions

CAPTURE and VOID cannot simply be reset after a test.

The A→B→A runner therefore had to be resumable. A previously independently verified PASS can be preserved while an untouched slot is retried.

PayPal Sandbox settlement behavior

A correct capture initially remained PENDING.

The PayPal response exposed the exact reason:

RECEIVING_PREFERENCE_MANDATES_MANUAL_ACTION

That led us to the Sandbox merchant receiving-preference configuration. After correcting the merchant configuration, the clean final gate produced terminal COMPLETED captures.

Proving rather than claiming

We did not want the final demo to rely on screenshots or self-reported success.

We added:

  • independent PayPal re-reads;
  • duplicate-effect checks;
  • hidden-world leak checks;
  • zero-unsafe-execution metrics;
  • SHA-256 locking of the final evidence;
  • a hosted proof snapshot whose build verifies its integrity.

Accomplishments that we're proud of

The result we are most proud of is the real blind PayPal Sandbox counterfactual:

CAPTURE → VOID → CAPTURE

from three initially identical visible timeout states.

The final proof has:

  • three independently verified real PayPal Sandbox outcomes;
  • zero unsafe financial executions;
  • zero duplicate financial effects;
  • no hidden-world leak;
  • a successful A→B→A causal flip;
  • locked evidence with SHA-256 integrity verification.

We are also proud that the product does not solve safety by simply removing autonomy.

REVERSA still uses AI to reason about uncertain transaction state, but financial authority is deliberately bounded by deterministic policy and independent verification.


What we learned

The biggest lesson is that agentic commerce needs a recovery layer, not just a payment tool.

API idempotency is necessary, but it answers a different question:

"Can I safely repeat this API request?"

REVERSA has to answer:

"What is the correct action now?"

That answer can depend on payment state and merchant state together.

We also learned that AI safety boundaries can improve the product experience. Requiring the system to gather explicit external evidence makes the recovery trace easier for humans to inspect and trust.

Another important lesson was to separate four responsibilities:

AI reconstructs.
Policy authorizes.
PayPal executes.
Independent evidence verifies.

That pattern is reusable well beyond payments whenever autonomous agents can trigger sensitive real-world actions.


What's next for REVERSA

The next production step is replacing the blind merchant-state harness with authenticated merchant integrations for:

  • inventory;
  • orders;
  • fulfillment;
  • webhook and event history.

From there, REVERSA can evolve into a reusable recovery service for AI shopping agents, autonomous checkout systems, and merchant copilots.

Planned extensions include:

  • merchant-configurable recovery policies;
  • webhook and event reconciliation;
  • approval thresholds for high-value actions;
  • multi-provider payment recovery;
  • human escalation for ambiguous cases;
  • recovery analytics and incident replay;
  • production-grade authorization, audit, and observability.

The long-term goal is simple:

One intended purchase. One correct financial outcome. Even when the transaction breaks halfway.

Built With

  • agentic-ai
  • ai-safety
  • fastapi
  • gpt-5.4-mini
  • httpx
  • next.js
  • openai
  • openai-responses-api
  • paypal
  • paypal-orders-api
  • paypal-payments-api
  • paypal-sandbox
  • pydantic
  • pytest
  • python
  • react
  • sha-256
  • structured-outputs
  • typescript
  • vercel
Share this project:

Updates

Submission history