Skip to content

ChannelServiceRoutes route result handling improvements - #452

Closed
Rodrigo Brandão (rodrigobr-msft) wants to merge 17 commits into
mainfrom
users/robrandao/general
Closed

ChannelServiceRoutes route result handling improvements#452
Rodrigo Brandão (rodrigobr-msft) wants to merge 17 commits into
mainfrom
users/robrandao/general

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request introduces several type safety improvements, error handling enhancements, and API behavior adjustments across the channel service and HTTP handling modules. The main focus is on making model serialization/deserialization more robust and explicit, improving type annotations for better static analysis, and ensuring more consistent API responses.

Type safety and serialization improvements:

  • Refactored the serialize_model and deserialize_from_body methods in ChannelServiceRoutes to use generic type variables and overloads, improving type safety and static analysis for model serialization and deserialization (_channel_service_routes.py). [1] [2] [3] [4]
  • Updated handler method signatures (e.g., get_activity_members, get_conversation_members, send_conversation_history, upload_attachment) to return more accurate types (list[dict] or dict | list[dict]), reflecting the actual API responses. [1] [2] [3] [4]

API consistency and response handling:

  • Changed methods like delete_activity and delete_conversation_member to return empty dictionaries instead of None, ensuring consistent JSON responses for DELETE endpoints (_channel_service_routes.py). [1] [2]
  • Updated the json_response function in the aiohttp route table to accept both dict and list[dict], supporting more flexible response types (channel_service_route_table.py).
  • Modified the accepted() static method in HttpResponse to explicitly set content_type=None, clarifying the response format for 202 Accepted responses (_http_response.py).

Error handling and initialization logic:

  • Improved initialization logic in HttpAdapterBase to enforce that either a channel_service_client_factory or a connection_manager must be provided, raising a clear error if neither is supplied (_http_adapter_base.py).

Copilot AI left a comment

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.

Pull request overview

This PR refines the channel service HTTP surface area by tightening typing for model (de)serialization and improving consistency/clarity in route and adapter behavior across the core hosting HTTP stack.

Changes:

  • Introduces generic, overloaded model serialization/deserialization helpers in ChannelServiceRoutes and updates several route handler return types to better reflect JSON payload shapes.
  • Adjusts DELETE route behavior in ChannelServiceRoutes to return an empty JSON object ({}) for more consistent JSON responses.
  • Improves HttpAdapterBase initialization validation and clarifies HttpResponseFactory.accepted() response metadata.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_http_response.py Tweaks the 202 Accepted factory to explicitly set content_type=None.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_http_adapter_base.py Refactors factory initialization/validation for clearer error handling.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/http/_channel_service_routes.py Adds typed (de)serialization helpers and updates multiple route handler return types and DELETE responses.
libraries/microsoft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/channel_service_route_table.py Broadens aiohttp json_response typing to support list payloads as well as dict payloads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copilot AI review requested due to automatic review settings July 9, 2026 18:55
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) marked this pull request as ready for review July 9, 2026 18:55

Copilot AI left a comment

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.

Pull request overview

Copilot reviewed 44 out of 45 changed files in this pull request and generated 3 comments.

Comment on lines +155 to +161
else:
res = re.match(item_service_url, service_url, re.IGNORECASE)
if res:
connection_name = item.get("CONNECTION")
connection = self.get_connection(connection_name)
if connection:
return connection
Comment on lines +119 to +122
if res:
return self.serialize_model(res)
else:
return {}
Comment on lines +110 to 112
async def delete_activity(self, request: HttpRequestProtocol) -> dict:
"""Handle DELETE /v3/conversations/{conversation_id}/activities/{activity_id}."""
conversation_id = request.get_path_param("conversation_id")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

4 participants