{"record":{"id":"d5a93d5a626087e4","repo":"HKUDS/Vibe-Trading","slug":"alpha-id-could-not-build-import-spec-for-py-fi","errorCode":null,"errorMessage":"{alpha.id}: could not build import spec for {py_file}","messagePattern":"(.+?): could not build import spec for (.+?)","errorType":"error_code","errorClass":"RegistryError","httpStatus":null,"severity":"error","filePath":"agent/src/factors/registry.py","lineNumber":366,"sourceCode":"            raise RegistryError(f\"{alpha_id}: module has no compute() function\")\n\n        try:\n            result = compute_fn(panel)\n        except Exception as exc:  # noqa: BLE001 — isolate compute failure\n            raise RegistryError(f\"{alpha_id}: compute() raised: {exc}\") from exc\n\n        return self._validate_output(alpha_id, result, panel)\n\n    def _load_module(self, alpha: Alpha) -> ModuleType:\n        if not self._use_filesystem_loader:\n            return importlib.import_module(alpha.module_path)\n        py_file = self._py_paths[alpha.id]\n        cached = sys.modules.get(alpha.module_path)\n        if cached is not None and getattr(cached, \"__file__\", None) == str(py_file):\n            return cached\n        spec = importlib.util.spec_from_file_location(alpha.module_path, py_file)\n        if spec is None or spec.loader is None:\n            raise RegistryError(f\"{alpha.id}: could not build import spec for {py_file}\")\n        module = importlib.util.module_from_spec(spec)\n        sys.modules[alpha.module_path] = module\n        try:\n            spec.loader.exec_module(module)\n        except Exception:\n            sys.modules.pop(alpha.module_path, None)\n            raise\n        return module\n\n    @staticmethod\n    def _validate_output(\n        alpha_id: str,\n        result: Any,\n        panel: dict[str, pd.DataFrame],\n    ) -> pd.DataFrame:\n        if not isinstance(result, pd.DataFrame):\n            raise RegistryError(\n                f\"{alpha_id}: compute() returned {type(result).__name__}, expected DataFrame\"","sourceCodeStart":348,"sourceCodeEnd":384,"githubUrl":"https://github.com/HKUDS/Vibe-Trading/blob/80ffdda44c5c4db0dd84d70e051cca591cea67df/agent/src/factors/registry.py#L348-L384","documentation":"When the registry uses a filesystem loader, it builds an importlib spec from the recorded .py path. If spec_from_file_location returns None or a spec without a loader (unrecognized extension, path issues), this RegistryError is raised.","triggerScenarios":"_load_module for an alpha whose recorded path is not a loadable .py file — wrong extension, empty path string, or an exotic filesystem importlib can't build a loader for.","commonSituations":"Zoo directory containing .pyc/.so or renamed files picked up by the scanner; registry state persisted and paths changed; platform differences in importlib loaders.","solutions":["Ensure the zoo contains real .py files with standard names","Re-scan the registry so _py_paths reflects current files","Check the path printed in the message exists and ends with .py"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import importlib.util\nspec = importlib.util.spec_from_file_location(mp, py_file)\nif spec is None or spec.loader is None: skip(aid)","typeGuard":null,"tryCatchPattern":"try:\n    out = registry.compute(aid, panel)\nexcept RegistryError as e:\n    if 'import spec' in str(e): skip(aid)\n    else: raise","preventionTips":["Keep only .py modules in the zoo directory","Re-scan registry after moving files"],"tags":["import","importlib","registry"],"backgroundTag":"module-import-failed","analyzedSha":"80ffdda44c5c4db0dd84d70e051cca591cea67df","analyzedAt":"2026-08-28T12:46:38.989Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}