Skip to content

fix(providers): add iteration cap to performAgentChain to prevent infinite loops#194

Open
manusjs wants to merge 1 commit intovxcontrol:masterfrom
manusjs:fix/agent-chain-iteration-cap
Open

fix(providers): add iteration cap to performAgentChain to prevent infinite loops#194
manusjs wants to merge 1 commit intovxcontrol:masterfrom
manusjs:fix/agent-chain-iteration-cap

Conversation

@manusjs
Copy link

@manusjs manusjs commented Mar 11, 2026

What

Adds a hard iteration cap to performAgentChain and escalating error behaviour in the repeating-detector to prevent infinite loops when a model repeatedly calls the same tool.

Fixes #175

Root Cause

performAgentChain in backend/pkg/providers/performer.go is an unbounded for {} loop. When the repeating detector fires it returns (message, nil) — a successful response — so wantToStop is never set and the loop continues. Production logs show 4800+ repeating-detector warnings in a single session.

Changes

  • performer.go: Added maxAgentChainIterations = 100 cap. Loop returns an error if exceeded.
  • Repeating detector: After N consecutive repeating detections (maxRepeatingBeforeAbort = 5) returns an actual error instead of a nil-error message, so the error path in performAgentChain fires.
  • performer_test.go (new): TestAgentChainIterationCap — mocks a chain that never stops and asserts error is returned after maxAgentChainIterations.

…inite loops

Fixes vxcontrol#175

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.

performAgentChain has no iteration cap — infinite loop on repeating tool calls

1 participant