HKUDS/Vibe-Trading · error · KeyError

alpha_id {alpha_id!r} not in registry

Error message

alpha_id {alpha_id!r} not in registry

What it means

Registry.get(alpha_id) looks up an Alpha by id and raises KeyError when the id is not present in the in-memory registry. This is the standard lookup failure for consumers like _compute_single_alpha, theme_breakdown, run_bench, and run_bench_strict.

Source

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

        zoo: str | None = None,
        theme: str | None = None,
        universe: str | None = None,
    ) -> list[str]:
        """Return alpha IDs matching the (optional) filters."""
        out: list[str] = []
        for a in self._alphas.values():
            if zoo is not None and a.zoo != zoo:
                continue
            if theme is not None and theme not in a.meta.get("theme", []):
                continue
            if universe is not None and universe not in a.meta.get("universe", []):
                continue
            out.append(a.id)
        return sorted(out)

    def get(self, alpha_id: str) -> Alpha:
        if alpha_id not in self._alphas:
            raise KeyError(f"alpha_id {alpha_id!r} not in registry")
        return self._alphas[alpha_id]

    def get_source(self, alpha_id: str) -> str:
        """Return the raw .py source of a registered alpha (size-capped).

        Raises:
            KeyError: alpha_id unknown.
            RegistryError: source file exceeds ``_MAX_PY_BYTES`` or cannot be read.
        """
        if alpha_id not in self._alphas:
            raise KeyError(f"alpha_id {alpha_id!r} not in registry")
        py_path = self._py_paths.get(alpha_id)
        if py_path is None:
            raise RegistryError(f"{alpha_id}: no source path recorded")
        try:
            size = py_path.stat().st_size
        except OSError as exc:
            raise RegistryError(f"{alpha_id}: cannot stat source: {exc}") from exc

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. List available ids via registry (e.g. sorted(registry._alphas) or the list API used in your version) and fix the id
  2. Verify the target module actually registered; if it was skipped, fix its underlying registration error first
  3. Keep ids in config in one canonical place to avoid drift

Example fix

# before
alpha = registry.get('momentum_fast ')
# after
alpha = registry.get('momentum_fast')
Defensive patterns

Strategy: try-catch

Validate before calling

if alpha_id not in registry._alphas: raise KeyError(alpha_id)  # or use a public listing API

Type guard

def is_registered(registry, alpha_id: str) -> bool:
    return alpha_id in registry._alphas

Try / catch

try:
    alpha = registry.get(alpha_id)
except KeyError:
    log.warning(f'unknown alpha {alpha_id}; available: {sorted(registry._alphas)}')
    raise

Prevention

When it happens

Trigger: Calling registry.get('nonexistent_id'), or passing an alpha id to run_bench that failed to register (e.g. its module had invalid metadata).

Common situations: Typos in alpha ids, ids from config referencing alphas that were removed, or zoo modules silently skipped at registration time due to their own errors — check registration logs.

Related errors


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