Ensure headers get set when rest clients receive an aiohttp.ClientSession instance - #618
Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 1 commit into
Draft
Rodrigo Brandão (rodrigobr-msft) wants to merge 1 commit into
Rodrigo Brandão (rodrigobr-msft) wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (4)
clientis created inside thetryblock (line 977). IfConnectorClient(...)raises before… · New Updatingsession.headersunconditionally will overwrite headers on a caller-provided… · New This overwritesAccept/Content-Typeon a caller-providedClientSession. Since… · New This note is now incorrect given the PR changes that setUser-AgentinMCSConnectorClient… · New
What changed in this PR
This PR standardizes outbound HTTP User-Agent headers across core connector clients by using get_product_info() and adds tests to verify the header is set and sent on requests.
Changes:
- Updated
ConnectorClient,UserTokenClient, andMCSConnectorClientinitialization to apply standardized headers (includingUser-Agent) toaiohttp.ClientSession. - Added tests validating
User-Agentis present on the session and transmitted on requests for Connector/UserToken/MCS clients. - Expanded connector test suite coverage to include
TeamsConnectorClientUser-Agentbehavior.
| File | Description |
|---|---|
| tests/hosting_core/connector/test_user_token_client.py | Adds assertions that UserTokenClient sets/sends standardized User-Agent. |
| tests/hosting_core/connector/test_mcs_connector_client.py | Introduces new tests verifying MCSConnectorClient User-Agent behavior. |
| tests/hosting_core/connector/test_connector_client.py | Adds User-Agent tests for ConnectorClient and TeamsConnectorClient. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/mcs/mcs_connector_client.py | Ensures MCSConnectorClient session includes standardized default headers including User-Agent. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/user_token_client.py | Applies headers to session after creation to ensure consistency even with provided sessions. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/client/connector_client.py | Applies headers to session after creation to ensure consistency even with provided sessions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+981
to
+983
| finally: | ||
| await server.close() | ||
| await client.client.close() |
Comment on lines
+792
to
+793
| session = session or ClientSession(base_url=endpoint) | ||
| session.headers.update(headers) |
Comment on lines
+228
to
+233
| headers = { | ||
| "Accept": "application/json", | ||
| "Content-Type": "application/json", | ||
| "User-Agent": get_product_info(), | ||
| } | ||
| self._client.headers.update(headers) |
Comment on lines
+16
to
+22
| """Ensures MCSConnectorClient sends a User-Agent header. | ||
|
|
||
| NOTE: Unlike ConnectorClient/TeamsConnectorClient and UserTokenClient, | ||
| MCSConnectorClient does not currently set a custom "agents-sdk-py" User-Agent | ||
| header on its session or outgoing requests, so these tests currently fail. | ||
| """ | ||
|
|
Copilot started reviewing on behalf of
Rodrigo Brandão (rodrigobr-msft)
October 2, 2026 19:38
View session
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.


This pull request ensures that all core connector clients in the Microsoft Agents Hosting Core library consistently set and send a standardized
User-Agentheader, as returned byget_product_info(), with every outgoing HTTP request. It also adds comprehensive tests to verify this behavior forConnectorClient,TeamsConnectorClient,UserTokenClient, andMCSConnectorClient.User-Agent header standardization:
ConnectorClientandUserTokenClientto set headers (includingUser-Agent) after session creation, ensuring consistent header application. (connector_client.py[1]user_token_client.py[2]MCSConnectorClientto set default headers withUser-Agenton its session during initialization. (mcs_connector_client.pylibraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/connector/mcs/mcs_connector_client.pyR228-R234)get_product_info()for theUser-Agentvalue. (mcs_connector_client.py[1]test_connector_client.py[2]test_user_token_client.py[3]Testing improvements:
ConnectorClient,TeamsConnectorClient, andUserTokenClientset and send the correctUser-Agentheader on all requests. (test_connector_client.py[1]test_user_token_client.py[2]MCSConnectorClientsets and sends the correctUser-Agentheader (noting that these tests currently fail if the header is not set). (test_mcs_connector_client.pytests/hosting_core/connector/test_mcs_connector_client.pyR1-R55)These changes improve observability and consistency across all connector clients by ensuring a uniform
User-Agentis present in all outgoing requests.