From dbc7cbf6c605b41a54c625919c2ccc483f75afca Mon Sep 17 00:00:00 2001 From: Zamil Majdy Date: Tue, 27 Jan 2026 10:00:48 -0600 Subject: [PATCH] chore(chat): make long-running operation TTL configurable Add `long_running_operation_ttl` to ChatConfig (default 600 seconds). This controls the Redis key TTL for tracking running operations, serving as a safety net if a pod dies during execution. --- .../backend/backend/api/features/chat/config.py | 6 ++++++ .../backend/backend/api/features/chat/service.py | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/autogpt_platform/backend/backend/api/features/chat/config.py b/autogpt_platform/backend/backend/api/features/chat/config.py index 95aef7f2ed..d782ab7242 100644 --- a/autogpt_platform/backend/backend/api/features/chat/config.py +++ b/autogpt_platform/backend/backend/api/features/chat/config.py @@ -38,6 +38,12 @@ class ChatConfig(BaseSettings): default=3, description="Maximum number of agent schedules" ) + # Long-running operation configuration + long_running_operation_ttl: int = Field( + default=600, + description="TTL in seconds for long-running operation tracking in Redis (safety net if pod dies)", + ) + # Langfuse Prompt Management Configuration # Note: Langfuse credentials are in Settings().secrets (settings.py) langfuse_prompt_name: str = Field( diff --git a/autogpt_platform/backend/backend/api/features/chat/service.py b/autogpt_platform/backend/backend/api/features/chat/service.py index 0f186f3fec..1f85b39926 100644 --- a/autogpt_platform/backend/backend/api/features/chat/service.py +++ b/autogpt_platform/backend/backend/api/features/chat/service.py @@ -72,7 +72,6 @@ langfuse = get_client() # Redis key prefix for tracking running long-running operations # Used for idempotency across Kubernetes pods - prevents duplicate executions on browser refresh RUNNING_OPERATION_PREFIX = "chat:running_operation:" -RUNNING_OPERATION_TTL = 600 # 10 minutes - safety net if pod dies during execution async def _mark_operation_started(tool_call_id: str) -> bool: @@ -84,7 +83,7 @@ async def _mark_operation_started(tool_call_id: str) -> bool: redis = await get_redis_async() key = f"{RUNNING_OPERATION_PREFIX}{tool_call_id}" # SETNX with TTL - atomic "set if not exists" - result = await redis.set(key, "1", ex=RUNNING_OPERATION_TTL, nx=True) + result = await redis.set(key, "1", ex=config.long_running_operation_ttl, nx=True) return result is not None