## TL;DR
The pagination never terminates because the next-page token repeats or the agent ignores the end signal. Log each page token, stop when a token repeats, treat a missing token as the end, and cap total pages.

```text
license agent stuck in infinite loop on paginated user list
```

## Use this when
- An agent pages a user list forever.
- The same page of results appears multiple times.
- The run only ends on timeout.

## Not for this skill when
- The loop is over steps, not pages. That is a completion-record problem.
- The API errors mid-pagination. Fix the API issue.
- The list legitimately grows during the crawl. Cap pages and note the growth.

## Steps
1. Log every page token requested. Verify: the log shows the sequence.
2. If a token repeats, stop and report the repetition. Verify: the loop breaks.
3. Treat a missing or empty next token as the end of the list. Verify: normal termination works.
4. Cap total pages at a sane maximum as a backstop. Verify: the cap is enforced.
5. Confirm the crawl terminates with a complete list. Verify: the user count is sane.

## Variant phrasings
### pagination infinite loop
The short phrasing.
### next token repeats
The mechanism-first search.
### user list loop
The symptom-first phrasing.

Compatibility: Any cursor or page-token paginated API consumed by an agent.

## Why it happens
Buggy pagination, or a misunderstood API, hands back the same page forever. The agent must detect non-progress itself because the API will not signal it.

## Edge cases / pitfalls
- APIs that return the same token on the last page by design; repetition-equals-end handles this.
- Eventual consistency causing genuinely new pages to appear mid-crawl; the cap bounds it.
- The token changing format between pages; normalize before comparing.
- Offset pagination with a shifting dataset; prefer cursors where the API offers them.

## Provenance

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