HKUDS/Vibe-Trading · error · HTTPException

alpha_id not found

Error message

alpha_id not found

What it means

Date parameters (start_date/end_date) are parsed with date.fromisoformat after str/strip. Any value that is not strict ISO YYYY-MM-DD raises this ValueError, with field_name telling you which parameter failed. Note fromisoformat in older Python (<3.11) also rejects 'YYYYMMDD' and other loose forms.

Source

Thrown at agent/src/api/alpha_routes.py:464

        }

    # -----------------------------------------------------------------------
    # GET /alpha/{alpha_id}
    # -----------------------------------------------------------------------

    @app.get("/alpha/{alpha_id}", dependencies=[Depends(require_auth)])
    async def get_alpha(alpha_id: str) -> dict[str, Any]:
        """Return alpha metadata + the source code of its zoo .py file."""
        if not _ALPHA_ID_RE.fullmatch(alpha_id or ""):
            raise HTTPException(status_code=400, detail="invalid alpha_id")

        from src.factors.registry import RegistryError, get_default_registry

        registry = get_default_registry()
        try:
            alpha = registry.get(alpha_id)
        except KeyError:
            raise HTTPException(
                status_code=404,
                detail={"status": "error", "error": "alpha_id not found"},
            )

        try:
            source_code = registry.get_source(alpha_id)
        except RegistryError as exc:
            # Source-read failure is a degraded but recoverable case — log and
            # surface a short placeholder. The reason here is a typed registry
            # error (size cap or OS error from a known path), safe to expose.
            logger.warning("failed to read source for %s: %s", alpha_id, exc)
            source_code = f"# <source unavailable: {exc}>"

        return {
            "status": "ok",
            "alpha": {
                "id": alpha.id,
                "zoo": alpha.zoo,

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Normalize to ISO before calling: parsed=date.fromisoformat(x) then pass parsed.isoformat(), or datetime.strptime(x,'%m/%d/%Y').strftime('%Y-%m-%d')
  2. Truncate datetimes: str(value)[:10] to drop the time component
  3. Validate format client-side with regex ^\d{4}-\d{2}-\d{2}$

Example fix

# before
execute(action='history', start_date='2024/01/01', end_date='2024/01/31')
# after
from datetime import datetime
fmt=lambda s: datetime.strptime(s,'%Y/%m/%d').strftime('%Y-%m-%d')
execute(action='history', start_date=fmt('2024/01/01'), end_date=fmt('2024/01/31'))
Defensive patterns

Strategy: validation

Validate before calling

from datetime import date, datetime

def to_iso(field_name, v):
    if isinstance(v, datetime):
        v = v.date()
    if isinstance(v, date):
        return v.isoformat()
    return datetime.strptime(str(v).strip(), '%Y-%m-%d').date().isoformat()

Type guard

import re
def is_iso_date(s) -> bool:
    return bool(re.fullmatch(r'\d{4}-\d{2}-\d{2}', str(s).strip())) and __import__('datetime').date.fromisoformat(str(s).strip()) is not None

Try / catch

try:
    tool.execute(action='history', start_date=sd, end_date=ed)
except ValueError as e:
    if 'must use YYYY-MM-DD format' in str(e):
        sd, ed = to_iso('start_date', sd), to_iso('end_date', ed)
        result = tool.execute(action='history', start_date=sd, end_date=ed)
    else:
        raise

Prevention

When it happens

Trigger: Calling execute(action='history', start_date='2024/01/01'), end_date='20240131', '2024-1-5' (non-padded), or 'Jan 1 2024'. Only zero-padded YYYY-MM-DD such as '2024-01-31' parses.

Common situations: Frontend date pickers emitting slashes or timestamps; Excel/CSV dates in MM/DD/YYYY; LLM callers natural-language dates; passing datetime objects with time components that stringify to '2024-01-31 00:00:00' (rejected on Python <3.11).

Related errors


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