mirror of
https://github.com/vxcontrol/pentagi.git
synced 2026-07-21 08:15:23 -04:00
[PR #178] [MERGED] fix: prevent infinite loop in performAgentChain on repeating tool calls #213
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/vxcontrol/pentagi/pull/178
Author: @mason5052
Created: 3/5/2026
Status: ✅ Merged
Merged: 3/11/2026
Merged by: @asdek
Base:
feature/next_release← Head:fix/agent-chain-iteration-cap📝 Commits (2)
1f896a9fix: add iteration cap and repeating escalation to performAgentChain536ea86fix: address review feedback on iteration cap and repeating escalation📊 Changes
1 file changed (+20 additions, -6 deletions)
View changed files
📝
backend/pkg/providers/performer.go(+20 -6)📄 Description
Description of the Change
Problem
The
performAgentChainloop inperformer.gois an unboundedfor {}with no iteration cap. When a model repeatedly calls the same tool, therepeatingDetectorfires and returns a message (nilerror), so the loop never breaks. This can result in 4,800+ iterations in a single session, consuming resources indefinitely.Closes #175
Solution
Add two safety mechanisms:
Iteration cap (
maxAgentChainIterations = 100): Hard limit on the main loop. Normal pentest flows use far fewer iterations; 100 is generous while preventing runaway loops.Repeating escalation (
maxSoftDetectionsBeforeAbort = 4): After 4 consecutive soft detection warnings (7 total identical calls), escalate from a soft message to an actual error that terminates the chain. The existing soft response is preserved for the first 4 detections, giving the LLM a chance to course-correct.Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
maxRetriesToCallSimpleChain, etc.)for iteration := 0; ; iteration++preserves all existing loop semanticslen(detector.funcCalls)is accessible (same package) and correctly tracks consecutive identical calls (resets on different calls perhelpers.go:detect())RepeatingToolCallThreshold(3) + maxSoftDetectionsBeforeAbort(4) = 7, so error fires on the 7th consecutive identical callSecurity Considerations
No security impact. This is a resource exhaustion prevention fix.
Checklist
go fmtandgo vet🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.