Skip to content

feat: convert websockets to server-side events#1587

Merged
tyler-dane merged 9 commits intomainfrom
feat/ws-to-sse
Mar 30, 2026
Merged

feat: convert websockets to server-side events#1587
tyler-dane merged 9 commits intomainfrom
feat/ws-to-sse

Conversation

@tyler-dane
Copy link
Copy Markdown
Contributor

@tyler-dane tyler-dane commented Mar 30, 2026

Note

Medium Risk
Touches realtime delivery and Google-sync error/notification paths; misconfigurations in SSE streaming/heartbeats or listener wiring could cause stale UI updates or missed import/revocation signals.

Overview
Switches the app’s realtime notification mechanism from socket.io WebSockets to Server-Sent Events (SSE) via an authenticated GET /api/events/stream endpoint, with a new backend sseServer handling per-user connections, heartbeats, and event fanout.

Migrates Google sync/import and revocation notifications (EVENT_CHANGED, SOMEDAY_EVENT_CHANGED, IMPORT_GCAL_*, USER_METADATA, GOOGLE_REVOKED) to shared core SSE constants/types, rewires backend emitters/error handling/sync processors to publish over SSE, and updates the web client to manage an EventSource stream (SSEProvider + hooks) instead of socket listeners.

Removes WebSocket infrastructure and dependencies across backend/web, updates Jest module mapping and tests accordingly, and adds documentation for the new Google sync + SSE flow and deployment considerations for long-lived text/event-stream connections.

Written by Cursor Bugbot for commit cc0b5ab. This will update automatically on new commits. Configure here.

Comment thread packages/web/src/sse/hooks/useEventSSE.ts
Comment thread packages/core/src/constants/sse.constants.ts Outdated
@tyler-dane tyler-dane force-pushed the feat/ws-to-sse branch 2 times, most recently from e2d02f1 to e682637 Compare March 30, 2026 02:17
Comment thread packages/backend/src/events/controllers/events.controller.ts Outdated
Comment thread packages/backend/src/__tests__/drivers/base.driver.ts Outdated
Comment thread packages/backend/src/servers/sse/sse.server.test.ts Outdated
Comment thread packages/backend/src/events/controllers/events.controller.ts
Comment thread jest.config.js
Comment thread packages/backend/src/servers/sse/sse.server.ts
…eal-time updates

- Updated documentation and codebase to replace WebSocket references with SSE, enhancing the real-time communication mechanism.
- Modified AGENTS.md, README, and various architecture documents to reflect the shift to SSE for Google Calendar sync and event notifications.
- Introduced a new feature document for Google Sync and SSE, detailing the architecture and event flow.
- Removed obsolete WebSocket code and dependencies from the backend, ensuring a cleaner and more maintainable codebase.
- Updated tests and hooks to utilize SSE, ensuring consistent behavior across the application.
- Updated "@adobe/css-tools" to version 4.4.4.
- Removed obsolete "socket.io" and "socket.io-client" dependencies.
- Updated "@emnapi/core" and "@emnapi/runtime" to version 1.9.1.
- Updated "@napi-rs/wasm-runtime" to version 1.1.2 with peer dependencies.
- Bumped "@opentelemetry/api" to version 1.9.1 and "@opentelemetry/core" to version 2.6.1.
- Updated "@posthog/core" to version 1.24.3 and "@posthog/types" to version 1.364.1.
- Updated "@sinclair/typebox" to version 0.34.49 and "@tanstack/react-store" to version 0.9.3.
- Updated "@tanstack/store" to version 0.9.3.
- Introduced an alias for the SSE module in the webpack configuration, enhancing module resolution and improving code organization.
- Added a condition in the loadAuthenticated function to return an unauthenticated state when NODE_ENV is set to "test", preventing session checks from blocking navigation during Playwright e2e tests.
- Replaced direct EventSource event listeners with an EventEmitter2 instance for improved event management.
- Updated hooks to utilize the new sseEmitter for handling SSE events, enhancing modularity and maintainability.
- Refactored tests to accommodate the changes in event handling, ensuring consistent behavior across the application.
…t coverage

- Changed the USER_METADATA publishing method in the SSE server to use a response object, improving the handling of server-sent events.
- Added a test to ensure that USER_METADATA is not replayed to existing tabs when a new tab opens, enhancing the reliability of the SSE implementation.
- Moved the initialization of eventName and dataLine variables outside the loop in the BaseDriver class, improving code clarity and reducing redundancy.
- Updated the test file for SSE server to remove redundant comments, enhancing readability while maintaining the test environment setup.
- Added a check to send a 500 status response if an error occurs while opening the SSE stream and headers have not been sent, improving error handling in the EventsController.
- Removed obsolete socket alias from jest configuration, streamlining module resolution for the web project.
- Updated the connection handling logic in the SSE server to utilize a dedicated method for removing dead connections, enhancing code clarity and maintainability.
- Refactored the subscription and error handling processes to ensure proper cleanup of connections, improving overall reliability of the SSE implementation.
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issue. You can view the agent here.

Comment thread packages/backend/src/events/controllers/events.controller.ts
@tyler-dane tyler-dane merged commit 69bfa29 into main Mar 30, 2026
10 checks passed
@tyler-dane tyler-dane deleted the feat/ws-to-sse branch March 30, 2026 11:34
tyler-dane added a commit to Muhammad-Nur-Alamsyah-Anwar/compass that referenced this pull request Mar 30, 2026
* refactor: transition from WebSocket to Server-Sent Events (SSE) for real-time updates

- Updated documentation and codebase to replace WebSocket references with SSE, enhancing the real-time communication mechanism.
- Modified AGENTS.md, README, and various architecture documents to reflect the shift to SSE for Google Calendar sync and event notifications.
- Introduced a new feature document for Google Sync and SSE, detailing the architecture and event flow.
- Removed obsolete WebSocket code and dependencies from the backend, ensuring a cleaner and more maintainable codebase.
- Updated tests and hooks to utilize SSE, ensuring consistent behavior across the application.

* chore(deps): update dependencies in yarn.lock

- Updated "@adobe/css-tools" to version 4.4.4.
- Removed obsolete "socket.io" and "socket.io-client" dependencies.
- Updated "@emnapi/core" and "@emnapi/runtime" to version 1.9.1.
- Updated "@napi-rs/wasm-runtime" to version 1.1.2 with peer dependencies.
- Bumped "@opentelemetry/api" to version 1.9.1 and "@opentelemetry/core" to version 2.6.1.
- Updated "@posthog/core" to version 1.24.3 and "@posthog/types" to version 1.364.1.
- Updated "@sinclair/typebox" to version 0.34.49 and "@tanstack/react-store" to version 0.9.3.
- Updated "@tanstack/store" to version 0.9.3.

* feat(webpack): add alias for Server-Sent Events (SSE) module

- Introduced an alias for the SSE module in the webpack configuration, enhancing module resolution and improving code organization.

* fix(loaders): handle SuperTokens session checks in test environment

- Added a condition in the loadAuthenticated function to return an unauthenticated state when NODE_ENV is set to "test", preventing session checks from blocking navigation during Playwright e2e tests.

* refactor(sse): transition to EventEmitter for SSE event handling

- Replaced direct EventSource event listeners with an EventEmitter2 instance for improved event management.
- Updated hooks to utilize the new sseEmitter for handling SSE events, enhancing modularity and maintainability.
- Refactored tests to accommodate the changes in event handling, ensuring consistent behavior across the application.

* refactor(sse): update USER_METADATA publishing method and enhance test coverage

- Changed the USER_METADATA publishing method in the SSE server to use a response object, improving the handling of server-sent events.
- Added a test to ensure that USER_METADATA is not replayed to existing tabs when a new tab opens, enhancing the reliability of the SSE implementation.

* refactor(base.driver): streamline event handling in BaseDriver class

- Moved the initialization of eventName and dataLine variables outside the loop in the BaseDriver class, improving code clarity and reducing redundancy.
- Updated the test file for SSE server to remove redundant comments, enhancing readability while maintaining the test environment setup.

* fix(events): ensure proper response handling for SSE stream errors

- Added a check to send a 500 status response if an error occurs while opening the SSE stream and headers have not been sent, improving error handling in the EventsController.
- Removed obsolete socket alias from jest configuration, streamlining module resolution for the web project.

* refactor(sse): improve connection management in SSE server

- Updated the connection handling logic in the SSE server to utilize a dedicated method for removing dead connections, enhancing code clarity and maintainability.
- Refactored the subscription and error handling processes to ensure proper cleanup of connections, improving overall reliability of the SSE implementation.
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.

1 participant