{"record":{"id":"47b1d1c57dd161a2","repo":"dagger/dagger","slug":"no-active-engine-session-to-connect-to","errorCode":null,"errorMessage":"No active engine session to connect to","messagePattern":"No active engine session to connect to","errorType":"exception","errorClass":"ClientConnectionError","httpStatus":null,"severity":"error","filePath":"sdk/python/src/dagger/client/_session.py","lineNumber":248,"sourceCode":"            logger.warning(\n                \"Cannot set connection config after connection already started\"\n            )\n        else:\n            self._cfg = cfg\n        return self\n\n    @property\n    def session(self) -> ClientSession:\n        if not self._session:\n            logger.debug(\"Configuring shared connection to GraphQL server\")\n\n            # Delay checking the environment until we actually need it.\n            if not self._params:\n                self._params = ConnectParams.from_env()\n\n            if not self._params:\n                msg = \"No active engine session to connect to\"\n                raise ClientConnectionError(msg)\n\n            self._session = ClientSession(self._params, self._cfg)\n        return self._session\n\n    def is_connected(self) -> bool:\n        return self._session is not None and self._session.has_session()\n\n    async def close(self) -> None:\n        if self._session:\n            await super().close()\n            self._session = None\n","sourceCodeStart":230,"sourceCodeEnd":260,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/sdk/python/src/dagger/client/_session.py#L230-L260","documentation":"Raised by ClientConnection.session() when no ConnectParams could be resolved — neither explicit params nor DAGGER_SESSION_HOST from the environment — so there is no active engine session to connect to. The SDK defers environment checks until a session is actually needed.","triggerScenarios":"Creating a ClientConnection with no explicit ConnectParams while DAGGER_SESSION_HOST is unset AND engine provisioning is not possible in that code path; or calling session() on a connection after params resolution failed.","commonSituations":"CI environments where DAGGER_SESSION_HOST was expected to be set by a `dagger session` step but wasn't; connecting from a subprocess with a scrubbed environment; mixing `dagger run`-provided env into a plain Python process.","solutions":["Set DAGGER_SESSION_HOST to the address of a running engine session (start one with `dagger session` or `dagger run`).","Or remove the custom-env assumption and let the SDK auto-provision: use `dagger run python yourscript.py` or plain `dagger.Connection()`.","If passing ConnectParams explicitly, ensure session_host is set and non-empty.","Check that the env var is actually exported in the process (os.environ) and not lost through subprocess/scheduler contexts."],"exampleFix":"// before (shell)\npython main.py  # no DAGGER_SESSION_HOST -> error\n\n// after\ndagger run python main.py\n# or\nexport DAGGER_SESSION_HOST=$(dagger session --host-only)  # then run the script","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"DAGGER_SESSION_HOST\") and not explicit_params:\n    # let SDK auto-provision or fail early with a clear message\n    print(\"No DAGGER_SESSION_HOST; SDK will provision its own engine\")","typeGuard":null,"tryCatchPattern":"from dagger import ClientConnectionError\ntry:\n    client = dagger.dag\nexcept ClientConnectionError as e:\n    raise SystemExit(\"Run via `dagger run` or set DAGGER_SESSION_HOST\") from e","preventionTips":["Run scripts through `dagger run python ...`","Export DAGGER_SESSION_HOST from `dagger session` before custom connections","Don't scrub os.environ in subprocesses that use the SDK"],"tags":["python","environment","connection","engine"],"backgroundTag":"missing-env-var","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}