HKUDS/Vibe-Trading · warning · RegistryError

{alpha_id}: source {size}B exceeds {_MAX_PY_BYTES}B cap

Error message

{alpha_id}: source {size}B exceeds {_MAX_PY_BYTES}B cap

What it means

get_source enforces a hard byte cap (_MAX_PY_BYTES) on source files to avoid loading huge generated blobs into memory. If the .py file's stat size exceeds the cap, reading is refused before any I/O.

Source

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

    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
        if size > _MAX_PY_BYTES:
            raise RegistryError(
                f"{alpha_id}: source {size}B exceeds {_MAX_PY_BYTES}B cap"
            )
        try:
            return py_path.read_text(encoding="utf-8")
        except OSError as exc:
            raise RegistryError(f"{alpha_id}: cannot read source: {exc}") from exc

    def health(self) -> dict[str, Any]:
        return {
            "loaded": len(self._alphas),
            "failed": len(self._load_errors),
            "errors": [
                {"alpha_id": e.alpha_id, "reason": e.reason} for e in self._load_errors
            ],
        }

    def compute(self, alpha_id: str, panel: dict[str, pd.DataFrame]) -> pd.DataFrame:
        """Lazy-import the alpha module and run its ``compute(panel)``.

View on GitHub (pinned to 80ffdda44c)

Solutions

  1. Split the oversized module or move large embedded data out of the .py file
  2. If genuinely needed, raise _MAX_PY_BYTES consciously (memory tradeoff)
  3. Generate the factor from a data file loaded at compute time instead of inline source

Example fix

// before
HUGE = [0.1, 0.2, ...  # 100k literals in alpha_big.py
// after
import json, pathlib
HUGE = json.loads(pathlib.Path(__file__).with_suffix('.json').read_text())
Defensive patterns

Strategy: validation

Validate before calling

if py_path.stat().st_size > registry._MAX_PY_BYTES:
    logger.warning('source too large; skipping fetch')

Try / catch

try:
    src = registry.get_source(aid)
except RegistryError as e:
    if 'exceeds' in str(e): src = '<source omitted: too large>'
    else: raise

Prevention

When it happens

Trigger: Calling get_source on a generated or vendored alpha module larger than _MAX_PY_BYTES (e.g. auto-generated factor files with embedded data).

Common situations: Code-generated alpha modules with inlined constants; notebooks or data accidentally saved into the module; raising the cap in a fork and forgetting the limit exists.

Related errors


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