chenhg5/cc-connect · error
send relay message: %w
Error message
send relay message: %w
What it means
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.
Source
Thrown at core/engine.go:16027
changed = true
} else {
changed = session.CompareAndSetAgentSessionID(id, agent.Name())
}
if !changed {
return
}
pendingName := session.GetName()
if pendingName != "" && pendingName != "session" && pendingName != "default" {
sessions.SetSessionName(id, pendingName)
}
sessions.Save()
}
saveRelaySessionID(agentSession.CurrentSessionID(), false)
if err := agentSession.Send(message, "", nil, nil); err != nil {
agentSession.Close()
return "", fmt.Errorf("send relay message: %w", err)
}
var textParts []string
for event := range agentSession.Events() {
switch event.Type {
case EventText:
if event.Content != "" {
textParts = append(textParts, event.Content)
}
if event.SessionID != "" {
saveRelaySessionID(event.SessionID, false)
}
case EventToolResult:
out := strings.TrimSpace(event.Content)
if out == "" {
out = strings.TrimSpace(event.ToolResult)
}
if out != "" {View on GitHub (pinned to 4000b2338a)
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
Defensive patterns
Strategy: retry
Validate before calling
// ensure session is alive before sending
select {
case <-agentSession.Done():
return "", fmt.Errorf("session closed before send")
default:
}
if err := agentSession.Send(message, "", nil, nil); err != nil { ... } Try / catch
if err := agentSession.Send(message, "", nil, nil); err != nil {
agentSession.Close()
// one immediate retry with a fresh session
if s2, serr := agent.StartSession(e.ctx, ""); serr == nil {
if serr2 := s2.Send(message, "", nil, nil); serr2 == nil {
agentSession = s2
goto stream
}
s2.Close()
}
return "", fmt.Errorf("send relay message: %w", err)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- start relay session: %w
- session process is not running
- get relay workspace agent: %w
- agent error (no details)
- relay: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/d5a3dd92dcc0418c.
Report an issue: GitHub.