{"record":{"id":"f220a02f232addca","repo":"Unity-Technologies/ml-agents","slug":"unityenvironment-worker-recv-failed","errorCode":null,"errorMessage":"UnityEnvironment worker: recv failed.","messagePattern":"UnityEnvironment worker: recv failed\\.","errorType":"exception","errorClass":"UnityCommunicationException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/subprocess_env_manager.py","lineNumber":104,"sourceCode":"        self.waiting = False\n        self.closed = False\n\n    def send(self, cmd: EnvironmentCommand, payload: Any = None) -> None:\n        try:\n            req = EnvironmentRequest(cmd, payload)\n            self.conn.send(req)\n        except (BrokenPipeError, EOFError):\n            raise UnityCommunicationException(\"UnityEnvironment worker: send failed.\")\n\n    def recv(self) -> EnvironmentResponse:\n        try:\n            response: EnvironmentResponse = self.conn.recv()\n            if response.cmd == EnvironmentCommand.ENV_EXITED:\n                env_exception: Exception = response.payload\n                raise env_exception\n            return response\n        except (BrokenPipeError, EOFError):\n            raise UnityCommunicationException(\"UnityEnvironment worker: recv failed.\")\n\n    def request_close(self):\n        try:\n            self.conn.send(EnvironmentRequest(EnvironmentCommand.CLOSE))\n        except (BrokenPipeError, EOFError):\n            logger.debug(\n                f\"UnityEnvWorker {self.worker_id} got exception trying to close.\"\n            )\n            pass\n\n\ndef worker(\n    parent_conn: Connection,\n    step_queue: Queue,\n    pickled_env_factory: str,\n    worker_id: int,\n    run_options: RunOptions,\n    log_level: int = logging_util.INFO,","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/subprocess_env_manager.py#L86-L122","documentation":"A sentinel error raised by UnityEnvWorker.recv when reading an EnvironmentResponse from the multiprocessing Connection raises BrokenPipeError or EOFError. It indicates the child worker process owning the UnityEnvironment is gone (crashed or exited), so its end of the pipe no longer exists; the raw pipe exception is wrapped into this UnityCommunicationException for uniform handling by the env manager.","triggerScenarios":"Thrown at ml-agents/mlagents/trainers/subprocess_env_manager.py:104 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Inspect stderr from the worker process to find why Unity exited (crash, build mismatch, fatal Unity log error)","Verify the environment binary path and that the build was made with a compatible ml-agents Unity package","Run with a single environment (num_envs=1) to reproduce and capture the root failure","Restart training after fixing the underlying Unity-side crash; the pipe error is only a symptom"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}