From d646442692f15cff0ca738e5d34d6ba5341e5720 Mon Sep 17 00:00:00 2001 From: 0xbyt4 <35742124+0xbyt4@users.noreply.github.com> Date: Fri, 13 Mar 2026 15:09:49 +0300 Subject: [PATCH] fix: restore Anthropic interrupt handler in _interruptible_api_call Rebase auto-merge silently overwrote main's Anthropic-aware interrupt handler with the older OpenAI-only version. Without this fix, interrupting an Anthropic API call closes the wrong client and leaves token generation running on the Anthropic side. --- run_agent.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/run_agent.py b/run_agent.py index d32f65cfd..2e66ceec4 100644 --- a/run_agent.py +++ b/run_agent.py @@ -2615,12 +2615,19 @@ class AIAgent: if self._interrupt_requested: # Force-close the HTTP connection to stop token generation try: - self.client.close() + if self.api_mode == "anthropic_messages": + self._anthropic_client.close() + else: + self.client.close() except Exception: pass # Rebuild the client for future calls (cheap, no network) try: - self.client = OpenAI(**self._client_kwargs) + if self.api_mode == "anthropic_messages": + from agent.anthropic_adapter import build_anthropic_client + self._anthropic_client = build_anthropic_client(self._anthropic_api_key) + else: + self.client = OpenAI(**self._client_kwargs) except Exception: pass raise InterruptedError("Agent interrupted during API call")