## TL;DR
The agent keeps closing a dispute that keeps reopening because it never reads the current status and has no reopen limit. Fix: fetch the live status first and only close from a closeable state, make the close idempotent, count reopens, and after three reopens hand the case to a human with the full timeline. A reopen is usually new information, not a failed close.

```text
fraud agent failed to close reopened disputes and looped
```

## Use this when
- The same dispute id cycles between closed and open across agent runs.
- Close-call volume for one dispute grows without the dispute staying closed.
- Analysts report the agent fighting their manual reopens.

## Not for this skill when
- A dispute reopens once because new evidence arrived. That is the system working.
- The dispute never closes because the provider API errors. That is a different failure.

## Steps
1. Fetch the live dispute status before every close attempt. Verify: the close call only fires when the status is open or under review, never when already closed.
2. Make the close idempotent with a client-generated key built from dispute id and attempt number. Verify: two close calls for the same attempt produce one close event.
3. Track a reopen counter per dispute, incremented on each closed-to-open transition. Verify: the counter matches the transitions in the event log.
4. Set a reopen ceiling of three. Past it, stop closing and create an analyst task with the timeline attached. Verify: the fourth reopen creates a task, not another close call.
5. Log every status transition with timestamp and actor. Verify: an auditor can replay the full close and reopen sequence.

## Variant phrasings
### dispute reopened after close agent loops
Reopen-focused phrasing.
### agent cannot close dispute keeps reopening
Symptom-level search.
### reopened dispute close loop
Short loop phrasing.

Compatibility: Stripe, Adyen, and Braintree dispute APIs expose a status field and accept idempotency keys on writes; the pattern ports across providers.

## Why it happens
The agent's plan says "close the dispute" and it retries the plan on failure. But a reopen is not a failed close, it is a new state, often from new evidence or a buyer filing again. Without reading state first and counting reopens, the agent fights the state machine forever.

## Edge cases / pitfalls
- A reopen with new evidence deserves a fresh review cycle, not a loop guard trip. Check the evidence delta before counting it.
- Idempotency keys scoped too broadly swallow legitimate retries; scope the key per close attempt.
- Some providers reopen disputes spuriously; the ceiling still applies, escalate and let a human confirm.
- Prefer provider webhooks for status changes over polling; polling burns rate limits.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_djuag9PYawvi01D98Eqx-w
