infiniflow/ragflow · error · RuntimeError

Provider not initialized. Call initialize() first.

Error message

Provider not initialized. Call initialize() first.

What it means

Guard in AliyunCodeInterpreterProvider.create_instance: the provider was used before a successful `initialize()` (which sets `_initialized` and `_config`). Every public provider method enforces this precondition, so calling any of them on a fresh or failed-to-initialize instance raises this RuntimeError.

Source

Thrown at agent/sandbox/providers/aliyun_codeinterpreter.py:144

        except Exception as e:
            logger.error(f"Aliyun Code Interpreter: Initialization failed - {str(e)}")
            return False

    def create_instance(self, template: str = "python") -> SandboxInstance:
        """
        Create a new sandbox instance in Aliyun Code Interpreter.

        Args:
            template: Programming language (python, javascript)

        Returns:
            SandboxInstance object

        Raises:
            RuntimeError: If instance creation fails
        """
        if not self._initialized or not self._config:
            raise RuntimeError("Provider not initialized. Call initialize() first.")

        # Normalize language
        language = self._normalize_language(template)

        try:
            # Get or create template
            if self.template_name:
                # Use existing template
                template_name = self.template_name
            else:
                # Try to get default template, or create one if it doesn't exist
                default_template_name = f"ragflow-{language}-default"
                try:
                    # Check if template exists
                    Template.get_by_name(default_template_name, config=self._config)
                    template_name = default_template_name
                except Exception:
                    # Create default template if it doesn't exist

View on GitHub (pinned to 554fb1133a)

Solutions

  1. Call and await/check `provider.initialize(config)` before create_instance, and treat a False/exception result as fatal rather than continuing.
  2. Inspect why initialize failed (credentials, region, endpoint) — the provider stays uninitialized after any init error.
  3. Gate calls behind `health_check()` if the base class exposes it, or assert `_initialized` in debug builds.

Example fix

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

# after
provider = AliyunCodeInterpreterProvider(...)
if not provider.initialize(config):
    raise RuntimeError("Aliyun sandbox provider failed to initialize; check credentials/region")
instance = provider.create_instance("python")
Defensive patterns

Strategy: validation

Validate before calling

if not provider.initialize(config):
    raise RuntimeError("Aliyun provider init failed; refusing to create instances")
# only now:
instance = provider.create_instance("python")

Type guard

def is_ready(p) -> bool:
    """True when the provider completed initialize() and holds a config."""
    return bool(getattr(p, "_initialized", False)) and getattr(p, "_config", None) is not None

Try / catch

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

Prevention

When it happens

Trigger: Instantiating the provider and immediately calling create_instance(); initialize() raised earlier (bad credentials/region) and the exception was swallowed, leaving `_initialized` False; reusing a provider after some reset path.

Common situations: Missing or malformed Aliyun sandbox config (AK/SK, region, account id) so initialize failed silently upstream; wiring code that caches a provider object but skips the init step on cache hit paths; tests constructing the provider directly.

Related errors


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