HKUDS/Vibe-Trading · error · ValueError

invalid alpha_id {aid!r}

Error message

invalid alpha_id {aid!r}

What it means

This NotImplementedError is part of the scaffold template (plugin_scaffold.py) written into newly created connectors. It marks get_account_snapshot as an unimplemented stub the developer must fill in by calling their broker's account endpoint and returning a normalized account envelope. Hitting it at runtime means the scaffold was installed without being implemented.

Source

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


class CompareRequest(BaseModel):
    """POST /alpha/compare body — a head-to-head of >= 2 named alphas."""

    alpha_ids: list[str] = Field(..., min_length=2, max_length=50)
    universe: str = Field(..., min_length=1, max_length=64)
    period: str = Field(..., min_length=4, max_length=32)
    sort: str = Field("ir", min_length=1, max_length=32)

    @field_validator("alpha_ids")
    @classmethod
    def _ids_well_formed(cls, v: list[str]) -> list[str]:
        # De-duplicate (preserve order) and validate each id shape.
        seen: set[str] = set()
        out: list[str] = []
        for aid in v:
            if not _ALPHA_ID_RE.fullmatch(aid or ""):
                raise ValueError(f"invalid alpha_id {aid!r}")
            if aid not in seen:
                seen.add(aid)
                out.append(aid)
        if len(out) < 2:
            raise ValueError("need at least 2 distinct alpha_ids to compare")
        return out

    @field_validator("universe")
    @classmethod
    def _universe_known(cls, v: str) -> str:
        if v not in _BENCH_UNIVERSES:
            raise ValueError(
                f"unknown universe {v!r}; expected one of {sorted(_BENCH_UNIVERSES)}"
            )
        return v

    @field_validator("sort")
    @classmethod

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Implement get_account_snapshot in the adapter to call the broker account API and return the normalized envelope dict (include missing_fields/readonly style keys per the scaffold's check_status shape)
  2. Reinstall the connector so the installed copy under plugin root picks up the edit
  3. Until implemented, avoid routing account reads to this profile

Example fix

# before
def get_account_snapshot(*, credentials, config):
    raise NotImplementedError("Call the broker account endpoint...")

# after
def get_account_snapshot(*, credentials, config):
    resp = broker_client(credentials).get_account()
    return {
        "account_id": resp["id"],
        "equity": float(resp["equity"]),
        "cash": float(resp["cash"]),
        "currency": resp.get("currency", "USD"),
    }
Defensive patterns

Strategy: try-catch

Type guard

def snapshot_implemented(adapter) -> bool:
    import inspect
    fn = getattr(adapter, "get_account_snapshot", None)
    return callable(fn) and not _is_stub(fn)

def _is_stub(fn) -> bool:
    src = inspect.getsource(fn)
    return "NotImplementedError" in src

Try / catch

try:
    snapshot = _local_plugin_call(profile, "get_account_snapshot", overrides)
except NotImplementedError:
    fallback_to_manual_refresh_or_skip()  # scaffold stub; not yet implemented

Prevention

When it happens

Trigger: Scaffolding a connector, installing it, and calling get_account/check_connection before replacing the stub body; the stub raises immediately since it has no logic.

Common situations: Developer installs the starter to test the pipeline and forgets the stubs raise; partial implementation where positions was filled in but account snapshot was not.

Related errors


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