{"record":{"id":"23ba213674cc8cdd","repo":"chenhg5/cc-connect","slug":"codex-app-server-stdout-pipe-w","errorCode":null,"errorMessage":"codex app-server stdout pipe: %w","messagePattern":"codex app-server stdout pipe: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/appserver_session.go","lineNumber":270,"sourceCode":"\t\targs = append(args, \"-c\", fmt.Sprintf(\"openai_base_url=%q\", baseURL))\n\t}\n\tcmd := exec.CommandContext(s.ctx, \"codex\", args...)\n\tcmd.Dir = s.workDir\n\tenv := append([]string(nil), s.extraEnv...)\n\tif s.codexHome != \"\" {\n\t\tenv = append(env, \"CODEX_HOME=\"+s.codexHome)\n\t}\n\tif len(env) > 0 {\n\t\tcmd.Env = core.MergeEnv(os.Environ(), env)\n\t}\n\n\tstdin, err := cmd.StdinPipe()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"codex app-server stdin pipe: %w\", err)\n\t}\n\tstdout, err := cmd.StdoutPipe()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"codex app-server stdout pipe: %w\", err)\n\t}\n\tstderr, err := cmd.StderrPipe()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"codex app-server stderr pipe: %w\", err)\n\t}\n\tif err := cmd.Start(); err != nil {\n\t\treturn fmt.Errorf(\"codex app-server start: %w\", err)\n\t}\n\n\ts.procMu.Lock()\n\ts.cmd = cmd\n\ts.stdin = stdin\n\ts.procMu.Unlock()\n\n\tslog.Info(\"codex app-server session started\", \"transport\", \"stdio\", \"pid\", cmd.Process.Pid, \"work_dir\", s.workDir)\n\n\ts.wg.Add(3)\n\tgo s.readLoop(stdout)","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L252-L288","documentation":"This error wraps a failure from cmd.StdoutPipe() when bootstrapping the codex app-server child process. Without the stdout pipe the session cannot read JSON-RPC responses from the app-server, so startup aborts. Like the sibling stdin/stderr pipe errors, it almost always indicates OS-level resource exhaustion rather than a codex-side problem.","triggerScenarios":"Calling StartSession on the codex agent; the process-startup path calls cmd.StdoutPipe() and the OS returns an error (typically EMFILE/ENFILE from fd exhaustion).","commonSituations":"File-descriptor limits exhausted on a busy daemon; long-running process leaking pipes from previous sessions; hardened containers with restrictive rlimits.","solutions":["Raise RLIMIT_NOFILE for the cc-connect process (ulimit -n or systemd LimitNOFILE).","Audit for pipe/fd leaks across session lifecycle: every Start should have a matching Close that releases pipes.","Restart the daemon to reclaim descriptors immediately."],"exampleFix":"// before\nstdout, err := cmd.StdoutPipe()\nif err != nil {\n    return fmt.Errorf(\"codex app-server stdout pipe: %w\", err)\n}\n// after\n// fix at the environment level instead:\n// systemd: LimitNOFILE=8192 in cc-connect.service\nstdout, err := cmd.StdoutPipe()\nif err != nil {\n    return fmt.Errorf(\"codex app-server stdout pipe (check fd limit): %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"var lim syscall.Rlimit\nsyscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim)\nif fdCount() > int(lim.Cur)-64 {\n    return errors.New(\"fd limit nearly exhausted; raise RLIMIT_NOFILE before starting sessions\")\n}","typeGuard":null,"tryCatchPattern":"if err := session.Start(ctx); err != nil {\n    if errors.Is(err, syscall.EMFILE) || errors.Is(err, syscall.ENFILE) {\n        slog.Error(\"pipe creation failed: fd exhaustion\", \"err\", err)\n        return err\n    }\n    return err\n}","preventionTips":["Ensure every Start has a matching Close that releases stdin/stdout/stderr pipes.","Raise LimitNOFILE for the daemon service.","Watch /proc/<pid>/fd count for leaks.","Use a race detector on session lifecycle tests."],"tags":["go","process","file-descriptors","pipe"],"backgroundTag":"file-descriptor-exhausted","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"}