Author: Manus AI Date: January 30, 2026
The autonomous self-correction loop is a powerful feature, but it introduces a critical risk: if the agent is unable to fix a persistent or complex bug, it could get stuck in an infinite loop of attempting the same failed fix, wasting time and resources. The v2.1 system lacks an explicit mechanism to detect and break out of such loops.
To mitigate this risk, we will implement a multi-layered defense system that combines prompt-based instructions with script-level safeguards. This system is designed to give the agent a fair chance to fix its own errors while providing a clear escalation path when it gets stuck.
This is the primary defense mechanism, implemented directly in the agent's prompt.
- Mechanism: The agent will be instructed to maintain a mental counter for how many times it has attempted to fix the exact same error within a single self-correction cycle.
- Limit: The retry limit will be set to 3 attempts.
- Action on Breach: If the agent fails to fix the same error after 3 attempts, it will trigger an "escalation protocol."
When the retry limit is breached, the agent will not simply halt. It will execute a strategic retreat to preserve the project's integrity and continue making progress on other tasks.
Protocol Steps:
- Log the Failure: Write a detailed entry in
progress.txtexplaining the persistent error, the attempted fixes, and the reason for escalation. - Revert Changes: Use
git reset --hardto revert all code changes back to the last known good state (the last successful commit). - Mark as Blocked: Update the
prd.jsonfile to modify the current user story:- Set
passes: "blocked". - Add a
notesfield explaining that the story is blocked and referencing theprogress.txtentry.
- Set
- Move On: The agent will then proceed to the next user story in the
prd.jsonfile, effectively bypassing the problematic task.
This safeguard already exists in ralph.sh but serves as the ultimate safety net.
- Mechanism: The main
ralph.shscript has aMAX_ITERATIONSvariable (defaulting to 10) that limits the total number of agent iterations. - Purpose: This ensures that even if the agent gets stuck in some unforeseen way not caught by the other layers, the entire process will eventually time out, preventing runaway execution.
- Update
enhanced_prompt.md: Add a new section detailing the retry limit and the full escalation protocol. - Update
ralph.sh: While the global limit exists, I will add comments to clarify its role as a final backstop. - Update Documentation: The main
README.mdand other relevant documents will be updated to reflect this new safety feature.