← Back to Pull requests

Invalidate import caches after installing plugin dependencies #2494

Open
unknown opened this pull request with 319 lines diff across 3 files
View on GitHub
unknown unknown commented on Nov 11, 2026 04:50 UTC
Author

Fixes #2493

Cause

ensure_plugin_dependencies checks the requirements with InstalledDistributions, which goes through importlib.metadata. That caches the listing of each sys.path directory, keyed on the directory's mtime. After uv pip install, pluggy's load_setuptools_entrypoints reads the same cache, so if the mtime of site-packages did not change, the new plugin stays invisible until the next run.

On macOS, uv's default link mode is clone, and cloning files into a directory on APFS does not update the directory's mtime. uv then sets the mtime itself, but that needs ownership of the directory, and a python.org framework install has a root:admin, group-writable site-packages. The call fails and uv only logs it at debug level (Failed to update mtime ... Permission denied with uv -v). pip always changed the mtime, which is why this started in 1.18.0.

Fix

Call importlib.invalidate_caches() after the install. It only clears the importlib.metadata cache from Python 3.11, so on 3.10 it also calls MetadataPathFinder().invalidate_caches() (on an instance, because in 3.10 that method is not a classmethod).

The new test in tests/cli/env/test_find.py has the mocked install write a module and a .dist-info that registers a new environment type into a directory on sys.path, then restores the directory's mtime. hatch env find has to find the new type on the first run.

Verification

  • Reproduced on macOS (APFS) with the pyproject.toml from the issue, using an ACL so site-packages is writable but its times can't be set (chmod +a "user:$(whoami) deny writeattr" .../site-packages). hatch 1.18.2 and master (893fa13) fail the first run with `Environment default has unknown type: pip-compile on Python 3.13 and 3.10. This branch works on both.

  • The new test fails without the fix and passes with it on 3.10 to 3.15.

  • Full suite on 3.13 and 3.10: the only failures are the tests/cli/publish tests that need Docker, and test_new_selected_python and test_creation_allow_system_packages, which fail the same way on master on my machine (a python.org 2.7 is python on PATH).

  • hatch fmt --check and hatch run types:check` pass.
  • Changelog entry added under Unreleased.

    AI disclosure

    Made with Claude Code (Anthropic). It traced the cause, reproduced the bug, wrote the fix, the test, the changelog entry and this description, and ran the checks. I went through the cause and the change before submitting.

    🤖 Generated with Claude Code

    Diff: 319 lines (+239 / -80) across 3 files Reviewer: cjames23 Review duration: 28281m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.40) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 319 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    42%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.345
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #2494"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 43.0% · Lower = rushed or shallow review
    43.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 23.1% · Safe to merge
    23.1%
    Repository