Skip to content

Middleware Set bug fixes, simplification, and testing#453

Closed
rodrigobr-msft wants to merge 11 commits into
mainfrom
users/robrandao/middleware-set
Closed

Middleware Set bug fixes, simplification, and testing#453
rodrigobr-msft wants to merge 11 commits into
mainfrom
users/robrandao/middleware-set

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

The class previously was breaking in a couple of ways, and the API was a bit polluted.

Copilot AI review requested due to automatic review settings July 9, 2026 18:25
@rodrigobr-msft rodrigobr-msft linked an issue Jul 9, 2026 that may be closed by this pull request

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 refactors MiddlewareSet to simplify the middleware API surface, fixes registration behavior, updates ChannelAdapter to use the simplified entrypoint, and adds a dedicated test suite to validate MiddlewareSet behavior.

Changes:

  • Refactor MiddlewareSet to remove older “receive_*” APIs and consolidate behavior into on_turn.
  • Update ChannelAdapter.run_pipeline to invoke the middleware pipeline via MiddlewareSet.on_turn.
  • Add a new test module covering middleware registration, ordering, nesting, and error propagation.

Reviewed changes

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

File Description
tests/hosting_core/test_middleware_set.py Adds new unit tests defining expected middleware pipeline behavior.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/middleware_set.py Refactors middleware pipeline execution and use() registration semantics.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/channel_adapter.py Switches pipeline execution to MiddlewareSet.on_turn.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/init.py Exports MiddlewareSet from the hosting core package.

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

Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Copilot AI review requested due to automatic review settings July 9, 2026 18:39

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 5 out of 5 changed files in this pull request and generated 8 comments.

Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Copilot AI review requested due to automatic review settings July 9, 2026 18:46

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 5 out of 5 changed files in this pull request and generated 8 comments.

Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Comment thread tests/hosting_core/test_middleware_set.py
Copilot AI review requested due to automatic review settings July 10, 2026 15:41
@rodrigobr-msft
rodrigobr-msft marked this pull request as ready for review July 10, 2026 15:41
@rodrigobr-msft
rodrigobr-msft requested a review from a team as a code owner July 10, 2026 15:41

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_logger.py:120

  • The updated implementation awaits the next step as logic(context), but the docstring for :param logic: still reads like a parameterless callback and doesn't mention it can be None. This can confuse middleware authors and users reading the docs.
        """Initialization for middleware.
        :param context: Context for the current turn of conversation with the user.
        :param logic: Function to call at the end of the middleware chain.
        """

Copilot AI review requested due to automatic review settings July 10, 2026 18:21

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 6 out of 6 changed files in this pull request and generated 3 comments.

Comment thread tests/hosting_core/storage/test_transcript_logger_middleware.py
Copilot AI review requested due to automatic review settings July 10, 2026 18:29

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 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_logger.py:120

  • TranscriptLoggerMiddleware.on_turn() now accepts logic as optional (... | None), but the docstring still describes it as a required function. This can confuse middleware authors/callers.
        """Initialization for middleware.
        :param context: Context for the current turn of conversation with the user.
        :param logic: Function to call at the end of the middleware chain.
        """

Comment on lines 234 to 236
:param callback: A callback method to run at the end of the pipeline.
:type callback: Callable[[TurnContext], Awaitable]
:return: Result produced by the middleware pipeline.
:rtype: typing.Any
"""
Copilot AI review requested due to automatic review settings July 10, 2026 18:34

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 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +90 to +92
await self._receive_activity_internal(context, None)
if logic:
await logic(context)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MiddlewareSet revisions needed

2 participants