zylon-ai/private-gpt · error · RuntimeError

Client not initialized

Error message

Client not initialized

What it means

Raised by _setup_environment() when it runs before a client exists on the adapter. The method pushes the preamble and matplotlib rcParams into the remote sandbox by executing setup code through self._client; with no client there is nowhere to send the code. In practice only reachable when start() is bypassed or _client was never set, since start() itself guards on the client first.

Source

Thrown at private_gpt/components/tabular/pandasai_sandbox.py:196

                self._run(self._client.close())
            if self._temp_dir and self._temp_dir.exists():
                shutil.rmtree(self._temp_dir, ignore_errors=True)
        except Exception as e:
            logger.error("Error stopping sandbox: %s", e)
        finally:
            self._started = False
            self._client = None
            self._temp_dir = None

        logger.debug("Remote sandbox session stopped successfully")

    # ------------------------------------------------------------------
    # Environment setup
    # ------------------------------------------------------------------

    def _setup_environment(self) -> None:
        if not self._client:
            raise RuntimeError("Client not initialized")

        temp_dir = f"/tmp/{self._user_id}"
        colors_repr = repr(self._CUSTOM_COLORS)

        setup_code = textwrap.dedent(
            f"""
            {self._PREAMBLE}

            CUSTOM_COLORS = {colors_repr}

            plt.rcParams.update({{
                'figure.facecolor': 'none',
                'axes.facecolor': 'none',
                'savefig.transparent': True,
                'axes.edgecolor': 'none',
                'axes.linewidth': 0,
                'xtick.bottom': False,
                'ytick.left': False,

View on GitHub (pinned to 4a030776a3)

Solutions

  1. Always call start() first — it validates the client and invokes _setup_environment in the correct order.
  2. If calling setup directly in tests, inject a stub client before doing so.
  3. Treat this error as an invariant violation: fix the call order rather than catching it.
Defensive patterns

Strategy: validation

Validate before calling

def environment_ready(sandbox) -> bool:
    return sandbox._client is not None and sandbox._started

Prevention

When it happens

Trigger: Calling the internal _setup_environment() directly without start(); subclass or test code that constructs the adapter and invokes setup before injecting a client; calling after stop() nulled _client.

Common situations: Unit tests exercising setup logic in isolation; a code path change that calls setup eagerly in __init__; adapter reuse after stop().

Related errors


AI-assisted analysis of zylon-ai/private-gpt@4a030776a3 (2026-08-15). Data as JSON: /api/errors/e8c292a102209526. Report an issue: GitHub.