From a59e8c8c8a1fd6571c7683c6744bc17a61958220 Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Wed, 9 Jul 2025 10:44:51 +0000 Subject: [PATCH] fix(agent): initialize DBConnection within the run_agent function and increase Redis connection settings --- .github/workflows/docker-build.yml | 22 +++++++++++----------- backend/agent/run_agent.py | 6 +++--- backend/services/redis.py | 6 +++--- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 28d856eb..6697dd49 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -66,14 +66,14 @@ jobs: docker compose build docker compose up -d - # - name: Deploy to prod - # if: steps.get_tag_name.outputs.environment == 'prod' - # uses: appleboy/ssh-action@v1 - # with: - # host: ${{ secrets.PROD_HOST }} - # username: ${{ secrets.PROD_USERNAME }} - # key: ${{ secrets.PROD_KEY }} - # script: | - # cd /mnt/gluster-shared/data/infra/suna - # set -a; source .env; set +a - # docker stack deploy -c docker-compose.yml suna + - name: Deploy to prod + if: steps.get_tag_name.outputs.environment == 'prod' + uses: appleboy/ssh-action@v1 + with: + host: ${{ secrets.PROD_HOST }} + username: ${{ secrets.PROD_USERNAME }} + key: ${{ secrets.PROD_KEY }} + script: | + cd /mnt/gluster-shared/data/infra/suna + set -a; source .env; set +a + docker stack deploy -c docker-compose.yml suna diff --git a/backend/agent/run_agent.py b/backend/agent/run_agent.py index 1bc7460f..5b759c52 100644 --- a/backend/agent/run_agent.py +++ b/backend/agent/run_agent.py @@ -19,7 +19,6 @@ import json from resumable_stream.runtime import create_resumable_stream_context, ResumableStreamContext _initialized = False -db = DBConnection() instance_id = "single" @@ -36,12 +35,11 @@ async def get_stream_context(): async def initialize(): """Initialize the agent API with resources from the main API.""" - global db, instance_id, _initialized + global instance_id, _initialized if not instance_id: instance_id = str(uuid.uuid4())[:8] await retry(lambda: redis.initialize_async()) - await db.initialize() _initialized = True logger.info(f"Initialized agent API with instance ID: {instance_id}") @@ -78,6 +76,8 @@ async def run_agent_run_stream( try: await initialize() + db = DBConnection() + await db.initialize() except Exception as e: logger.critical(f"Failed to initialize: {e}") raise e diff --git a/backend/services/redis.py b/backend/services/redis.py index 511d279a..f19fcc10 100644 --- a/backend/services/redis.py +++ b/backend/services/redis.py @@ -29,7 +29,7 @@ def initialize(): redis_password = os.getenv("REDIS_PASSWORD", "") # Connection pool configuration - max_connections = int(os.getenv("REDIS_MAX_CONNECTIONS", 1024)) + max_connections = int(os.getenv("REDIS_MAX_CONNECTIONS", 2048)) retry_on_timeout = not (os.getenv("REDIS_RETRY_ON_TIMEOUT", "True").lower() != "true") logger.info(f"Initializing Redis connection pool to {redis_host}:{redis_port} with max {max_connections} connections") @@ -40,8 +40,8 @@ def initialize(): port=redis_port, password=redis_password, decode_responses=True, - socket_timeout=5.0, - socket_connect_timeout=5.0, + socket_timeout=20.0, + socket_connect_timeout=20.0, retry_on_timeout=retry_on_timeout, health_check_interval=30, max_connections=max_connections,