# agent loop detected re-fetching same answer library entry after failed sync: how to fix it

An agent re-fetching the same answer library entry after a failed sync is looping on a stale cache. Invalidate the cache entry on sync failure and fetch fresh, with a cap on refetch attempts. The loop ends when the agent stops trusting its cached copy.

```text
agent loop detected re-fetching same answer library entry after failed sync
```

## When to use this skill
- An agent refetches the same entry repeatedly
- Logs show identical fetch calls in a loop

## When not to use this skill
- Fetches vary but all fail (a broader API issue)
- The entry content is wrong (a data issue)

## Tool compatibility
Agent library sync with local caching.
Related area: agent frameworks and agent runtime tooling.
Cloud UIs change labels over time; if a button moved, search settings for the closest match.

## Before you start
- Sign in to the tool and keep one tab open so sessions stay clean
- Copy the exact error text and note the time it happened
- Set aside 15 to 20 minutes; most of these resolve in a single pass

## Quick diagnosis
Make sure this is the right skill before you invest the 15 minutes.
- If you are dealing with an agent refetches the same entry repeatedly, start at step 1 below.
- If instead fetches vary but all fail (a broader API issue), stop here; you need a different skill.
- If neither quite matches, compare your screen against the verbatim error block at the top; that block is exactly what this skill covers.

## Fix it in steps
### 1. Invalidate cache on sync failure

```
Clear the cached entry whenever its sync fails.
```
Expected: the next fetch hits the source, not the stale cache.

### 2. Cap refetch attempts

```
Allow at most three fetches of the same entry per run.
```
Expected: the agent gives up instead of looping forever.

### 3. Log the sync failure reason

```
Record why the sync failed so the loop has a diagnosable cause.
```
Expected: a clear error instead of silent refetching.

### 4. Fix the underlying sync issue

```
Address the root sync failure using the sync troubleshooting path.
```
Expected: fetches succeed and the loop never starts.

## Confirm each step worked
Run through this checklist before moving on. If a check fails, redo that step instead of pushing ahead.
- Step 1 (invalidate cache on sync failure): Expected: the next fetch hits the source, not the stale cache.
- Step 2 (cap refetch attempts): Expected: the agent gives up instead of looping forever.
- Step 3 (log the sync failure reason): Expected: a clear error instead of silent refetching.
- Step 4 (fix the underlying sync issue): Expected: fetches succeed and the loop never starts.

## Quick recap
1. Invalidate cache on sync failure
2. Cap refetch attempts
3. Log the sync failure reason
4. Fix the underlying sync issue

## Still stuck?
Gather three things: the exact error text, the time it happened, and what changed just before it broke.
Check the vendor status page for an active incident. Then open a support ticket with those three things;
it cuts the back-and-forth in half. For agent runs, attach the last 50 lines of the agent log too,
since the loop or timeout signature in the log usually names the cause.

## Variant phrasings
### agent refetching same entry loop
Invalidate on failure, cap attempts. If this matches what you saw, the steps above apply as written.

### re-fetch loop answer library
The stale cache is what keeps the loop alive. If this matches what you saw, the steps above apply as written.

## Why it happens
The agent caches the entry, the sync fails, and the agent refetches to check, getting the same cached copy. Each fetch looks like progress, so nothing breaks the cycle until the cache is invalidated or attempts are capped.

## Edge cases
- Distinguish sync failure from fetch failure in logs
- Cache TTLs should be short for syncing content
- Alert on repeated refetches, they signal a stuck sync

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_Nu6xlRuOccyZm-u7NOZHgQ
