Skip to content

feat(data-connect): add concrete WebSocketTransport#9736

Merged
stephenarosaj merged 9 commits intopasta/mainfrom
pasta/spaghetti
Mar 23, 2026
Merged

feat(data-connect): add concrete WebSocketTransport#9736
stephenarosaj merged 9 commits intopasta/mainfrom
pasta/spaghetti

Conversation

@stephenarosaj
Copy link
Copy Markdown
Contributor

Description

✨ This PR introduces WebSocketTransport, a concrete implementation of the streaming transport layer built on top of native WebSockets. This physical transport implements long-lived, full-duplex connections with the server, managing the low-level connection lifecycle separately from the higher-level streaming logic handled in AbstractDataConnectStreamTransport.

Changes

  • WebSocket Concrete Implementation: Created the WebSocketTransport class to manage active connections.
  • Lazy Connection Execution: Implemented a lazy connection pattern where the physical socket connection is not opened on instantiation, but rather intentionally deferred until requested.
  • Connection De-duplication: openConnection() prevents duplicate connection attempts by tracking pending connectionAttempt promises and short-circuiting if there's already an active connection.
  • Incoming Message Parsing: handleWebSocketMessage strictly parses the incoming DataConnectResponse wire protocol messages, ensuring optional arrays like extensions correctly default to empty objects if omitted.
  • Disconnection Lifecycle Handling: Implemented both closeConnection() and handleWebsocketDisconnect() internally to safely and reliably ensure isReady and internal states are cleared on unexpected server drops or client closures.

Testing

Unit tests were added to test/unit/websocketTransport.test.ts to cover all behavior:

  • Confirmed lazy operations accurately pause payload delivery via sendMessage until a successful WebSocket.OPEN is confirmed.
  • Confirmed idempotency of openConnection by verifying parallel or delayed executions silently adopt a single, shared pending promise.
  • Confirmed the isReady getter property remains precisely aligned with live readyState shifts at every physical connection phase.
  • Confirmed disconnection logic properly wipes internal references (this.connection and this.connectionAttempt) upon explicit method invocation or external simulateClose() drops.
  • Verified payload integrity throws errors if core properties like result or requestId are missing, and handles optional extensions properly.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 19, 2026

⚠️ No Changeset found

Latest commit: 04c8acf

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@stephenarosaj stephenarosaj changed the base branch from main to pasta/main March 19, 2026 21:26
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Data Connect SDK by introducing a new streaming transport layer built upon WebSockets. This refactoring not only provides a concrete WebSocketTransport implementation for real-time data interactions but also establishes a more modular and extensible architecture for handling different communication protocols. The changes ensure efficient connection management, robust message parsing, and proper lifecycle handling for streaming operations, laying the groundwork for future streaming capabilities.

Highlights

  • New WebSocket Transport Implementation: Introduced WebSocketTransport, a concrete implementation for streaming data using native WebSockets, enabling long-lived, full-duplex connections.
  • Modular Transport Layer Architecture: Refactored the transport layer with AbstractDataConnectStreamTransport and DataConnectTransportManager to support multiple transport types (REST and streaming) and manage their lifecycle.
  • Lazy Connection and De-duplication: Implemented lazy connection execution for WebSockets, deferring physical socket opening until needed, and added connection de-duplication to prevent redundant connection attempts.
  • Robust Message Handling: Enhanced incoming message parsing in WebSocketTransport to strictly handle DataConnectResponse wire protocol messages, ensuring optional fields like extensions default correctly.
  • Comprehensive Disconnection Management: Integrated closeConnection() and handleWebsocketDisconnect() for reliable clearing of internal states and isReady property upon client closures or unexpected server disconnections.
  • Core API Integration: Updated DataConnect, MutationManager, and QueryManager to utilize the new DataConnectTransportInterface and DataConnectTransportManager, making the new transport architecture the default.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a concrete WebSocketTransport for the data-connect streaming layer, which is a significant feature. The implementation is well-structured, with good separation of concerns, lazy connection management, and de-duplication of connection attempts. The accompanying unit tests are comprehensive and cover the described behaviors well. I've identified one high-severity issue regarding a potential unhandled promise rejection that should be addressed.

Comment thread packages/data-connect/src/network/stream/websocket.ts Outdated
@stephenarosaj
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a well-structured and robust WebSocketTransport implementation for DataConnect. The code effectively implements lazy connections, de-duplicates connection attempts, and includes thorough error handling. The addition of comprehensive unit tests and the refactoring of test utilities are also commendable. I have a couple of suggestions to further improve error reporting and the robustness of message parsing.

Comment thread packages/data-connect/src/network/stream/websocket.ts Outdated
Comment thread packages/data-connect/src/network/stream/websocket.ts
@stephenarosaj stephenarosaj marked this pull request as ready for review March 21, 2026 15:57
@stephenarosaj stephenarosaj requested review from a team and dconeybe as code owners March 21, 2026 15:57
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe left a comment

Choose a reason for hiding this comment

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

LGTM with only minor comments.

Comment thread packages/data-connect/src/network/stream/websocket.ts
Comment thread packages/data-connect/src/network/stream/websocket.ts
@stephenarosaj stephenarosaj merged commit eba5543 into pasta/main Mar 23, 2026
29 checks passed
@stephenarosaj stephenarosaj deleted the pasta/spaghetti branch March 23, 2026 15:30
@firebase firebase locked and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants