HKUDS/Vibe-Trading · error · RegistryError

{path.name}: __alpha_meta__ not a literal: {exc}

Error message

{path.name}: __alpha_meta__ not a literal: {exc}

What it means

After finding __alpha_meta__, the loader calls ast.literal_eval on the assigned expression so metadata stays purely static. If the value is not a literal (e.g. a function call, name reference, or concatenation of variables), literal_eval raises and it is wrapped in RegistryError.

Source

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

    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

    size = path.stat().st_size
    if size > _MAX_YAML_BYTES:
        raise RegistryError(f"{path.name}: {size}B exceeds {_MAX_YAML_BYTES}B YAML cap")
    text = path.read_text(encoding="utf-8")

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Inline the full dict literally in each module
  2. Use only str/int/bool/list/dict literal values
  3. Generate the literal with a script if sharing content across many alphas

Example fix

# before
__alpha_meta__ = {**BASE_META, 'alpha_id': 'x'}
# after
__alpha_meta__ = {'alpha_id': 'x', 'theme': 'momentum', ...}
Defensive patterns

Strategy: validation

Validate before calling

import ast
node = ...  # meta value node
assert isinstance(node, (ast.Dict,)) or _is_literal(node), 'must be a literal'

Try / catch

try:
    load_alpha_meta_from_py(path)
except RegistryError as e:
    if 'not a literal' in str(e): inline_the_dict(path)

Prevention

When it happens

Trigger: Writing __alpha_meta__ = build_meta() or __alpha_meta__ = {**BASE, 'alpha_id': 'x'} — any non-literal expression.

Common situations: Trying to reuse shared meta constants across alphas, f-strings or .format() in meta values, or copy-pasting code-style dict construction into a data-only context.

Related errors


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