github/copilot-sdk · error · IllegalStateException
Cannot connect: no process for stdio and no host:port for…
Error message
Cannot connect: no process for stdio and no host:port for TCP
What it means
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.
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.
Example fix
// before manager.connectToServer(); // manager never started // after manager.startCliServer(); JsonRpcClient client = manager.connectToServer();
Defensive patterns
Strategy: validation
Validate before calling
if (manager == null || (!manager.hasProcess() && !options.hasTcpEndpoint())) {
manager.startCliServer(); // or configure tcp host/port
} Try / catch
try {
client = manager.connectToServer();
} catch (IllegalStateException e) {
if (e.getMessage().contains("no process")) {
manager.startCliServer();
client = manager.connectToServer();
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- CLI process exited unexpectedly.
- Timeout waiting for CLI to announce port
- CLI process exited unexpectedly.
- copilot_runtime_connection_open failed.
- CLI process not started
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/b404a326fde6f7c4.
Report an issue: GitHub.
Appendix: source
Thrown at java/sdk/src/main/java/com/github/copilot/CliServerManager.java:164
* the CLI process (null if connecting to external server)
* @param tcpHost
* the host to connect to (null for stdio mode)
* @param tcpPort
* the port to connect to (null for stdio mode)
* @return the JSON-RPC client connected to the server
* @throws IOException
* if connection fails
*/
JsonRpcClient connectToServer(Process process, String tcpHost, Integer tcpPort) throws IOException {
if (tcpHost != null && tcpPort != null) {
// TCP mode: external server or child process with explicit port
Socket socket = new Socket(tcpHost, tcpPort);
return JsonRpcClient.fromSocket(socket);
} else if (process != null) {
// Stdio mode: child process
return JsonRpcClient.fromProcess(process);
} else {
throw new IllegalStateException("Cannot connect: no process for stdio and no host:port for TCP");
}
}
private void startStderrReader(Process process) {
var thread = new Thread(() -> {
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getErrorStream(), StandardCharsets.UTF_8))) {
String line;
while ((line = reader.readLine()) != null) {
synchronized (stderrBuffer) {
stderrBuffer.append(line).append('\n');
}
LOG.fine("[CLI] " + line);
}
} catch (IOException e) {
LOG.log(Level.FINE, "Error reading stderr", e);
}
}, "cli-stderr-reader");View on GitHub (pinned to cd8cf15dc3)