AgentProof: Deterministic Payment Resilience & Chaos Testing

Inspiration

Payment integrations are the lifeblood of online commerce, but they are also the most fragile. When a checkout runs smoothly, everything looks fine. But under real-world conditions—network drops, rapid double-clicks, retry storms, and duplicate webhook notifications—subtle timing bugs emerge:

  • A buyer is charged twice for a single cart.
  • An order is fulfilled twice because a webhook arrived out of order.
  • A merchant charges more than the authorized limit.

Standard unit tests run sequentially and pass 100% of the time, while typical staging sandboxes cannot simulate concurrent race conditions. Developers only discover these bugs when angry customers demand refunds. We asked ourselves: What if we could systematically break payment flows in a controlled sandbox and automatically find the exact sequence that caused the failure? That question inspired AgentProof.


What It Does

AgentProof tests real PayPal Sandbox payments against deterministic chaos. Rather than relying on guesswork, it formalizes payment safety:

  1. Live Sandbox Verification: Executes real end-to-end PayPal Sandbox transactions with cryptographic webhook verification.
  2. Deterministic Chaos Injection: Explores adversarial interleavings—simulating dropped connections, duplicate webhooks, and retry races.
  3. Automated Invariant Checking: Evaluates payment guarantees after every step, such as ensuring captured amount never exceeds customer authorization: $$\text{Captured Amount} \le \text{Authorized Limit}$$ $$\text{Fulfillments} = \begin{cases} 1 & \text{if payment successful} \ 0 & \text{otherwise} \end{cases}$$
  4. Minimal Counterexample Shrinking: If a violation occurs among hundreds of permutations, AgentProof reduces the sequence to the smallest possible steps ($2$ or $3$ actions) so developers can replay and fix it immediately.
  5. AI Attack Scenarios: Uses Google Gemini to generate creative edge-case attack scenarios tailored to merchant-specific business logic.
  6. AG Studio Analytics: Provides interactive charts and an embedded conversational assistant to explore failure patterns without cryptic technical jargon.

How We Built It

We designed AgentProof from day one as a modern, high-performance monorepo:

  • Frontend: Built with React 19, Vite, and TypeScript, styled for a clean developer-tool aesthetic. We integrated AG Grid and AG Studio to render interactive datasets and visual failure timelines.
  • Backend: Powered by the Bun runtime and Hono framework for high-throughput, low-latency API handling.
  • Database & State: PostgreSQL paired with Drizzle ORM manages sessions, idempotency logs, webhook traces, and execution results.
  • Payment Gateway: Integrated directly with PayPal Sandbox REST APIs v2 alongside cryptographically verified webhook listeners.
  • AI Engine: Integrated Google Gemini 2.5 Flash to analyze merchant business constraints, generate red-team attack scenarios, and answer questions through our conversational analytics assistant.
  • Chaos Engine: A custom property-based model explorer capable of generating combinatorial schedules, evaluating invariants, and pruning failure traces into minimal reproducible artifacts.

Challenges We Faced

  1. Bridging Real-World Latency with Deterministic Testing: Real payment APIs take seconds to complete, making exhaustive live testing slow. We solved this by pairing real baseline PayPal Sandbox checkouts with our local deterministic chaos engine that explores hundreds of timing permutations without incurring API rate limits.
  2. Cryptographic Webhook Handshakes in Local Development: Verifying PayPal webhooks requires public callback endpoints with valid SSL certificates and PayPal transmission signatures. We established an automated tunnel workflow with real-time signature verification against PayPal's public certs.
  3. Translating Complex Chaos Data into Human Insights: Property-based testing outputs dense JSON traces that overwhelm developers. We spent considerable effort building clean mappings in AG Studio and prompting Gemini to deliver crisp, jargon-free explanations of failures.
  4. Test Case Shrinking: When a complex 15-step schedule failed, finding which two events triggered the race condition was challenging. Implementing greedy shrinking algorithms allowed us to isolate the minimal failure path deterministically.

What We Learned

  • Idempotency is harder than it looks: Even teams with good intentions often make subtle assumptions about webhook arrival order and network retry timing that lead to duplicate fulfillments.
  • AI as an Adversary: LLMs excel at imagining unexpected corner cases—like a buyer canceling authorization right as a delayed capture request fires—that humans overlook.
  • The Power of Interactive Analytics: Integrating AG Studio transformed our tool from a CLI test runner into an intuitive audit dashboard where non-engineers and product managers can assess payment reliability.

Built With

Share this project:

Updates

Submission history