{"record":{"id":"d13ea1fe4b737b14","repo":"github/copilot-sdk","slug":"cli-process-exited-unexpectedly-d13ea1","errorCode":null,"errorMessage":"CLI process exited unexpectedly","messagePattern":"CLI process exited unexpectedly","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"go/client.go","lineNumber":2414,"sourceCode":"\tvar processError error\n\tc.processErrorPtr = &processError\n\tgo func() {\n\t\twaitErr := proc.Wait()\n\t\tvar stderrOutput string\n\t\tif buf, ok := proc.Stderr.(*truncbuffer.TruncBuffer); ok {\n\t\t\tstderrOutput = strings.TrimSpace(buf.String())\n\t\t}\n\t\tif waitErr != nil {\n\t\t\tif stderrOutput != \"\" {\n\t\t\t\tprocessError = fmt.Errorf(\"CLI process exited: %w\\nstderr: %s\", waitErr, stderrOutput)\n\t\t\t} else {\n\t\t\t\tprocessError = fmt.Errorf(\"CLI process exited: %w\", waitErr)\n\t\t\t}\n\t\t} else {\n\t\t\tif stderrOutput != \"\" {\n\t\t\t\tprocessError = fmt.Errorf(\"CLI process exited unexpectedly\\nstderr: %s\", stderrOutput)\n\t\t\t} else {\n\t\t\t\tprocessError = errors.New(\"CLI process exited unexpectedly\")\n\t\t\t}\n\t\t}\n\t\tclose(done)\n\t}()\n}\n\n// connectToServer establishes a connection to the server.\nfunc (c *Client) connectToServer(ctx context.Context) error {\n\tif c.useStdio || c.useInProcess {\n\t\t// Already connected: stdio in startCLIServer, FFI streams in startInProcess.\n\t\treturn nil\n\t}\n\n\t// Connect via TCP\n\treturn c.connectViaTCP(ctx)\n}\n\n// connectViaTCP connects to the CLI server via TCP socket.","sourceCodeStart":2396,"sourceCodeEnd":2432,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L2396-L2432","documentation":"The CLI subprocess terminated without the wait error indicating a normal exit, so the monitor goroutine records processError = \"CLI process exited unexpectedly\", optionally with captured stderr. This error is surfaced through processErrorPtr to the JSON-RPC client and to callers awaiting the process result.","triggerScenarios":"The CLI process crashes (non-zero, unexpected exit) while the client is running; wait() returns without a recognized exit-status error and stderr may or may not be available.","commonSituations":"Runtime crashes mid-session; OOM kills; signal termination (SIGKILL from supervisors); corrupt or incompatible runtime binaries; underlying native library faults in runtime.node.","solutions":["Read the stderr attached to the error for the underlying cause","Check dmesg/journal for OOM or signal kills and raise limits if needed","Ensure the runtime binary matches the SDK version; reinstall/upgrade if mismatched","Handle the processDone/processError channel in your app to restart the client gracefully"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"select {\ncase <-client.ProcessDone():\n    if err := *client.ProcessError(); err != nil && strings.Contains(err.Error(), \"exited unexpectedly\") {\n        log.Errorf(\"CLI crashed: %v\", err)\n        // restart client with backoff\n    }\ncase <-ctx.Done():\n}","preventionTips":["Monitor processDone/processError and implement automatic restart with backoff","Capture and persist stderr for post-mortem","Match runtime and SDK versions; watch for OOM/signals in logs"],"tags":["go","process","crash","stderr"],"backgroundTag":"process-exited-unexpectedly","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"}