From 758c4ad1efb0dea2e6d91dd0dc9656a59f80a6fd Mon Sep 17 00:00:00 2001 From: Teknium Date: Sat, 11 Apr 2026 15:29:15 -0700 Subject: [PATCH] fix: remove dead hasattr checks for retry counters initialized in reset block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit All retry counters (_invalid_tool_retries, _invalid_json_retries, _empty_content_retries, _incomplete_scratchpad_retries, _codex_incomplete_retries) are initialized to 0 at the top of run_conversation() (lines 7566-7570). The hasattr guards added before the reset block existed are now dead code — the attributes always exist. Removed 7 redundant hasattr checks (5 original targets + 2 bonus for _codex_incomplete_retries found during cleanup). --- run_agent.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/run_agent.py b/run_agent.py index a3f04c6e01..0ff11d5537 100644 --- a/run_agent.py +++ b/run_agent.py @@ -9385,8 +9385,6 @@ class AIAgent: # Check for incomplete (opened but never closed) # This means the model ran out of output tokens mid-reasoning — retry up to 2 times if has_incomplete_scratchpad(assistant_message.content or ""): - if not hasattr(self, '_incomplete_scratchpad_retries'): - self._incomplete_scratchpad_retries = 0 self._incomplete_scratchpad_retries += 1 self._vprint(f"{self.log_prefix}⚠️ Incomplete detected (opened but never closed)") @@ -9414,12 +9412,9 @@ class AIAgent: } # Reset incomplete scratchpad counter on clean response - if hasattr(self, '_incomplete_scratchpad_retries'): - self._incomplete_scratchpad_retries = 0 + self._incomplete_scratchpad_retries = 0 if self.api_mode == "codex_responses" and finish_reason == "incomplete": - if not hasattr(self, "_codex_incomplete_retries"): - self._codex_incomplete_retries = 0 self._codex_incomplete_retries += 1 interim_msg = self._build_assistant_message(assistant_message, finish_reason) @@ -9490,8 +9485,6 @@ class AIAgent: ] if invalid_tool_calls: # Track retries for invalid tool calls - if not hasattr(self, '_invalid_tool_retries'): - self._invalid_tool_retries = 0 self._invalid_tool_retries += 1 # Return helpful error to model — model can self-correct next turn @@ -9527,8 +9520,7 @@ class AIAgent: }) continue # Reset retry counter on successful tool call validation - if hasattr(self, '_invalid_tool_retries'): - self._invalid_tool_retries = 0 + self._invalid_tool_retries = 0 # Validate tool call arguments are valid JSON # Handle empty strings as empty objects (common model quirk) @@ -9930,8 +9922,7 @@ class AIAgent: break # Reset retry counter/signature on successful content - if hasattr(self, '_empty_content_retries'): - self._empty_content_retries = 0 + self._empty_content_retries = 0 self._thinking_prefill_retries = 0 if (