chenhg5/cc-connect · error
wps-agentspace: init: %w
Error message
wps-agentspace: init: %w
What it means
The wps-agentspace platform wraps any failure to send the WebSocket "init" handshake frame after a successful dial as "wps-agentspace: init: %w". sendInit writes a JSON init frame carrying the device UUID/name and timestamp; if that write fails (connection already closed, send deadline exceeded, marshal error), connect aborts and the connectLoop retries with backoff. It means the TCP/TLS handshake succeeded but the application-level init exchange did not.
Source
Thrown at platform/wps-agentspace/wpsagentspace.go:390
})
p.mu.Lock()
p.conn = conn
p.mu.Unlock()
// Reset backoff on successful connection
defer func() {
p.mu.Lock()
if p.conn == conn {
p.conn = nil
}
p.mu.Unlock()
_ = conn.Close()
}()
// Send init
if err := p.sendInit(); err != nil {
return fmt.Errorf("wps-agentspace: init: %w", err)
}
// Start heartbeat
hbCtx, hbCancel := context.WithCancel(ctx)
defer hbCancel()
go p.heartbeatLoop(hbCtx)
// Start write loop
writeDone := make(chan struct{})
go func() {
defer close(writeDone)
p.writeLoop(conn)
}()
// Read loop
return p.readLoop(conn, ctx)
}
View on GitHub (pinned to 4000b2338a)
Solutions
- Check the wrapped cause (%w) in logs — if it is 'use of closed connection' or a write timeout, the server/proxy dropped the socket; retry and inspect server-side access logs
- Verify the configured appID/baseURL so you are dialing the correct AgentSpace endpoint that accepts init frames
- Confirm outbound WebSocket (wss) connectivity to agentspace.wps.cn from the host, including proxies and firewalls
- If init failures persist, check device registration/permissions for the configured device UUID on the WPS side
Example fix
// before
if err := p.sendInit(); err != nil {
return fmt.Errorf("wps-agentspace: init: %w", err)
}
// after
if err := p.sendInit(); err != nil {
slog.Warn("wps-agentspace: init send failed, will retry", "error", err)
return fmt.Errorf("wps-agentspace: init: %w", err) // connectLoop backoff retries
} Defensive patterns
Strategy: retry
Validate before calling
// before starting: verify endpoint reachability
resp, err := http.Head("https://agentspace.wps.cn")
if err != nil || resp.StatusCode >= 500 { log.Printf("endpoint unreachable: %v", err) } Try / catch
if err := p.sendInit(); err != nil {
var ne net.Error
if errors.As(err, &ne) && ne.Timeout() {
// transient: rely on connectLoop backoff
}
return fmt.Errorf("wps-agentspace: init: %w", err)
} Prevention
- Keep the heartbeat and connectLoop backoff enabled so transient init failures self-heal
- Validate appID/baseURL config before Start
- Test outbound wss connectivity to agentspace.wps.cn from the deployment host
- Watch logs for repeated init failures — that signals server-side rejection, not network noise
When it happens
Trigger: The server closes the connection immediately after dialing (rejection, auth wall, proxy interference); the underlying gorilla/websocket write fails due to a broken connection; or writeJSON's json.Marshal of initData fails (not possible with current fields, but wrapped the same way).
Common situations: WPS AgentSpace rejecting a device before init completes; corporate proxy/VPN dropping freshly established WebSocket connections; server restart racing with connectLoop so the conn is closed between dial and init; network flaps right after connect.
Related errors
- qq: ws connect failed (%s): %w
- dial: %s
- wps-agentspace: dial: %w
- wecom-ws: ack timeout
- connect permission bridge: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/c667dc3bf8503f3d.
Report an issue: GitHub.