Skip to content

Fix Poetry package actions targeting mismatched environments - #1956

Open
Stella Huang (StellaHuang95) wants to merge 1 commit into
microsoft:mainfrom
StellaHuang95:stellahuang-microsoft-crispy-tribble
Open

Stella Huang (StellaHuang95) wants to merge 1 commit into
microsoft:mainfrom
StellaHuang95:stellahuang-microsoft-crispy-tribble

Conversation

@StellaHuang95

Copy link
Copy Markdown
Contributor

Summary

Fix project-scoped Poetry package actions so they cannot mutate or inspect Poetry environment B while attributing packages and events to a different selected environment A.

  • verify Poetry's actual target against the selected environment before every project-sensitive mutation, list, refresh, direct-dependency query, and cached read
  • pin the verified target with an operation-scoped VIRTUAL_ENV, then verify the pin before mutation
  • invalidate public and installed-package caches safely across project-scoped Poetry managers, serialize operations by physical environment identity, and update caches before events
  • preserve public best-effort poetry show behavior, private/headless process policy, cancellation, and non-Poetry callers
  • provide one actionable mismatch error without duplicate refresh notifications

Fixes #1866

Root cause

Project tree commands combined the displayed/selected environment with the project's configured Poetry package manager. Poetry commands execute from the project directory, so Poetry selected its own project environment, while package caches and change events used the supplied selected environment object. Only the private tooling path had a target check, and ordinary cached reads could bypass Poetry entirely.

A real Poetry probe also demonstrated that verify-once is insufficient if the inherited environment changes: after poetry env info --path reported B, changing only VIRTUAL_ENV caused the immediately following poetry add to mutate A. The fix therefore verifies and pins one filesystem-identified target for each operation.

Validation

  • mandatory pre-commit checks:
    • npm run lint
    • npm run compile-tests
    • npm run unittest — 3,447 passing, 10 pending
  • npm run compile (webpack) passed
  • focused Poetry/package/cache/process-policy tests passed
  • multiple specialized reviewer passes; every concrete finding addressed; final verdict LGTM
  • real Poetry 2.1.4 with disposable external A, project .venv B, paths containing spaces, and an offline wheel:
    • mismatch rejected before mutation/list/refresh attribution; manifest, lockfile, A, and B unchanged
    • matched install/list/direct-dependency/event/uninstall operations stayed on B; A stayed untouched
    • input and progress cancellation changed nothing
    • retarget probe confirmed the operation-scoped pin is required (VERIFIED_TARGET=B, inherited VIRTUAL_ENV=A, unpinned mutation installed only into A)
  • real VS Code Extension Development Host integration passed using the exact order from the report: register project with pip, select A, then override the project package manager to Poetry; project manage/query commands rejected and pre/post hashes/import state were identical

Review hardening

The final implementation additionally covers:

  • realpath + device/inode identity, including symlinks, Windows aliases, and distinct POSIX backslash paths
  • target changes invalidating cached inventory before an ordinary cached read
  • shared private installed-inventory baselines and operation serialization across project-scoped manager clones
  • cancellation while waiting behind another operation without later executing the canceled mutation
  • public/private cache separation, stale async read ordering, post-mutation refresh failure, and cache-before-event ordering
  • stdout/stderr separation for public and private Poetry commands

Notes

The Extension Host verification used the extension's registered test commands after configuring the real project, selected environment, and project-scoped Poetry override; it did not automate mouse interaction with the package input box. Input cancellation and matched interactive manager behavior are covered by production-manager tests with real Poetry plus unit coverage.

Verify and pin project-scoped Poetry operations to the selected environment, keep package caches and events correctly attributed, and preserve cancellation and public package-manager behavior.

Fixes microsoft#1866

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

Copilot-Session: e9acda38-e616-4bc7-a805-f32670a99b94
@rchiodo

Rich Chiodo (rchiodo) commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🔒 Automated review in progress — Rich Chiodo (@rchiodo) is auto-reviewing this PR.

@rchiodo Rich Chiodo (rchiodo) 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.

Approved via Review Center.

@rchiodo Rich Chiodo (rchiodo) added the review-auto:approved Automated review: no blocking findings (approval posted). label Oct 27, 2026

@bschnurr Bill Schnurr (bschnurr) 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.

Approved via Review Center.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Approved via Review Center.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Poetry package actions can misidentify their target environment

4 participants