Python: Make workspace file hooks opt-in for GitHubCopilotAgent - #7517
Open
giles17 wants to merge 1 commit into
Open
Python: Make workspace file hooks opt-in for GitHubCopilotAgent#7517giles17 wants to merge 1 commit into
giles17 wants to merge 1 commit into
Conversation
Session behavior currently varies with the working directory the agent runs in, because the CLI picks up file hook definitions from the checkout. Give `enable_file_hooks` an explicit default of False in `_build_session_kwargs` so a session behaves consistently regardless of the checkout, and let callers opt in through `default_options` or per-run options. Add the option to `GitHubCopilotOptions` with documentation, and cover the default, the opt-in, and the per-run override with tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42d0b850-56e0-4346-9b3e-cc3de339b16b
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
This PR makes GitHubCopilotAgent session behavior deterministic across working directories by explicitly defaulting workspace-driven Copilot SDK session options (starting with enable_file_hooks) to opt-in, preventing implicit .github/hooks/ influence unless callers request it.
Changes:
- Add a module-level
_WORKSPACE_CONFIG_DEFAULTSmap and apply its defaults in_build_session_kwargswhen the resolved option value isNone. - Document
enable_file_hooksas a supportedGitHubCopilotOptionskey and explain the opt-in behavior and security considerations. - Update and add unit tests to validate the new default and precedence rules (runtime options override agent defaults).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| python/packages/github_copilot/agent_framework_github_copilot/_agent.py | Introduces _WORKSPACE_CONFIG_DEFAULTS, documents enable_file_hooks, and applies an explicit default in session kwargs construction. |
| python/packages/github_copilot/tests/test_github_copilot_agent.py | Updates strict resume-session assertion and adds tests covering default/off + override precedence for enable_file_hooks. |
| python/packages/github_copilot/README.md | Documents workspace-driven options and how to opt into enable_file_hooks. |
| python/packages/github_copilot/AGENTS.md | Records the convention for session option defaults and where to add future workspace-driven defaults. |
giles17
marked this pull request as ready for review
August 4, 2026 20:56
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.
Motivation & Context
GitHubCopilotAgentsession behavior depends on which working directory the agent runs in. The Copilot CLI loads file hooks from a checkout's.github/hooks/, controlled by the SDKenable_file_hookssession option, and the agent never sets it, so it inherits the runtime default.That makes runs harder to reason about and reproduce: the same agent, the same options, and the same prompt can behave differently based only on the directory the process started in. It is also invisible to callers, since it sits outside the small set of options the agent gives an explicit default.
Description & Review Guide
What are the major changes?
_build_session_kwargsnow applies an explicit default forenable_file_hooks(False), alongside the existingon_permission_requestdefault. The defaults live in a module-level_WORKSPACE_CONFIG_DEFAULTSmap so future additions have one home.None, so an explicitTrueorFalsefrom eitherdefault_optionsor per-run options is preserved.enable_file_hooksis now a documentedGitHubCopilotOptionskey.AGENTS.mdrecords the convention.What is the impact of these changes?
.github/hooks/definitions being picked up automatically needenable_file_hooks=Trueindefault_optionsor per-run options. Nothing else on the wire changes, and theon_permission_request/on_pre_tool_usepaths are untouched.enable_host_git_operations, are deliberately left alone so prompt quality is unaffected.assert_called_once_withonresume_sessionand needed the new kwarg added; that is a strict-matcher update, not a behavior change.What do you want reviewers to focus on?
Falseis the right default forenable_file_hooks, and whether the opt-in path reads clearly in the README.Related Issue
Fixes #7516
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.