From 9c07dd72db9698aed236f11e8da041cebda794e8 Mon Sep 17 00:00:00 2001 From: Corey Cauble Date: Fri, 9 Jan 2026 14:35:20 -0800 Subject: [PATCH] Fixed issues requested by coderabbitai Applied Fixes More flexible string matching: Changed from response.lower().strip().startswith("limit reached") to "limit reached" in response.lower() to handle cases where the message has prefix text or variations in whitespace. Improved regex pattern: Updated to r"(?i)\bresets(?:\s+at)?\s+(\d+)(?::(\d+))?\s*(am|pm)\s*\(([^)]+)\)" which now handles: Optional "at" after "resets" (e.g., "resets at 3pm" or "resets 3pm") Flexible whitespace around components Word boundaries to prevent partial matches Timezone sanitization: Added .strip() to tz_name = match.group(4).strip() to remove any leading/trailing whitespace that could cause ZoneInfo() to fail. Safety clamp: Added delay_seconds = min(delta.total_seconds(), 24 * 60 * 60) to ensure the delay never exceeds 24 hours, preventing the agent from being stuck waiting for extremely long periods. --- agent.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/agent.py b/agent.py index 19f1560..50edc46 100644 --- a/agent.py +++ b/agent.py @@ -201,20 +201,19 @@ async def run_autonomous_agent( delay_seconds = AUTO_CONTINUE_DELAY_SECONDS target_time_str = None - if response.lower().strip().startswith("limit reached"): + if "limit reached" in response.lower(): print("Claude Agent SDK indicated limit reached.") # Try to parse reset time from response match = re.search( - r"resets (\d+)(?::(\d+))?(am|pm) \(([^)]+)\)", + r"(?i)\bresets(?:\s+at)?\s+(\d+)(?::(\d+))?\s*(am|pm)\s*\(([^)]+)\)", response, - re.IGNORECASE, ) if match: hour = int(match.group(1)) minute = int(match.group(2)) if match.group(2) else 0 period = match.group(3).lower() - tz_name = match.group(4) + tz_name = match.group(4).strip() # Convert to 24-hour format if period == "pm" and hour != 12: @@ -234,7 +233,9 @@ async def run_autonomous_agent( target += timedelta(days=1) delta = target - now - delay_seconds = delta.total_seconds() + delay_seconds = min( + delta.total_seconds(), 24 * 60 * 60 + ) # Clamp to 24 hours max target_time_str = target.strftime("%B %d, %Y at %I:%M %p %Z") except Exception as e: