feat: improve recursive environment glob diagnostics (Fixes #427) - #495
Conversation
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>
Performance Report (Linux) ➖
Legend
|
Test Coverage Report (Linux)
Coverage increased! Great work! |
Performance Report (macOS)
Legend
|
Test Coverage Report (Windows)
Coverage increased! Great work! |
Performance Report (Windows) ✅
Legend
|
There was a problem hiding this comment.
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
environmentDirectoriescontains 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_patterndon'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
Remove the duplicate recursive warning and cover pattern filtering plus directory-only expansion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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_patterndoesn’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 ofis_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
environmentDirectoriespatterns, butenvironment_directoriesis 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
environmentDirectoriesis 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 consumesenvironment_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>
There was a problem hiding this comment.
Review details
Suppressed comments (1)
docs/JSONRPC.md:88
- This new guidance warns against recursive patterns, but the preceding
workspaceDirectoriesdocs 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
Treat globstar only as a complete path segment and document environmentDirectories as container directories. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Review details
Suppressed comments (3)
crates/pet-fs/src/glob.rs:25
is_recursive_glob_patternonly 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 ofis_recursive_glob_patternwhen 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
.venvand*/.venv, but the updatedenvironmentDirectoriesdocs only mention/home/user/.../envsexamples. Either update the docs to include the.venv/*/.venvrecommendations (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>
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
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. SinceenvironmentDirectoriesis 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>
## 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>
Summary
environmentDirectoriescontains recursive**path segmentsfoo**barValidation
cargo test -p pet-fscargo test -p pet configure.\scripts\rust-precommit.ps1Fixes #427