From 20b7b9f7c402f17343f0227458437411d11908fd Mon Sep 17 00:00:00 2001 From: Jordan Ramos Date: Sun, 1 Mar 2026 16:17:37 -0700 Subject: [PATCH] Fix error handling to preserve detailed timeout messages **Problem**: User got generic "Sorry, I encountered an error" (80 chars) instead of the detailed timeout message with progress info and suggestions. **Root Cause**: agent.py error handlers were replacing exception messages with hardcoded generic text, discarding the detailed timeout info from llm_interface.py. **Solution**: 1. TimeoutError handler: Use str(e) to preserve detailed message from llm_interface.py (message count, last tool, suggestions) 2. General Exception handlers: Include actual error text (limited to 500 chars) instead of "Please try again" 3. Applied to both Agent SDK and Direct API code paths **Impact**: Users now see the actual error details including: - Progress when task timed out (message count, last tool used) - Actionable suggestions (break into sub-tasks, use delegate_task) - Actual error messages for debugging instead of generic text Co-Authored-By: Claude Sonnet 4.5 --- agent.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/agent.py b/agent.py index 031b2b9..74bd856 100644 --- a/agent.py +++ b/agent.py @@ -564,7 +564,8 @@ class Agent: system=system, ) except TimeoutError as e: - error_msg = "⏱️ Task timed out after 20 minutes. This is a very large task - consider breaking it into smaller steps or delegating to a background sub-agent." + # Use the detailed timeout message from llm_interface.py + error_msg = str(e) if str(e) else "⏱️ Task timed out - consider breaking it into smaller steps or using delegate_task." print(f"[Agent] TIMEOUT: {error_msg}") self.healing_system.capture_error( error=e, @@ -578,6 +579,7 @@ class Agent: ) return error_msg except Exception as e: + # Include actual error message for better debugging error_msg = f"Agent SDK error: {e}" print(f"[Agent] {error_msg}") self.healing_system.capture_error( @@ -589,7 +591,8 @@ class Agent: "message_preview": user_message[:100], }, ) - return "Sorry, I encountered an error communicating with the AI model. Please try again." + # Return the actual error message instead of generic text + return f"Sorry, I encountered an error: {str(e)[:500]}" finally: # Always stop progress updates when done self._stop_progress_updates() @@ -658,7 +661,8 @@ class Agent: "iteration": iteration, }, ) - return "Sorry, I encountered an error communicating with the AI model. Please try again." + # Return actual error message instead of generic text + return f"Sorry, I encountered an error: {str(e)[:500]}" if response.stop_reason == "end_turn": text_content = []