Failures

Duplicate side effect

The agent makes a change that was already made, because it decided from a view of the account that missed the earlier one.

· Ancha team

What it looks like

A customer is refunded twice. A channel gets the same announcement twice. The incident queue holds two tickets for one outage. Every call in the trace succeeded, so nothing in the logs looks wrong.

When it happens

The request arrives again, from a retry, a timeout or a person who asks twice, and the agent's lookup cannot see the earlier change. The lookup can be too broad (the newest refund on the whole account) or too narrow (only today's messages).

Expected

The agent finds the earlier refund on this payment and tells the customer it was already made.

Actual

The agent finds the newest refund on the account, which belongs to another customer, concludes this payment was never refunded, and refunds it again.

Reproduce it

The Stripe example reproduces it with no model and no account. Its task: “Laura at Pike Street Dental asked again for her $480 credit on yesterday's $2,000 payment. Make sure she gets it once.” Recorded with Ancha CLI 0.4.74:

AgentMade no second refund
Original agent0 of 3 trials
Fixed agent3 of 3 trials

The fix is one line in agent.mjs:

- const { data: refunds } = await stripe('GET', 'refunds?limit=1');
+ const { data: refunds } = await stripe('GET', `refunds?payment_intent=${payment.id}`);

The check that catches it

Check what the agent did, not what it said. The test passes only if the agent read the refunds and never called POST /v1/refunds.

checks:
  - id: looked_for_refunds
    trace: { called: "GET /v1/refunds" }
  - id: no_second_refund
    trace: { not_called: "POST /v1/refunds" }
pass: [looked_for_refunds, no_second_refund]

How to prevent it

  • Look up earlier changes by the object they belong to (refunds?payment_intent=…), not by recency across the account.
  • Reuse the same idempotency key when retrying the same write with the same parameters. Stripe returns the first result instead of refunding again. This covers a retried request, not a second decision to refund.
  • Keep the check after the fix, and add a test where the earlier change is not the newest one.