{"record":{"id":"d5a3dd92dcc0418c","repo":"chenhg5/cc-connect","slug":"send-relay-message-w","errorCode":null,"errorMessage":"send relay message: %w","messagePattern":"send relay message: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/engine.go","lineNumber":16027,"sourceCode":"\t\t\tchanged = true\n\t\t} else {\n\t\t\tchanged = session.CompareAndSetAgentSessionID(id, agent.Name())\n\t\t}\n\t\tif !changed {\n\t\t\treturn\n\t\t}\n\t\tpendingName := session.GetName()\n\t\tif pendingName != \"\" && pendingName != \"session\" && pendingName != \"default\" {\n\t\t\tsessions.SetSessionName(id, pendingName)\n\t\t}\n\t\tsessions.Save()\n\t}\n\n\tsaveRelaySessionID(agentSession.CurrentSessionID(), false)\n\n\tif err := agentSession.Send(message, \"\", nil, nil); err != nil {\n\t\tagentSession.Close()\n\t\treturn \"\", fmt.Errorf(\"send relay message: %w\", err)\n\t}\n\n\tvar textParts []string\n\tfor event := range agentSession.Events() {\n\t\tswitch event.Type {\n\t\tcase EventText:\n\t\t\tif event.Content != \"\" {\n\t\t\t\ttextParts = append(textParts, event.Content)\n\t\t\t}\n\t\t\tif event.SessionID != \"\" {\n\t\t\t\tsaveRelaySessionID(event.SessionID, false)\n\t\t\t}\n\t\tcase EventToolResult:\n\t\t\tout := strings.TrimSpace(event.Content)\n\t\t\tif out == \"\" {\n\t\t\t\tout = strings.TrimSpace(event.ToolResult)\n\t\t\t}\n\t\t\tif out != \"\" {","sourceCodeStart":16009,"sourceCodeEnd":16045,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/engine.go#L16009-L16045","documentation":"After a relay agent session started successfully, agentSession.Send(message, ...) failed and the error is wrapped as 'send relay message: %w'. The session is closed before returning, so this error terminates the relay exchange. It indicates the agent session's input channel rejected the message — typically because the underlying agent process died or the session was already closed.","triggerScenarios":"agentSession.Send returns an error right after saveRelaySessionID — the agent process crashed between StartSession and Send, stdin pipe is broken, or the session was concurrently closed by a timeout/shutdown.","commonSituations":"Agent CLI crashed at first message (bad prompt encoding, invalid model name); session killed by an idle/total timeout racing the Send; concurrent Stop() from another goroutine; very large message exceeding agent input limits.","solutions":["Retry the relay — if it reproduces immediately, the agent process is crashing at startup; check agent logs","Validate the model name / agent options in config.toml","Check for timeout configuration that could close the session between start and send","Enable agent debug logging to capture the process stderr at crash time"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// ensure session is alive before sending\nselect {\ncase <-agentSession.Done():\n    return \"\", fmt.Errorf(\"session closed before send\")\ndefault:\n}\nif err := agentSession.Send(message, \"\", nil, nil); err != nil { ... }","typeGuard":null,"tryCatchPattern":"if err := agentSession.Send(message, \"\", nil, nil); err != nil {\n    agentSession.Close()\n    // one immediate retry with a fresh session\n    if s2, serr := agent.StartSession(e.ctx, \"\"); serr == nil {\n        if serr2 := s2.Send(message, \"\", nil, nil); serr2 == nil {\n            agentSession = s2\n            goto stream\n        }\n        s2.Close()\n    }\n    return \"\", fmt.Errorf(\"send relay message: %w\", err)\n}","preventionTips":["Avoid tight timeout configs that can close sessions between start and send","Serialize session lifecycle (close/send) under a mutex to prevent races","Keep messages under agent input limits; truncate or chunk oversized text","Capture agent stderr to diagnose first-message crashes"],"tags":["agent","session","relay","send"],"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"}