{"record":{"id":"1acb5c9d9397baa7","repo":"chenhg5/cc-connect","slug":"session-process-is-not-running","errorCode":null,"errorMessage":"session process is not running","messagePattern":"session process is not running","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agent/claudecode/session.go","lineNumber":981,"sourceCode":"\n\tif toolName == \"AskUserQuestion\" {\n\t\tevt.Questions = parseUserQuestions(input)\n\t}\n\n\tselect {\n\tcase cs.events <- evt:\n\tcase <-cs.ctx.Done():\n\t\treturn\n\t}\n}\n\n// Send writes a user message (with optional images and files) to the Claude process stdin.\n// Images are sent as base64 in the multimodal content array.\n// Files are saved to local temp files and referenced in the text prompt\n// so Claude Code can read them with its built-in tools.\nfunc (cs *claudeSession) 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\tif len(images) == 0 && len(files) == 0 {\n\t\treturn cs.writeJSON(map[string]any{\n\t\t\t\"type\":    \"user\",\n\t\t\t\"message\": map[string]any{\"role\": \"user\", \"content\": prompt},\n\t\t})\n\t}\n\n\tattachDir := filepath.Join(cs.workDir, \".cc-connect\", \"attachments\")\n\tif err := os.MkdirAll(attachDir, 0o755); err != nil {\n\t\tslog.Warn(\"claudeSession: mkdir attachments failed\", \"error\", err, \"path\", attachDir)\n\t}\n\n\tvar parts []map[string]any\n\tvar savedPaths []string\n\n\t// Save and encode images","sourceCodeStart":963,"sourceCodeEnd":999,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/agent/claudecode/session.go#L963-L999","documentation":"Send refuses to write to the claude process when cs.alive is false, returning 'session process is not running'. The alive flag is cleared when the process exits (readLoop/Close), so this error means the message arrived for a session whose process has already died or been closed.","triggerScenarios":"Calling Send on a claudeSession after: the claude process exited (crash, stderr failure relayed as EventError), Close() was called, or the engine considered the session live but the process died concurrently between the event feed and the send.","commonSituations":"User sends a message in the chat platform while the CLI crashed seconds earlier; cron/timer job targeting a stale session; engine raced process exit; daemon resumed with sessions that never survived restart.","solutions":["Start a new session via StartSession and re-send the prompt — the old session is unrecoverable","Check the session's event feed for the earlier EventError (e.g. stderr from the CLI) explaining why it died","If this happens often, add engine-level auto-restart: on EventError/Send failure, recreate the session for the same conversation","Upgrade/pin the Claude CLI if crashes are the root cause of frequent dead sessions"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// gate sends on session liveness and recreate when dead\nfunc safeSend(s core.AgentSession, isAlive func() bool, prompt string) error {\n    if !isAlive() {\n        return errors.New(\"session dead: recreate with StartSession before sending\")\n    }\n    return s.Send(prompt, \"\", nil, nil)\n}","typeGuard":null,"tryCatchPattern":"if err := sess.Send(prompt, msgID, nil, nil); err != nil {\n    if strings.Contains(err.Error(), \"not running\") {\n        sess, err = agent.StartSession(ctx, lastPrompt)\n        if err == nil {\n            err = sess.Send(prompt, msgID, nil, nil)\n        }\n    }\n}","preventionTips":["Subscribe to session events and drop references as soon as EventError/close fires","Recreate sessions proactively on process-exit events instead of sending into dead ones","Avoid long-lived idle sessions; close and rebuild rather than reusing possibly-dead handles","Check for prior stderr/crash events to fix the root cause of repeated process death"],"tags":["process-lifecycle","session","send"],"backgroundTag":"invalid-state-transition","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"}