From 7511e4de59aee7e2bd6f912b138c263de01e05e2 Mon Sep 17 00:00:00 2001 From: MHJoy99 <75517252+MHJoy99@users.noreply.github.com> Date: Sun, 13 Sep 2026 12:09:28 +0600 Subject: [PATCH] fix(streaming): drop Anthropic ping keepalives before OpenAI conversion Upstream Anthropic keepalive frames (event: ping) leaked into OpenAI Chat Completions SSE streams, crashing strict clients (Cursor, Hermes, OpenAI SDKs) on unexpected event types. Error events still forward. Fixes #5203 --- .../service/gateway_forward_as_chat_completions.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/backend/internal/service/gateway_forward_as_chat_completions.go b/backend/internal/service/gateway_forward_as_chat_completions.go index 32d38cf40d..0f6611c142 100644 --- a/backend/internal/service/gateway_forward_as_chat_completions.go +++ b/backend/internal/service/gateway_forward_as_chat_completions.go @@ -418,6 +418,15 @@ func (s *GatewayService) handleCCStreamingFromAnthropic( } processAnthropicEvent := func(event *apicompat.AnthropicStreamEvent) bool { + if event == nil { + return false + } + // Drop Anthropic keepalive pings before OpenAI conversion: + // leaking `event: ping` frames crashes OpenAI-stream clients. + // Error events must still forward — they carry upstream failures. + if event.Type == "ping" { + return false + } if firstChunk { firstChunk = false ms := int(time.Since(startTime).Milliseconds())