{"record":{"id":"4c00fecb2b51570d","repo":"Unity-Technologies/ml-agents","slug":"unityenvironment-worker-send-failed","errorCode":null,"errorMessage":"UnityEnvironment worker: send failed.","messagePattern":"UnityEnvironment worker: send failed\\.","errorType":"exception","errorClass":"UnityCommunicationException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/subprocess_env_manager.py","lineNumber":94,"sourceCode":"    environment_stats: EnvironmentStats\n\n\nclass UnityEnvWorker:\n    def __init__(self, process: Process, worker_id: int, conn: Connection):\n        self.process = process\n        self.worker_id = worker_id\n        self.conn = conn\n        self.previous_step: EnvironmentStep = EnvironmentStep.empty(worker_id)\n        self.previous_all_action_info: Dict[str, ActionInfo] = {}\n        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            )","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/subprocess_env_manager.py#L76-L112","documentation":"A sentinel error raised by UnityEnvWorker.send when writing an EnvironmentRequest to the multiprocessing Connection fails with BrokenPipeError or EOFError. It means the child worker process hosting the UnityEnvironment has died or closed its end of the pipe (e.g. Unity crashed or exited), so the parent can no longer send it commands; the underlying pipe failure is converted into this UnityCommunicationException.","triggerScenarios":"Thrown at ml-agents/mlagents/trainers/subprocess_env_manager.py:94 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check earlier logs for the root cause of the worker process dying (Unity editor/player crash, bad environment build, scene errors)","Ensure the Unity executable or editor build matches the ml-agents package version and contains the correct Academy/Behavior components","Enable worker restarts / reduce num_envs to isolate which environment instance is failing","If using --num-areas or multiple envs, verify ports and worker IDs do not collide"],"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"}