{"record":{"id":"a9e9a401eb0473e1","repo":"github/copilot-sdk","slug":"copilot-runtime-connection-open-failed-a9e9a4","errorCode":null,"errorMessage":"copilot_runtime_connection_open failed.","messagePattern":"copilot_runtime_connection_open failed\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"python/copilot/_ffi_runtime_host.py","lineNumber":443,"sourceCode":"            )\n\n        self._outbound_callback = _OutboundCallback(self._on_outbound)\n        self._connection_id = self._lib.connection_open(\n            self._server_id,\n            self._outbound_callback,\n            None,\n            None,\n            0,\n            None,\n            0,\n            None,\n            0,\n        )\n        if not self._connection_id:\n            self._outbound_callback = None\n            self._lib.host_shutdown(self._server_id)\n            self._server_id = 0\n            raise RuntimeError(\"copilot_runtime_connection_open failed.\")\n\n    def _on_outbound(\n        self,\n        _user_data: int | None,\n        bytes_ptr: ctypes._Pointer,\n        bytes_len: int,\n    ) -> None:\n        \"\"\"Native server → client callback (invoked on a foreign runtime thread).\n\n        The native pointer is only valid for this call, so the bytes are copied\n        out before returning. Exceptions must not cross the FFI boundary, so\n        everything is caught and logged.\n        \"\"\"\n        with self._callback_lock:\n            if self._disposed:\n                return\n            self._active_callbacks += 1\n        try:","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/python/copilot/_ffi_runtime_host.py#L425-L461","documentation":"After host_start succeeds, start_blocking opens a connection with copilot_runtime_connection_open; a zero connection id means the connection could not be established. The library then shuts the host down again and raises this error.","triggerScenarios":"connection_open returning 0 during start_blocking — the native host is running but refused/failed to open the RPC connection (e.g. host failed internal init right after start, resource limits, or invalid connection parameters).","commonSituations":"Native host crashed immediately after start; out-of-memory or fd limits in the process; a runtime version whose connection protocol does not accept the parameters used.","solutions":["Retry start_blocking once after ensuring process resource limits (fds, memory) are sufficient.","Verify the runtime library version matches the Python client version (upgrade both together).","Check the host's stderr/native logs for the root cause of the connection failure.","Reinstall the runtime if the binary is suspected corrupt."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    host.start_blocking()\nexcept RuntimeError as e:\n    if \"connection_open failed\" in str(e):\n        host.dispose(); host = recreate_host(); host.start_blocking()","preventionTips":["Check fd/memory limits before starting the host.","Keep runtime and Python client versions in lockstep.","Collect native stderr logs for diagnosis."],"tags":["ffi","connection","native"],"backgroundTag":"connection-refused","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}