Skip to content

Add force_base_channel support to conversation references for Copilot Web OAuth flows#392

Open
Copilot wants to merge 6 commits into
mainfrom
copilot/add-force-base-channel-option
Open

Add force_base_channel support to conversation references for Copilot Web OAuth flows#392
Copilot wants to merge 6 commits into
mainfrom
copilot/add-force-base-channel-option

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 13, 2026

M365 Copilot Web can send composite channelId values (for example, msteams:copilot-web), but OAuth token exchange must use the base channel. This change ports the .NET behavior by adding an opt-in base-channel mode and wiring OAuth flow state construction to use it.

  • Activity conversation reference API

    • Extended Activity.get_conversation_reference() with optional force_base_channel: bool | None = None.
    • When enabled, the method emits the base channel by splitting on the first : (preserving existing behavior when unset/false).
  • OAuth flow token-exchange path

    • Updated _OAuthFlow.begin_flow() to build TokenExchangeState.conversation with:
      • activity.get_conversation_reference(force_base_channel=True)
    • This ensures token exchange uses channel-compatible conversation metadata for Copilot Web traffic.
  • Focused coverage for new behavior

    • Added/updated tests to cover:
      • base-channel extraction for composite and multi-segment channel IDs
      • non-forced behavior retaining full channel ID
      • OAuth flow invocation using force_base_channel=True
# activity.py
conversation = activity.get_conversation_reference(force_base_channel=True)
# "msteams:copilot-web" -> "msteams"

Copilot AI self-assigned this May 13, 2026
Copilot AI review requested due to automatic review settings May 13, 2026 22:00
Copilot AI review requested due to automatic review settings May 13, 2026 22:00
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 22:04
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 22:07
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 22:08
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 22:10
Copilot AI requested review from Copilot and removed request for Copilot May 13, 2026 22:11
Copilot AI changed the title [WIP] Add force_base_channel option to get_conversation_reference Add force_base_channel support to conversation references for Copilot Web OAuth flows May 13, 2026
Copilot AI requested a review from MattB-msft May 13, 2026 22:12
@MattB-msft MattB-msft requested a review from axelsrz May 13, 2026 22:17
axelsrz
axelsrz previously approved these changes May 14, 2026
@axelsrz axelsrz marked this pull request as ready for review May 14, 2026 00:07
@axelsrz axelsrz requested a review from a team as a code owner May 14, 2026 00:07
Copilot AI review requested due to automatic review settings May 14, 2026 00:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds opt-in base-channel conversation references so OAuth state can handle composite Copilot Web channel IDs.

Changes:

  • Added force_base_channel to Activity.get_conversation_reference().
  • Updated OAuth flow state construction to request a base-channel conversation reference.
  • Added focused tests for base-channel extraction and OAuth usage.

Reviewed changes

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

File Description
libraries/microsoft-agents-activity/microsoft_agents/activity/activity.py Adds base-channel extraction support to conversation references.
libraries/microsoft-agents-hosting-core/microsoft_agents/hosting/core/_oauth/_oauth_flow.py Uses the new option when building OAuth token exchange state.
tests/activity/test_activity.py Adds tests for forced and non-forced channel reference behavior.
tests/hosting_core/_oauth/test_oauth_flow.py Updates OAuth test setup and verifies the forced-base call is made.

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

Comment thread tests/activity/test_activity.py
Comment thread tests/hosting_core/_oauth/test_oauth_flow.py
Copilot AI review requested due to automatic review settings May 14, 2026 00:16
axelsrz
axelsrz previously approved these changes May 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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

Comments suppressed due to low confidence (1)

tests/hosting_core/_oauth/test_oauth_flow.py:250

  • TokenExchangeState does not expose a top-level channel_id; the channel lives under its conversation field. These assertions will raise AttributeError when the spy captures the state instance instead of validating the encoded state's conversation channel.
        encoded_state_instance = get_encoded_state_spy.call_args.args[0]
        assert encoded_state_instance.channel_id == base_channel_id
        assert encoded_state_instance.channel_id != composite_channel_id

token_exchange_state = TokenExchangeState(
connection_name=self._abs_oauth_connection_name,
conversation=activity.get_conversation_reference(),
conversation=activity.get_conversation_reference(force_base_channel=True),
Comment thread tests/hosting_core/_oauth/test_oauth_flow.py Outdated
@axelsrz axelsrz force-pushed the copilot/add-force-base-channel-option branch from bbac31c to 9f7cd18 Compare May 14, 2026 00:30
@MattB-msft MattB-msft enabled auto-merge (squash) May 14, 2026 00:42
@MattB-msft MattB-msft disabled auto-merge May 14, 2026 00:43
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.

Add force_base_channel option to get_conversation_reference for M365 Copilot Web OAuth

4 participants