{"record":{"id":"5805d3f59e34cdbb","repo":"infiniflow/ragflow","slug":"provider-not-initialized-call-initialize-first-5805d3","errorCode":null,"errorMessage":"Provider not initialized. Call initialize() first.","messagePattern":"Provider not initialized\\. Call initialize\\(\\) first\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/providers/self_managed.py","lineNumber":94,"sourceCode":"    def create_instance(self, template: str = \"python\") -> SandboxInstance:\n        \"\"\"\n        Create a new sandbox instance.\n\n        Note: For self-managed provider, instances are managed internally\n        by the executor_manager's container pool. This method returns\n        a logical instance handle.\n\n        Args:\n            template: Programming language (python, nodejs)\n\n        Returns:\n            SandboxInstance object\n\n        Raises:\n            RuntimeError: If instance creation fails\n        \"\"\"\n        if not self._initialized:\n            raise RuntimeError(\"Provider not initialized. Call initialize() first.\")\n\n        # Normalize language\n        language = self._normalize_language(template)\n\n        # The executor_manager manages instances internally via container pool\n        # We create a logical instance ID for tracking\n        instance_id = str(uuid.uuid4())\n\n        return SandboxInstance(\n            instance_id=instance_id,\n            provider=\"self_managed\",\n            status=\"running\",\n            metadata={\n                \"language\": language,\n                \"endpoint\": self.endpoint,\n                \"pool_size\": self.pool_size,\n            },\n        )","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/self_managed.py#L76-L112","documentation":"Raised by SelfManagedProvider.create_instance() when the provider's initialize() has not completed, i.e. self._initialized is False. SelfManagedProvider delegates execution to a remote sandbox service reached over HTTP; create_instance only mints a logical UUID for tracking, but it still requires a successful initialize() (endpoint configured and reachable) first. RuntimeError, thrown before any instance is created.","triggerScenarios":"Constructing SelfManagedProvider() and calling create_instance('python') without calling initialize(config); initialize() previously raised (bad endpoint/config) leaving _initialized False, then the caller ignores the failure and proceeds; using a new provider object after a restart while the code path assumes prior init.","commonSituations":"Missing initialize() call in a custom integration or test; an exception during initialize() being swallowed by a broad try/except that then continues to create_instance(); lifecycle code that creates the provider lazily but calls execute paths in the wrong order.","solutions":["Call provider.initialize(config) with a valid config (endpoint, timeout, etc.) and only call create_instance() after it returns True.","Check the result/exceptions of initialize() and abort the workflow on failure instead of continuing.","Initialize once at provider construction or session start and reuse the instance; do not re-create the provider per request without init.","If initialize() fails, inspect its error (endpoint URL, connectivity) before retrying."],"exampleFix":"# before\nprovider = SelfManagedProvider()\ninstance = provider.create_instance(\"python\")\n\n# after\nprovider = SelfManagedProvider()\nif not provider.initialize(config):\n    raise RuntimeError(\"sandbox provider failed to initialize\")\ninstance = provider.create_instance(\"python\")","handlingStrategy":"validation","validationCode":"provider = SelfManagedProvider()\nassert provider.initialize(config), \"sandbox init failed\"\n# only now:\ninstance = provider.create_instance(\"python\")","typeGuard":"def is_ready(provider) -> bool:\n    \"\"\"True after a successful initialize().\"\"\"\n    return bool(getattr(provider, \"_initialized\", False))","tryCatchPattern":"try:\n    instance = provider.create_instance(\"python\")\nexcept RuntimeError as e:\n    if \"not initialized\" in str(e):\n        provider.initialize(config)\n        instance = provider.create_instance(\"python\")\n    else:\n        raise","preventionTips":["Encapsulate provider lifecycle: construct + initialize in one factory used by all call sites.","Fail the whole workflow when initialize() raises instead of continuing.","Check provider.health_check() before batches of executions."],"tags":["sandbox","lifecycle","self-managed-provider","initialization"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}