HKUDS/Vibe-Trading · error · HTTPException

exit_threshold must be below enter_threshold

Error message

exit_threshold must be below enter_threshold

What it means

Hysteresis-based regime detection requires an exit threshold strictly below the enter threshold; otherwise enter/exit bands would overlap or invert. The endpoint rejects exit_threshold >= enter_threshold with 400.

Source

Thrown at agent/src/api/system_routes.py:344

        edge-density series, causally smoothed, and run through a two-threshold
        hysteresis state machine. Descriptive risk context, not a trading
        signal. Shares /correlation's rate-limit budget.
        """
        from backtest.regime import compute_regime_timeline

        if not _correlation_rate_limiter.allow(_client_key(request)):
            raise HTTPException(
                status_code=status.HTTP_429_TOO_MANY_REQUESTS,
                detail="Rate limit exceeded, try again later",
            )

        code_list = [c.strip() for c in codes.split(",") if c.strip()]
        if len(code_list) < 2:
            raise HTTPException(status_code=400, detail="At least 2 asset codes required")
        if len(code_list) > 20:
            raise HTTPException(status_code=400, detail="Maximum 20 assets per request")
        if exit_threshold >= enter_threshold:
            raise HTTPException(status_code=400, detail="exit_threshold must be below enter_threshold")

        try:
            return compute_regime_timeline(
                codes=code_list,
                days=days,
                corr_window=corr_window,
                edge_threshold=edge_threshold,
                smooth_window=smooth_window,
                enter_threshold=enter_threshold,
                exit_threshold=exit_threshold,
            )
        except ValueError as exc:
            raise HTTPException(status_code=400, detail=str(exc))
        except Exception:
            logger.exception("Regime timeline computation failed for codes=%s", code_list)
            raise HTTPException(status_code=500, detail="Regime timeline computation failed")

    @app.post("/system/shutdown")

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Set exit_threshold below enter_threshold, e.g. enter=0.7 exit=0.5
  2. Check parameter order/naming when constructing the query string
  3. Confirm both thresholds use the same scale (0-1 fractions)

Example fix

# before
params = {'enter_threshold': 0.6, 'exit_threshold': 0.6}
# after
params = {'enter_threshold': 0.7, 'exit_threshold': 0.5}
Defensive patterns

Strategy: validation

Validate before calling

assert enter_threshold > exit_threshold, 'exit_threshold must be below enter_threshold'

Prevention

When it happens

Trigger: GET /system/correlation-regime with enter_threshold=0.6&exit_threshold=0.6 or enter_threshold=0.5&exit_threshold=0.7 (defaults or explicit params).

Common situations: Clients omitting one threshold so defaults clash, swapping the two parameter names, or scaling thresholds (e.g. 0-100 vs 0-1) inconsistently.

Related errors


AI-assisted analysis of HKUDS/Vibe-Trading@80ffdda44c (2026-08-28). Data as JSON: /api/errors/f0d0c97b15b7ec91. Report an issue: GitHub.