{"record":{"id":"8ddee67a24eed1f8","repo":"chenhg5/cc-connect","slug":"codex-app-server-connection-closed-w","errorCode":null,"errorMessage":"codex app-server connection closed: %w","messagePattern":"codex app-server connection closed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"agent/codex/appserver_session.go","lineNumber":1028,"sourceCode":"\t\tdefault:\n\t\t\t// Notification (no id).\n\t\t\tvar notif rpcNotificationEnvelope\n\t\t\tif err := json.Unmarshal(data, &notif); err != nil {\n\t\t\t\tslog.Debug(\"codex app-server: bad notification envelope\", \"error\", err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\ts.handleNotification(notif.Method, notif.Params)\n\t\t}\n\t}\n\n\terr := scanner.Err()\n\tif err != nil {\n\t\tif s.ctx.Err() == nil && !errors.Is(err, io.EOF) {\n\t\t\tslog.Warn(\"codex app-server read failed\", \"error\", err)\n\t\t\tif errors.Is(err, bufio.ErrTooLong) {\n\t\t\t\ts.emitError(fmt.Errorf(\"codex app-server line exceeds max size (%d bytes): %w\", maxLineSize, err))\n\t\t\t} else {\n\t\t\t\ts.emitError(fmt.Errorf(\"codex app-server connection closed: %w\", err))\n\t\t\t}\n\t\t}\n\t\ts.alive.Store(false)\n\t\ts.rejectPending(err)\n\t\ts.rejectPendingApprovals(err)\n\t\treturn\n\t}\n\n\ts.alive.Store(false)\n\ts.rejectPending(io.EOF)\n\ts.rejectPendingApprovals(io.EOF)\n}\n\nfunc (s *appServerSession) stderrLoop(r io.Reader) {\n\tdefer s.wg.Done()\n\tscanner := bufio.NewScanner(r)\n\tbuf := make([]byte, 0, 64*1024)\n\tscanner.Buffer(buf, 1024*1024)","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L1010-L1046","documentation":"The reader goroutine's scan failed for a reason other than the line-size limit while the session context was still live — the app-server's stdout closed unexpectedly. The library logs the read failure, emits this wrapped error, marks the session dead, and rejects all pending requests and approvals with the same error.","triggerScenarios":"The codex process dies or closes its stdout pipe mid-session so scanner returns a non-EOF, non-ErrTooLong error (e.g. EPIPE) before s.ctx is cancelled.","commonSituations":"OOM-killer or crash terminating codex mid-turn; user kills the codex process; pipe broken when the parent reaps the process; container restart; a codex panic writing to stderr and exiting hard.","solutions":["Check codex stderr and system logs (journalctl, dmesg for OOM) for the crash cause","Restart the session/agent after the process dies — this error is terminal for the session","Verify codex isn't being killed by resource limits (memory, cgroup)","Look at the wrapped cause for the actual OS error and fix accordingly (EPIPE → process death)"],"exampleFix":"// before\nerr := sess.Send(ctx, prompt, nil) // fails after process death, session unusable\n// after\nif err != nil && !sess.IsAlive() {\n    slog.Warn(\"codex session died, restarting\", \"err\", err)\n    sess, err = agent.StartSession(ctx, opts)\n}","handlingStrategy":"retry","validationCode":"if !sess.IsAlive() {\n    sess, err = agent.StartSession(ctx, opts)\n    if err != nil { return fmt.Errorf(\"codex session dead and restart failed: %w\", err)\n} }","typeGuard":null,"tryCatchPattern":"if err := sess.Send(ctx, prompt, nil); err != nil {\n    if !sess.IsAlive() { // connection closed by dead process\n        if s2, rerr := agent.StartSession(ctx, opts); rerr == nil {\n            return s2.Send(ctx, prompt, nil)\n        }\n    }\n    return err\n}","preventionTips":["Monitor codex memory usage; raise limits to avoid OOM kills","Capture stderr to a log file so crash causes are diagnosable","Watch session Events() for terminal errors and auto-restart the session","Keep codex updated; crashes often come from fixed bugs"],"tags":["process","stream","codex","crash"],"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"}