## TL;DR

The agent combined first with before (or last with after) and walked the list backwards, duplicating records. Forward pagination is first + after; backward is last + before. Pick one direction and stick to it.

## Error

```text
record count doubled with every sync; duplicates everywhere
```

## Steps

1. Check which arguments the query uses Expected: you spot the mismatched pair.
2. Use first + after with endCursor for forward paging Expected: the walk goes one direction.
3. Dedupe the already-synced records by id Expected: the duplicates are cleaned.
4. Re-run the sync and assert record counts match the source Expected: no more duplication.

## When to use

- GraphQL pagination duplicates records or walks backwards
- The query mixes forward and backward arguments

## When not to use

- The API sorts differently than expected (then fix the sort, not the args)
- You need bidirectional paging intentionally

## Tool compatibility

- GraphQL pagination arguments
- Generated GraphQL clients

## Variant phrasings

### graphql sync duplicated everything

You mixed first/after with last/before. Use first + after forward.

### graphql walking backwards

Same: pick one direction.

## Why it happens

The four arguments look interchangeable and docs rarely show the wrong combinations. Agents guess, and half the guesses walk backwards.

## Edge cases

- Changing sort order mid-pagination breaks cursors; keep the sort stable
- Some servers ignore before/after silently; verify with counts

## Provenance

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