From 6d0464ea07ee434acb12f38215871dbef6f7c568 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 8 May 2026 10:53:19 -0500 Subject: [PATCH] Add httplib2 15s timeout + cache_discovery=False to prevent hangs --- .../agent_claw_main/tools/google_workspace.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/agentclaw/app/agent_claw_main/tools/google_workspace.py b/agentclaw/app/agent_claw_main/tools/google_workspace.py index 50548c2..159095e 100644 --- a/agentclaw/app/agent_claw_main/tools/google_workspace.py +++ b/agentclaw/app/agent_claw_main/tools/google_workspace.py @@ -1,12 +1,16 @@ """Direct Google Calendar and Gmail tools using google-api-python-client.""" import json import boto3 +import httplib2 from strands import tool from google.oauth2.credentials import Credentials from google.auth.transport.requests import Request from googleapiclient.discovery import build from datetime import datetime, timezone, timedelta +# Set a 15-second timeout on httplib2 to prevent hangs +_HTTP_TIMEOUT = 15 + _sm = None @@ -55,7 +59,8 @@ def list_calendars() -> str: """List all Google Calendars for the current user.""" try: creds = _get_creds(_actor_id()) - svc = build('calendar', 'v3', credentials=creds) + http = creds.authorize(httplib2.Http(timeout=_HTTP_TIMEOUT)) + svc = build('calendar', 'v3', http=http, credentials=creds, cache_discovery=False) result = svc.calendarList().list().execute() items = result.get('items', []) if not items: @@ -75,7 +80,8 @@ def get_calendar_events(calendar_id: str = 'primary', days_ahead: int = 7) -> st """ try: creds = _get_creds(_actor_id()) - svc = build('calendar', 'v3', credentials=creds) + http = creds.authorize(httplib2.Http(timeout=_HTTP_TIMEOUT)) + svc = build('calendar', 'v3', http=http, credentials=creds, cache_discovery=False) now = datetime.now(timezone.utc) time_max = now + timedelta(days=days_ahead) result = svc.events().list( @@ -108,7 +114,8 @@ def list_gmail_messages(max_results: int = 10, query: str = 'in:inbox') -> str: """ try: creds = _get_creds(_actor_id()) - svc = build('gmail', 'v1', credentials=creds) + http = creds.authorize(httplib2.Http(timeout=_HTTP_TIMEOUT)) + svc = build('gmail', 'v1', http=http, credentials=creds, cache_discovery=False) result = svc.users().messages().list( userId='me', q=query, maxResults=max_results ).execute() @@ -139,7 +146,8 @@ def get_gmail_message(message_id: str) -> str: """ try: creds = _get_creds(_actor_id()) - svc = build('gmail', 'v1', credentials=creds) + http = creds.authorize(httplib2.Http(timeout=_HTTP_TIMEOUT)) + svc = build('gmail', 'v1', http=http, credentials=creds, cache_discovery=False) msg = svc.users().messages().get( userId='me', id=message_id, format='full' ).execute()