Repository navigation
perf: bound wildcard segment work in nested repository scans - #23149
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughNested-repository ignore rules now compile path patterns into glob segments and collapse consecutive Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The nested-repository matcher change has no identified issue requiring resolution before merge. The remaining platform and application validation gaps do not establish a defect. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change appears to reduce costly wildcard matching while preserving the checks that control repository scanning. No new security issue was established, but the authority to choose scan roots and the behavior of alternative filesystem adapters remain unconfirmed. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Manual wildcard matcher replaces per-segment
RegExp—compileGlobSegmentnow returnsGlobSegment = string | { pattern: string }andglobSegmentMatcheswalks*→[^/]*/?→[^/]with a latest-star backtracking loop, so an adverse.gitignoreglob can no longer drive catastrophic regex backtracking. - Adverse-work and semantics tests added — a
cpuUsageguard (50 adverse matches under 500 ms), an exhaustive short pattern/name comparison against a regex oracle, and a literal/code-unit edge-case table.
I verified the new matcher preserves the old semantics beyond the added tests: 3.6M exhaustive pattern/value pairs against the removed regex and 5M random pairs against an independent DP oracle (including /, ., [, \n, and surrogate code units) produced zero mismatches. Worst-case work is genuinely bounded at O(pattern length × name length) — measured ~0.5·n² growth up to n=3200 with no exponential blowup, which is the regression the PR targets. Ignore-rule ordering, negation, basenameOnly, anchored base-segment scoping, and the ** recursion are unchanged, and the module's matcher helpers are private, so no external caller is affected. The disclosed ordinary-wildcard slowdown (a few× on a 10k-match microbenchmark) is negligible in absolute terms for this synchronous path.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
… segment The wildcard-segment fix left the larger blowup in place. A short .gitignore line made only of `**` segments still costs exponential work in the outer path walk: `**/**/.../z` at 24 segments and 73 characters, against an eight-segment candidate, takes about 49 million recursive calls and ~150 ms here — larger than the 25 ms single-segment case this branch removes. Rules are inherited down the tree and re-checked for every directory, so that price is per directory, the runtime's 15s scan timeout fires, and the user silently gets a short repo list. Two independent bounds, both kept: - `**` spans zero or more segments, so `**/**` accepts exactly what `**` accepts. Parsing now collapses a run of them to one segment, taking the reported shape from 49M recursive calls to 26 matcher steps. - The walk memoizes on (pattern index, candidate index), so no other arrangement of `**` can reintroduce the blowup. A rule holding at most one `**` is already linear and skips the table, because allocating it costs more than the walk it would save on the shapes real ignore files contain. The budget suite's process-CPU ceiling is replaced by a matcher step counter read through `readNestedRepoGlobMatchSteps`, so an algorithmic regression fails the suite rather than passing on a fast machine. Each bound has its own budget case, and each fails when only the other is applied. The equivalence oracle now also covers multi-segment and anchored patterns including `**`, checked against the pre-change per-segment expression walking uncollapsed segments. Code-unit and metacharacter cases are unchanged. Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
Reviewed the delta since the prior pullfrog review (135eb7a → f3db53f), which extends the work bound from a single wildcard segment to the outer ** path walk.
- Collapsed consecutive
**at parse time —compilePathSegmentsmerges adjacent**runs, so**/**/**/xcompiles to the same two-segment pattern as**/x; a differential case confirms a collapsed and an expanded run accept identical paths. - Memoized the path walk when it can revisit a pair —
pathSegmentsMatchnow takes amemoizeflag and caches(patternIndex, candidateIndex)results in aMap, enabled only when a rule has more than one**run (memoizePathWalk). A single**already visits each pair once, so the allocation is skipped on the common shapes. - Replaced the CPU-time adverse-work guard with a deterministic step budget —
globMatchSteps/readNestedRepoGlobMatchStepscount matcher steps, and the budget tests assert on a delta, so an algorithmic regression fails independently of machine speed. - Added oracle-based coverage — multi-segment patterns up to three segments are compared against an uncollapsed/regex reference, with new budget cases pinning the collapse and memoization shapes.
I verified the semantics hold: the collapse is safe (** matches zero or more segments, so **/** ≡ **), the memo key is unique (candidateIndex < memoStride), and memoizing a (patternIndex, candidateIndex) state is sound because the walk is a pure DAG. The focused suites pass locally (nested-repo-glob-budget.test.ts, nested-repo-scan-rules.test.ts — 32 tests). The disclosed ordinary-wildcard slowdown versus the native regex remains and is unchanged by this commit.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
A short ignore rule containing many stars can make nested repository discovery spend tens of milliseconds rejecting one directory. The matcher now avoids repeatedly trying the same combinations of stars.
What Changed
Replace the wildcard segment's regular expression with a loop that retries only the latest star. Literal matching, ignore-rule order, negation, directory traversal and provider routing stay unchanged.
These timings use the actual exported predicate with injected ignore-file text; parsing is outside the timer. They do not measure a whole scan or application latency.
Why
A latest-star retry loop bounds each segment to O(pattern length × name length) with a fixed number of indices. The existing glob converter elsewhere also uses backtracking and has different semantics. Extending this private matcher keeps the change small without adding a dependency or cache. The outer recursive ** path matcher remains outside this bound.
Separate trade-off PR: ordinary wildcard matches can take longer, as shown above. Native regular expressions are faster for those simple cases. The unchanged literal path showed only small measurement noise. No measured heap or whole-app speed claim.
Linked Issue
Fixes #23147
Visual Proof
N/A
This changes synchronous matching work without a layout or interaction change. No rendered scan timing is claimed.
Testing
83 tests pass across seven project-group suites. The new 14-case suite passes; its original version fails the adverse-work guard (50 names used 1.31 seconds of process CPU against a broad 500 ms ceiling). This is a machine-dependent CPU guard, not a deterministic instruction count. 41,140 small pattern/name comparisons and Unicode, slash, newline and regex-metacharacter probes preserve original semantics. Node typecheck, focused lint, formatting and changed-code quality pass.
Existing suites exercise owned temporary directories, symlinks and read-only Git probes; remote graph providers are mocked. All commands use background-launch mode. No user filesystem scan, external provider, native Electron window, live SSH/WSL or native Windows/Linux execution. Full build and platform application checks remain gaps.
Review
Independent review approved the exact two file hashes. Seventeen independent cases pass on original and candidate, including 30,000 comparisons against a separate dynamic-programming oracle and two in-memory Windows/POSIX scanner fixtures; a candidate-only loop instrumentation case also passes. Independent timings confirm both the adverse gain and ordinary suffix slowdown. Thirty-four focused permanent cases pass independently, with the same original CPU-guard failure.
Merge risk: low to moderate. Matching semantics have broad comparison coverage, but this replaces a core ignore-rule primitive and ordinary wildcard work is slower.
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Shared by local and SSH scan adapters; no new process, Git command, filesystem operation, wire field, host selection, status ownership or permission change. Folder workspace imports remain supported. Total scan input size, pending I/O and outer ** recursion remain existing limits; this PR bounds only an individual wildcard segment. Mobile and Git-provider behavior are unaffected.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)