{"record":{"id":"82622ca4f7379142","repo":"infiniflow/ragflow","slug":"provider-not-initialized-call-initialize-first-82622c","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/ssh.py","lineNumber":124,"sourceCode":"                \"node_bin\": self.node_bin,\n                \"work_dir\": self.work_dir,\n                \"timeout\": self.timeout,\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 SSH provider configuration.\")\n\n        self._assert_connectivity()\n\n        self._initialized = True\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        client = self._create_ssh_client()\n        sftp = client.open_sftp()\n\n        try:\n            remote_work_dir = self._create_remote_workspace(client)\n            stdout, stderr, exit_code = self._run_remote_command(\n                client,\n                f\"mkdir -p {shlex.quote(posixpath.join(remote_work_dir, 'artifacts'))}\",\n                timeout=min(self.timeout, 10),\n            )\n            if exit_code != 0:\n                raise RuntimeError(f\"Failed to create remote artifacts directory: {stderr or stdout or 'unknown error'}\")\n        except Exception:\n            sftp.close()\n            client.close()\n            raise","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/providers/ssh.py#L106-L142","documentation":"Raised by SSHProvider.create_instance() when called before initialize() succeeded (self._initialized is False). create_instance immediately opens a real SSH client (self._create_ssh_client()) and SFTP session, which requires host/credentials from initialization; the guard fails fast with RuntimeError instead of attempting a connection with empty config.","triggerScenarios":"Constructing SSHProvider() and calling create_instance('python') without initialize(config); proceeding after an initialize() that raised SandboxProviderConfigError or failed _assert_connectivity(); a retry loop that re-creates the provider object but skips re-init.","commonSituations":"Integration code assuming the constructor connects; initialize() failure swallowed by broad exception handling; provider instances recreated per request in web handlers without lifecycle management.","solutions":["Call initialize(config) with valid SSH parameters and confirm it returns True before create_instance().","Treat any initialize() exception as fatal for that provider instance; do not continue to instance creation.","Wrap lifecycle in a helper that returns an initialized provider, so call sites cannot get an un-initialized one.","If initialize() failed, fix the underlying config/connectivity issue first (see the SSH config/connectivity errors it raises)."],"exampleFix":"# before\nprovider = SSHProvider()\ninstance = provider.create_instance(\"python\")\n\n# after\nprovider = SSHProvider()\nprovider.initialize({\"host\": h, \"username\": u, \"private_key\": k})\ninstance = provider.create_instance(\"python\")","handlingStrategy":"validation","validationCode":"provider = SSHProvider()\nassert provider.initialize(config), \"SSH init failed\"\ninstance = provider.create_instance(\"python\")","typeGuard":"def is_ready(provider) -> bool:\n    \"\"\"True after successful SSH 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":["Never swallow initialize() exceptions; abort the request path when SSH setup fails.","Create one initialized provider at startup and reuse it for all instances."],"tags":["sandbox","ssh","lifecycle","initialization"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}