chenhg5/cc-connect · error
wps-agentspace: not connected
Error message
wps-agentspace: not connected
What it means
sendText returns the sentinel error "wps-agentspace: not connected" when p.conn is nil, i.e. the platform has no active WebSocket session. This happens whenever a reply/send is attempted outside the window between a successful init and the deferred conn cleanup in connect (wpsagentspace.go:379-386). It is a state error telling the caller the message could not be delivered and should be retried after reconnection.
Source
Thrown at platform/wps-agentspace/wpsagentspace.go:614
// Dispatch to handler
if p.handler != nil {
msg := &core.Message{
SessionKey: sessionKey,
Platform: "wps-agentspace",
Content: content,
ReplyCtx: rc,
UserID: chatID,
}
go p.handler(p, msg)
}
return nil
}
// sendText sends a text message to a chat.
func (p *Platform) sendText(chatID, content string, rc *replyContext) error {
if p.conn == nil {
return fmt.Errorf("wps-agentspace: not connected")
}
msg := messageData{
Role: "assistant",
Type: "answer",
Content: content,
SessionID: rc.SessionID,
ChatID: chatID,
MessageID: rc.MessageID,
Timestamp: time.Now().UnixMilli(),
DeviceUUID: p.deviceUuid,
DeviceName: p.deviceName,
}
return p.writeJSON("message", msg)
}
// sendTyping sends a typing indicator.View on GitHub (pinned to 4000b2338a)
Solutions
- Ensure the write path goes through p.sendCh / writeLoop so sends are queued and flushed on reconnect instead of requiring a live conn, or retry after connectLoop re-establishes the session
- Check connectLoop logs for why the connection is down (dial/init/read errors upstream) and fix that root cause
- If this happens at shutdown, treat it as expected: messages cannot be delivered after Stop()
- Verify network connectivity to agentspace.wps.cn and valid credentials so a connection can be maintained
Example fix
// before
func (p *Platform) sendText(chatID, content string, rc *replyContext) error {
if p.conn == nil {
return fmt.Errorf("wps-agentspace: not connected")
}
...
}
// after — snapshot conn under lock to avoid racing the cleanup in connect
func (p *Platform) sendText(chatID, content string, rc *replyContext) error {
p.mu.Lock()
conn := p.conn
p.mu.Unlock()
if conn == nil {
return fmt.Errorf("wps-agentspace: not connected")
}
...
} Defensive patterns
Strategy: retry
Validate before calling
// caller-side pre-check
p.mu.Lock()
connected := p.conn != nil
p.mu.Unlock()
if !connected { /* queue message or wait for reconnect before replying */ } Try / catch
if err := platform.Send(msg); err != nil {
if strings.Contains(err.Error(), "not connected") {
// transient: re-enqueue and deliver after reconnect
}
} Prevention
- Route all sends through the writeLoop queue rather than writing directly to p.conn
- Check connection health before long-running agent tasks that end in a reply
- Add retry-with-backoff around Send for transient disconnects
- Monitor connectLoop status; alert if the platform stays disconnected
When it happens
Trigger: Engine replies to a user message while connectLoop is between attempts (socket dropped, backoff pending); Stop() was called and closed the connection; sendText races with the deferred cleanup that nils p.conn; the platform never connected because earlier dial/init errors kept failing.
Common situations: Agent finishes a long-running task just as the AgentSpace WebSocket drops, so the reply finds no socket; cc-connect was stopped/restarted while a pipeline was mid-reply; server outage means no connection is ever established, so every send fails with this error.
Related errors
- qq: ws connect failed (%s): %w
- dial: %s
- wps-agentspace: dial: %w
- wps-agentspace: init: %w
- yuanbao: not connected
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/60a6045e92b5b1ad.
Report an issue: GitHub.