Harness Engineering Practices
P12. Semantic Circuit Breakers and "Discard Context" Restarts
🎯 Point
Ever seen an agent repeat the same error three times? "Push through" is far slower than "restart with a lesson learned."
📝 Overview
Instead of simple max-iteration limits, semantically detect "same error twice," "oscillating between two edits," or "no net progress" and halt. When stuck, don't keep kneading in contaminated context. Roll back to the last good checkpoint, discard failure history from context, carry just a one-line lesson, and restart with a fresh approach.
🔍 Explanation
When an agent gets stuck, the least efficient response is "try harder in the same context." As failure history accumulates in context, the agent gets dragged toward repeating the same mistakes. Semantic circuit breakers judge "is there actual progress" rather than counting iterations. When they detect oscillation (change A to B then back to A) or repeated identical errors, they trigger a git rollback to the last clean state, then restart in fresh context with only "last time X failed, try a different approach." Git is the agent's Undo.
🛠 How to Practice
- Implement logic in the harness that compares error messages and test results to detect "same error twice" and "A-B edit oscillation"
- On halt, git checkout to the last clean commit and discard contaminated context
- On restart, carry only a one-line lesson ("last time X failed") into the fresh context
- Tune circuit breaker thresholds per task difficulty (strict for easy tasks, more lenient for hard ones)
💼 Use Cases
- Issue-to-PR agents looping on the same test failure they can't fix
- Compile error fixing: detecting fix-then-break-then-revert cycles
- Legacy code modernization: recognizing when a fundamentally different approach is needed
⚠ Pitfalls
Too-sensitive circuit breakers cut off agents one step from a solution. Too-lenient ones waste cost in infinite loops. Tuning the definition of "progress" per task is critical. Distilling accurate lessons at restart time is also hard — wrong lessons carried into a restart can trigger different failure patterns.
#
HarnessEngineering# #
AIAgent#