HKUDS/Vibe-Trading · error · ValueError

start_date must be on or before end_date

Error message

start_date must be on or before end_date

What it means

Final date check in _validate_backtest_dates: after both dates parse successfully, start must not be after end. Inverted ranges would produce empty or nonsensical backtests, so they are rejected up front.

Source

Thrown at agent/src/tools/autopilot_tool.py:247

        return candidate, None
    return "auto", (
        f"hypothesis data_source {candidate!r} is not a known loader source; "
        "fell back to 'auto'"
    )


def _validate_backtest_dates(start_date: str, end_date: str) -> None:
    """Validate backtest dates before writing any run artifacts."""
    try:
        start = datetime.strptime(start_date, "%Y-%m-%d").date()
    except ValueError as exc:
        raise ValueError("start_date must be YYYY-MM-DD") from exc
    try:
        end = datetime.strptime(end_date, "%Y-%m-%d").date()
    except ValueError as exc:
        raise ValueError("end_date must be YYYY-MM-DD") from exc
    if start > end:
        raise ValueError("start_date must be on or before end_date")


def _run_dir_for_hypothesis(hypothesis_id: str) -> Path:
    """Return a path-contained run directory for any persisted hypothesis id."""
    suffix = hashlib.sha256(hypothesis_id.encode("utf-8")).hexdigest()[:12]
    return Path.home() / ".vibe-trading" / "runs" / f"autopilot_{suffix}"


class GenerateBacktestConfigTool(BaseTool):
    """Generate backtest config.json from a research hypothesis.

    Reads a hypothesis, derives config fields from its universe and
    data_sources, and writes a ready-to-run config.json to a run directory.
    The agent should then create signal_engine.py from the signal_definition
    and call the backtest tool.
    """

    name = "generate_backtest_config"

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Swap the arguments so the earlier date is start_date
  2. Order programmatically: start, end = sorted([start, end])
  3. Assert ordering in tests that exercise the execute path

Example fix

// before
execute(start_date=end, end_date=start)
// after
execute(start_date=start, end_date=end)
Defensive patterns

Strategy: validation

Validate before calling

from datetime import date
sd, ed = date.fromisoformat(start_date), date.fromisoformat(end_date)
assert sd <= ed

Type guard

def dates_ordered(s: str, e: str) -> bool:
    from datetime import date
    return date.fromisoformat(s) <= date.fromisoformat(e)

Try / catch

try:
    _validate_backtest_dates(start_date, end_date)
except ValueError as e:
    if 'on or before' in str(e):
        start_date, end_date = end_date, start_date

Prevention

When it happens

Trigger: Calling autopilot execute with start_date='2024-01-01' and end_date='2023-12-31' — both well-formed but ordered wrongly.

Common situations: Parameter order swaps in wrapper code; date pickers returning (to, from); LLM misordering 'from'/'to' fields.

Related errors


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