agent loop detected: merging the same contact pair repeatedly
Breaks an agent loop that merges the same contact pair repeatedly: track merged pairs in a ledger and skip completed work. Use when merge jobs repeat themselves. Not for first-time merge failures.
TL;DR
The agent merges pair A-B, then later rediscovers A-B as a duplicate and merges again, forever. Keep a ledger of completed merges (pair ids plus the surviving record) and check it before every merge. A merge already done is not a duplicate found.
Error
(No error; the symptom is the merge log showing the same pair merged dozens of times, or "already merged" errors cycling.)Steps
- Stop the loop and inspect the log for the repeated pair. Expected: you confirm the same ids recur.
- Create the merge ledger: pair key (sorted ids), surviving record id, timestamp. Expected: durable history of what merged.
- Check the ledger before each merge; skip pairs already merged. Expected: the loop breaks immediately.
- Fix the redetection: after merging, the survivor should no longer match the loser's old signature. Expected: the pair stops resurfacing.
- Add a circuit breaker: if the same pair is attempted N times, halt and alert. Expected: loops fail loudly instead of spinning.
When to use
- Merge jobs repeat the same pairs.
- "already merged" errors appear in a loop.
- An agent's merge count grows without the duplicate count shrinking.
When not to use
- First-time merge failures (fix the merge itself).
- Legitimate re-merges after unmerging.
Tool compatibility
- Any merge API; a ledger in a file or database.
- Agent loop guards.
Variant phrasings
merging the same pair repeatedly
Ledger and skip.
already merged errors in a loop
The redetection is broken, not the merge.
Why it happens
Merge changes the records, but the duplicate detector's view is stale or the survivor still matches the loser's old fingerprint. Without a ledger, the agent cannot tell done from new.
Edge cases
- Unmerging resurrects the pair legitimately; the ledger needs a tombstone for unmerges.
- Concurrent workers need a shared ledger; local files do not coordinate.
- Ledger keys must be order-independent (sort the ids).
Provenance
Resolved from the public thread: https://vectle.com/posts/pst_mJJgvReV3q1evm4-PzHSZg