{"record":{"id":"ffb7a76c0bb9a716","repo":"chenhg5/cc-connect","slug":"s-read-response-w","errorCode":null,"errorMessage":"%s read response: %w","messagePattern":"(.+?) read response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/session.go","lineNumber":736,"sourceCode":"\n\treturn strings.TrimSpace(resp.Config.Model), normalizeRuntimeReasoningEffort(stringValue(resp.Config.ModelReasoningEffort)), nil\n}\n\nfunc rpcRequestOverIO(stdin io.Writer, reader *bufio.Reader, id int64, method string, params any, out any) error {\n\tpayload := map[string]any{\n\t\t\"jsonrpc\": \"2.0\",\n\t\t\"id\":      id,\n\t\t\"method\":  method,\n\t\t\"params\":  params,\n\t}\n\tif err := writeRPCMessage(stdin, payload); err != nil {\n\t\treturn err\n\t}\n\n\tfor {\n\t\tline, err := reader.ReadBytes('\\n')\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"%s read response: %w\", method, err)\n\t\t}\n\n\t\tvar probe map[string]json.RawMessage\n\t\tif err := json.Unmarshal(bytes.TrimSpace(line), &probe); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif _, ok := probe[\"id\"]; !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tvar resp rpcResponseEnvelope\n\t\tif err := json.Unmarshal(bytes.TrimSpace(line), &resp); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\trespID, ok := rpcIDToInt64(resp.ID)\n\t\tif !ok || respID != id {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":718,"sourceCodeEnd":754,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/session.go#L718-L754","documentation":"rpcRequestOverIO reads newline-delimited JSON-RPC responses from the codex app-server; when ReadBytes fails (EOF because the process exited, or a pipe I/O error) before a matching response arrives, it returns an error prefixed with the RPC method name. This means the app-server died or closed its stdout before answering the request, not that the response was malformed.","triggerScenarios":"reader.ReadBytes('\\n') returns io.EOF or another read error inside rpcRequestOverIO while waiting for a reply to a method such as an initialization or config RPC issued by loadCodexRuntimeConfig.","commonSituations":"The codex app-server crashes or exits during startup (bad args, missing auth); the binary version does not support app-server mode and exits immediately; a request timeout in the caller kills the process while the RPC is pending; pipe broken by process kill.","solutions":["Run the codex binary manually (`codex app-server` or the configured subcommand) to see why it exits — startup crashes are the usual cause.","Update the Codex CLI to a version that supports app-server JSON-RPC mode.","Check `command` and args in the codex agent config for typos or flags the installed version rejects.","Check authentication (`codex login`) — some versions exit when credentials are missing.","Capture the app-server's stderr output to identify the exit reason; retry once transient resource pressure is resolved."],"exampleFix":"// before: old codex build exits on the app-server subcommand\n$ codex --version\ncodex-cli 0.1.0  // unsupported\n// after\n$ npm i -g @openai/codex && codex --version\ncodex-cli 0.9.0","handlingStrategy":"retry","validationCode":"// verify the app-server subcommand starts and answers before RPC use\ncmd := exec.Command(cfg.Command, \"app-server\", \"--help\")\nif err := cmd.Run(); err != nil {\n    return fmt.Errorf(\"codex app-server unsupported or failing: %w\", err)\n}","typeGuard":"func isRPCReadError(err error, method string) bool {\n    return err != nil && strings.HasPrefix(err.Error(), method+\" read response:\")\n}","tryCatchPattern":"resp, err := rpcRequestOverIO(stdin, stdout, ctx, \"initialize\", params, &out)\nif isRPCReadError(err, \"initialize\") {\n    // app-server exited early; capture stderr and retry with a fresh process\n    slog.Error(\"app-server died during RPC\", \"err\", err, \"stderr\", stderr.String())\n}","preventionTips":["Keep the Codex CLI updated to a version that supports app-server JSON-RPC","Capture and log the child's stderr to diagnose early exits","Authenticate codex before launching app-server sessions","Apply request timeouts that allow the process time to answer before teardown"],"tags":["codex","json-rpc","process-exit","pipe-read"],"backgroundTag":"broken-pipe","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}