{"record":{"id":"aaff5f98916b8d46","repo":"github/copilot-sdk","slug":"cli-server-process-exited-before-reporting-port","errorCode":null,"errorMessage":"CLI server process exited before reporting port","messagePattern":"CLI server process exited before reporting port","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":2232,"sourceCode":"\t\tportRegex := regexp.MustCompile(`listening on port (\\d+)`)\n\n\t\tctx, cancel := context.WithTimeout(ctx, 10*time.Second)\n\t\tdefer cancel()\n\n\t\tfor {\n\t\t\tselect {\n\t\t\tcase <-ctx.Done():\n\t\t\t\tkillErr := c.killProcess()\n\t\t\t\tbaseErr := fmt.Errorf(\"failed waiting for CLI server to start: %w\", ctx.Err())\n\t\t\t\tif buf, ok := proc.Stderr.(*truncbuffer.TruncBuffer); ok {\n\t\t\t\t\tif stderr := strings.TrimSpace(buf.String()); stderr != \"\" {\n\t\t\t\t\t\tbaseErr = fmt.Errorf(\"%w; stderr: %s\", baseErr, stderr)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn errors.Join(baseErr, killErr)\n\t\t\tcase <-c.processDone:\n\t\t\t\tkillErr := c.killProcess()\n\t\t\t\tbaseErr := errors.New(\"CLI server process exited before reporting port\")\n\t\t\t\tif buf, ok := proc.Stderr.(*truncbuffer.TruncBuffer); ok {\n\t\t\t\t\tif stderr := strings.TrimSpace(buf.String()); stderr != \"\" {\n\t\t\t\t\t\tbaseErr = fmt.Errorf(\"%w; stderr: %s\", baseErr, stderr)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\treturn errors.Join(baseErr, killErr)\n\t\t\tdefault:\n\t\t\t\tif scanner.Scan() {\n\t\t\t\t\tline := scanner.Text()\n\t\t\t\t\tif matches := portRegex.FindStringSubmatch(line); len(matches) > 1 {\n\t\t\t\t\t\tport, err := strconv.Atoi(matches[1])\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\tkillErr := c.killProcess()\n\t\t\t\t\t\t\treturn errors.Join(fmt.Errorf(\"failed to parse port: %w\", err), killErr)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tc.actualPort = port\n\t\t\t\t\t\treturn nil\n\t\t\t\t\t}","sourceCodeStart":2214,"sourceCodeEnd":2250,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L2214-L2250","documentation":"While waiting for the CLI server to report its port, the process terminated on its own (processDone channel closed). The library surfaces a base error that is enriched with captured stderr (if any) and joined with the kill error. This indicates the CLI server crashed or exited early during startup.","triggerScenarios":"Starting a Client whose CLI server subprocess dies before printing its listening port — bad binary, missing runtime assets, fatal startup error in stderr, port/binding failure.","commonSituations":"Incompatible or corrupt copilot binary; runtime.node missing; the process being OOM-killed or killed by a sandbox; a stale/incompatible binary version after an upgrade.","solutions":["Inspect the joined stderr in the returned error to find the process's own failure message","Verify the runtime binary path/COPILOT_CLI_PATH points to a working, version-compatible executable","Check for sandbox/memory limits killing the child process and increase them","Retry startup; if persistent, reinstall or rebuild the runtime bundle"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if _, err := os.Stat(cliPath); err != nil {\n    return fmt.Errorf(\"CLI server binary not found at %s\", cliPath)\n}","typeGuard":null,"tryCatchPattern":"if err := client.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"exited before reporting port\") {\n        log.Errorf(\"CLI server failed to start: %v\", err) // stderr is embedded\n        // inspect stderr / retry once with backoff\n    }\n}","preventionTips":["Log the stderr portion of the joined error at startup","Verify binary/runtime versions match the SDK before deploy","Watch for sandbox or resource limits that kill child processes"],"tags":["go","process","startup","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"}