{"record":{"id":"c0a598bf497ba8ce","repo":"chenhg5/cc-connect","slug":"codex-app-server-initialized-notify-w","errorCode":null,"errorMessage":"codex app-server initialized notify: %w","messagePattern":"codex app-server initialized notify: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/codex/appserver_session.go","lineNumber":319,"sourceCode":"\t\t\"capabilities\": map[string]any{\n\t\t\t\"experimentalApi\": true,\n\t\t\t\"optOutNotificationMethods\": []string{\n\t\t\t\t\"command/exec/outputDelta\",\n\t\t\t\t\"item/agentMessage/delta\",\n\t\t\t\t\"item/plan/delta\",\n\t\t\t\t\"item/fileChange/outputDelta\",\n\t\t\t\t\"item/reasoning/summaryTextDelta\",\n\t\t\t\t\"item/reasoning/textDelta\",\n\t\t\t},\n\t\t},\n\t}\n\n\tvar resp initResponse\n\tif err := s.request(\"initialize\", params, &resp); err != nil {\n\t\treturn fmt.Errorf(\"codex app-server initialize: %w\", err)\n\t}\n\tif err := s.notify(\"initialized\", nil); err != nil {\n\t\treturn fmt.Errorf(\"codex app-server initialized notify: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (s *appServerSession) ensureThread(resumeID string) error {\n\tif resumeID != \"\" && resumeID != core.ContinueSession {\n\t\tparams := s.threadRequestParams()\n\t\tparams[\"threadId\"] = resumeID\n\t\tparams[\"persistExtendedHistory\"] = true\n\n\t\tvar resp threadResumeResponse\n\t\tif err := s.request(\"thread/resume\", params, &resp); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif resp.Thread.ID == \"\" {\n\t\t\treturn fmt.Errorf(\"codex app-server resume returned empty thread id\")\n\t\t}\n\t\ts.applyThreadRuntimeState(resp.Cwd, resp.Model, resp.ReasoningEffort)","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/codex/appserver_session.go#L301-L337","documentation":"This error wraps a failure of the JSON-RPC \"initialized\" notification sent after a successful \"initialize\" response, completing the LSP-style handshake with the codex app-server. Failing here means the transport broke between initialize and the notification — typically the app-server process died or closed its stdin. Initialize itself succeeded, so the protocol version is compatible but the connection dropped.","triggerScenarios":"Calling StartSession on the codex agent; s.notify(\"initialized\", nil) fails because the app-server exited right after initialize (crash in its post-initialize path), or the pipe writes fail (broken pipe/timeout).","commonSituations":"App-server crash triggered by initialize response handling; race where Close() is called concurrently during startup; fd/pipe issues under resource pressure; flaky sandbox blocking further IPC.","solutions":["Inspect app-server stderr for a crash immediately after initialize; fix the underlying cause.","Check for concurrent Close/Stop calls racing with startup and serialize session lifecycle.","Retry StartSession once — a transient crash during handshake is often environmental.","Update or reinstall the codex CLI if crashes are reproducible across initialize cycles."],"exampleFix":"// before\nif err := s.notify(\"initialized\", nil); err != nil {\n    return fmt.Errorf(\"codex app-server initialized notify: %w\", err)\n}\n// after\nif err := s.notify(\"initialized\", nil); err != nil {\n    if !s.alive.Load() {\n        return fmt.Errorf(\"codex app-server initialized notify: session closed during handshake: %w\", err)\n    }\n    return fmt.Errorf(\"codex app-server initialized notify: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Ensure no concurrent teardown is possible before starting the session\nif !sessionLifecycleMu.TryLock() {\n    return errors.New(\"session close/start race detected; serialize lifecycle\")\n}","typeGuard":null,"tryCatchPattern":"if err := session.Start(ctx); err != nil {\n    if strings.Contains(err.Error(), \"initialized notify\") {\n        // initialize succeeded but the pipe died: child crashed post-init\n        slog.Error(\"codex app-server died after initialize; inspect stderr\", \"err\", err)\n    }\n    return err\n}","preventionTips":["Serialize Start/Close with a mutex to avoid teardown racing handshake.","Keep app-server stderr attached to structured logs.","Retry startup once on transient handshake failures.","Keep the codex CLI updated to versions without known post-init crashes."],"tags":["json-rpc","handshake","ipc","broken-pipe"],"backgroundTag":"handshake-failed","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"}