← All articles
Practical guideWorkflow testing

How do I find which agent workflows could double-charge or double-email?

List every step that can't be undone (money moves, a message goes out, a record is created elsewhere), then ask what happens when each runs twice. Do it by hand, or let a tool find the steps and try the failures.

In this article
Conceptual illustration · AgentTwin journal

Illustrative test design

Illustrative test design: one required record for the request, one required notification for that record, and unrelated state left unchanged.
Check the effects, not only the reply. Illustrative test design; this image is not a run result.

List every step that can't be undone (money moves, an email or Slack message goes out, a record is created in another system), then ask what happens when each one runs twice. You can do that by hand, or let a tool find the steps and try the failures for you.

By hand

  1. Inventory the side-effecting steps. Charges, refunds and transfers. Emails, texts and Slack messages. Records created in CRMs and ticket systems. Read-only steps (searching, summarizing, reading) are safe to repeat; ignore them.
  2. Find what can repeat a step. Retries after timeouts and 5xx errors, rate limits, a webhook delivered twice, a crash and resume, a person or agent asking again.
  3. Check each step for a guard. An idempotency key, a unique constraint, or a "have I done this?" lookup before acting.
  4. Order by cost. Money first, then customer-facing messages, then internal records.

Automatically

npx agenttwin does these four steps for your repository. It scans for the services your code calls and the workflows that reach them (routes, webhooks, jobs and existing test suites), tests the top three by default, and prints each finding with an estimated cost per incident and the file and line. Discovery never runs your code or uploads source.

A report from a demo support agent (written for AgentTwin's product films, run on AgentTwin 0.3.38) looked like this:

$64.50 per incident  Your agent announced on Gmail although the Stripe refund never happened (Stripe returned a 500)
$60.00 per incident  The Stripe refund never happened when Stripe returned a 500
$48.00 per incident  Your agent refunded ch_at_1001 twice
$0.75 per incident   Your agent posted the same Slack message twice

Costs are estimates, and the report lists its assumptions (for example, engineering time at $120 an hour, and the share of incidents that reach support).

Related: Choose your first AI-agent workflow test and Idempotency keys.

Continue readingRegression tests for an AI agent that writes to a database and posts to Slack →
Evaluate one workflow

Can your workflow pass the same check after a failure?

Bring the entry point, dependency operations and result you need to preserve. Discuss whether AgentTwin supports the test, what preparation is needed and the scope and costs before proceeding.

Discuss your workflow Try the sample first →← Back to all articles