Skip to content

Fixing linting issues in hosting/core/app - #488

Merged
Rodrigo Brandão (rodrigobr-msft) merged 4 commits into
mainfrom
users/robrandao/linter-app
Jul 22, 2026
Merged

Fixing linting issues in hosting/core/app#488
Rodrigo Brandão (rodrigobr-msft) merged 4 commits into
mainfrom
users/robrandao/linter-app

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and refactorings across the authentication, agent application, and streaming components. The main focus is on improving type safety and error handling, modernizing type hints, and clarifying the initialization and configuration logic. Additionally, some deprecated methods are flagged, and logging is enhanced for better debugging.

Agent Application and State Management:

  • Refactored type annotations throughout agent_application.py to use modern union syntax (e.g., Type | None), improving code clarity and type safety.
  • Ensured consistent usage of the _storage attribute instead of repeatedly accessing self._options.storage, reducing potential errors and code duplication. [1] [2] [3] [4]
  • Changed the default turn state factory to use the generic StateT type, and renamed the setter method to set_turn_state_factory for clarity. [1] [2]
  • Marked parse_env_vars_configuration as deprecated, guiding users to a new method for loading configuration from the environment.

OAuth and Authorization Handling:

  • Improved error handling in OAuth flow: now raises explicit exceptions if required objects (e.g., UserTokenClient, ClaimsIdentity with 'aud' claim) are missing in the turn state, preventing subtle bugs. [1] [2]
  • Added validation to require auth_handler_settings if no auth_handler is provided during authorization handler construction.
  • Updated method signatures to use modern type hints for optional parameters (e.g., str | None instead of Optional[str]). [1] [2] [3]
  • In agentic authorization, added explicit checks and error logging for missing tenant IDs, improving debuggability and robustness. [1] [2]
  • Ensured that a TokenResponse object is always returned (never None) to standardize downstream handling.

Streaming Response Improvements:

  • Added TYPE_CHECKING imports and improved type annotations for TurnContext in streaming_response.py, enhancing static analysis and code clarity. [1] [2] [3] [4]

These changes collectively improve maintainability, type safety, and error transparency across the codebase.

Copilot AI review requested due to automatic review settings July 22, 2026 15:51

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 parts of the hosting-core app layer (routing/state initialization), OAuth authorization handlers, and streaming response helpers to improve type safety (modern union syntax), strengthen runtime validation in OAuth flows, and standardize token-return behavior.

Changes:

  • Modernized type annotations across app/OAuth/streaming components (e.g., T | None, TYPE_CHECKING usage).
  • Hardened OAuth flow handling by validating required turn-state objects (e.g., UserTokenClient, ClaimsIdentity.aud) and adding clearer error paths/logging for missing agentic tenant IDs.
  • Standardized token handling so OAuth helper methods return TokenResponse objects instead of None.

Reviewed changes

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

Show a summary per file
File Description
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/streaming/streaming_response.py Adds TYPE_CHECKING-based typing improvements for TurnContext references in streaming response handling.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/connector_user_authorization.py Standardizes OBO helper to always return a TokenResponse.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/agentic_user_authorization.py Adds explicit tenant-id validation + logging for agentic token retrieval.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py Improves runtime validation for required OAuth turn-state keys and modernizes optional typing syntax.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/_authorization_handler.py Enforces presence of auth_handler_settings when constructing a handler from settings.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py Refactors state factory/storage usage, adds deprecation marker for env var parsing helper, and modernizes type hints.

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

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

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

Comment thread tests/hosting_core/app/_oauth/_handlers/test_connector_user_authorization.py Outdated
Copilot AI review requested due to automatic review settings July 22, 2026 16:15

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

Comments suppressed due to low confidence (1)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py:801

  • turn_state_factory appears to have been renamed to set_turn_state_factory. If turn_state_factory was part of the public fluent/decorator API, this is a breaking change for existing consumers. Consider keeping turn_state_factory as a deprecated alias that forwards to set_turn_state_factory to preserve backwards compatibility while still guiding users to the new name.
    def set_turn_state_factory(self, func: Callable[[], StateT]):
        """
        Custom Turn State Factory
        """
        logger.debug(f"Setting custom turn state factory: {func.__name__}")

Copilot AI review requested due to automatic review settings July 22, 2026 17:34
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit 2fa4ef9 into main Jul 22, 2026
17 of 18 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/linter-app branch July 22, 2026 17:37

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

Comments suppressed due to low confidence (1)

libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py:803

  • Renaming the public AgentApplication.turn_state_factory decorator to set_turn_state_factory is a breaking API change for existing callers (even if internal uses were updated). Consider keeping a deprecated turn_state_factory shim that forwards to set_turn_state_factory, and add explicit return type annotations so decorator-style usage stays type-safe.
    def set_turn_state_factory(self, func: Callable[[], StateT]):
        """
        Custom Turn State Factory
        """
        logger.debug(f"Setting custom turn state factory: {func.__name__}")
        self._turn_state_factory = func
        return func

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.

3 participants