Evan a73a94a6a3
fix(agents): keep HarnessGuard from rewriting the result that ends a loop (#8001)
* fix(agents): keep HarnessGuard from rewriting the result that ends a loop

The alternating-loop check fired when three of the last four tool calls
failed, without checking the current call. After A and B failed in turn,
a successful B therefore received the OSCILLATION DETECTED warning: the
model was told to stop just as the loop ended, and structured output such
as JSON was corrupted by the appended text.

Only a failing call now continues the pattern, so successful results reach
the model unchanged. Failing alternation still warns.

* fix(agents): only warn on an alternating loop when the whole window failed

The oscillation check still counted 3 errors out of the last 4 calls, so a
window that contained a success could warn on the next failure, e.g.
A err, B err, A ok, B err. A success ends the loop, so require all four
calls in the window to have failed, and pin the break shapes with tests.

---------

Co-authored-by: Totoro <msy626836554@gmail.com>
2026-11-08 19:20:51 +08:00
..