{"record":{"id":"b31169f8dc502958","repo":"kovidgoyal/kitty","slug":"remote-control-connection-was-closed-by-kitty-with","errorCode":null,"errorMessage":"Remote control connection was closed by kitty without any response being received","messagePattern":"Remote control connection was closed by kitty without any response being received","errorType":"exception","errorClass":"SocketClosed","httpStatus":null,"severity":"error","filePath":"kitty/remote_control.py","lineNumber":364,"sourceCode":"            else:\n                for chunk in data:\n                    if isinstance(chunk, str):\n                        chunk = chunk.encode('utf-8')\n                    out.write(chunk)\n                    out.flush()\n        self.socket.shutdown(socket.SHUT_WR)\n\n    def simple_recv(self, timeout: float) -> bytes:\n        dcs = re.compile(rb'\\x1bP@kitty-cmd([^\\x1b]+)\\x1b\\\\')\n        self.socket.settimeout(timeout)\n        st = monotonic()\n        with self.socket.makefile('rb') as src:\n            data = src.read()\n        m = dcs.search(data)\n        if m is None:\n            if monotonic() - st > timeout:\n                raise TimeoutError('Timed out while waiting to read cmd response')\n            raise SocketClosed('Remote control connection was closed by kitty without any response being received')\n        return bytes(m.group(1))\n\n\nclass RCIO(TTYIO):\n    def simple_recv(self, timeout: float) -> bytes:\n        ans: list[bytes] = []\n        read_command_response(self.tty_fd, timeout, ans)\n        return b''.join(ans)\n\n\ndef do_io(to: str | None, original_cmd: dict[str, Any], no_response: bool, response_timeout: float, encrypter: 'CommandEncrypter') -> dict[str, Any]:\n    payload = original_cmd.get('payload')\n    if not isinstance(payload, GeneratorType):\n        send_data: bytes | Iterator[bytes] = encode_send(encrypter(original_cmd))\n    else:\n\n        def send_generator() -> Iterator[bytes]:\n            assert payload is not None","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/remote_control.py#L346-L382","documentation":"The socket was closed by kitty without any DCS-framed response — usually kitty exited or the connection (often an SSH tunnel) dropped mid-request.","triggerScenarios":"The read returns data without a DCS match while still inside the timeout: kitty crashed/exited or the socket was closed. Common with 'kitten @cmd --to ssh:host' when the SSH connection terminates.","commonSituations":"SSH transport dying, kitty being quit while a remote-control command is in flight, or a KittyNotRunningSibling scenario.","solutions":["Check that kitty is still running (pid/socket)","For SSH transports, verify the SSH connection is alive and retry","Re-establish the remote control channel and resend the command"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"except SocketClosed: re-open transport / re-run kitten command","preventionTips":["Keep the SSH session alive during RC calls","Check kitty's pid/socket existence before long command batches"],"tags":["kitty","remote-control","socket-closed"],"backgroundTag":"connection-closed-unexpectedly","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}