From 26f387e719e63d2fc8c165e25033dafa5b42bca3 Mon Sep 17 00:00:00 2001 From: pewdiepie-archdaemon Date: Fri, 18 Sep 2026 14:59:34 +0000 Subject: [PATCH] fix repeated invalid tool argument loops --- src/clean_agent_preview.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/clean_agent_preview.py b/src/clean_agent_preview.py index 03c0e709d..cb7d2fe89 100644 --- a/src/clean_agent_preview.py +++ b/src/clean_agent_preview.py @@ -5049,6 +5049,24 @@ async def stream_preview(*, endpoint_url, model, messages, headers, turn_contrac name, args, user_text=direct_user_text, ) if semantic_error: + # Semantic/schema guards run before the ordinary + # execution failure guard below. Count their + # rejected canonical call too, otherwise a model + # can emit the same malformed request for every + # remaining round without ever reaching that guard. + if failed_call_counts.get(call_signature, 0) >= 2: + calls += 1 + terminal_suppression_violation = True + permanently_suppressed_tools.add(canonical(name)) + round_recovery_messages.append( + f'{name} was disabled after the same invalid arguments were ' + 'rejected twice. Use a corrected tool call, another offered tool, ' + 'or finish from existing evidence.' + ) + raise ValueError( + 'This exact invalid call was repeated after two validation failures; ' + 'the tool is disabled for this turn.' + ) raise ValueError(semantic_error) if canonical(name) == 'bash': command = str(args.get('command') or '')