HKUDS/Vibe-Trading · error · RegistryError

{path.name}: __alpha_meta__ assignment not found

Error message

{path.name}: __alpha_meta__ assignment not found

What it means

load_alpha_meta_from_py scans top-level statements for an assignment to __alpha_meta__. If no such assignment exists in the module, RegistryError is raised because there is no metadata to extract (the module is never imported, only parsed).

Source

Thrown at agent/src/factors/registry.py:170

    """
    size = path.stat().st_size
    if size > _MAX_PY_BYTES:
        raise RegistryError(f"{path.name}: {size}B exceeds {_MAX_PY_BYTES}B cap")

    source = path.read_text(encoding="utf-8")
    tree = ast.parse(source, filename=str(path))

    meta_node: ast.expr | None = None
    for stmt in tree.body:
        if not isinstance(stmt, ast.Assign):
            continue
        targets = [t for t in stmt.targets if isinstance(t, ast.Name)]
        if any(t.id == "__alpha_meta__" for t in targets):
            meta_node = stmt.value
            break

    if meta_node is None:
        raise RegistryError(f"{path.name}: __alpha_meta__ assignment not found")

    try:
        raw = ast.literal_eval(meta_node)
    except (ValueError, SyntaxError) as exc:
        raise RegistryError(f"{path.name}: __alpha_meta__ not a literal: {exc}") from exc

    if not isinstance(raw, dict):
        raise RegistryError(f"{path.name}: __alpha_meta__ must be dict, got {type(raw).__name__}")

    try:
        return AlphaMeta(**raw)
    except ValidationError as exc:
        raise RegistryError(f"{path.name}: AlphaMeta validation failed: {exc}") from exc


def _safe_yaml_load(path: Path) -> Any:
    """yaml.safe_load with hard 5 MB size cap (defence in depth)."""
    import yaml  # local import keeps registry import-light

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Add a module-level __alpha_meta__ = {...} dict literal to the file
  2. Move helper modules out of the zoo directory
  3. Make the assignment unconditional and top-level

Example fix

# before
# alpha.py: no meta
# after
__alpha_meta__ = {'alpha_id': 'my_alpha', ...}
Defensive patterns

Strategy: validation

Validate before calling

import ast
tree = ast.parse(path.read_text())
assert any(isinstance(s, ast.Assign) and any(getattr(t, 'id', None) == '__alpha_meta__' for t in s.targets) for s in tree.body), 'missing __alpha_meta__'

Try / catch

try:
    load_alpha_meta_from_py(path)
except RegistryError as e:
    if 'assignment not found' in str(e): add_meta_literal(path)

Prevention

When it happens

Trigger: A zoo .py file without a module-level __alpha_meta__ = {...} statement, e.g. a helper module accidentally placed in the zoo dir, or a meta dict defined via function call or inside a class body.

Common situations: Placing utility modules in the zoo directory, building __alpha_meta__ dynamically (loops/conditionals) instead of a literal, or the statement being nested inside if TYPE_CHECKING or similar.

Related errors


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