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.
This commit is contained in:
Zamil Majdy
2026-01-27 10:00:48 -06:00
parent abe3707f17
commit dbc7cbf6c6
2 changed files with 7 additions and 2 deletions

View File

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

View File

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