Repository navigation
Python: keep Windows backslashes in LocalShellTool shell paths - #9858
Open
NingLin Liu (ninglinLiu) wants to merge 15 commits into
Open
NingLin Liu (ninglinLiu) wants to merge 15 commits into
NingLin Liu (ninglinLiu) wants to merge 15 commits into
Conversation
Fixes microsoft#9819 resolve_shell used shlex.split on string overrides, which treats \\ as an escape on every platform and turns C:\\Windows\\...\\powershell.exe into a mangled path. On win32, split without escape processing and only honour double quotes so unquoted Windows paths (and AGENT_FRAMEWORK_SHELL) work.
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 02:53 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
requested a review
from Darren Cohen (dargilco)
as a code owner
October 30, 2026 02:53
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 02:53 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Windows shell overrides mishandle partially quoted executable paths and quoted option values, while Windows-mocking tests fail on Linux/macOS because basename handling remains POSIX.
2 open issues
What changed in this PR
This PR addresses #9819 by preserving Windows backslashes in Python LocalShellTool string overrides while keeping POSIX parsing unchanged.
Changes:
- Adds platform-aware splitting for
shell=andAGENT_FRAMEWORK_SHELL. - Adds regression tests for unquoted Windows paths, environment overrides, and quoted paths containing spaces.
| File | Description |
|---|---|
python/packages/tools/tests/test_shell_resolve.py |
Adds Windows path and PowerShell flag regression tests. |
python/packages/tools/agent_framework_tools/shell/_resolve.py |
Introduces and applies platform-aware shell override parsing. |
Review effort: Balanced
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 08:38 — with
GitHub Actions
Inactive
Ruff escape-sequence-in-docstring failed Package Checks after the win32 shell-path fix; mark the docstring raw so ``\\`` examples are valid.
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 08:41 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 08:48 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 09:12 — with
GitHub Actions
Inactive
os.path.basename does not split on backslashes on Linux, so win32 path overrides in unit tests (and any cross-platform callers) were treated as non-PowerShell and got -c instead of -Command. Normalize separators before basename.
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 09:13 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 11:35 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 12:08 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 14:05 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 16:05 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 17:19 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 17:22 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 17:40 — with
GitHub Actions
Inactive
Adjacent quoted/unquoted path fragments and --flag="value with spaces" must stay one argv element; shlex(posix=False) was splitting them.
NingLin Liu (ninglinLiu)
temporarily deployed
to
github-app-auth
October 30, 2026 18:10 — with
GitHub Actions
Inactive
NingLin Liu (ninglinLiu)
deployed
to
github-app-auth
October 30, 2026 19:34 — with
GitHub Actions
Active
This branch was successfully deployed
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
LocalShellTool(shell=r"C:\Windows\...\powershell.exe")and unquotedAGENT_FRAMEWORK_SHELLpaths fail on Windows withFileNotFoundErrorbecauseresolve_shellusedshlex.split, which treats\as an escape and drops every backslash. The PowerShell-Commandflag is also missed after the path is mangled.Description & Review Guide
_split_shell_override: on win32, non-POSIXshlexthat keeps backslashes and only honours"..."quotes; elsewhere keepshlex.split.shell=argument andAGENT_FRAMEWORK_SHELL.CommandLineToArgvW-style double-quote handling.Related Issue
Fixes #9819
AI Assistance
AI assistance details: locating the
shlex.splitwin32 escape behaviour, implementing_split_shell_override, and writing the regression tests and this PR description.Contribution Checklist