{"record":{"id":"32bd8bbbdb8158dc","repo":"HKUDS/Vibe-Trading","slug":"alpha-id-source-size-b-exceeds-max-py-bytes","errorCode":null,"errorMessage":"{alpha_id}: source {size}B exceeds {_MAX_PY_BYTES}B cap","messagePattern":"(.+?): source (.+?)B exceeds (.+?)B cap","errorType":"exception","errorClass":"RegistryError","httpStatus":null,"severity":"warning","filePath":"agent/src/factors/registry.py","lineNumber":304,"sourceCode":"\n    def get_source(self, alpha_id: str) -> str:\n        \"\"\"Return the raw .py source of a registered alpha (size-capped).\n\n        Raises:\n            KeyError: alpha_id unknown.\n            RegistryError: source file exceeds ``_MAX_PY_BYTES`` or cannot be read.\n        \"\"\"\n        if alpha_id not in self._alphas:\n            raise KeyError(f\"alpha_id {alpha_id!r} not in registry\")\n        py_path = self._py_paths.get(alpha_id)\n        if py_path is None:\n            raise RegistryError(f\"{alpha_id}: no source path recorded\")\n        try:\n            size = py_path.stat().st_size\n        except OSError as exc:\n            raise RegistryError(f\"{alpha_id}: cannot stat source: {exc}\") from exc\n        if size > _MAX_PY_BYTES:\n            raise RegistryError(\n                f\"{alpha_id}: source {size}B exceeds {_MAX_PY_BYTES}B cap\"\n            )\n        try:\n            return py_path.read_text(encoding=\"utf-8\")\n        except OSError as exc:\n            raise RegistryError(f\"{alpha_id}: cannot read source: {exc}\") from exc\n\n    def health(self) -> dict[str, Any]:\n        return {\n            \"loaded\": len(self._alphas),\n            \"failed\": len(self._load_errors),\n            \"errors\": [\n                {\"alpha_id\": e.alpha_id, \"reason\": e.reason} for e in self._load_errors\n            ],\n        }\n\n    def compute(self, alpha_id: str, panel: dict[str, pd.DataFrame]) -> pd.DataFrame:\n        \"\"\"Lazy-import the alpha module and run its ``compute(panel)``.","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/registry.py#L286-L322","documentation":"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.","triggerScenarios":"Calling get_source on a generated or vendored alpha module larger than _MAX_PY_BYTES (e.g. auto-generated factor files with embedded data).","commonSituations":"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.","solutions":["Split the oversized module or move large embedded data out of the .py file","If genuinely needed, raise _MAX_PY_BYTES consciously (memory tradeoff)","Generate the factor from a data file loaded at compute time instead of inline source"],"exampleFix":"// before\nHUGE = [0.1, 0.2, ...  # 100k literals in alpha_big.py\n// after\nimport json, pathlib\nHUGE = json.loads(pathlib.Path(__file__).with_suffix('.json').read_text())","handlingStrategy":"validation","validationCode":"if py_path.stat().st_size > registry._MAX_PY_BYTES:\n    logger.warning('source too large; skipping fetch')","typeGuard":null,"tryCatchPattern":"try:\n    src = registry.get_source(aid)\nexcept RegistryError as e:\n    if 'exceeds' in str(e): src = '<source omitted: too large>'\n    else: raise","preventionTips":["Keep generated modules small; store data externally","Treat the cap as a lint threshold for generated code"],"tags":["size-limit","source-code","registry"],"backgroundTag":"payload-too-large","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}