Commit 8a97c28
committed
fix(loop): re-enable loop intervention system messages
**Problem:**
Claude and other models were looping endlessly when stuck (calling same tool 25+ times).
Loop detection was working but intervention message injection was DISABLED due to previous
GitHub Copilot API 400 errors.
**Root Cause:**
Comment in code: "system message injection removed (was causing GitHub Copilot 400 errors)"
The 400 errors were caused by bugs that were FIXED in previous commits:
- Delta mode fixes (d1c3ea7)
- User role requirement (5fff807)
- Trailing whitespace (822c12c)
**Solution:**
Re-enabled system-reminder intervention message injection in both:
1. Basic loop detection path (AgentOrchestrator.swift line ~2318)
2. Streaming loop detection path (AgentOrchestrator.swift line ~3668)
When loop detected (3+ consecutive calls to same tool):
- Creates intervention message explaining the loop
- Wraps in <system-reminder> tags (Claude-compatible format)
- Appends to internalMessages for next API request
- Model receives warning and changes behavior
**Testing:**
✅ Build: PASS
✅ Claude: Stops looping after intervention (was 25+ calls, now stops at 3)
✅ GPT-4.1: Works correctly, no regressions
✅ No API errors (400s no longer occur due to previous fixes)
✅ Loop intervention message appears in API request
✅ Model adapts behavior after receiving intervention1 parent 5fff807 commit 8a97c28
2 files changed
Lines changed: 41 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2320 | 2320 | | |
2321 | 2321 | | |
2322 | 2322 | | |
| 2323 | + | |
| 2324 | + | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
2323 | 2337 | | |
2324 | | - | |
| 2338 | + | |
2325 | 2339 | | |
2326 | 2340 | | |
2327 | 2341 | | |
| |||
3658 | 3672 | | |
3659 | 3673 | | |
3660 | 3674 | | |
| 3675 | + | |
| 3676 | + | |
| 3677 | + | |
| 3678 | + | |
| 3679 | + | |
| 3680 | + | |
| 3681 | + | |
| 3682 | + | |
| 3683 | + | |
| 3684 | + | |
| 3685 | + | |
| 3686 | + | |
| 3687 | + | |
| 3688 | + | |
3661 | 3689 | | |
3662 | | - | |
| 3690 | + | |
3663 | 3691 | | |
3664 | 3692 | | |
3665 | 3693 | | |
| |||
5148 | 5176 | | |
5149 | 5177 | | |
5150 | 5178 | | |
| 5179 | + | |
| 5180 | + | |
| 5181 | + | |
| 5182 | + | |
| 5183 | + | |
| 5184 | + | |
| 5185 | + | |
5151 | 5186 | | |
5152 | 5187 | | |
5153 | 5188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
567 | 567 | | |
568 | 568 | | |
569 | 569 | | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
570 | 574 | | |
571 | 575 | | |
572 | 576 | | |
| |||
0 commit comments