Skip to content

Python: reject unsupported Copilot provider function middleware - #10090

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:copilot-provider-middleware
Nov 5, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 2 commits into
microsoft:mainfrom
eavanvalkenburg:copilot-provider-middleware

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

The GitHub Copilot SDK owns its tool-calling loop. The adapter cannot apply Agent Framework function middleware supplied by a context provider, so it should reject that unsupported configuration rather than silently accept it.

The documentation also needs to distinguish SDK option forwarding from the lifetime of an existing service session. Changing MCP configuration is not an authoritative access check or a guarantee that capabilities already resident in a resumed session have been revoked.

Description & Review Guide

  • What are the major changes? Add a shared before-provider check that raises MiddlewareException for provider-contributed function middleware before SDK session creation or resumption and tool registration. Reuse the existing middleware categorizer for class-based, decorated, annotated, and bundled middleware. Add 56 parametrized regression cases covering both agent classes, response modes, session paths, per-run rechecking, and the same provider/tool behavior through normal Agent. Document the middleware limitation, MCP option precedence, service-session lifetime, and fresh-session usage in the package and consumer guidance.
  • What is the impact of these changes? Runs that supply unsupported provider function middleware now fail explicitly. Runs without it retain their existing tool behavior. This does not add function-middleware execution to the SDK loop, change core/Handoff behavior, or add MCP catalog invalidation. The session-lifetime clarification does not change runtime behavior.
  • What do you want reviewers to focus on? Check that unsupported middleware is rejected on every invocation before either SDK session path, including bundles and resumed sessions. Check that the documentation clearly separates configuration forwarding, persistent service state, and authoritative MCP service/tool authorization.

Commands run from python/:

Command Result
uv run --no-sync poe syntax -P github_copilot Passed: formatting and lint checks.
OTEL_SDK_DISABLED=true uv run --no-sync poe test -P github_copilot -C -m "not integration" Passed: 265 tests, 6 integration tests deselected, 96% package coverage.
uv run --no-sync poe pyright -P github_copilot Passed: 0 errors and 0 warnings.
uv run --no-sync poe test-typing -P github_copilot Passed: mypy, pyrefly, ty, zuban, and Pyright.
env -u OTEL_SDK_DISABLED OTEL_TRACES_EXPORTER=none OTEL_METRICS_EXPORTER=none OTEL_LOGS_EXPORTER=none uv run --no-sync python -m pytest -c packages/core/pyproject.toml packages/core/tests -m "not integration" -n 4 --dist worksteal --maxfail=1 Passed: 9,335 tests, 21 skipped, 2 expected failures.
uv run --no-sync --group tool-markdown python -m scripts.check_md_code_blocks packages/github_copilot/README.md ../skills/agent-framework-builder-python/references/extensibility.md ../skills/agent-framework-builder-python/references/integrations.md Passed.
uv build --package agent-framework-github-copilot Passed: wheel and source distribution built.

Live Copilot CLI/MCP integration tests were not run.

Related Issue

N/A - maintainer-directed adapter correction and documentation clarification; no new public issue is required.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: implementation, regression tests, documentation, and this PR description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings November 4, 2026 10:14
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Nov 4, 2026

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.

🟢 Approval recommended

No active review issues block approval of the middleware-validation and MCP session-boundary changes.

No open issues 🎉

What changed in this PR

This PR makes the Python GitHub Copilot adapter explicitly reject provider-contributed function middleware that its SDK-owned tool loop cannot execute. It also clarifies that MCP configuration changes do not guarantee revocation of capabilities in resumed service sessions.

Changes:

  • Reject unsupported function middleware before SDK session creation, resumption, or tool registration.
  • Add parametrized regression coverage for middleware forms, agent classes, response modes, session paths, and per-run validation.
  • Document middleware limitations, MCP option precedence, authorization boundaries, and fresh-session usage.
File Description
skills/​agent-framework-builder-python/​references/​integrations.md Clarifies MCP authorization and fresh-session guidance.
skills/​agent-framework-builder-python/​references/​extensibility.md Documents the Copilot function-middleware limitation.
python/​packages/​github_copilot/​tests/​test_github_copilot_agent.py Adds rejection, per-run validation, and standard Agent comparison tests.
python/​packages/​github_copilot/​tests/​conftest.py Adds shared middleware, provider, and client fixtures.
python/​packages/​github_copilot/​README.md Explains middleware support and MCP session lifetime.
python/​packages/​github_copilot/​agent_framework_github_copilot/​_agent.py Adds provider middleware validation and updates API documentation.

Review effort: Balanced

@github-actions github-actions Bot 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.

MAF Automated Review — Iteration 1

Result: No findings
Scope: full PR (1 commit(s)): ef857d50ac75
Model: gpt-5.6-sol

Overview

The change adds a per-invocation guard that rejects provider-contributed function middleware before either Copilot SDK session path or provider tool registration. Shared middleware categorization covers class-based, decorated, annotated, and bundled middleware, while parametrized tests exercise both agent classes, response modes, new and resumed sessions, and repeated runs. No PR-introduced Critical, High, or Medium issue remained after reconciliation.

Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.

Merged via the queue into microsoft:main with commit 2d4cce8 Nov 5, 2026
52 checks passed
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) deleted the copilot-provider-middleware branch November 5, 2026 10:04

This branch was previously deployed

1 inactive deployment
github-app-auth — fb9990bd Deployed Nov 4, 2026 by eavanvalkenburg via add_label #27127
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants