{"record":{"id":"2f462255bbd0c157","repo":"langchain-ai/deepagents","slug":"extension-factory-in-source-path-failed-exc","errorCode":null,"errorMessage":"Extension factory in {source.path} failed: {exc}","messagePattern":"Extension factory in (.+?) failed: (.+?)","errorType":"exception","errorClass":"ExtensionError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/extensions/loader.py","lineNumber":109,"sourceCode":"    snapshot = registry._snapshot()\n    api = ExtensionAPI(registry, source, cwd=cwd, mode=mode)\n    try:\n        await factory(api)\n    except (KeyboardInterrupt, asyncio.CancelledError):\n        registry._rollback(snapshot)\n        api._deactivate()\n        sys.modules.pop(name, None)\n        raise\n    except (SystemExit, Exception) as exc:\n        registry._rollback(snapshot)\n        api._deactivate()\n        sys.modules.pop(name, None)\n        msg = (\n            f\"Extension factory in {source.path} attempted to exit: {exc}\"\n            if isinstance(exc, SystemExit)\n            else f\"Extension factory in {source.path} failed: {exc}\"\n        )\n        raise ExtensionError(msg) from exc\n    return api\n","sourceCodeStart":91,"sourceCodeEnd":111,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/extensions/loader.py#L91-L111","documentation":"Raised by `load_extension` when an extension factory raises any exception other than `SystemExit` while executing. The loader cleans the module out of `sys.modules` and wraps the failure in `ExtensionError`, preserving the original exception via `raise ... from exc` so the root cause stays in the traceback.","triggerScenarios":"Any uncaught exception inside the async factory body: failed imports at factory time, network/filesystem errors during init, attribute errors on the injected API, bad config reads, constructor exceptions.","commonSituations":"Extensions importing optional dependencies that are not installed; factories reading config files that are malformed or absent; API version drift where the factory calls an API method that no longer exists.","solutions":["Read the chained `__cause__` traceback to find the real failing line in the factory","Install or fix whatever dependency/resource the factory failed on","Wrap risky setup in the factory and raise a descriptive error, or defer non-essential work to first use"],"exampleFix":"// before\nasync def extension(api):\n    client = ExpensiveClient(api.config[\"token\"])  # KeyError if missing\n\n// after\nasync def extension(api):\n    token = api.config.get(\"token\")\n    if not token:\n        raise RuntimeError(\"'token' is required in the [tools.search] config\")\n    client = ExpensiveClient(token)","handlingStrategy":"try-catch","validationCode":"# pre-flight: import the extension module and dry-run its factory deps\ntry:\n    importlib.import_module(ext_module_name)\nexcept ImportError as exc:\n    logger.error(\"extension dep missing: %s\", exc)","typeGuard":null,"tryCatchPattern":"try:\n    api = await load_extension(source, registry)\nexcept ExtensionError as exc:\n    logger.exception(\"extension %s failed\", source.path)  # chained cause shown","preventionTips":["Keep factory bodies minimal; defer risky work to first use","Guard optional imports inside the factory with try/except ImportError","Pin and test extensions against the host API version"],"tags":["extensions","plugin-loading","exception-wrapping"],"backgroundTag":"plugin-initialization-failed","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}