{"record":{"id":"000abb8ac372d370","repo":"chenhg5/cc-connect","slug":"s-write-timed-out","errorCode":null,"errorMessage":"%s write timed out","messagePattern":"(.+?) write timed out","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"agent/codex/appserver_session.go","lineNumber":1676,"sourceCode":"}\n\nfunc (s *appServerSession) writeJSONWithTimeout(method string, v any, timeout time.Duration) error {\n\tdone := make(chan error, 1)\n\tgo func() {\n\t\tdone <- s.writeJSON(v)\n\t}()\n\n\ttimer := time.NewTimer(timeout)\n\tdefer timer.Stop()\n\n\tctxDone := s.contextDone()\n\tselect {\n\tcase err := <-done:\n\t\treturn err\n\tcase <-ctxDone:\n\t\treturn s.contextErr()\n\tcase <-timer.C:\n\t\terr := fmt.Errorf(\"%s write timed out\", method)\n\t\tslog.Warn(\"codex app-server write timed out, closing session\", \"method\", method, \"timeout\", timeout)\n\t\ts.abortTransport()\n\t\treturn err\n\t}\n}\n\nfunc (s *appServerSession) contextDone() <-chan struct{} {\n\tif s.ctx == nil {\n\t\treturn nil\n\t}\n\treturn s.ctx.Done()\n}\n\nfunc (s *appServerSession) contextErr() error {\n\tif s.ctx == nil {\n\t\treturn context.Canceled\n\t}\n\tif err := s.ctx.Err(); err != nil {","sourceCodeStart":1658,"sourceCodeEnd":1694,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L1658-L1694","documentation":"Returned by `writeJSONWithTimeout` when writing a JSON-RPC payload to the codex app-server's stdin does not complete within the timeout. The adapter logs a warning and calls `abortTransport()`, killing the child process and closing the session — so this error also tears down the session. The message is `<method> write timed out`.","triggerScenarios":"`requestWithTimeout` (or notify with timeout) calls `writeJSONWithTimeout`; the goroutine writing to the child's stdin pipe blocks past the deadline because the app-server stopped reading stdin (full pipe, hung process) or the OS pipe is stalled.","commonSituations":"Codex app-server deadlocked or crashed while the OS pipe buffer is full; stdin buffer exhausted by a large payload; heavy system load stalling the write; child process stopped (SIGSTOP) or PID reaped unexpectedly.","solutions":["Recreate the codex session — `abortTransport` already killed the process, the session is unusable.","Check whether the codex process hangs on startup (run it manually with the same args).","Reduce payload size (huge context/instructions) that can fill the pipe buffer.","Check host resource pressure (CPU, memory, stopped processes).","Upgrade codex to a version without known stdin-handling deadlocks."],"exampleFix":"// caller side: treat write timeout as fatal for the session\nif err := sess.request(\"turn/create\", params, &out); err != nil {\n    if strings.Contains(err.Error(), \"write timed out\") {\n        // before: retry on dead session\n        // after: rebuild session\n        sess = newAppServerSession(...)\n    }\n}","handlingStrategy":"fallback","validationCode":"// check the session is alive and process running before writing\nif !sess.Alive() {\n    return fmt.Errorf(\"codex session dead; restart before requesting\")\n}","typeGuard":null,"tryCatchPattern":"if err := sess.request(method, params, out); err != nil {\n    if strings.Contains(err.Error(), \"write timed out\") {\n        slog.Warn(\"codex write timed out; session was aborted\")\n        // session is dead — recreate from scratch\n        return recreateSessionAndRetry(ctx, method, params, out)\n    }\n    return err\n}","preventionTips":["Treat any write-timeout error as fatal: the transport was aborted.","Keep payloads small; huge contexts can fill the stdin pipe.","Monitor codex process health (cmd.Wait) to detect hangs early.","Avoid SIGSTOP'd or resource-starved hosts for the codex child."],"tags":["codex","timeout","ipc","pipe","process"],"backgroundTag":"broken-pipe","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"}