chenhg5/cc-connect · error

copilotSession: stdout pipe: %w

Error message

copilotSession: stdout pipe: %w

What it means

Right after acquiring the stdin pipe, newCopilotSession calls child.StdoutPipe() to receive the copilot CLI's JSON-RPC responses. On failure the context is cancelled and the error is wrapped as "copilotSession: stdout pipe: %w". Like the stdin variant, it indicates the OS refused to create the pipe, so session setup cannot continue.

Source

Thrown at agent/copilot/session.go:115

	child.Dir = workDir
	prepareCmdForKill(child)

	env := os.Environ()
	if len(extraEnv) > 0 {
		env = core.MergeEnv(env, extraEnv)
	}
	child.Env = env

	stdin, err := child.StdinPipe()
	if err != nil {
		cancel()
		return nil, fmt.Errorf("copilotSession: stdin pipe: %w", err)
	}

	stdout, err := child.StdoutPipe()
	if err != nil {
		cancel()
		return nil, fmt.Errorf("copilotSession: stdout pipe: %w", err)
	}

	var stderrBuf bytes.Buffer
	child.Stderr = &stderrBuf

	if err := child.Start(); err != nil {
		cancel()
		return nil, fmt.Errorf("copilotSession: start: %w", err)
	}

	cs := &copilotSession{
		cmd:                child,
		rpc:                newRPCClient(stdin),
		reader:             newLSPReader(stdout),
		events:             make(chan core.Event, 64),
		mode:               mode,
		model:              model,
		provider:           provider,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Audit session lifecycle for leaked pipes (Close()/Wait on finished sessions) and fix the leak
  2. Raise the fd limit (ulimit -n / systemd LimitNOFILE) for the daemon
  3. Always construct a new exec.Cmd per session instead of reusing one
  4. Restart the process if fds are exhausted; then verify the leak is fixed under load
Defensive patterns

Strategy: try-catch

Try / catch

sess, err := StartSession(ctx, cfg, resumeID)
if err != nil {
    if strings.Contains(err.Error(), "stdout pipe") {
        slog.Error("copilot: cannot create stdout pipe (fd exhaustion?)", "err", err)
    }
    return fmt.Errorf("start session: %w", err)
}

Prevention

When it happens

Trigger: StartSession → newCopilotSession where StdoutPipe() fails — fd exhaustion, an exec.Cmd that has already been started/Waited, or OS pipe limits hit.

Common situations: Long-running daemon leaking pipes from earlier sessions; low fd limits in constrained environments; accidental double-start of the same exec.Cmd.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/0cfc06595afa49d7. Report an issue: GitHub.