Skip to content

feat: improve recursive environment glob diagnostics (Fixes #427) - #495

Merged
Karthik Nadig (karthiknadig) merged 10 commits into
mainfrom
feature/issue-427
Aug 6, 2026
Merged

feat: improve recursive environment glob diagnostics (Fixes #427)#495
Karthik Nadig (karthiknadig) merged 10 commits into
mainfrom
feature/issue-427

Conversation

@karthiknadig

@karthiknadig Karthik Nadig (karthiknadig) commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

  • warn immediately when environmentDirectories contains recursive ** path segments
  • report exact pattern names and elapsed time for slow configure glob expansions
  • recommend non-recursive container-directory patterns in the JSON-RPC documentation
  • support recursive globstar detection through brace expansion without flagging foo**bar
  • add direct coverage for classification and directory-only expansion

Validation

  • cargo test -p pet-fs
  • cargo test -p pet configure
  • .\scripts\rust-precommit.ps1

Fixes #427

Warn before expanding recursive environmentDirectories and report exact per-pattern timings for slow configure globs.

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

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Performance Report (Linux) ➖

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 1ms 1ms 1ms 0ms 0%
Full Refresh 55ms 499ms 55ms 0ms 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

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Test Coverage Report (Linux)

Metric Value
Current Coverage 80.7%
Base Branch Coverage 80.6%
Delta .1% ✅

Coverage increased! Great work!

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Performance Report (macOS)

Metric PR (P50) PR (P95) Baseline (P50) Delta
Server Startup 98ms 648ms 69ms 29ms
Full Refresh 144ms 30209ms 118ms 26ms

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

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Test Coverage Report (Windows)

Metric Value
Current Coverage 77.6%
Base Branch Coverage 77.52%
Delta 0.08% ✅

Coverage increased! Great work!

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Performance Report (Windows) ✅

Metric PR (P50) PR (P95) Baseline (P50) Delta Change
Server Startup 9ms 12ms 9ms 0ms 0%
Full Refresh 136ms 1401ms 164ms -28ms -17.1%

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)

Copilot AI 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.

Pull request overview

This PR improves configure-time diagnostics around glob expansion for workspaceDirectories / environmentDirectories, aiming to make risky recursive patterns (**) and slow glob expansions easier to identify before the client times out.

Changes:

  • Adds per-pattern timing and slow-expansion warnings during configure glob expansion.
  • Warns when environmentDirectories contains recursive glob patterns and updates JSON-RPC docs to recommend bounded patterns.
  • Adds initial unit coverage for recursive glob pattern detection.
Show a summary per file
File Description
docs/JSONRPC.md Documents bounded environmentDirectories patterns and discourages recursive ** patterns due to timeout risk.
crates/pet/src/jsonrpc.rs Adds per-pattern glob expansion timing/warnings and early recursive pattern warnings during configure.
crates/pet-fs/src/glob.rs Introduces is_recursive_glob_pattern helper and adds basic unit tests for it.

Review details

Suppressed comments (1)

crates/pet-fs/src/glob.rs:215

  • The new tests for is_recursive_glob_pattern don't cover the false-positive case where "**" appears within a single segment (e.g. "foo**bar"). Adding a negative assertion will lock in the intended semantics (recursive only when "**" is its own path segment).
        assert!(is_recursive_glob_pattern("**/.venv"));
        assert!(is_recursive_glob_pattern("/home/user/**/venv"));
        assert!(!is_recursive_glob_pattern(".venv"));
        assert!(!is_recursive_glob_pattern("*/.venv"));
    }
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread crates/pet/src/jsonrpc.rs
Comment thread crates/pet-fs/src/glob.rs
Remove the duplicate recursive warning and cover pattern filtering plus directory-only expansion.

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

Copilot AI 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.

Review details

Suppressed comments (4)

crates/pet-fs/src/glob.rs:25

  • is_recursive_glob_pattern() currently returns true for any string containing "", but the doc comment says it should detect globstar recursion across path components. This can produce false positives (e.g., "foobar") and cause misleading warnings.
/// Returns true when a glob can traverse an unbounded number of path components.
pub fn is_recursive_glob_pattern(path: &str) -> bool {
    path.contains("**")
}

crates/pet-fs/src/glob.rs:214

  • The new test_is_recursive_glob_pattern doesn’t cover the common false-positive case where "**" appears within a single path component (which should not be treated as recursive globstar traversal). Adding a regression assertion here will protect the intended semantics of is_recursive_glob_pattern().
    fn test_is_recursive_glob_pattern() {
        assert!(is_recursive_glob_pattern("**/.venv"));
        assert!(is_recursive_glob_pattern("/home/user/**/venv"));
        assert!(!is_recursive_glob_pattern(".venv"));
        assert!(!is_recursive_glob_pattern("*/.venv"));

crates/pet/src/jsonrpc.rs:607

  • The warning message recommends '.venv' / '*/.venv' as bounded environmentDirectories patterns, but environment_directories is treated as a set of directories that contain multiple environments (PET enumerates their children). Suggest updating the guidance in this warning to avoid steering users toward patterns that would typically point at a single environment directory.
        warn!(
            "Recursive environmentDirectories pattern '{}' can make configure slow; prefer bounded patterns such as '.venv' or '*/.venv'",
            pattern.display()
        );

docs/JSONRPC.md:88

  • environmentDirectories is described as a list of (generally global) directories that contain environments; examples like ".venv" and "*/.venv" are typically workspace-relative environment folders and don’t match how PET consumes environment_directories (it enumerates child directories under each entry). Consider updating the examples/warning to reflect directories that contain environments, and format the recursive example as inline code for readability.
   * Bounded glob patterns are supported (e.g., ".venv", "*/.venv", "/home/user/envs/*").
   * Avoid recursive workspace-wide patterns such as "**/.venv": they can traverse large directory trees,
   * delay configure responses, and trigger client timeouts.
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Match recursive wildcards only as path segments, remove duplicate warnings, and add helper coverage.

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

Copilot AI 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.

Review details

Suppressed comments (1)

docs/JSONRPC.md:88

  • This new guidance warns against recursive patterns, but the preceding workspaceDirectories docs still give a recursive example ("**/.venv") and contain a typo ("enviornents"). That’s inconsistent and may encourage exactly the pattern we’re discouraging.
   * Bounded glob patterns are supported (e.g., ".venv", "*/.venv", "/home/user/envs/*").
   * Avoid recursive workspace-wide patterns such as "**/.venv": they can traverse large directory trees,
   * delay configure responses, and trigger client timeouts.
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread crates/pet-fs/src/glob.rs Outdated
Treat globstar only as a complete path segment and document environmentDirectories as container directories.

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

Copilot AI 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.

Review details

Suppressed comments (2)

docs/JSONRPC.md:88

  • “Bounded patterns” is ambiguous without a definition, and PET will still expand recursive ** patterns (this PR adds warnings for them). Consider rephrasing to “Glob patterns are supported” while keeping the explicit guidance to avoid recursive ** patterns for performance.
   * Values identify directories that contain environments. Bounded patterns are supported (e.g., `/home/user/envs`, `/home/user/*/envs`).
   * Avoid recursive patterns such as `/home/user/**/envs`: they can traverse large directory trees,
   * delay configure responses, and trigger client timeouts.

docs/JSONRPC.md:77

  • The term “bounded glob patterns” isn’t defined here, which makes it unclear what patterns are considered acceptable. Since PET supports ** but this is discouraged for performance reasons, it would be clearer to say “Glob patterns are supported” and explicitly call out avoiding recursive ** patterns.

This issue also appears on line 86 of the same file.

   * Bounded glob patterns are supported (e.g., `/home/user/projects/*`).
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

State that glob patterns remain supported while explicitly discouraging recursive globstar traversal.

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

Copilot AI 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.

Review details

Suppressed comments (3)

crates/pet-fs/src/glob.rs:25

  • is_recursive_glob_pattern only detects ** when it is the entire path segment. Since PET glob expansion supports brace groups (e.g. {bin,Scripts}), a recursive option inside a brace group like "{foo,**}/.venv" would currently be missed, even though it can still traverse unbounded components.
/// Returns true when a glob can traverse an unbounded number of path components.
pub fn is_recursive_glob_pattern(path: &str) -> bool {
    path.split(['/', '\\']).any(|segment| segment == "**")
}

crates/pet-fs/src/glob.rs:214

  • Consider adding a test case for recursive ** within a brace-expanded segment (e.g. {foo,**}/.venv) to cover the intended behavior of is_recursive_glob_pattern when brace expansion is used elsewhere in the glob implementation.
    fn test_is_recursive_glob_pattern() {
        assert!(is_recursive_glob_pattern("**/.venv"));
        assert!(is_recursive_glob_pattern("/home/user/**/venv"));
        assert!(!is_recursive_glob_pattern(".venv"));

docs/JSONRPC.md:88

  • The PR description says the JSON-RPC docs should recommend bounded patterns like .venv and */.venv, but the updated environmentDirectories docs only mention /home/user/.../envs examples. Either update the docs to include the .venv/*/.venv recommendations (and an example of a recursive pattern like **/.venv), or adjust the PR description to match the documentation change.
   * Values identify directories that contain environments. Glob patterns are supported (e.g., `/home/user/envs`, `/home/user/*/envs`).
   * Avoid recursive patterns such as `/home/user/**/envs`: they can traverse large directory trees,
   * delay configure responses, and trigger client timeouts.
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Classify globstar alternatives after brace expansion and cover the recursive brace case.

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

Copilot AI 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.

Review details

Suppressed comments (1)

crates/pet/src/jsonrpc.rs:607

  • The warning message includes POSIX-specific example paths (/home/user/...), which can be confusing on Windows where this diagnostic is also emitted. Consider using a platform-neutral placeholder (e.g. <root>/envs) so the guidance is clear everywhere.
        warn!(
            "Recursive environmentDirectories pattern '{}' can make configure slow; prefer bounded container-directory patterns such as '/home/user/envs' or '/home/user/*/envs'",
            pattern.display()
        );
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Keep configure diagnostics clear on Windows, macOS, and Linux with relative container-directory examples.

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

Copilot AI 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.

Review details

Suppressed comments (2)

docs/JSONRPC.md:88

  • The examples for environmentDirectories (e.g., envs, */envs) look like relative paths, but the rest of the docs/sample usage describe these as fully-qualified paths. Relative patterns are resolved against PET's current working directory, which is client-dependent and can make this guidance misleading. Consider switching the examples to absolute/fully-qualified patterns (or explicitly stating how relative paths are resolved).
   * Values identify directories that contain environments. Glob patterns are supported (e.g., `envs`, `*/envs`).
   * Avoid recursive patterns such as `**/envs`: they can traverse large directory trees,
   * delay configure responses, and trigger client timeouts.

crates/pet/src/jsonrpc.rs:607

  • The warning message recommends patterns like envs / */envs, which read as relative paths. Since environmentDirectories is generally passed as fully-qualified paths (and relative patterns depend on the server CWD), consider making the suggestion path-anchored to avoid confusion.
    for pattern in recursive_environment_patterns(patterns) {
        warn!(
            "Recursive environmentDirectories pattern '{}' can make configure slow; prefer non-recursive container-directory patterns such as 'envs' or '*/envs'",
            pattern.display()
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Avoid suggesting CWD-dependent relative environmentDirectories patterns while remaining platform neutral.

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

Copilot AI 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.

Review details

  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@karthiknadig
Karthik Nadig (karthiknadig) marked this pull request as ready for review August 5, 2026 23:13
Karthik Nadig (karthiknadig) added a commit that referenced this pull request Aug 5, 2026
## Summary

- add a PET-wide Rust coding skill alongside locator-specific guidance
- capture path identity/cache, Unicode-safe parsing, hot-path
I/O/allocation, and cross-platform rules
- require tests to prove claimed read-count, cache-hit, and event-count
invariants
- wire the recurring checks into the Reviewer agent for every Rust
change

## Review retrospective

Recent feedback clustered around:
- normalized cache keys and caller-facing path preservation (#487, #490)
- Unicode-safe byte indexing and ASCII format handling (#493)
- proving optimization scope and read counts (#493)
- duplicate side effects and precise pattern semantics (#495)
- workflow assignment/merge postconditions, already addressed in #486

Fixes #496

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@karthiknadig
Karthik Nadig (karthiknadig) merged commit cc8f859 into main Aug 6, 2026
37 checks passed
@karthiknadig
Karthik Nadig (karthiknadig) deleted the feature/issue-427 branch August 6, 2026 04:35
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.

Improve diagnostics for risky environment directory glob patterns

4 participants