Repository navigation
Ensure headers get set when rest clients receive an aiohttp.ClientSession instance - #618
Conversation
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.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Connector and token-client tests do not exercise the caller-provided session regression addressed by the implementation.
Review effort: Balanced
Findings: 2
Open (2)
Resolved since last review (4)
clientis created inside thetryblock (line 977). IfConnectorClient(...)raises before… This note is now incorrect given the PR changes that setUser-AgentinMCSConnectorClient… This overwritesAccept/Content-Typeon a caller-providedClientSession. Since… Updatingsession.headersunconditionally will overwrite headers on a caller-provided…
…into users/robrandao/user-agent


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.