chenhg5/cc-connect · error

codex app-server stderr pipe: %w

Error message

codex app-server stderr pipe: %w

What it means

This error wraps a failure from cmd.StderrPipe() while starting the codex app-server child process. The stderr pipe is required to capture app-server diagnostics; failing to allocate it aborts startup. The cause is OS-level, most commonly file-descriptor exhaustion.

Source

Thrown at agent/codex/appserver_session.go:274

	env := append([]string(nil), s.extraEnv...)
	if s.codexHome != "" {
		env = append(env, "CODEX_HOME="+s.codexHome)
	}
	if len(env) > 0 {
		cmd.Env = core.MergeEnv(os.Environ(), env)
	}

	stdin, err := cmd.StdinPipe()
	if err != nil {
		return fmt.Errorf("codex app-server stdin pipe: %w", err)
	}
	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return fmt.Errorf("codex app-server stdout pipe: %w", err)
	}
	stderr, err := cmd.StderrPipe()
	if err != nil {
		return fmt.Errorf("codex app-server stderr pipe: %w", err)
	}
	if err := cmd.Start(); err != nil {
		return fmt.Errorf("codex app-server start: %w", err)
	}

	s.procMu.Lock()
	s.cmd = cmd
	s.stdin = stdin
	s.procMu.Unlock()

	slog.Info("codex app-server session started", "transport", "stdio", "pid", cmd.Process.Pid, "work_dir", s.workDir)

	s.wg.Add(3)
	go s.readLoop(stdout)
	go s.stderrLoop(stderr)
	go s.waitLoop()
	return nil
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Raise the file-descriptor limit (ulimit -n 8192 or systemd LimitNOFILE=8192).
  2. Check for fd leaks with lsof and ensure sessions close all three pipes.
  3. Restart the daemon as an immediate mitigation.
Defensive patterns

Strategy: try-catch

Validate before calling

var lim syscall.Rlimit
syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)
if fdCount() > int(lim.Cur)-64 {
    return errors.New("fd limit nearly exhausted")
}

Try / catch

if err := session.Start(ctx); err != nil {
    if errors.Is(err, syscall.EMFILE) || errors.Is(err, syscall.ENFILE) {
        // environment problem, not a codex bug: surface actionable message
        return fmt.Errorf("fd exhaustion (raise RLIMIT_NOFILE): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling StartSession on the codex agent; the third pipe acquisition (cmd.StderrPipe()) in the startup sequence returns an error — nearly always EMFILE/ENFILE after stdin/stdout pipes succeeded.

Common situations: See trigger scenarios.

Related errors


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