Skip to content

Comments

fix: canonicalize prefix paths before comparison to handle symlinked venvs (Fixes #358)#359

Merged
karthiknadig merged 5 commits intomainfrom
bug/issue-358
Feb 25, 2026
Merged

fix: canonicalize prefix paths before comparison to handle symlinked venvs (Fixes #358)#359
karthiknadig merged 5 commits intomainfrom
bug/issue-358

Conversation

@karthiknadig
Copy link
Member

Fix false positive "Prefix is incorrect" telemetry warning when a venv prefix path is a symlink.

  • Canonicalize both discovered and resolved prefix paths before comparison so symlinks to the same directory are treated as equal
  • Wrap canonicalized paths in norm_case() to handle Windows \\?\ UNC prefix from canonicalize
  • Fall back to original path if canonicalization fails (e.g., path no longer exists)

Fixes #358

@karthiknadig karthiknadig requested a review from Copilot February 25, 2026 01:33
@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Test Coverage Report (Linux)

Metric Value
Current Coverage 59.1%
Base Branch Coverage 58.3%
Delta .8% ✅

Coverage increased! Great work!

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Performance Report (Linux) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 1ms 1ms 1ms 0ms 0%
Full Refresh 71ms 557ms 78ms -7ms 0%

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Performance Report (Windows) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 9ms 12ms 10ms -1ms -10%
Full Refresh 159ms 1268ms 181ms -22ms -12.2%

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Test Coverage Report (Windows)

Metric Value
Current Coverage 55.32%
Base Branch Coverage 54.58%
Delta 0.74% ✅

Coverage increased! Great work!

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a false positive "Prefix is incorrect" telemetry warning that occurs when a venv's prefix path is a symlink. The issue arose because the telemetry validation code compared prefix paths directly without resolving symlinks, causing symlinked paths to be flagged as incorrect even though they point to the same directory.

Changes:

  • Canonicalize both discovered and resolved prefix paths before comparison to resolve symlinks
  • Wrap canonicalized paths in norm_case() to handle Windows UNC prefix (\\?\) added by canonicalize
  • Use fallback to original path if canonicalization fails (e.g., path no longer exists)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

crates/pet-telemetry/src/lib.rs:53

  • The canonicalization approach in the telemetry module differs from the pattern used in crates/pet-env-var-path/src/lib.rs where Unix-specific canonicalization is applied selectively. In normalize_search_path, canonicalize is only called on Unix (to handle merged-usr symlinks) but not on Windows (to preserve junction tracking for tools like Scoop). Here, canonicalize is called on both platforms. While wrapping with norm_case handles the Windows UNC prefix issue, consider documenting why this approach is correct for prefix paths specifically, or whether Windows junction paths in venv prefixes could cause similar issues to those mentioned in issue #187 for Scoop.
    let invalid_prefix = if let Some(ref env_prefix) = env.prefix {
        let resolved_prefix = resolved.prefix.clone()?;
        // Canonicalize both paths to handle symlinks — a venv prefix like
        // /usr/local/venvs/myvenv may be a symlink to /usr/local/venvs/versioned/myvenv-1.0.51,
        // and sys.prefix returns the resolved target. Without this, the comparison
        // produces a false positive "Prefix is incorrect" warning. (See #358)
        // Wrap in norm_case to handle Windows UNC prefix (`\\?\`) from canonicalize.
        let env_canonical =
            norm_case(std::fs::canonicalize(env_prefix).unwrap_or(env_prefix.clone()));
        let resolved_canonical =
            norm_case(std::fs::canonicalize(&resolved_prefix).unwrap_or(resolved_prefix));
        env_canonical != resolved_canonical

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 2 comments.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

@karthiknadig karthiknadig enabled auto-merge (squash) February 25, 2026 03:46
@karthiknadig karthiknadig merged commit 3def20f into main Feb 25, 2026
33 of 34 checks passed
@karthiknadig karthiknadig deleted the bug/issue-358 branch February 25, 2026 06:13
@github-actions
Copy link

github-actions bot commented Feb 25, 2026

Performance Report (macOS)

Metric PR (P50) PR (P95) Baseline (P50) Delta
Server Startup 55ms 499ms 48ms 7ms
Full Refresh 121ms 26419ms 93ms 28ms

Results based on 10 iterations. P50 = median, P95 = 95th percentile.


Legend
  • 🚀 Significant speedup (>100ms faster)
  • ✅ Faster than baseline
  • ➖ No significant change
  • 🔺 Slower than baseline (>100ms)
  • ⚠️ Significant slowdown (>500ms)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive "Prefix is incorrect" telemetry warning for symlinked venvs

2 participants