Python: [BREAKING] Make workspace file hooks opt-in for GitHubCopilotAgent - #7517
Open
giles17 wants to merge 3 commits into
Open
Python: [BREAKING] Make workspace file hooks opt-in for GitHubCopilotAgent#7517giles17 wants to merge 3 commits into
giles17 wants to merge 3 commits 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
moonbox3
reviewed
Aug 5, 2026
Address review feedback: with only one workspace-controlled option, the _WORKSPACE_CONFIG_DEFAULTS map and its loop are more machinery than needed. Inline the default as a single conditional in _build_session_kwargs and move the explanatory comment with it. No behavior change: the same key resolves to the same value at the same point, and callers can still opt in through default_options or per-run options. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 42d0b850-56e0-4346-9b3e-cc3de339b16b
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.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?
This is a breaking change to a stable package, and is marked as such. Sessions no longer pick up
.github/hooks/definitions from the working directory by default.Migration: callers who rely on repository file hooks should set
enable_file_hooks=Trueindefault_options(or per-run options):Nothing else on the wire changes, and the
on_permission_request/on_pre_tool_usepaths are untouched.Options that only shape prompt context, such as
enable_host_git_operations, are deliberately left alone so prompt quality is unaffected.One existing test used
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?
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.