Basic stress testing and JWT/MSAL usage optimizations#175
Conversation
…into users/robrandao/optimizations
There was a problem hiding this comment.
Pull Request Overview
Introduces a benchmarking tool and async/MSAL/JWT authentication adaptations.
- Adds a new dev/benchmark suite with coroutine and thread executors, token generation, and aggregation utilities plus docs and env templates.
- Updates MSAL auth flows to run blocking calls in threads; converts JWT token validation to async.
- Adjusts dev dependencies (adds click) and provides Windows free-threaded Python setup docs.
Reviewed Changes
Copilot reviewed 21 out of 22 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/authentication_msal/test_msal_auth.py | Removes now-invalid mocking after refactoring client creation to set internal state instead of returning a client. |
| tests/_common/testing_objects/mocks/mock_msal_auth.py | Adapts mock to new _create_client_application side-effect pattern. |
| jwt_token_validator.py | Converts token validation to async and introduces JWKS client caching helpers. |
| jwt_authorization_middleware.py | Awaits new async validate_token API. |
| msal_auth.py | Adds async wrappers for client credential and OBO flows; refactors client creation to retain instance. |
| dev_dependencies.txt | Adds click for CLI benchmarking tool. |
| dev/benchmark/src/payload_sender.py | Adds payload sender factory with token injection. |
| dev/benchmark/src/main.py | CLI entry point for running benchmarks. |
| dev/benchmark/src/generate_token.py | Adds Azure AD client credential token generation utilities. |
| dev/benchmark/src/executor/thread_executor.py | Thread-based executor implementation. |
| dev/benchmark/src/executor/executor.py | Base executor abstraction and timing wrapper. |
| dev/benchmark/src/executor/execution_result.py | Data class representing execution outcome. |
| dev/benchmark/src/executor/coroutine_executor.py | Asyncio-based executor implementation. |
| dev/benchmark/src/executor/init.py | Re-exports executor components. |
| dev/benchmark/src/config.py | Environment-based benchmark configuration loader (naming inconsistency). |
| dev/benchmark/src/aggregated_results.py | Aggregation and display of execution metrics. |
| dev/benchmark/requirements.txt | Requirements for benchmarking tool. |
| dev/benchmark/payload.json | Sample activity payload for benchmarking. |
| dev/benchmark/env.template | Template for required environment variables. |
| dev/benchmark/README.md | Documentation for benchmarking and free-threaded Python setup. |
| dev/README.md | High-level developer tools overview. |
Comments suppressed due to low confidence (1)
dev/benchmark/src/generate_token.py:1
- Docstring references Direct Line token and secret, but this function requests an Azure AD client credential token against tenant OAuth2 endpoint. Update wording to reflect Azure AD client credentials flow.
import requests
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/jwt_token_validator.py
Show resolved
Hide resolved
...aries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/jwt_token_validator.py
Show resolved
Hide resolved
...aries/microsoft-agents-authentication-msal/microsoft_agents/authentication/msal/msal_auth.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated 9 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/jwt_token_validator.py
Show resolved
Hide resolved
...soft-agents-hosting-aiohttp/microsoft_agents/hosting/aiohttp/jwt_authorization_middleware.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
...osoft-agents-hosting-core/microsoft_agents/hosting/core/authorization/jwt_token_validator.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 21 out of 22 changed files in this pull request and generated no new comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…into users/robrandao/optimizations
…into users/robrandao/optimizations
…crosoft/Agents-for-python into users/robrandao/optimizations
This pull request introduces a new benchmarking tool for the Microsoft 365 Agents SDK for Python, including documentation, configuration templates, and a modular implementation for concurrent benchmarking using threads or asyncio. It also includes an update to the MSAL authentication library to avoid blocking the event loop by running synchronous MSAL calls in a thread. The most important changes are grouped below.
This pull request introduces a new Python benchmarking tool for the Microsoft 365 Agents SDK and adds async support for MSAL authentication. The changes include new documentation, configuration templates, and a modular benchmarking suite capable of running concurrent requests to an agent using either threads or coroutines. Additionally, the MSAL authentication library is updated to avoid blocking the event loop by running synchronous MSAL methods in a separate thread.
New Benchmarking Tool
dev/benchmarkdirectory with a modular benchmarking suite:CoroutineExecutor,ThreadExecutor,Executor,ExecutionResult) and aggregation of results (AggregatedResults). [1] [2] [3] [4] [5]main.py) usingclickfor configuration, and a payload sender supporting authentication token generation. [1] [2] [3]env.template), requirements (requirements.txt), and payload (payload.json) files. [1] [2] [3]clickto development dependencies.MSAL Authentication Improvements
Updated
MsalAuthinmsal_auth.pyto support async token acquisition:asyncio.to_threadto run synchronous MSAL methods in a thread, preventing event loop blocking. [1] [2] [3]asyncioand initializes the MSAL auth client in the constructor. [1] [2]Benchmarking Tool Implementation:
Added a new
dev/benchmarkdirectory containing a Python benchmarking tool with modular executors (CoroutineExecutor,ThreadExecutor), result aggregation, token generation, and payload sending utilities. This enables concurrent benchmarking of agent endpoints using threads or asyncio. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]Added supporting files:
requirements.txt,env.template, and a samplepayload.jsonfor configuration and demonstration. [1] [2] [3]Documentation:
dev/README.mdanddev/benchmark/README.md, including setup instructions for running the benchmark tool, especially for Windows and Python 3.13+ free-threaded versions. [1] [2]Dependency Updates:
dev_dependencies.txtto includeclickfor CLI support in the benchmarking tool.MSAL Authentication Improvements:
MsalAuthinmsal_auth.pyto run synchronous MSAL token acquisition methods in a separate thread usingasyncio.to_thread, preventing event loop blocking in async contexts. This affects bothget_access_tokenandacquire_token_on_behalf_ofmethods. [1] [2] [3] [4] [5]