Skip to content

Bug: TradingAgents hangs with post-7/31 deepseek-v4-flash — long reasoning chains exhaust token budget / trip gateway idle timeout #1204

Description

@ariesy

Bug: TradingAgents hangs indefinitely with DeepSeek V4 Flash (post-7/31 stable) — long reasoning chains exhaust token budget / trip gateway idle timeout

Environment

  • Branch: dev (15caeb9, 2026-08-02)
  • Provider: openai (OpenAI-compatible) with TRADINGAGENTS_LLM_BACKEND_URL=https://opencode.ai/zen/go/v1
  • Models: deepseek-v4-flash (both quick & deep think; the 7/31 stable release)
  • Ticker: 159566.SZ (A-share ETF), all 4 analysts + full pipeline

Symptom

The run hangs indefinitely during the analyst/data-collection phase: process sits in wait_woken with near-zero CPU, the log stops updating after the initial data-fetch errors (StockTwits/Reddit/Polymarket are all non-fatal, expected for A-shares), and no report directory is ever created. Reproduced 3/3 times (pro+flash, flash-only, strict .env flash). A similar run on 2026-07-30 with the previous (pre-7/31) v4-flash completed fine.

Root-cause evidence (direct API tests against the same backend)

Prompt max_tokens Result
trivial ("reply OK") 100 OK — content returned, reasoning = 26 tokens
complex (analysis request) 500 empty contentreasoning_tokens: 500, finish_reason: length (reasoning chain ate the whole budget)
complex 2048 OK — reasoning 529 + content 55 tokens
complex not set no response in 90s (curl HTTP 000 timeout)

Analysis

  1. The 7/31 stable v4-flash (post-training) produces much longer reasoning chains — 500+ tokens for complex tasks vs ~26 for trivial ones.
  2. _PASSTHROUGH_KWARGS in llm_clients/openai_client.py does not include max_tokens, so TradingAgents sends no upper bound.
  3. With no bound, the backend lets the reasoning chain run long, and a single generation exceeds the ~3 min idle timeout of the gateway (the same timeout documented in feat(llm): add OpenCode Go provider #782 for opencode-go) → connection dropped → process hangs.
  4. With a small bound (wherever a default applies), the reasoning chain consumes the entire budget and content comes back empty → downstream agents get nothing to parse.

Proposed fix

  1. Inject a sensible default max_tokens (e.g. 8192) into the OpenAI-compatible client calls, overridable via a new TRADINGAGENTS_MAX_TOKENS env var (mirroring the existing _ENV_OVERRIDES pattern).
  2. Consider enabling streaming for the OpenAI-compatible path (as feat(llm): add OpenCode Go provider #782 did for opencode-go), including reasoning_content capture from stream deltas, so long generations keep the socket alive.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions