{"record":{"id":"251d4edea50f2541","repo":"infiniflow/ragflow","slug":"provider-not-initialized-call-initialize-first-251d4e","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/tenki.py","lineNumber":125,"sourceCode":"                \"max_lifetime\": self.max_lifetime,\n                \"max_output_bytes\": self.max_output_bytes,\n                \"max_artifacts\": self.max_artifacts,\n                \"max_artifact_bytes\": self.max_artifact_bytes,\n            }\n        )\n        if not is_valid:\n            raise SandboxProviderConfigError(error_message or \"Invalid Tenki provider configuration.\")\n\n        self._client = self._create_client()\n        self._assert_connectivity()\n\n        self._initialized = True\n        logger.info(\"Tenki provider initialized\")\n        return True\n\n    def create_instance(self, template: str = \"python\") -> SandboxInstance:\n        if not self._initialized:\n            raise RuntimeError(\"Provider not initialized. Call initialize() first.\")\n\n        language = self._normalize_language(template)\n        errors = self._tenki_errors()\n\n        create_kwargs: dict[str, Any] = {\n            \"allow_outbound\": self.allow_outbound,\n            \"max_duration\": self.max_lifetime,\n            \"metadata\": {\"source\": \"ragflow\"},\n        }\n        if self.image:\n            create_kwargs[\"image\"] = self.image\n        if self.cpu_cores > 0:\n            create_kwargs[\"cpu_cores\"] = self.cpu_cores\n        if self.memory_mb > 0:\n            create_kwargs[\"memory_mb\"] = self.memory_mb\n        if self.disk_size_gb > 0:\n            create_kwargs[\"disk_size_gb\"] = self.disk_size_gb\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/tenki.py#L107-L143","documentation":"Raised by TenkiProvider.create_instance() when the provider's _initialized flag is False. The provider contract requires initialize(config) to run successfully before any sandbox can be provisioned; every later call checks this guard first.","triggerScenarios":"Calling create_instance() on a fresh TenkiProvider, or after an initialize() that raised SandboxProviderConfigError or failed its connectivity assert (those paths never set _initialized = True).","commonSituations":"Reusing a provider object across worker restarts without re-initializing, or assuming the constructor sets up the client. It also surfaces after a failed initialize() because the exception left the provider half-configured.","solutions":["Call and await a successful provider.initialize(config) before create_instance().","Wrap initialize() in try/except and treat any SandboxProviderConfigError as fatal rather than continuing to create_instance().","If initialize() previously failed, build a new TenkiProvider instance and initialize it with corrected config."],"exampleFix":"# before\nprovider = TenkiProvider()\ninstance = provider.create_instance(\"python\")\n\n# after\nprovider = TenkiProvider()\nprovider.initialize({\"api_key\": key})\ninstance = provider.create_instance(\"python\")","handlingStrategy":"validation","validationCode":"if not getattr(provider, \"_initialized\", False):\n    provider.initialize(config)  # must not raise\n# or track it yourself:\ninitialized = provider.initialize(config)","typeGuard":"def is_ready(provider) -> bool:\n    return bool(getattr(provider, \"_initialized\", False))","tryCatchPattern":"try:\n    instance = provider.create_instance(template)\nexcept RuntimeError as exc:\n    if \"not initialized\" in str(exc):\n        provider.initialize(config)\n        instance = provider.create_instance(template)\n    else:\n        raise","preventionTips":["Initialize the provider once at startup and treat a False/raising initialize() as a fatal boot error.","Never reuse a provider object whose initialize() raised; rebuild it.","Wrap provider lifecycle (initialize/create/destroy) in a small manager class so ordering cannot be skipped."],"tags":["lifecycle","sandbox","tenki"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}