## TL;DR

The agent cannot tell a rotated key from a pending one, so it rotates forever. Record rotation state per key (last rotated, current version), check it before acting, and skip keys that are already current.

## Error

```text
agent loop detected: re-rotating the same already-rotated key
```

## Steps

1. Confirm the loop: the same key rotates on every run with no new trigger. Expected: the loop proven.
2. Add a state record per key: last rotation time and resulting version. Expected: durable memory.
3. Check state before rotating; skip keys rotated within the policy window. Expected: no repeat work.
4. Require a trigger for rotation: schedule, event, or explicit request. Expected: rotations have reasons.
5. Alert on unexpected re-rotation attempts. Expected: loops surface fast.

## When to use

- Agents re-rotating keys in a loop.
- Building rotation agents.

## When not to use

- Rotations failing (different problem).
- Intentional frequent rotation (then the window is just short).

## Tool compatibility

- Rotation state stores; agent loops.

## Variant phrasings

### agent keeps rotating the same key

Track state.

### rotation loop

Check-before-act.

## Why it happens

Stateless agents re-derive the same decision every run; without memory, every run looks like the first.

## Edge cases

- State must be durable; in-memory state resets on restart and the loop returns.
- Clock skew can make fresh rotations look old; use version, not just time.
- Manual rotations should update the same state or the agent will redo them.

## Provenance

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