{"record":{"id":"f5201ce6a46879e1","repo":"chenhg5/cc-connect","slug":"wps-agentspace-write-buffer-full","errorCode":null,"errorMessage":"wps-agentspace: write buffer full","messagePattern":"wps-agentspace: write buffer full","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wps-agentspace/wpsagentspace.go","lineNumber":662,"sourceCode":"\tframe := wsFrame{\n\t\tEvent: event,\n\t}\n\tjsonData, err := json.Marshal(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"wps-agentspace: marshal: %w\", err)\n\t}\n\tframe.Data = jsonData\n\n\traw, err := json.Marshal(frame)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"wps-agentspace: marshal frame: %w\", err)\n\t}\n\n\tselect {\n\tcase p.writeCh <- raw:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"wps-agentspace: write buffer full\")\n\t}\n}\n\n// writeLoop serializes all WebSocket writes.\nfunc (p *Platform) writeLoop(conn *websocket.Conn) {\n\tfor msg := range p.writeCh {\n\t\tif p.stopped.Load() {\n\t\t\treturn\n\t\t}\n\t\t// msg is already JSON-encoded bytes from writeJSON\n\t\tif err := conn.WriteMessage(websocket.TextMessage, msg.([]byte)); err != nil {\n\t\t\tslog.Error(\"wps-agentspace: write error\", \"error\", err)\n\t\t\treturn\n\t\t}\n\t}\n}\n\n// --- Crypto utilities ---","sourceCodeStart":644,"sourceCodeEnd":680,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wps-agentspace/wpsagentspace.go#L644-L680","documentation":"writeJSON pushes the serialized frame onto p.writeCh, a bounded channel drained by writeLoop; if the buffer is full it gives up immediately with this error instead of blocking. It means the single writer goroutine cannot keep up or has stopped (e.g. the connection is dead and writeLoop exited).","triggerScenarios":"Sending more WebSocket frames than writeLoop drains, or writeLoop has exited (connection closed) leaving messages to fill the buffer; called from sendInit, heartbeatLoop, handleFrame, sendText, sendTyping.","commonSituations":"Network stall or dropped WebSocket connection causes writes to block in the websocket library, backing up writeCh; bursts of typing indicators plus messages overflow the buffer.","solutions":["Check whether the WebSocket connection is still alive and writeLoop is running; reconnect if the connection dropped","Increase the writeCh buffer capacity if legitimate throughput exceeds the current size","Reduce send frequency (e.g. throttle sendTyping heartbeats)","Treat this error as a signal to tear down and re-establish the connection"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if p.writeCh == nil || !p.connected() { return errors.New(\"not connected\") }","typeGuard":null,"tryCatchPattern":"if err := p.sendText(chatID, text); err != nil { if strings.Contains(err.Error(), \"write buffer full\") { time.Sleep(backoff); return p.sendText(chatID, text) } }","preventionTips":["Monitor writeLoop liveness and reconnect on stall","Size writeCh generously for expected burst traffic","Throttle typing indicators and heartbeats","Treat buffer-full as a health signal to reset the connection"],"tags":["websocket","backpressure","buffer-full"],"backgroundTag":"connection-refused","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}