Skip to content

fix(reflection): prevent action loops by reducing max attempts and adding loop detection#114

Merged
dzianisv merged 2 commits intomainfrom
issue-80-reflection-loop-prevention
Feb 18, 2026
Merged

fix(reflection): prevent action loops by reducing max attempts and adding loop detection#114
dzianisv merged 2 commits intomainfrom
issue-80-reflection-loop-prevention

Conversation

@dzianisv
Copy link
Owner

Summary

Fixes #80 — Reflection plugin causes loops by pushing the agent to continue even when it's stuck repeating the same actions.

Changes

  • Reduced MAX_ATTEMPTS from 5 to 3 — agent gets pushed at most 2 times before receiving terminal guidance
  • Added detectActionLoop() function — detects repeated identical bash commands (normalizes timestamps, triggers when 60%+ of commands are repeated 3+ times)
  • Updated buildEscalatingFeedback() — action loop returns "STOP: Action Loop Detected" message; final attempt returns "Final Attempt" with give-up guidance
  • Updated buildSelfAssessmentPrompt() — injects ## Reflection History section with attempt count; adds rules against retrying same failing approach
  • Updated call site in runReflection() — passes currentAttemptCount and actionLoopCheck.detected to the updated functions
  • Added 17 new unit tests covering detectActionLoop, attempt-aware prompting, and escalating feedback edge cases

Testing

  • npm test — 341 tests pass (336 + 5 skipped)
  • npm run eval:judge — 23/23 pass
  • npm run eval:stuck — 12/12 pass
  • npm run eval:compression — 12/12 pass

@dzianisv
Copy link
Owner Author

Just adding a stupid counter doesn't work . Doom loop has to be detected by the genai/reflection layer. #114.

…ding loop detection (#80)

- Reduce MAX_ATTEMPTS from 5 to 3 to stop pushing stuck agents
- Add detectActionLoop() to detect repeated identical bash commands
- Update buildEscalatingFeedback() with action loop and final attempt messages
- Update buildSelfAssessmentPrompt() with attempt count awareness
- Add 17 new unit tests for loop detection and attempt-aware prompting
@dzianisv dzianisv force-pushed the issue-80-reflection-loop-prevention branch from e1907e6 to 57ad843 Compare February 18, 2026 11:08
@dzianisv dzianisv merged commit 9204fca into main Feb 18, 2026
2 checks passed
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.

Reflection plugin cause loops

1 participant

Comments