Skip to content

fix: validate executable filename before spawning in resolve_environment (Fixes #364)#365

Merged
karthiknadig merged 1 commit intomainfrom
bug/issue-364
Feb 27, 2026
Merged

fix: validate executable filename before spawning in resolve_environment (Fixes #364)#365
karthiknadig merged 1 commit intomainfrom
bug/issue-364

Conversation

@karthiknadig
Copy link
Member

Adds validation in resolve_environment() to check that the executable filename matches a Python executable pattern before proceeding with the locator chain or spawning. Previously, any file (e.g., Jupyter kernel spec bash wrapper scripts) would be spawned with -c "import sys;...", wasting ~13 seconds and executing arbitrary non-Python executables.

  • Made is_python_executable_name() public in pet-python-utils to reuse existing regex patterns
  • Added early return with warn! log in resolve_environment() when filename doesn't match

Fixes #364

@karthiknadig karthiknadig requested a review from Copilot February 26, 2026 19:57
@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Performance Report (Linux) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 1ms 1ms 1ms 0ms 0%
Full Refresh 97ms 520ms 98ms -1ms 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 26, 2026

Test Coverage Report (Linux)

Metric Value
Current Coverage 62.7%
Base Branch Coverage 62.7%
Delta 0% ➖

Coverage unchanged.

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Performance Report (Windows) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 10ms 13ms 10ms 0ms 0%
Full Refresh 163ms 613ms 181ms -18ms -9.9%

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 26, 2026

Test Coverage Report (Windows)

Metric Value
Current Coverage 58.89%
Base Branch Coverage 58.89%
Delta 0% ➖

Coverage unchanged.

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 adds filename validation to prevent spawning non-Python executables in the resolve_environment() function, fixing issue #364 where Jupyter kernel spec helper scripts were being executed with Python arguments, causing ~13 second delays and confusing error logs.

Changes:

  • Made is_python_executable_name() function public in pet-python-utils to enable validation of executable filenames
  • Added early validation check in resolve_environment() to reject files that don't match Python executable naming patterns (python, python3, python3.11, etc.) before attempting to spawn them

Reviewed changes

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

File Description
crates/pet-python-utils/src/executable.rs Made is_python_executable_name() function public to allow reuse for validation
crates/pet/src/resolve.rs Added import of is_python_executable_name and early validation check to reject non-Python executables before spawning
Comments suppressed due to low confidence (1)

crates/pet/src/resolve.rs:63

  • Consider adding a test case to verify that non-Python executables (like bash scripts) are properly rejected by resolve_environment. This would help prevent regression of the fix for issue #364. The test could create a temporary non-Python file and verify that resolve_environment returns None with an appropriate warning.
    if executable.is_file() && !is_python_executable_name(&executable) {
        warn!(
            "Path {:?} does not look like a Python executable, skipping resolve",
            executable
        );
        return None;
    }

@github-actions
Copy link

github-actions bot commented Feb 26, 2026

Performance Report (macOS)

Metric PR (P50) PR (P95) Baseline (P50) Delta
Server Startup 54ms 512ms 63ms -9ms
Full Refresh 105ms 26319ms 138ms -33ms

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)

@karthiknadig karthiknadig merged commit c86c74b into main Feb 27, 2026
34 checks passed
@karthiknadig karthiknadig deleted the bug/issue-364 branch February 27, 2026 01:14
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.

fix: validate executable filename before spawning in resolve_environment

3 participants