{"record":{"id":"49613523f2248018","repo":"chenhg5/cc-connect","slug":"session-process-is-not-running-496135","errorCode":null,"errorMessage":"session process is not running","messagePattern":"session process is not running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/copilot/session.go","lineNumber":696,"sourceCode":"func summarizeToolInput(tool string, input map[string]any) string {\n\tif input == nil {\n\t\treturn \"\"\n\t}\n\tb, err := json.Marshal(input)\n\tif err != nil {\n\t\treturn \"\"\n\t}\n\ts := string(b)\n\tif len(s) > 200 {\n\t\ts = s[:200] + \"...\"\n\t}\n\treturn s\n}\n\n// Send sends a user message to the running Copilot process.\nfunc (cs *copilotSession) Send(prompt string, messageID string, images []core.ImageAttachment, files []core.FileAttachment) error {\n\tif !cs.alive.Load() {\n\t\treturn fmt.Errorf(\"session process is not running\")\n\t}\n\n\t// Handle images: save to temp dir and append file references\n\tif len(images) > 0 {\n\t\timgPaths, err := saveImagesToTempDir(cs.workDir, images)\n\t\tif err != nil {\n\t\t\tslog.Warn(\"copilotSession: failed to save images\", \"error\", err)\n\t\t} else {\n\t\t\tprompt = core.AppendFileRefs(prompt, imgPaths)\n\t\t}\n\t}\n\n\t// Handle files\n\tif len(files) > 0 {\n\t\tfilePaths := core.SaveFilesToDisk(cs.workDir, messageID, files)\n\t\tprompt = core.AppendFileRefs(prompt, filePaths)\n\t}\n","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/copilot/session.go#L678-L714","documentation":"Send checks the session's atomic alive flag before doing anything and refuses to talk to a dead Copilot process with 'session process is not running'. It exists so callers get an immediate, clear error instead of a write to a closed pipe or a silent hang.","triggerScenarios":"copilotSession.Send called when cs.alive.Load() is false — i.e. after readLoop's deferred cleanup ran because the CLI process exited (crash, kill, clean exit).","commonSituations":"User sends a chat message after the CLI crashed earlier in the conversation; long idle period during which the CLI was OOM-killed; engine retrying delivery to a session whose process already died; systemd restarting the service and stale session references being used.","solutions":["Start a new session (/new) or restart the agent so a fresh Copilot process is spawned, then resend the message.","Check earlier logs for 'process exited' / 'copilotSession: process failed' with stderr to find why the CLI died, and fix that root cause.","Re-authenticate the CLI if it exited due to auth expiry.","If kills are environmental (OOM, supervisor), increase limits so the process survives.","Add health checking/automatic restart for the agent process if this recurs."],"exampleFix":"// before: sending into a dead session\nsession.Send(\"continue the task\", msgID, nil, nil) // \"session process is not running\"\n// after: recreate the session first\nif !sessionAlive(session) {\n    session = agent.StartSession(ctx, opts) // fresh CLI process\n}\nsession.Send(\"continue the task\", msgID, nil, nil)","handlingStrategy":"type-guard","validationCode":"if !cs.alive.Load() {\n    return fmt.Errorf(\"cannot send: session process is not running\")\n}","typeGuard":"func canSend(s *copilotSession) bool { return s.alive.Load() }","tryCatchPattern":"if err := session.Send(prompt, msgID, nil, nil); err != nil {\n    if strings.Contains(err.Error(), \"not running\") {\n        session = agent.StartSession(ctx, opts)\n        err = session.Send(prompt, msgID, nil, nil)\n    }\n}","preventionTips":["Check session liveness before sending instead of reusing cached session handles","Restart the session after any 'process exited' event","Monitor host memory so the CLI is not OOM-killed mid-conversation","Recreate sessions after service restarts rather than reusing old handles"],"tags":["process-lifecycle","session-lifecycle","send","dead-process"],"backgroundTag":"connection-refused","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"}