Skip to content

feat(data-connect): Add Message Preparation & Headers#9704

Merged
stephenarosaj merged 10 commits intopasta/mainfrom
pasta/tortellini
Mar 11, 2026
Merged

feat(data-connect): Add Message Preparation & Headers#9704
stephenarosaj merged 10 commits intopasta/mainfrom
pasta/tortellini

Conversation

@stephenarosaj
Copy link
Copy Markdown
Contributor

@stephenarosaj stephenarosaj commented Mar 10, 2026

Overview

✨ This PR focuses on the stateful construction of outgoing messages, ensuring that authentication, telemetry, and connection handshake metadata are correctly applied according to the stream's state.

Key Changes

  • src/network/stream/streamTransport.ts:
    • Implemented the _prepareMessage private method.
    • Handshake logic: Automatically attaches the full connector resource path (name) to the first message of every stream.
    • Header Management: Handles attachment of:
      • authToken (sent on the first message or when the token changes).
      • appCheckToken (sent on the first message).
      • X-Goog-Api-Client (SDK telemetry).
      • x-firebase-gmpid (App ID).
    • State Tracking: Added _isFirstStreamMessage and _lastSentAuthToken tracking properties.
    • Lifecycle Support: Updated onConnectionReady to reset state flags for new physical connections.
    • connectorResourcePath getter: Encapsulates resource path construction.

Testing

New unit tests were added in test/unit/streamTransport.test.ts to verify the stateful header logic:

  • Confirmed name and all headers are present on the initial request.
  • Confirmed name/headers meant only for the first message are not included in future messages.
  • Confirmed telemetry headers are included with every message.
  • Confirmed authToken is present when it changes.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 10, 2026

⚠️ No Changeset found

Latest commit: c92077e

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

@gemini-code-assist
Copy link
Copy Markdown
Contributor

gemini-code-assist Bot commented Mar 10, 2026

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 DataConnectStreamTransport by introducing stateful message preparation, ensuring that outgoing messages are correctly formatted with dynamic headers and metadata based on the stream's current state. This includes managing authentication tokens, app check tokens, and telemetry headers, particularly for the initial message of a stream.

Highlights

  • Stateful Message Preparation: Implemented the _prepareMessage method within AbstractDataConnectStreamTransport to dynamically attach necessary headers and metadata to outgoing stream messages, ensuring proper authentication, telemetry, and connection handshake logic.
  • Dynamic Header Management: Headers such as authToken, appCheckToken, X-Goog-Api-Client, and x-firebase-gmpid are now conditionally included based on the stream's state, with authToken only sent when it changes or on the first message, and appCheckToken only on the first message.
  • Stream State Tracking: Introduced _isFirstStreamMessage and _lastSentAuthToken properties to accurately track the state of the stream and manage header inclusion, with onConnectionReady resetting these flags for new physical connections.
  • Unit Test Coverage: Added extensive unit tests for AbstractDataConnectStreamTransport to verify the correct behavior of stream message preparation and header logic under various scenarios.

🧠 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.

Changelog * **packages/data-connect/src/network/stream/streamTransport.ts** * Implemented the `_prepareMessage` method to manage stream request headers, including `authToken`, `appCheckToken`, `X-Goog-Api-Client`, and `x-firebase-gmpid`. * Added state tracking for `_isFirstStreamMessage` and `_lastSentAuthToken`. * Integrated `onConnectionReady` to reset stream state flags. * Removed the `onAuthTokenChanged` method. * **packages/data-connect/test/unit/streamTransport.test.ts** * Added new unit tests for the `AbstractDataConnectStreamTransport` to verify the correct behavior of `_prepareMessage` regarding header and name attachment under various conditions.
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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

@stephenarosaj stephenarosaj changed the title Pasta/tortellini feat(data-connect): Add Message Preparation & Headers Mar 10, 2026
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 stateful message preparation for stream transports, adding logic to handle headers for authentication, telemetry, and connection handshakes. While the changes are generally well-tested, a critical security vulnerability was identified where the authentication state is not correctly cleared on the server upon client sign-out, potentially leading to session persistence.

Comment thread packages/data-connect/src/network/stream/streamTransport.ts
Comment thread packages/data-connect/src/network/stream/streamTransport.ts
@firebase firebase deleted a comment from gemini-code-assist Bot Mar 10, 2026
@firebase firebase deleted a comment from gemini-code-assist Bot Mar 10, 2026
@firebase firebase deleted a comment from gemini-code-assist Bot Mar 10, 2026
@firebase firebase deleted a comment from gemini-code-assist Bot Mar 10, 2026
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 some minor suggestions.

Comment thread packages/data-connect/src/network/stream/streamTransport.ts Outdated
Comment thread packages/data-connect/src/network/stream/streamTransport.ts Outdated
Comment thread packages/data-connect/src/network/stream/streamTransport.ts Outdated
* the stream.
*/
get connectorResourcePath(): string {
return `projects/${this._project}/locations/${this._location}/services/${this._serviceName}/connectors/${this._connectorName}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Optional: Consider generating this string in the constructor and saving it to a private variable. IIUC, its value will never change during the lifetime of the object, and saving its value to an instance variable communicates this clearly.

Comment thread packages/data-connect/test/unit/streamTransport.test.ts Outdated
@stephenarosaj stephenarosaj merged commit 7d150ac into pasta/main Mar 11, 2026
29 checks passed
@stephenarosaj stephenarosaj deleted the pasta/tortellini branch March 11, 2026 00:52
@firebase firebase locked and limited conversation to collaborators Apr 10, 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.

3 participants