infiniflow/ragflow · error · RuntimeError

Provider not initialized. Call initialize() first.

Error message

Provider not initialized. Call initialize() first.

What it means

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.

Source

Thrown at agent/sandbox/providers/tenki.py:125

                "max_lifetime": self.max_lifetime,
                "max_output_bytes": self.max_output_bytes,
                "max_artifacts": self.max_artifacts,
                "max_artifact_bytes": self.max_artifact_bytes,
            }
        )
        if not is_valid:
            raise SandboxProviderConfigError(error_message or "Invalid Tenki provider configuration.")

        self._client = self._create_client()
        self._assert_connectivity()

        self._initialized = True
        logger.info("Tenki provider initialized")
        return True

    def create_instance(self, template: str = "python") -> SandboxInstance:
        if not self._initialized:
            raise RuntimeError("Provider not initialized. Call initialize() first.")

        language = self._normalize_language(template)
        errors = self._tenki_errors()

        create_kwargs: dict[str, Any] = {
            "allow_outbound": self.allow_outbound,
            "max_duration": self.max_lifetime,
            "metadata": {"source": "ragflow"},
        }
        if self.image:
            create_kwargs["image"] = self.image
        if self.cpu_cores > 0:
            create_kwargs["cpu_cores"] = self.cpu_cores
        if self.memory_mb > 0:
            create_kwargs["memory_mb"] = self.memory_mb
        if self.disk_size_gb > 0:
            create_kwargs["disk_size_gb"] = self.disk_size_gb

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Call and await a successful provider.initialize(config) before create_instance().
  2. Wrap initialize() in try/except and treat any SandboxProviderConfigError as fatal rather than continuing to create_instance().
  3. If initialize() previously failed, build a new TenkiProvider instance and initialize it with corrected config.

Example fix

# before
provider = TenkiProvider()
instance = provider.create_instance("python")

# after
provider = TenkiProvider()
provider.initialize({"api_key": key})
instance = provider.create_instance("python")
Defensive patterns

Strategy: validation

Validate before calling

if not getattr(provider, "_initialized", False):
    provider.initialize(config)  # must not raise
# or track it yourself:
initialized = provider.initialize(config)

Type guard

def is_ready(provider) -> bool:
    return bool(getattr(provider, "_initialized", False))

Try / catch

try:
    instance = provider.create_instance(template)
except RuntimeError as exc:
    if "not initialized" in str(exc):
        provider.initialize(config)
        instance = provider.create_instance(template)
    else:
        raise

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/251d4edea50f2541. Report an issue: GitHub.