{"record":{"id":"98918a6d64092c83","repo":"chenhg5/cc-connect","slug":"copilot-probe-stdin-pipe-w","errorCode":null,"errorMessage":"copilot probe: stdin pipe: %w","messagePattern":"copilot probe: stdin pipe: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/copilot/copilot.go","lineNumber":218,"sourceCode":"type probeSnapshot struct {\n\tcmd  string\n\tworkDir string\n\tenv     []string\n}\n\n// newProbeSession spawns a copilot --headless --stdio probe process, starts a\n// read loop, and returns a probeSession. Caller must call close() when done.\nfunc newProbeSession(ctx context.Context, snapshot probeSnapshot) (*probeSession, error) {\n\tprobeCtx, cancel := context.WithCancel(ctx)\n\n\tcmd := exec.CommandContext(probeCtx, snapshot.cmd, \"--headless\", \"--stdio\", \"--no-auto-update\")\n\tcmd.Dir = snapshot.workDir\n\tcmd.Env = snapshot.env\n\n\tstdin, err := cmd.StdinPipe()\n\tif err != nil {\n\t\tcancel()\n\t\treturn nil, fmt.Errorf(\"copilot probe: stdin pipe: %w\", err)\n\t}\n\tstdout, err := cmd.StdoutPipe()\n\tif err != nil {\n\t\tcancel()\n\t\treturn nil, fmt.Errorf(\"copilot probe: stdout pipe: %w\", err)\n\t}\n\tcmd.Stderr = io.Discard\n\n\tif err := cmd.Start(); err != nil {\n\t\tcancel()\n\t\treturn nil, fmt.Errorf(\"copilot probe: start: %w\", err)\n\t}\n\n\trpc := newRPCClient(stdin)\n\treader := newLSPReader(stdout)\n\tdone := make(chan struct{})\n\n\tgo func() {","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/copilot/copilot.go#L200-L236","documentation":"newProbeSession builds a short-lived `copilot` subprocess (used by ListSessions and DeleteSession to inspect the CLI's session store) and wires os.Pipe-based stdin/stdout. This error wraps a StdinPipe() creation failure, which is rare and normally indicates resource exhaustion or the process being unable to create OS pipes. The function cancels its context before returning so no zombie process is left.","triggerScenarios":"cmd.StdinPipe() returns err inside newProbeSession, invoked from ListSessions or DeleteSession: OS-level pipe/file-descriptor exhaustion (ulimit -n), process resource limits in containers, or an out-of-memory condition in the parent.","commonSituations":"Long-running cc-connect leaking file descriptors until EMFILE; containers with very low RLIMIT_NOFILE; fork/proc limits hit after many concurrent probes; kernel pressure on hosts with thousands of connections.","solutions":["Raise the file-descriptor limit: `ulimit -n 4096` or systemd LimitNOFILE=4096","Check for fd leaks in the running process: `ls /proc/<pid>/fd | wc -l` and restart if it is near the limit","Audit container limits (docker `--ulimit nofile=...`, k8s securityContext/rlimits)","Reduce concurrent ListSessions/DeleteSession calls; retry the operation after freeing descriptors"],"exampleFix":"// before: probe fails under fd pressure\nsessions, err := agent.ListSessions(ctx)\n// after: pre-check fd headroom\nif countOpenFDs(os.Getpid()) > softFDLimit() {\n    log.Fatalf(\"too many open fds; raise ulimit -n before listing copilot sessions\")\n}\nsessions, err := agent.ListSessions(ctx)","handlingStrategy":"try-catch","validationCode":"n := countOpenFDs(os.Getpid())\nvar l syscall.Rlimit\nsyscall.Getrlimit(syscall.RLIMIT_NOFILE, &l)\nif uint64(n) > l.Cur-64 { return errors.New(\"fd headroom too low for copilot probe; raise ulimit -n\") }","typeGuard":null,"tryCatchPattern":"sessions, err := agent.ListSessions(ctx)\nif err != nil && strings.Contains(err.Error(), \"stdin pipe\") {\n    // resource exhaustion: free descriptors, then retry once\n    runtime.GC()\n    sessions, err = agent.ListSessions(ctx)\n}","preventionTips":["Set LimitNOFILE=4096 (systemd) or ulimit -n 4096 in launch scripts","Monitor /proc/<pid>/fd count for leaks in long-running processes","Configure container fd limits (docker --ulimit, k8s rlimits)","Avoid unbounded concurrent ListSessions/DeleteSession calls"],"tags":["go","process","pipes","copilot","resources"],"backgroundTag":"pipe-creation-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}