fix(api): keep IM event streams alive#43
Merged
Conversation
wanghaojie124
pushed a commit
to wanghaojie124/csgclaw
that referenced
this pull request
May 9, 2026
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
This PR keeps the IM event SSE stream alive while the conversation is idle.
/api/v1/eventsnow sends a lightweight SSE comment heartbeat every 15 seconds. This does not change the event payload contract, but it gives browsers, proxies, and other network layers periodic bytes so they are less likely to close an otherwise idle conversation stream.Why
The web UI depends on the SSE connection for chat and room updates. When there is no message traffic for a while, the connection can look idle from the network layer's perspective and may be dropped. If that happens silently, the conversation UI can miss later updates until the client reconnects.
Sending SSE comments is a low-risk keepalive mechanism: clients ignore comment lines such as
: ping, while the TCP/HTTP connection still sees activity.Testing
env GOCACHE=/Users/jared/opencsg-workspace/csgclaw-workspace/csgclaw/.gocache go test ./internal/api -run TestHandleIMEventsExposeRoomIDOnlyI also attempted:
env GOCACHE=/Users/jared/opencsg-workspace/csgclaw-workspace/csgclaw/.gocache go test ./internal/api -run 'TestIMEvents|TestHandleIMEvents'The broader event test run is blocked in this local sandbox by
httptestlistener creation failing withbind: operation not permitted.