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.
This commit is contained in:
Corey Cauble
2026-01-09 14:35:20 -08:00
committed by GitHub
parent 2b2e28a2c5
commit 9c07dd72db

View File

@@ -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: