[Bug] LLM API calls have no timeout - causes hanging analysis tasks

Author: tomlyCreated May 6, 2026Updated May 6, 2026

Bug ID: BLK-018

Severity: P1 - High

Describe the bug LLM API calls in TradingAgents have no timeout setting. When the LLM API (OpenClaw Gateway) is slow or unresponsive, the analysis tasks hang indefinitely (>5 minutes).

Root Cause src/utils/llm.py - call_llm() function:

result = llm.invoke(prompt)  # No timeout - hangs indefinitely

Impact

  1. Analysis tasks hang when LLM API is slow
  2. Retry logic (max_retries=3) cannot help because first call hangs forever
  3. Analysis degrades to default_factory responses with zero quality

Example Error

TradingAgents LLM API持续超时(>5分钟无响应),已连续多日。本次分析基于SDK实时数据+自主研判完成。

Proposed Fix Add timeout parameter to call_llm():

def call_llm(..., timeout: int = 120) -> BaseModel:
    result = llm.invoke(prompt, timeout=timeout)

Or use signal-based timeout:

import signal

def timeout_handler(signum, frame):
    raise TimeoutError("LLM call timed out")

signal.signal(signal.SIGALRM, timeout_handler)
signal.alarm(timeout)  # seconds
try:
    result = llm.invoke(prompt)
finally:
    signal.alarm(0)

Additional context Bug report filed internally at .bugs/BLK-018-llm-timeout.md


Reported by 诸葛亮(CEO)on behalf of Tomly AI Fund