{"record":{"id":"78b514afd4ea0d9f","repo":"github/copilot-sdk","slug":"w-stderr-s","errorCode":null,"errorMessage":"%w; stderr: %s","messagePattern":"%w; stderr: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/client.go","lineNumber":2226,"sourceCode":"\t\t}\n\n\t\tc.monitorProcess()\n\n\t\tproc := c.process\n\t\tscanner := bufio.NewScanner(stdout)\n\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 {","sourceCodeStart":2208,"sourceCodeEnd":2244,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/client.go#L2208-L2244","documentation":"This is the augmented form of the start-wait timeout error: after the base error (context deadline/cancellation) is created, the library appends the CLI server's captured stderr via '%w; stderr: %s'. The stderr content is the actual diagnostic; the base error only tells you the wait timed out.","triggerScenarios":"Context cancellation while the CLI server is starting AND the process wrote anything to stderr (warnings, panics, flag errors) before being killed.","commonSituations":"CLI failing fast with a startup error message while the parent's timeout also fires; CLI emitting warnings on stderr that got captured before the kill.","solutions":["Read the 'stderr: ...' suffix first — it contains the CLI's own error (bad flag, missing auth, port in use).","Fix the underlying CLI issue indicated in the stderr text.","If stderr is only warnings, raise the context timeout so the server can finish starting.","Run the CLI manually with the same arguments to reproduce and see full output."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := client.Start(ctx); err != nil {\n    if i := strings.Index(err.Error(), \"stderr: \"); i >= 0 {\n        log.Errorf(\"CLI stderr during failed start: %s\", err.Error()[i+8:])\n    }\n    if errors.Is(err, context.DeadlineExceeded) { /* retry with longer ctx */ }\n    return err\n}","preventionTips":["Always surface the stderr suffix in your logs/alerts.","Fix the CLI-level error printed in stderr before adjusting timeouts.","Run the CLI manually with the same args to reproduce startup failures.","Validate CLI config/env before invoking the client."],"tags":["process","timeout","stderr","diagnostics"],"backgroundTag":"process-start-timeout","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}