From d77c616905d95ddd86175b1e79ba3cef4dd79755 Mon Sep 17 00:00:00 2001 From: Argenis Date: Wed, 18 Mar 2026 15:45:10 -0400 Subject: [PATCH] fix: reset tool call dedup cache each iteration to prevent loops (#3910) The seen_tool_signatures HashSet was initialized outside the iteration loop, causing cross-iteration deduplication of legitimate tool calls. This triggered a self-correction spiral where the agent repeatedly attempted skipped calls until hitting max_iterations. Moving the HashSet inside the loop ensures deduplication only applies within a single iteration, as originally intended. Fixes #3798 --- src/agent/loop_.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/agent/loop_.rs b/src/agent/loop_.rs index 859b68d93..2224882de 100644 --- a/src/agent/loop_.rs +++ b/src/agent/loop_.rs @@ -2421,9 +2421,10 @@ pub(crate) async fn run_tool_call_loop( }; let turn_id = Uuid::new_v4().to_string(); - let mut seen_tool_signatures: HashSet<(String, String)> = HashSet::new(); for iteration in 0..max_iterations { + let mut seen_tool_signatures: HashSet<(String, String)> = HashSet::new(); + if cancellation_token .as_ref() .is_some_and(CancellationToken::is_cancelled)