Skip to content

Watch package changes through PackageWatcher instead of TerminaPacakageWatcher - #1698

Merged
Eduardo Villalpando Mello (edvilme) merged 8 commits into
mainfrom
terminal-package-wathcer
Aug 14, 2026
Merged

Watch package changes through PackageWatcher instead of TerminaPacakageWatcher#1698
Eduardo Villalpando Mello (edvilme) merged 8 commits into
mainfrom
terminal-package-wathcer

Conversation

@edvilme

Copy link
Copy Markdown
Contributor

This pull request refactors and improves the package change detection and watcher system for Python environments. It consolidates the logic for watching package changes across all environment managers into a single, manager-agnostic watcher registration, and removes redundant or manager-specific watcher code. The new system ensures that package changes are detected and handled consistently, regardless of environment type or package manager.

Fixes #1683

Core improvements to package watcher system:

  • A new registerPackageWatchers function is introduced in packageWatcher.ts, which registers package watchers for all active environments, sharing watchers when environments are active in multiple scopes and cleaning up watchers when no longer needed. This replaces the old per-manager watcher registration. (src/managers/common/packageWatcher.tsL2-R11, F89a1842L51R51)
  • The watcher registration is now called once during extension activation, rather than per environment manager, ensuring all active environments are covered. [1] [2]
  • The watcher logic is updated to better handle watcher sharing and disposal, and to use improved glob patterns for .dist-info directories, catching more package changes. (F89a1842L18R18, F89a1842L43R43)

Cleanup and removal of legacy code:

  • The old terminalPackageWatcher.ts and its related imports and registration are removed, as its functionality is now covered by the new watcher system. [1] [2] [3]
  • Manager-specific watcher registration code is removed from builtin/main.ts and poetry/main.ts, further consolidating watcher logic. [1] [2] [3] [4]

API and test updates:

  • The InternalPackageManager class now exposes a getPackageWatchTargets method to allow custom watch targets per package manager.
  • Tests are updated to use the new watcher registration API. [1] [2]

These changes improve maintainability, reliability, and coverage of package change detection across all Python environments managed by the extension.

@edvilme Eduardo Villalpando Mello (edvilme) added the bug Issue identified by VS Code Team member as probable bug label Aug 6, 2026
@StellaHuang95

Stella Huang (StellaHuang95) commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🔒 Automated review in progress — Stella Huang (@StellaHuang95) is auto-reviewing this PR.

@StellaHuang95

Copy link
Copy Markdown
Contributor

GitHub cannot anchor PR review comments to unchanged lines in the diff. Falling back to a general PR comment for src/features/terminal/terminalPackageWatcher.ts:L1.

Warning · Non-blocking recommendation

Removing this watcher drops refreshes for environments manually activated in a terminal but not selected in any workspace scope. Please confirm that this behavior is intentionally out of scope for #1683 and document the tradeoff in the PR description.

Comment thread package-lock.json Outdated
"integrity": "sha512-D7DbgGFtsqIPIFMPJwCad9Gfi/hC0PWErRRHFnaCWoEDYi5tQUDiJCTmGUbBiLzjqAck4KcXt9Ayj0CNlIrF+w==",
"dev": true,
"license": "BSD-2-Clause",
"peer": true,

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.

Info · Optional note

These "peer": true additions appear unrelated to the watcher refactor and look like incidental lockfile reserialization. Please revert this churn to keep the change focused.

Comment thread package.json Outdated

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.

@StellaHuang95 Stella Huang (StellaHuang95) added the review-auto:approved Automated review: no blocking findings (approval posted). label Aug 7, 2026
log: LogOutputChannel,
): Disposable {
// Watch targets
const watchTargets = [

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.

Warning · Non-blocking recommendation

The three createFileSystemWatcher boolean arguments are now unlabeled despite changing the change-event behavior. Please retain inline parameter-name comments so the create/change/delete semantics remain auditable.

Comment thread src/managers/common/packageWatcher.ts Outdated
Comment thread src/managers/common/packageWatcher.ts Outdated
@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:changes-requested Automated review: posted blocking findings to address. and removed review-auto:approved Automated review: no blocking findings (approval posted). labels Aug 11, 2026

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.

Re-review at cbd90966: the existing terminal-only environment finding remains unresolved. I found two additional watcher lifecycle issues inline. Also, docs/startup-flow.md still says activation registers the deleted terminal package watcher and should be updated to describe registerPackageWatchers. Targeted TypeScript compilation, webpack compilation, and all 14 Package Watcher unit tests pass, but none cover these integration seams.

Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts
@edvilme

Copy link
Copy Markdown
Contributor Author

As per team-sync, we decided the best approach would be to replace the TerminalPackageWatcher with the PackageWatcher which was a more reliable and efficient way of detecting actual changes to the packages

Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts Outdated
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: a7de2667-ab70-47de-a8fd-5b00953e14f7
sharedWatchers.set(watcherKey, {
disposable: watchPackageChangesForEnvironment(environment, selectedPackageManager, log),
references: 1,
});

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.

Warning · Non-blocking recommendation

The scoped-environment cache is only rebound here; it is never cleared when a project is removed. Ensure the authoritative project/environment lifecycle releases that scope, and add a regression test confirming the final watcher reference is disposed.

const watcherKey = `${environment.envId.managerId}:${environment.envId.id}:${selectedPackageManager.id}`;
if (activeWatcherByConsumer.get(consumer) === watcherKey) {
return;
}

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.

Warning · Non-blocking recommendation

A delayed activated: true event can arrive after onDidCloseTerminal releases this terminal, recreating a watcher with no later close event. Reject activation for closed terminals or track closed terminals, and test the close-before-activation ordering.

@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:approved Automated review: no blocking findings (approval posted). and removed review-auto:changes-requested Automated review: posted blocking findings to address. labels Aug 14, 2026

@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.

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

Copilot-Session: a7de2667-ab70-47de-a8fd-5b00953e14f7
Comment thread src/managers/common/packageWatcher.ts
Comment thread src/managers/common/packageWatcher.ts
@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:changes-requested Automated review: posted blocking findings to address. and removed review-auto:approved Automated review: no blocking findings (approval posted). labels Aug 14, 2026
};

const envChangeDisposable = envManager.onDidChangeEnvironment?.((changes) => {
const environmentChangeDisposable = envManagers.onDidChangeActiveEnvironment((changes) => {

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.

Warning · Non-blocking recommendation

Active consumers are not re-evaluated when onDidChangePackageManager reports registration or unregistration, so a late manager can leave an environment unwatched and removal can retain a stale watcher. Retain recomputation context for every consumer, subscribe to that lifecycle event, and add a test that registers and unregisters a manager after activation.

@StellaHuang95 Stella Huang (StellaHuang95) added review-auto:approved Automated review: no blocking findings (approval posted). and removed review-auto:changes-requested Automated review: posted blocking findings to address. labels Aug 14, 2026
@edvilme
Eduardo Villalpando Mello (edvilme) merged commit 89cce49 into main Aug 14, 2026
88 checks passed
@edvilme
Eduardo Villalpando Mello (edvilme) deleted the terminal-package-wathcer branch August 14, 2026 21:50
@rchiodo

Copy link
Copy Markdown
Contributor

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

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

Labels

bug Issue identified by VS Code Team member as probable bug review-auto:approved Automated review: no blocking findings (approval posted).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

terminalPackageWatcher completely hangs VS Code’s extension host infinitely

4 participants