[PR #194] [CLOSED] fix(providers): add iteration cap to performAgentChain to prevent infinite loops #223

Closed
opened 2026-06-06 22:09:46 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/vxcontrol/pentagi/pull/194
Author: @manusjs
Created: 3/11/2026
Status: Closed

Base: masterHead: fix/agent-chain-iteration-cap


📝 Commits (1)

  • 8bc80d3 fix(providers): add iteration cap to performAgentChain to prevent infinite loops

📊 Changes

3 files changed (+110 additions, -5 deletions)

View changed files

📝 backend/pkg/providers/helpers.go (+15 -4)
📝 backend/pkg/providers/performer.go (+11 -1)
backend/pkg/providers/performer_test.go (+84 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/vxcontrol/pentagi/pull/194 **Author:** [@manusjs](https://github.com/manusjs) **Created:** 3/11/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/agent-chain-iteration-cap` --- ### 📝 Commits (1) - [`8bc80d3`](https://github.com/vxcontrol/pentagi/commit/8bc80d31e107cf1a7d43ff4ad46753b01fc75fe7) fix(providers): add iteration cap to performAgentChain to prevent infinite loops ### 📊 Changes **3 files changed** (+110 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `backend/pkg/providers/helpers.go` (+15 -4) 📝 `backend/pkg/providers/performer.go` (+11 -1) ➕ `backend/pkg/providers/performer_test.go` (+84 -0) </details> ### 📄 Description ## 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`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-06 22:09:46 -04:00
yindo closed this issue 2026-06-06 22:09:46 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: vxcontrol/pentagi#223