Skip to content

fix(api): keep IM event streams alive#43

Merged
RussellLuo merged 1 commit into
OpenCSGs:mainfrom
jialudev:fix/api-im-events-heartbeat
May 9, 2026
Merged

fix(api): keep IM event streams alive#43
RussellLuo merged 1 commit into
OpenCSGs:mainfrom
jialudev:fix/api-im-events-heartbeat

Conversation

@jialudev
Copy link
Copy Markdown
Collaborator

@jialudev jialudev commented May 9, 2026

Summary

This PR keeps the IM event SSE stream alive while the conversation is idle.

/api/v1/events now 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 TestHandleIMEventsExposeRoomIDOnly

I 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 httptest listener creation failing with bind: operation not permitted.

@RussellLuo RussellLuo merged commit 2f11e6d into OpenCSGs:main May 9, 2026
wanghaojie124 pushed a commit to wanghaojie124/csgclaw that referenced this pull request May 9, 2026
@jialudev jialudev deleted the fix/api-im-events-heartbeat branch May 14, 2026 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants