{"record":{"id":"b404a326fde6f7c4","repo":"github/copilot-sdk","slug":"cannot-connect-no-process-for-stdio-and-no-host-p","errorCode":null,"errorMessage":"Cannot connect: no process for stdio and no host:port for TCP","messagePattern":"Cannot connect: no process for stdio and no host:port for TCP","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"java/sdk/src/main/java/com/github/copilot/CliServerManager.java","lineNumber":164,"sourceCode":"     *            the CLI process (null if connecting to external server)\n     * @param tcpHost\n     *            the host to connect to (null for stdio mode)\n     * @param tcpPort\n     *            the port to connect to (null for stdio mode)\n     * @return the JSON-RPC client connected to the server\n     * @throws IOException\n     *             if connection fails\n     */\n    JsonRpcClient connectToServer(Process process, String tcpHost, Integer tcpPort) throws IOException {\n        if (tcpHost != null && tcpPort != null) {\n            // TCP mode: external server or child process with explicit port\n            Socket socket = new Socket(tcpHost, tcpPort);\n            return JsonRpcClient.fromSocket(socket);\n        } else if (process != null) {\n            // Stdio mode: child process\n            return JsonRpcClient.fromProcess(process);\n        } else {\n            throw new IllegalStateException(\"Cannot connect: no process for stdio and no host:port for TCP\");\n        }\n    }\n\n    private void startStderrReader(Process process) {\n        var thread = new Thread(() -> {\n            try (BufferedReader reader = new BufferedReader(\n                    new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) {\n                String line;\n                while ((line = reader.readLine()) != null) {\n                    synchronized (stderrBuffer) {\n                        stderrBuffer.append(line).append('\\n');\n                    }\n                    LOG.fine(\"[CLI] \" + line);\n                }\n            } catch (IOException e) {\n                LOG.log(Level.FINE, \"Error reading stderr\", e);\n            }\n        }, \"cli-stderr-reader\");","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/java/sdk/src/main/java/com/github/copilot/CliServerManager.java#L146-L182","documentation":"CliServerManager.connectToServer builds a JsonRpcClient either from a TCP socket (host/port configured) or from the spawned stdio child process. If neither is available — no process was started and no TCP host/port is set — it throws IllegalStateException because there is no transport to connect through. This reflects an inconsistently initialized CliServerManager.","triggerScenarios":"Calling connectToServer on a CliServerManager that was constructed without starting the CLI process (startCliServer never invoked or failed) and without cliUrl/tcp host+port options.","commonSituations":"Skipping startCliServer and calling connect directly; startCliServer failed earlier leaving process null; building a manager for TCP mode but forgetting to set host/port options.","solutions":["Call startCliServer (or configure a TCP host/port + token) before connectToServer.","Check that CLI startup did not silently fail; verify the process reference is non-null.","Set CliUrl in options if you intend TCP mode instead of a locally spawned CLI."],"exampleFix":"// before\nmanager.connectToServer(); // manager never started\n// after\nmanager.startCliServer();\nJsonRpcClient client = manager.connectToServer();","handlingStrategy":"validation","validationCode":"if (manager == null || (!manager.hasProcess() && !options.hasTcpEndpoint())) {\n    manager.startCliServer(); // or configure tcp host/port\n}","typeGuard":null,"tryCatchPattern":"try {\n  client = manager.connectToServer();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"no process\")) {\n    manager.startCliServer();\n    client = manager.connectToServer();\n  } else throw e;\n}","preventionTips":["Always call startCliServer before connectToServer unless TCP mode is fully configured.","Encapsulate start+connect in one helper method.","Assert manager state (process or host/port) at initialization time."],"tags":["java","connection","state","cli"],"backgroundTag":"invalid-state-transition","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"}