OAuth continuation fix#468
Closed
rodrigobr-msft wants to merge 14 commits into
Closed
Conversation
…into users/robrandao/oauth-continuation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors how OAuth continuation activities are replayed by queueing the replay asynchronously, improves logging and handling of OAuth sign-in completion responses, and reduces transcript log noise by omitting unset fields during JSON serialization.
Changes:
- Queue OAuth continuation replays via a new
_queue_auth_continuation()/_replay_auth_continuation()flow with failure logging callback. - Send an explicit
invoke_responsewhen the OAuth sign-in flow completes successfully. - Serialize transcript activities with
exclude_unset=True(currently applied to console transcript logging).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/agent_application.py | Adds async queuing/replay for OAuth continuation activities plus failure logging. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/app/oauth/_handlers/_user_authorization.py | Adds a success log + invoke response when the sign-in flow completes. |
| libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/storage/transcript_logger.py | Reduces console transcript JSON verbosity by excluding unset fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rodrigobr-msft
marked this pull request as ready for review
July 15, 2026 17:34
Comment on lines
+323
to
+324
| :param context: The context object for the current turn. | ||
| :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext` | ||
| :type context: :class:`microsoft_agents.hosting.core.turn_context.TurnContext |
Comment on lines
+341
to
+346
| return _AuthInterceptResult( | ||
| should_skip_turn=context.activity.type | ||
| == ActivityTypes.invoke, | ||
| should_replay=True, | ||
| continuation_activity=None, | ||
| ) |
Comment on lines
+233
to
+240
| elif flow_state.tag == _FlowStateTag.COMPLETE: | ||
| logger.info("Sign-in flow completed successfully.") | ||
| await context.send_activity( | ||
| Activity( | ||
| type=ActivityTypes.invoke_response, | ||
| value=InvokeResponse(status=200), | ||
| ) | ||
| ) |
Comment on lines
+1023
to
+1029
| if not context.identity: | ||
| logger.error( | ||
| "Cannot replay turn because context.identity is not set. Ensure that the adapter is configured to set the identity." | ||
| ) | ||
| raise ApplicationError( | ||
| "Cannot replay turn because context.identity is not set. Ensure that the adapter is configured to set the identity." | ||
| ) |
| __replay_turn, | ||
| ) | ||
|
|
||
| context.activity = act |
Comment on lines
+1049
to
+1056
| def __log_task_result(task: asyncio.Task): | ||
| try: | ||
| task.result() | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Error occurred while replaying the turn.", | ||
| exc_info=True, | ||
| ) |
Comment on lines
+1041
to
+1045
| await self._adapter.continue_conversation_with_claims( | ||
| context.identity, | ||
| act, | ||
| __replay_turn, | ||
| ) |
Comment on lines
+718
to
+721
| res = await authorization._on_turn_auth_intercept(context, auth_handler_id) | ||
|
|
||
| assert continuation_activity == old_activity | ||
| assert intercepts | ||
| assert res.continuation_activity == old_activity | ||
| assert res.should_skip_turn |
| assert intercepts | ||
| assert res.continuation_activity == old_activity | ||
| assert res.should_skip_turn | ||
| assert not res.should_replay |
Comment on lines
+1031
to
+1037
| async def __replay(act: Activity): | ||
|
|
||
| await self._adapter.continue_conversation_with_claims( | ||
| context.identity, | ||
| act, | ||
| __replay_turn, | ||
| ) |
Comment on lines
+1039
to
+1046
| def __log_task_result(task: asyncio.Task): | ||
| try: | ||
| task.result() | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Error occurred while replaying the turn.", | ||
| exc_info=True, | ||
| ) |
Comment on lines
339
to
+343
| if not sign_in_state: | ||
| # flow just completed, no continuation activity | ||
| return False, None | ||
| is_invoke = context.activity.type == ActivityTypes.invoke | ||
| return _AuthInterceptResult( | ||
| should_skip_turn=is_invoke, |
Comment on lines
+1025
to
+1027
| for key, val in context.turn_state.items(): | ||
| if replay_context.turn_state.get(key, None) is None: | ||
| replay_context.turn_state[key] = val |
Comment on lines
+1039
to
+1046
| def __log_task_result(task: asyncio.Task): | ||
| try: | ||
| task.result() | ||
| except Exception as e: | ||
| logger.error( | ||
| f"Error occurred while replaying the turn.", | ||
| exc_info=True, | ||
| ) |
Comment on lines
+1018
to
+1022
| async def _handle_turn_skip( | ||
| self, context: TurnContext, turn_state: StateT, result: _AuthInterceptResult | ||
| ): | ||
| """Handle the case where the turn should be skipped due to an auth intercept result.""" | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces improvements to how OAuth continuation activities are handled and queued, adds better logging for user authorization flows, and refines activity logging in transcripts. The main changes focus on making authentication flows more robust and observable, especially in scenarios involving asynchronous operations and error handling.
OAuth Continuation Handling and Robustness:
agent_application.pyto use a new_queue_auth_continuationmethod. This now queues the continuation asynchronously, improving reliability and decoupling the flow from the current turn context. Errors during replay are now logged via a dedicated callback. [1] [2]_queue_auth_continuation,_replay_auth_continuation, and_log_auth_continuation_failureto encapsulate the queuing, replay, and error logging of authentication continuations. This also includes proper handling for adapters with claims support.asyncioto enable asynchronous task creation for continuation activities.User Authorization Flow Logging:
Transcript Logging Improvements: