chenhg5/cc-connect · error
yuanbao: not connected
Error message
yuanbao: not connected
What it means
Reply obtains the current WebSocket connection via getWS(); if it returns nil the platform has no live connection and this error is returned instead of attempting a write. It means the client is not connected to the yuanbao gateway at send time.
Source
Thrown at platform/yuanbao/platform.go:416
if !ok {
return fmt.Errorf("yuanbao: invalid reply context type %T", rctx)
}
if content == "" {
return nil
}
content = core.StripMarkdown(content)
p.startReplyHeartbeat(rc.chatID)
defer p.stopReplyHeartbeat(rc.chatID, true)
msgBody := [][]byte{encodeTextBody(content)}
var frame []byte
if rc.chatType == "group" {
frame = encodeSendGroupMessage(rc.targetID, msgBody, p.getBotID(), "", "", "")
} else {
frame = encodeSendC2CMessage(rc.targetID, msgBody, p.getBotID(), "", 0, "", "")
}
ws := p.getWS()
if ws == nil {
return fmt.Errorf("yuanbao: not connected")
}
err := ws.WriteMessage(websocket.BinaryMessage, frame)
if err != nil {
slog.Error("yuanbao: reply send failed", "error", err)
}
return err
}
func (p *Platform) Send(ctx context.Context, rctx any, content string) error {
return p.Reply(ctx, rctx, content)
}
func (p *Platform) ReconstructReplyCtx(sessionKey string) (any, error) {
parts := strings.SplitN(sessionKey, ":", 3)
if len(parts) < 2 || parts[0] != "yuanbao" {
return nil, fmt.Errorf("yuanbao: invalid session key %q", sessionKey)
}
chatID := parts[1]View on GitHub (pinned to 4000b2338a)
Solutions
- Check startup logs for the connection/auth failure that left getWS() nil and fix it (ws_url, token, network)
- Retry the reply after the platform reconnects; add retry-with-backoff around Reply
- Verify the bot process is running and the WebSocket heartbeat keeps the connection alive
- Queue outbound messages until the connected state is restored
Defensive patterns
Strategy: retry
Validate before calling
if p.getWS() == nil { return errors.New("yuanbao not connected; defer send") } Try / catch
err := p.Reply(ctx, rctx, text)
for i := 0; err != nil && strings.Contains(err.Error(), "not connected") && i < 5; i++ { time.Sleep(time.Second << i); err = p.Reply(ctx, rctx, text) } Prevention
- Wait for the platform's connected/ready signal before sending
- Keep heartbeat/reconnect logic healthy and monitored
- Queue outbound messages during disconnects
- Alert on repeated not-connected errors
When it happens
Trigger: Calling Reply (directly or via ReconstructReplyCtx) before Start finishes connecting, after a disconnect, or during a reconnect window.
Common situations: Network outage dropped the WebSocket; server restarted the bot; reply attempt races with shutdown; connection never established due to bad ws_url or auth failure.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- qq: ws connect failed (%s): %w
- dial: %s
- wps-agentspace: dial: %w
- wps-agentspace: init: %w
- wps-agentspace: not connected
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/0dfd95ad80867b08.
Report an issue: GitHub.