fix: change SSE keepalive from event to comment format#1707
Open
danielzhou82 wants to merge 1 commit intoWei-Shaw:mainfrom
Open
fix: change SSE keepalive from event to comment format#1707danielzhou82 wants to merge 1 commit intoWei-Shaw:mainfrom
danielzhou82 wants to merge 1 commit intoWei-Shaw:mainfrom
Conversation
e20602e to
3eeeb85
Compare
…ent watchdog Change keepalive ping from SSE event (`event: ping\ndata: ...`) to SSE comment (`: keepalive\n\n`) across all streaming handlers. SSE comments keep HTTP connections alive but are not yielded by the Anthropic SDK, so client-side idle watchdogs (e.g. Claude Code's 90s timeout) continue counting down correctly when the upstream connection dies silently.
3eeeb85 to
f24c270
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
event: ping\ndata: {"type": "ping"}\n\n(SSE event) to: keepalive\n\n(SSE comment) across all streaming handlersProblem
When using Claude Code through sub2api with extended thinking enabled, the client occasionally hangs (time keeps ticking but no tokens arrive). Root cause:
bufio.Scanner.Scan()blocks forever (Go'shttp.Transporthas no read timeout on response body)Fix
Replace SSE event pings with SSE comments in all 4 streaming paths:
gateway_service.go— main Claude streaming handlerantigravity_gateway_service.go— two Antigravity streaming handlersopenai_gateway_messages.go— OpenAI-compat Anthropic streaming handlergateway_helper.go—SSEPingFormatClaudeconstantSSE comments (
:<space>text\n\n) are valid SSE frames that keep HTTP connections alive but are silently discarded by spec-compliant SSE parsers, including the Anthropic SDK.Test plan
🤖 Generated with Claude Code