Skip to content

get_trade_recommendation MCP tool times out (cumulative latency, not a single broken dependency) #65

@JohnFunkCode

Description

@JohnFunkCode

Component: quantcore-stock-price MCP wrapper → quantcore-apiRecommendationsService
Environment: Prod (quantcore-prod-20260606) — reproduced 2026-06-18 with symbol=AVGO
Severity: High — the flagship "one-shot recommendation" tool is currently unusable; it returns Upstream request timed out on every call.

Symptom

get_trade_recommendation(AVGO) fails with Upstream request timed out on every attempt (4/4 retries). Connectivity and auth are healthy — get_stock_price(AVGO) and mcp_health_check on the same prod stack return immediately, so the token (QUANTCORE_MCP_TOKEN) is valid and the wrappers are reachable.

Root cause

The failure is not a single hung dependency. Every sub-analysis the tool aggregates was tested individually against AVGO on prod and all succeeded:

get_stock_price, get_rsi, get_macd, get_stochastic, get_volume_analysis, get_candlestick_patterns, get_unusual_calls, get_delta_adjusted_oi, get_dark_pool, get_short_interest, get_bid_ask_spread, get_news_sentiment, get_stop_loss_analysis.

The aggregator runs all of these sequentially within a single request, and several are independently slow due to multiple yfinance round-trips:

  • get_unusual_calls and get_delta_adjusted_oi each scan 3 option expirations.
  • get_stop_loss_analysis alone runs 7 nested sub-analyses (price/BB, VWAP, MACD, RSI, delta-adjusted OI / gamma wall, historical drawdown, short interest).

Summed serially, total wall-clock exceeds the upstream/Cloud Run request timeout (~60s) and the gateway kills the request before it returns.

Proposed fixes (most durable first)

  1. Parallelize the fan-out in RecommendationsService (e.g. asyncio.gather or a thread pool) so sub-analyses run concurrently. Wall-clock drops to ~the slowest single call instead of the sum.
  2. Cache/share the OHLCV download. Many sub-tools each re-fetch the same price history from yfinance. Fetch once, pass the DataFrame down — removes most redundant latency.
  3. Raise the Cloud Run / gateway timeout (--timeout=300) as a stopgap only; Build Alert System #1+added alert system #2 are the real fix.

Side-finding (separate, lower priority)

get_news_sentiment(AVGO) returns INSUFFICIENT_DATA (0 stored articles), so the recommendation's sentiment leg would be empty even once the timeout is fixed. News likely needs collect_news(AVGO) run first / a backfill job. Worth a separate ticket.

Acceptance criteria

  • get_trade_recommendation returns a full recommendation for a liquid symbol (e.g. AVGO) within the gateway timeout.
  • No regression in the individual sub-tool outputs.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions