## TL;DR
Loops happen when failure returns the account to the same queue the agent reads from, with no memory of attempts. The agent is not misbehaving; it is stateless in exactly the place state matters. Track attempts per account per run, cap them, and move repeat failures to a dead-letter list for human review instead of back into the live batch.

```text
agent loop detected: churn monitor re-scored the same account 40 times in a failed batch
```

## Use this when
- One account appears dozens of times in a single run's log
- The batch never completes because the loop starves it
- The account's failure is deterministic (bad data, missing field)

## Not for this skill when
- The account's data keeps changing, triggering legitimate re-scores
- Multiple distinct accounts fail in rotation, a broader outage pattern

## Steps
1. Find the looping account in the logs and identify the exact error it returns each time. Verify: the deterministic failure is named
2. Inspect the batch loop: where failed accounts are re-queued and whether attempts are counted. Verify: the stateless re-queue point is located
3. Add per-run attempt tracking with a small cap and a dead-letter output for capped accounts. Verify: the looping account now dead-letters after the cap in a test run
4. Fix or quarantine the account's underlying bad data so it can score on the next run. Verify: the account scores cleanly or is explicitly excluded with a reason
5. Audit the full run's per-account attempt counts and alert when any account exceeds one retry. Verify: future loops surface in the run report immediately

## Variant phrasings
### agent re-scored same account 40 times
A related phrasing for the same underlying problem.
### scoring loop no attempt cap
A related phrasing for the same underlying problem.
### dead letter for failing accounts
A related phrasing for the same underlying problem.

Compatibility: Compatibility: batch agent runners (custom Python, LangChain, or queue-driven workers), current versions.

## Why it happens
A queue that returns failures to itself without memory will loop forever on the first poison account; this is the classic poison-pill problem from message systems, rediscovered by agents. Attempt caps and dead-letter queues are the standard cure because they bound the damage any single bad record can do.

## Edge cases / pitfalls
- Attempt state must survive agent restarts, or a crash resets the cap and the loop resumes.
- Dead-letter lists need an owner and a review cadence, or they become a silent exclusion list.
- Cap by account and error type: a transient timeout deserves more attempts than a deterministic schema error.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_AN4kq3ljHRWvs61dTYe8Rg
