Skip to content

fix(engine): sequence-loop detector requires stagnant repeats - #55

Merged
lostmartian merged 1 commit into
mainfrom
fix/sequence-loop-iterations
Sep 17, 2026
Merged

lostmartian merged 1 commit into
mainfrom
fix/sequence-loop-iterations

Conversation

@lostmartian

Copy link
Copy Markdown
Collaborator
## What

Consecutive repetition of a step-name pattern now counts as a loop only when the repeated steps are stagnant (identical inputs and outputs). Repetition with different inputs is treated as legitimate iteration.

## Why

Found by our own live gate on the public demo repo. The demo agent queries three states, producing `decide -> call -> decide -> call -> decide -> call`. The detector flagged that as a loop and the gate hard-blocked the run with `Blocked by: loops` even though trajectory divergence was `0.0` and every call had different arguments. That shape is the single most common agent pattern, so this was a false positive that would hit real users immediately.

## How

`detect_sequence_loops` already computed a `stagnant` flag and then ignored it. The loop is now appended only when `stagnant` is true. Runaway loops with drifting args stay covered by `max_tool_repeats` and the token/step bands, and the identical-call invariant is unchanged.

## Testing

- make lint -> All checks passed
- uv run python -m pytest -> 437 passed (5 new tests)

New tests: iteration over items is not a loop; repeats with changed outputs are not a loop; stagnant repeats still are.

@lostmartian
lostmartian merged commit 27bcf18 into main Sep 17, 2026
6 checks passed
@lostmartian
lostmartian deleted the fix/sequence-loop-iterations branch September 17, 2026 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant