Repository navigation
Add noninteractive, isolated Python environment tooling for agents - #1900
Conversation
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
|
Result: 🔴 Verification detailsVerification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Summary: [unavailable] Container verification could not start and local execution was not authorized for this PR HEAD: C:\Program Files\RedHat\Podman\podman.EXE --connection pyrx-automation failed: stderr: Error: unable to start container "051c6d0c6a956b5517c772b42aad7b236d7a17dac3df0c55d2d5c2bc0452f266": crun: open `memory.max` for writing: No such file or directory: OCI runtime attempted to invoke a command that was not found Test runs: none recorded. |
bb4e456 to
b463643
Compare
0d4c8ca to
69d9624
Compare
Expose a private versioned tool API for configuration, environment queries and package installation while preserving interactive public entry points. - Use isolation by default without selection-origin tracking. - Create project environments from selected base interpreters and protect global/base Python from tool-driven package installation. - Preserve scoped selections across reload and support existing cached Poetry/Pipenv environments and first-use enabled PEP 723 scripts. - Propagate cancellation, process-cleanup failures and actionable errors without interactive fallback. - Add unit, compatibility and cross-platform regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Share full public initialization between direct calls and the fast path. Invalidate the completed discovery snapshot if the later base preparation fails, and clear failed direct initialization so the next lookup retries. Resolve the captured deferred so existing waiters are released safely. Keep successful initialization cached and private discovery independent of human onboarding. Add regression coverage for base persistence, discovery and global-selection failures, plus concurrent private reads. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Run private Conda commands without a shell and resolve project-scoped package managers for shared Poetry environments. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
0801a6b to
1f16146
Compare
|
Result: 🔴 Verification detailsVerification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Summary: [unavailable] Container verification could not start and local execution was not authorized for this PR HEAD: C:\Program Files\RedHat\Podman\podman.EXE --connection pyrx-automation failed: stderr: Error: unable to start container "01a9ec8132191f11549aa0ae6eb6df8abe6a55e722642de5bc83b10a91860844": crun: open `memory.max` for writing: No such file or directory: OCI runtime attempted to invoke a command that was not found Test runs: none recorded. |
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
# Use noninteractive environment tooling in Python agent flows ## Summary Route Python language-model environment tools through the compatible Python Environments `__pythonTools` v1 capability. Agents can configure, query, and install without extension-owned interpreter, folder, or package pickers while retaining VS Code's host approval controls. This is the consumer half of the paired Python Environments change. Ordinary Python command-palette workflows are not redirected to the private API. ## Changes - Use the private capability for `configure_python_environment`, `get_python_environment_details`, `get_python_executable_details`, and `install_python_packages`. - Validate the capability version and all three methods before dispatch. Do not fall back after a private operation starts, returns an error, or is cancelled. - Describe isolation-by-default configuration and exact `pythonPath` selection clearly. Propagate global/base installation protection from the provider. - Forward explicit resource targets and return the effective resource and quoted shell command prefixes. An omitted resource retains the first-workspace-folder default. - Keep compatible configure/install requests on the private route without a workspace so `NO_WORKSPACE` cannot be bypassed through global package installation. Read-only no-workspace queries retain their previous route. - Redirect the hidden create/select LM tools to configuration when the capability is available. - Keep legacy integration for disabled Environments and a validated, one-warning-per-session compatibility route for missing or incompatible providers. - Add optional resource targeting to the shared interpreter command for agent compatibility calls. Existing no-argument human callers retain their folder and interpreter pickers. ## Compatibility and human impact Normal selection, creation, Run Python File, debugging, and testing retain their existing entry points. Agent configuration intentionally updates the project selection that those human operations subsequently use. Chat confirmation/result text changes, and old-provider agent calls can see a new compatibility warning, stricter resource validation, and updated explicit-selection persistence. Compatibility does not provide the new private API's isolation and process-cleanup guarantees. ## Validation - Full ESLint and one-shot TypeScript compilation pass after rebasing onto current upstream `main`. - Latest full Windows unit run: **5,425 passing, 34 pending, 8 failures**. All eight are the `Path`/`PATH` assertions previously reproduced with identical failures on the pristine base; no feature-specific test failed. - Real VS Code before/after comparisons verified public selection, package install/remove, Run Python File, debugging, unittest discovery/execution, and switching back to global Python. - Real agent/VSIX checks covered isolated setup, explicit selection, global-install rejection, no-workspace behavior, reload, multi-root, manager-specific flows, and cancellation. - A baseline agent configuration was observed entering Python-version and interpreter pickers. The compatible private route completed the corresponding setup without those extension-owned choices. ## Known findings before merge - In the old-provider compatibility picker, choosing its nested **Create Environment** action does not forward the pinned folder into the separate creation command. That subflow is not fully target-pinned. - Returned private error DTOs are displayed as errors, but `BaseTool` can emit `failed=false` because it distinguishes thrown errors rather than returned error results. - The companion provider has a reproduced package-resolution gap when multiple tracked projects share one Poetry environment. - Real-chat model decisions, all approval modes, macOS/remote E2E, and third-party callers are not exhaustively verified. ## Companion change Provider PR: [microsoft/vscode-python-environments#1900](microsoft/vscode-python-environments#1900). The new noninteractive behavior is used only when the provider exposes the compatible capability; there is no hard dependency on a particular extension version. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Add noninteractive, isolated Python environment tooling for agents
Summary
Add a private, versioned
__pythonToolscapability to the existing flat extension export so Python agent tools can configure environments, inspect interpreters/packages, and install packages without requiring extension-owned pickers or dialogs.The companion Python-extension change consumes this capability. The public API contract is unchanged, and host tool approval remains in force.
Motivation
Agent requests currently reuse interactive environment workflows, which can pause for interpreter, manager, package, or environment-creation choices. A selected global interpreter can also become the package-installation target.
This change gives agents an explicit noninteractive path with isolation by default, actionable errors, and scoped results, without recording why an interpreter was selected.
Behavior
pythonPathstill selects that exact existing interpreter. Package tools reject global/base environments even when selected explicitly.python.defaultInterpreterPathis configured. Nested targets persist exact project entries without replacing root defaults.Human-flow compatibility
Built-in managers opt in through internal symbol capabilities and explicit operation flags. Normal public selection, creation, package, and execution entry points retain their interactive behavior, including public quick-create's
.venv-Nsuffixing.This is not a claim that all shared code is untouched:
finally()promise.Validation
main: 2,752 passing, 7 pending. Six new failure-path assertions failed before the retry fix and now pass; successful initialization remains cached. The new upstream venv deletion, unresolved-selection recovery, refresh selection-race, uv bootstrap, and scoped Conda discovery tests also pass with the combined implementation.Known findings before merge
.python-version/pyproject.tomlinterpreter constraints are not automatically resolved. Selected base interpreters anddefaultInterpreterPathare honored; PEP 723 constraints are handled separately.Companion change
Python consumer PR: microsoft/vscode-python#26208.
The consumer checks the private version/method shape and retains a compatibility route when the capability is unavailable.