Skip to content

Python: compose GitHub Copilot session hooks correctly - #9649

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
mainfrom
msrc-144435
Oct 23, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
mainfrom
msrc-144435

Conversation

@eavanvalkenburg

Copy link
Copy Markdown
Member

Motivation & Context

GitHub Copilot sessions can combine caller-configured lifecycle hooks with Agent Framework's default tool-approval hook. Hook composition should preserve unrelated caller hooks without changing the established precedence of a caller-provided on_pre_tool_use handler.

Description & Review Guide

  • What are the major changes? Compose the default approval hook with unrelated SDK session hooks, type the merged hook dictionary as SessionHooks, and extend the existing forwarding regression test across streaming and non-streaming runs.
  • What is the impact of these changes? Existing custom on_pre_tool_use handlers retain precedence, while other lifecycle hooks no longer replace provider-managed approval behavior.
  • What do you want reviewers to focus on? The hook-precedence rules and the narrowness of the composition change.

Related Issue

N/A - privately tracked security issue. Public issue details are intentionally omitted.

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 refinement, regression tests, documentation, and 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.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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

The narrow change preserves hook precedence and approval behavior, with regression coverage for both run modes and no identified blocking issues.

No open issues 🎉

What changed in this PR

This PR fixes GitHub Copilot session-hook composition so unrelated caller hooks no longer suppress Agent Framework’s default tool-approval hook.

Changes:

  • Preserve caller-provided on_pre_tool_use precedence while merging unrelated hooks with default approval behavior.
  • Type the merged hook dictionary as SessionHooks and document the composition rules.
  • Extend the forwarding regression test to verify approval decisions in streaming and non-streaming runs.
File Description
python/​packages/​github_copilot/​tests/​test_github_copilot_agent.py Tests unrelated-hook preservation and default approval in both run modes.
python/​packages/​github_copilot/​README.md Documents preservation of unrelated session hooks.
python/​packages/​github_copilot/​agent_framework_github_copilot/​_agent.py Corrects hook composition while preserving custom pre-tool-use precedence.

Review effort: Balanced

@github-code-quality

Copy link
Copy Markdown
Contributor

Code coverage overview

Languages: Python

Python / code-coverage/python

main 3b725b3 msrc-144435 0341062 +/-
92% 92% 0%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.

@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)): 034106253689
Model: gpt-5.6-sol

Overview

The change composes unrelated caller session hooks with the framework-managed approval hook while preserving caller on_pre_tool_use precedence. A fresh typed hook dictionary, deny-by-default permission handling, deprecated-path guards, and parameterized streaming/non-streaming coverage constrain the changed behavior. No publishable Critical, High, or Medium defect was established.

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.

@jpalvarezl Jose Alvarez (jpalvarezl) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the hook composition, session creation and resumption paths, sync/async callback contract, approval precedence, deprecated callback compatibility, and streaming/non-streaming regression coverage. No blocking issues found.

Merged via the queue into main with commit ea32b6d Oct 23, 2026
62 of 64 checks passed

This branch was successfully deployed

1 active deployment
github-app-auth — 03410625 Deployed Oct 23, 2026 by eavanvalkenburg via team_check #7337
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.

3 participants