mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-10 06:45:28 -05:00
## Summary - Fixed "Timeout context manager should be used inside a task" error occurring intermittently in FileInput blocks when downloading files from Google Cloud Storage - Implemented proper async session management for GCS client to ensure operations run within correct task context - Added comprehensive logging to help diagnose and monitor the issue in production ## Changes ### Core Fix - Modified `CloudStorageHandler._retrieve_file_gcs()` to create a fresh GCS client and session for each download operation - This ensures the aiohttp session is always created within the proper async task context, preventing the timeout error - The fix trades a small amount of efficiency for reliability, but only affects download operations ### Logging Enhancements - Added detailed logging in `store_media_file()` to track execution context and async task state - Enhanced `scan_content_safe()` to specifically catch and log timeout errors with CRITICAL level - Added context logging in virus scanner around `asyncio.create_task()` calls - Upgraded key debug logs to info level for visibility in production ### Code Quality - Fixed unbound variable issue where `async_client` could be referenced before initialization - Replaced bare `except:` clauses with proper exception handling - Fixed unused parameters warning in `__aexit__` method ## Testing - The timeout error was occurring intermittently in production when FileInput blocks processed GCS files - With these changes, the error should be eliminated as the session is always created in the correct context - Comprehensive logging allows monitoring of the fix effectiveness in production ## Context The root cause was that `gcloud-aio-storage` was creating its internal aiohttp session/timeout context outside of an async task context when called by the executor. This happened intermittently depending on how the executor scheduled block execution. ## Related Issues - Addresses timeout errors reported in FileInput block execution - Improves reliability of file uploads from the platform ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: <!-- Put your test plan here: --> - [x] Test a multiple file input agent and it works - [x] Test the agent that is causing the failure and it works 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> --------- Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Reinier van der Leer <pwuts@agpt.co>