Skip to content

fix(workspace): preserve filter ordering across exclusions and inclusions (pnpm/pnpm#9354) - #15581

Merged
zkochan merged 2 commits into
mainfrom
fix-9354
Sep 24, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-9354

Conversation

@zkochan

@zkochan zkochan commented Sep 24, 2026 •

Copy link
Copy Markdown
Member

Summary

When combining multiple --filter selectors with exclusions (!) and inclusions, --filter selectors are now evaluated in ordered chunks of matching polarity. When the first selector is an exclusion, selection begins with every project in the workspace; otherwise it starts empty. Subsequent inclusion selectors re-include projects that were previously excluded (e.g. --filter '!./packages/**' --filter '@scope/pkg').

Fixes #9354

Squash Commit Body

When combining multiple --filter flags with exclusions and inclusions, evaluate selectors in ordered polarity chunks so later inclusion filters can re-include packages that were excluded earlier.

Fixes #9354

Checklist

  • I checked the referenced issue and verified that none of the PRs already linked to it solves it.
  • Bug fixes are implemented in every affected version (pnpm v11 and v12).
  • Added a changeset (.changeset/filter-multiplicity-ordered-exclusion.md) targeting @pnpm/workspace.projects-filter, pnpm, and pacquet.
  • Added or updated tests in both TypeScript and Rust.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • --filter selectors are applied in order. A later inclusion filter can re-include a package excluded by an earlier filter, while other excluded packages remain excluded.
    • Recursive filtering follows the same ordered behavior.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 06b70085-4d2a-456e-9701-bee40f0cf984

📥 Commits

Reviewing files that changed from the base of the PR and between d299672 and a5ebca5.

📒 Files selected for processing (1)
  • pnpm/crates/workspace-projects-filter/src/filter.rs
 _____________________________________________________________________________________________________
< Write code that writes code. Code generators increase your productivity and help avoid duplication. >
 -----------------------------------------------------------------------------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 9f7fbc77-4dbf-49b7-bf45-f117d3fdf6dc

📥 Commits

Reviewing files that changed from the base of the PR and between 2ebf755 and d299672.

📒 Files selected for processing (7)
  • .changeset/filter-multiplicity-ordered-exclusion.md
  • pnpm/crates/cli/tests/suite/install_filters.rs
  • pnpm/crates/workspace-projects-filter/src/filter.rs
  • pnpm/crates/workspace-projects-filter/src/filter/tests.rs
  • pnpm11/pnpm/test/recursive/filter.ts
  • pnpm11/workspace/projects-filter/src/index.ts
  • pnpm11/workspace/projects-filter/test/index.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Workspace filtering now applies selectors in order in the Rust and TypeScript implementations. A later inclusion selector can restore projects removed by an earlier exclusion. The changes add unit and integration regression tests and a patch-release changeset.

Changes

Ordered workspace filtering

Layer / File(s) Summary
Rust filter behavior and validation
pnpm/crates/workspace-projects-filter/src/filter.rs, pnpm/crates/workspace-projects-filter/src/filter/tests.rs, pnpm/crates/cli/tests/suite/install_filters.rs, .changeset/filter-multiplicity-ordered-exclusion.md
The Rust filter processes adjacent selectors with the same inclusion or exclusion polarity in order. Tests cover selector re-inclusion and package installation results. The changeset records patch releases and describes the ordered filtering behavior.
TypeScript filter behavior and validation
pnpm11/workspace/projects-filter/src/index.ts, pnpm11/workspace/projects-filter/test/index.ts, pnpm11/pnpm/test/recursive/filter.ts
The TypeScript filter processes adjacent inclusion and exclusion groups in order. Tests cover re-inclusion by name and path, including recursive execution.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Assessment against linked issues

Objective Addressed Explanation
[ #9354 ] Re-include a package with a later inclusion filter after an earlier exclusion filter. ✅

Suggested labels: product: pnpm@11, product: pacquet

Merge Risk: ⚪ Minimal · up to d2996

Ordered filters behave as intended in the reviewed cases, including re-inclusion. No actionable merge-blocking risk remains after normal checks.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     15.1±1.34ms    24.8 MB/sec    1.07     16.2±1.33ms    23.2 MB/sec
packument/parse                                  1.00     43.2±1.36µs  1535.1 MB/sec    1.32     57.1±6.87µs  1160.8 MB/sec
tarball/download_dependency                      1.00      4.3±0.31ms  1002.8 KB/sec    3.03     13.1±2.47ms   331.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    210.7±8.93ms 75.9 KElem/sec    1.77   372.4±63.20ms 43.0 KElem/sec
workspace_resolution/hoist_heavy                 1.00   318.9±38.47ms        ? ?/sec    2.04   651.8±66.23ms        ? ?/sec
workspace_sort/chained_projects                  1.00     15.2±1.70ms        ? ?/sec    2.03    30.8±10.17ms        ? ?/sec

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Same-run regression check

HEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval.

Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.

Scenario Engine main median HEAD median Change Tolerance Result
isolated-fresh-restore-cold-cache-cold-store pacquet 2416.55 ms 2323.48 ms -3.9% 120.83 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store pnpr 1431.64 ms 1554.39 ms 8.6% 71.58 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pacquet 319.90 ms 346.02 ms 8.2% 16.00 ms Inconclusive (overlapping samples)
isolated-fresh-restore-hot-cache-hot-store pnpr 345.65 ms 327.16 ms -5.4% 17.28 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pacquet 11.71 ms 8.69 ms -25.7% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 7.56 ms 11.77 ms 55.7% 2.00 ms Inconclusive (overlapping samples)
isolated-repeat-install-cold-cache-hot-store pacquet 8.18 ms 9.63 ms 17.8% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 11.40 ms 9.03 ms -20.7% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 2987.76 ms 2795.80 ms -6.4% 149.39 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1581.47 ms 1627.47 ms 2.9% 79.07 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 552.89 ms 612.46 ms 10.8% 27.64 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pnpr 393.58 ms 515.50 ms 31.0% 19.68 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-hot-store pacquet 1746.65 ms 1683.96 ms -3.6% 87.33 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pnpr 313.97 ms 324.88 ms 3.5% 15.70 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 239.63 ms 251.54 ms 5.0% 11.98 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 95.45 ms 101.53 ms 6.4% 4.77 ms Inconclusive (overlapping samples)
isolated-peer-heavy-resolve-hot-cache-offline pacquet 850.28 ms 897.74 ms 5.6% 42.51 ms Inconclusive (overlapping samples)
isolated-linked-workspace-resolve-hot-cache-offline pacquet 243.04 ms 256.66 ms 5.6% 12.15 ms Inconclusive (overlapping samples)
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4579.88 ms 4558.41 ms -0.5% 228.99 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 3590.26 ms 3591.88 ms 0.0% 179.51 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pacquet 164.21 ms 206.03 ms 25.5% 8.21 ms Inconclusive (overlapping samples)
gvs-fresh-restore-hot-cache-hot-store pnpr 166.16 ms 177.33 ms 6.7% 8.31 ms Inconclusive (overlapping samples)

Integrated-Benchmark Report (Linux)

Commit: d299672822aa

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.393 ± 0.118 2.296 2.578 1.63 ± 0.17
pacquet@main 2.449 ± 0.126 2.329 2.698 1.67 ± 0.17
pnpr@HEAD 1.543 ± 0.132 1.342 1.732 1.05 ± 0.13
pnpr@main 1.469 ± 0.133 1.327 1.725 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.3934377018,
      "stddev": 0.11792165267728281,
      "median": 2.3234760047,
      "user": 1.4992591,
      "system": 1.43250584,
      "min": 2.2955833872,
      "max": 2.5782009172
    },
    {
      "command": "pacquet@main",
      "mean": 2.4492535018000003,
      "stddev": 0.12576558871212226,
      "median": 2.4165523352000005,
      "user": 1.5348002999999997,
      "system": 1.4417027399999998,
      "min": 2.3290417372000003,
      "max": 2.6981724342
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.542885224,
      "stddev": 0.13152622981346904,
      "median": 1.5543887076999998,
      "user": 1.4988581999999997,
      "system": 1.52639444,
      "min": 1.3424336032,
      "max": 1.7320922502
    },
    {
      "command": "pnpr@main",
      "mean": 1.4688764861,
      "stddev": 0.13303381727829763,
      "median": 1.4316377512,
      "user": 1.4710437,
      "system": 1.50107744,
      "min": 1.3267219352,
      "max": 1.7254904672
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 347.0 ± 40.1 302.4 404.0 1.09 ± 0.15
pacquet@main 317.5 ± 22.4 283.4 363.3 1.00
pnpr@HEAD 326.0 ± 14.9 291.5 347.6 1.03 ± 0.09
pnpr@main 346.7 ± 15.9 327.8 379.8 1.09 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34700101274,
      "stddev": 0.040097824006519095,
      "median": 0.34602075804000004,
      "user": 0.39114041999999993,
      "system": 0.87353956,
      "min": 0.30244499454,
      "max": 0.40400616454000005
    },
    {
      "command": "pacquet@main",
      "mean": 0.31753424624000004,
      "stddev": 0.02235795768614138,
      "median": 0.31990274404,
      "user": 0.36685831999999996,
      "system": 0.80067676,
      "min": 0.28341883654000005,
      "max": 0.36334474854000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.32598558584000004,
      "stddev": 0.01493020924320367,
      "median": 0.32715508854,
      "user": 0.35060962,
      "system": 0.7940700600000001,
      "min": 0.29151900154000004,
      "max": 0.34760410654000007
    },
    {
      "command": "pnpr@main",
      "mean": 0.34665131664000004,
      "stddev": 0.015891839026895206,
      "median": 0.34565289354000006,
      "user": 0.36567721999999997,
      "system": 0.8320740600000001,
      "min": 0.32778567854,
      "max": 0.37980732654000005
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.8 ± 1.1 7.0 14.0 1.15 ± 0.17
pacquet@main 12.0 ± 2.0 8.6 22.0 1.57 ± 0.28
pnpr@HEAD 11.1 ± 2.9 7.0 17.9 1.45 ± 0.39
pnpr@main 7.6 ± 0.6 6.8 12.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008806903446096656,
      "stddev": 0.0010949446774531797,
      "median": 0.008693611000000002,
      "user": 0.005101394944237921,
      "system": 0.004212798215613384,
      "min": 0.006992387,
      "max": 0.014026386000000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.01197720267567567,
      "stddev": 0.001974461979515932,
      "median": 0.011707857500000002,
      "user": 0.0069205854054054045,
      "system": 0.005684688243243241,
      "min": 0.008573847,
      "max": 0.022001774
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011065378325471706,
      "stddev": 0.002860892138422115,
      "median": 0.011768265000000002,
      "user": 0.006358477169811321,
      "system": 0.005312388396226415,
      "min": 0.006997896,
      "max": 0.017899790000000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.007648335642172527,
      "stddev": 0.0005766503273941903,
      "median": 0.007557828,
      "user": 0.004505989904153353,
      "system": 0.003547150607028754,
      "min": 0.0068393790000000005,
      "max": 0.012494620000000001
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 10.0 ± 1.5 7.4 15.0 1.17 ± 0.24
pacquet@main 8.5 ± 1.1 7.2 13.6 1.00
pnpr@HEAD 9.3 ± 1.3 7.5 16.8 1.09 ± 0.21
pnpr@main 11.6 ± 1.7 8.6 17.2 1.36 ± 0.27
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009968759082081455,
      "stddev": 0.0015199965149541423,
      "median": 0.00963237534,
      "user": 0.005426603076923075,
      "system": 0.005168268778280543,
      "min": 0.007373388340000001,
      "max": 0.015011342340000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.008530354319338851,
      "stddev": 0.0011267897896120257,
      "median": 0.008177714340000001,
      "user": 0.0049432585123966935,
      "system": 0.0041582578512396684,
      "min": 0.007209209340000001,
      "max": 0.013595697340000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.009270127580549826,
      "stddev": 0.001317641448049176,
      "median": 0.009033405340000002,
      "user": 0.004967803711340205,
      "system": 0.004901399999999999,
      "min": 0.00751473134,
      "max": 0.01682788734
    },
    {
      "command": "pnpr@main",
      "mean": 0.011642404373519561,
      "stddev": 0.0017436433965678708,
      "median": 0.011398318340000001,
      "user": 0.006337138100558656,
      "system": 0.005998410055865924,
      "min": 0.008588361340000001,
      "max": 0.01719867334
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.808 ± 0.060 2.743 2.928 1.73 ± 0.11
pacquet@main 2.996 ± 0.146 2.841 3.219 1.84 ± 0.14
pnpr@HEAD 1.627 ± 0.040 1.558 1.709 1.00 ± 0.06
pnpr@main 1.625 ± 0.095 1.550 1.838 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.80829682216,
      "stddev": 0.06030773247099352,
      "median": 2.79580402856,
      "user": 2.90734708,
      "system": 2.18466492,
      "min": 2.7433518760599997,
      "max": 2.92809579606
    },
    {
      "command": "pacquet@main",
      "mean": 2.9961196578600005,
      "stddev": 0.1456458713267898,
      "median": 2.98775862706,
      "user": 3.29983808,
      "system": 2.45949552,
      "min": 2.84126386806,
      "max": 3.2186856860599997
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.62707254926,
      "stddev": 0.040052473317199216,
      "median": 1.62747305256,
      "user": 1.9306281799999998,
      "system": 1.9202470199999997,
      "min": 1.55788398006,
      "max": 1.70900263806
    },
    {
      "command": "pnpr@main",
      "mean": 1.6245168213599999,
      "stddev": 0.09485018313853735,
      "median": 1.5814664520600001,
      "user": 1.8346864800000002,
      "system": 1.73776762,
      "min": 1.54968813406,
      "max": 1.83803446606
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 610.1 ± 65.7 512.4 767.8 1.48 ± 0.40
pacquet@main 535.0 ± 51.3 463.4 599.8 1.30 ± 0.35
pnpr@HEAD 526.8 ± 141.6 357.0 726.4 1.28 ± 0.47
pnpr@main 412.9 ± 104.0 289.1 593.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6100640311000001,
      "stddev": 0.0656851461054446,
      "median": 0.6124590326000001,
      "user": 0.87996114,
      "system": 0.9430152999999999,
      "min": 0.5123962616000001,
      "max": 0.7678340986000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.5350477733,
      "stddev": 0.051318701560067216,
      "median": 0.5528901936000001,
      "user": 0.8039130399999997,
      "system": 0.834608,
      "min": 0.4633758896,
      "max": 0.5997640436
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.52680901,
      "stddev": 0.14160220100629786,
      "median": 0.5154959721,
      "user": 0.45244354,
      "system": 0.8829549999999999,
      "min": 0.3569837506,
      "max": 0.7263845426000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.4128574992,
      "stddev": 0.10403799459042064,
      "median": 0.39358010610000005,
      "user": 0.34863743999999997,
      "system": 0.7313879999999999,
      "min": 0.2891406296,
      "max": 0.5936002016
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.701 ± 0.049 1.641 1.795 5.46 ± 0.39
pacquet@main 1.767 ± 0.081 1.660 1.876 5.68 ± 0.45
pnpr@HEAD 0.329 ± 0.018 0.308 0.362 1.06 ± 0.09
pnpr@main 0.311 ± 0.020 0.281 0.334 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.70096477952,
      "stddev": 0.048535130581962405,
      "median": 1.68396308362,
      "user": 1.02933846,
      "system": 0.88741194,
      "min": 1.64137741412,
      "max": 1.7945673151200001
    },
    {
      "command": "pacquet@main",
      "mean": 1.7671289861200001,
      "stddev": 0.08128776681124335,
      "median": 1.74664751612,
      "user": 1.16569426,
      "system": 0.9998508399999999,
      "min": 1.66018952212,
      "max": 1.87634194012
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.32942824942000004,
      "stddev": 0.018109808271315933,
      "median": 0.32488327512000004,
      "user": 0.27002015999999995,
      "system": 0.60481394,
      "min": 0.30845318012000006,
      "max": 0.36188330412
    },
    {
      "command": "pnpr@main",
      "mean": 0.31128857472,
      "stddev": 0.020172700546678614,
      "median": 0.31397172562000003,
      "user": 0.24332156000000005,
      "system": 0.5776920400000001,
      "min": 0.28094888912000004,
      "max": 0.33442304612
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 250.4 ± 18.4 222.3 278.4 2.58 ± 0.23
pacquet@main 245.8 ± 15.9 230.4 282.1 2.54 ± 0.21
pnpr@HEAD 100.5 ± 3.9 93.0 111.6 1.04 ± 0.07
pnpr@main 96.9 ± 5.1 92.0 110.2 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2503812393527273,
      "stddev": 0.018372894575692467,
      "median": 0.25154465308,
      "user": 0.26588061999999996,
      "system": 0.09066533636363637,
      "min": 0.22226848508000002,
      "max": 0.27843576708
    },
    {
      "command": "pacquet@main",
      "mean": 0.24583793953454547,
      "stddev": 0.015871794517620805,
      "median": 0.23962971608,
      "user": 0.26257198363636364,
      "system": 0.08365506363636363,
      "min": 0.23037243208000002,
      "max": 0.28207141608
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.10053855497655172,
      "stddev": 0.003946952991300633,
      "median": 0.10153289708,
      "user": 0.04307003379310344,
      "system": 0.017302941379310342,
      "min": 0.09295786008000001,
      "max": 0.11155398808
    },
    {
      "command": "pnpr@main",
      "mean": 0.09691378332137929,
      "stddev": 0.00507058367742729,
      "median": 0.09545045408,
      "user": 0.03912686137931033,
      "system": 0.016724768965517244,
      "min": 0.09204006308,
      "max": 0.11018842208
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 883.0 ± 106.8 716.0 1032.8 1.01 ± 0.17
pacquet@main 875.0 ± 98.2 766.7 1099.5 1.00
pnpm@HEAD 4287.5 ± 303.5 3759.0 4682.6 4.90 ± 0.65
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.8830275398666667,
      "stddev": 0.10679971745739449,
      "median": 0.8977365252,
      "user": 0.9398342888888889,
      "system": 0.2399998933333333,
      "min": 0.7159637912,
      "max": 1.0328452032
    },
    {
      "command": "pacquet@main",
      "mean": 0.8749536637555556,
      "stddev": 0.09824582125931337,
      "median": 0.8502778742,
      "user": 0.9226730666666665,
      "system": 0.23496533777777776,
      "min": 0.7666700102,
      "max": 1.0994810272
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.287451696088889,
      "stddev": 0.30353130954091884,
      "median": 4.2993467122,
      "user": 6.917819955555556,
      "system": 0.3091651155555556,
      "min": 3.7589836512,
      "max": 4.6825763082
    }
  ]
}

Scenario: Isolated linker: linked-workspace resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 256.0 ± 16.2 230.6 289.7 1.05 ± 0.08
pacquet@main 244.2 ± 12.1 225.5 266.6 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2559653450236363,
      "stddev": 0.016206729408101174,
      "median": 0.25666320566000006,
      "user": 0.19883125818181818,
      "system": 0.11321574,
      "min": 0.23060086266000002,
      "max": 0.28966509966000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.24421531741000002,
      "stddev": 0.01212833451818624,
      "median": 0.24304263466,
      "user": 0.19622794,
      "system": 0.09909182333333333,
      "min": 0.22554206466,
      "max": 0.26662310666000005
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.535 ± 0.125 4.377 4.792 1.26 ± 0.06
pacquet@main 4.606 ± 0.178 4.425 4.996 1.28 ± 0.07
pnpr@HEAD 3.602 ± 0.131 3.437 3.819 1.00
pnpr@main 3.620 ± 0.129 3.478 3.849 1.00 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.53487945206,
      "stddev": 0.12455203997105291,
      "median": 4.55840673846,
      "user": 1.9587884000000002,
      "system": 1.7609630999999997,
      "min": 4.37650798296,
      "max": 4.79231670396
    },
    {
      "command": "pacquet@main",
      "mean": 4.60554247696,
      "stddev": 0.17759546201662538,
      "median": 4.579877956460001,
      "user": 1.9674337999999998,
      "system": 1.7774376999999997,
      "min": 4.42476492396,
      "max": 4.99574907896
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.60163762066,
      "stddev": 0.13134917562342233,
      "median": 3.59188064596,
      "user": 1.8384873000000002,
      "system": 1.7268424999999996,
      "min": 3.43706940796,
      "max": 3.8193296769600003
    },
    {
      "command": "pnpr@main",
      "mean": 3.6196443893600003,
      "stddev": 0.12927323920030023,
      "median": 3.59025578196,
      "user": 1.9194465,
      "system": 1.8034112999999998,
      "min": 3.4781918219600003,
      "max": 3.8494119179600004
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 207.6 ± 21.2 166.2 241.1 1.29 ± 0.20
pacquet@main 160.7 ± 19.5 125.6 187.8 1.00
pnpr@HEAD 174.8 ± 17.1 148.4 205.8 1.09 ± 0.17
pnpr@main 168.8 ± 14.0 147.0 192.9 1.05 ± 0.15
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20763638046333335,
      "stddev": 0.021180388520158022,
      "median": 0.20603236588,
      "user": 0.25195820333333335,
      "system": 0.23282225666666664,
      "min": 0.16619998838,
      "max": 0.24111660138000002
    },
    {
      "command": "pacquet@main",
      "mean": 0.1607014283175,
      "stddev": 0.019513862301566706,
      "median": 0.16421284638,
      "user": 0.196541745,
      "system": 0.17436740250000002,
      "min": 0.12562717038000001,
      "max": 0.18784307538
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.17483983380857143,
      "stddev": 0.01706971095752567,
      "median": 0.17732924088000002,
      "user": 0.20774369142857144,
      "system": 0.18025591142857142,
      "min": 0.14841395338000002,
      "max": 0.20575504138
    },
    {
      "command": "pnpr@main",
      "mean": 0.16884270995142855,
      "stddev": 0.01399714101259682,
      "median": 0.16616412638,
      "user": 0.19564447714285713,
      "system": 0.17766169714285712,
      "min": 0.14698215338,
      "max": 0.19290663238
    }
  ]
}

@zkochan
zkochan marked this pull request as ready for review September 24, 2026 17:47
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Preserve workspace filter ordering across exclusions and inclusions

🐞 Bug fix 🧪 Tests 🕐 20-40 Minutes

Grey Divider

AI Description

• Evaluates filter selectors in ordered polarity chunks across Rust and TypeScript implementations.
• Allows later inclusions to re-include projects removed by earlier exclusions.
• Adds unit and CLI regressions for pnpm v11 and v12 behavior.
Diagram

graph TD
  A["Ordered selectors"] --> B["Polarity chunks"] --> C{"First excludes?"}
  C -->|Yes| D["All projects"] --> F["Apply chunks"] --> G["Filtered projects"]
  C -->|No| E["Empty selection"] --> F
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Evaluate every selector individually
  • ➕ Makes command-line ordering explicit without a chunking abstraction.
  • ➕ Produces the same add-or-remove model for simple selectors.
  • ➖ Invokes graph filtering once per selector instead of batching adjacent selectors.
  • ➖ May increase repeated graph traversal and dependency-expansion work.
2. Build a single stateful graph traversal
  • ➕ Could reduce repeated traversal of the workspace graph.
  • ➕ Could apply selector ordering within one filtering operation.
  • ➖ Requires substantial changes to established selector and dependency matching logic.
  • ➖ Raises parity and maintenance risk across the Rust and TypeScript implementations.

Recommendation: Keep the ordered polarity-chunk approach. It restores expected ordering while reusing the existing graph-filtering behavior, batches compatible adjacent selectors, and can be mirrored cleanly across pnpm v11 and v12.

Files changed (7) +296 / -30

Bug fix (2) +105 / -30
filter.rsApply Rust workspace selectors in ordered polarity chunks +55/-16

Apply Rust workspace selectors in ordered polarity chunks

• Replaces global include/exclude partitioning with ordered chunks of adjacent selectors sharing the same polarity. Selection starts from all projects for an exclusion-first sequence, then adds or removes each chunk's matches while preserving unmatched filters.

pnpm/crates/workspace-projects-filter/src/filter.rs

index.tsApply TypeScript workspace selectors in ordered polarity chunks +50/-14

Apply TypeScript workspace selectors in ordered polarity chunks

• Ports ordered chunk evaluation to the pnpm v11 TypeScript filter implementation. It initializes selection according to the first selector, sequentially adds or removes matches, and filters invalid graph directories.

pnpm11/workspace/projects-filter/src/index.ts

Tests (4) +184 / -0
install_filters.rsVerify filtered installs can re-include an excluded package +20/-0

Verify filtered installs can re-include an excluded package

• Adds a Rust CLI regression test that excludes the packages directory and then re-includes one package by name. It verifies only the restored package is installed.

pnpm/crates/cli/tests/suite/install_filters.rs

tests.rsCover Rust exclusion and re-inclusion sequences +58/-0

Cover Rust exclusion and re-inclusion sequences

• Adds unit coverage for exclusion-first and include-exclude-include selector sequences. Both cases verify that a specific package can be restored after a broader exclusion.

pnpm/crates/workspace-projects-filter/src/filter/tests.rs

filter.tsVerify pnpm v11 recursive commands re-include packages +56/-0

Verify pnpm v11 recursive commands re-include packages

• Adds an end-to-end recursive command test for an exclusion followed by a package-name inclusion. It confirms the restored package runs while another excluded package does not.

pnpm11/pnpm/test/recursive/filter.ts

index.tsCover TypeScript exclusion and re-inclusion ordering +50/-0

Cover TypeScript exclusion and re-inclusion ordering

• Adds workspace-filter unit tests for broad exclusions followed by specific inclusions. Coverage includes both exclusion-first and include-exclude-include sequences.

pnpm11/workspace/projects-filter/test/index.ts

Documentation (1) +7 / -0
filter-multiplicity-ordered-exclusion.mdDocument ordered filter evaluation as a patch release +7/-0

Document ordered filter evaluation as a patch release

• Adds patch changesets for '@pnpm/workspace.projects-filter', 'pnpm', and 'pacquet'. Documents that later inclusion filters can restore previously excluded packages.

.changeset/filter-multiplicity-ordered-exclusion.md

@qodo-code-review

qodo-code-review Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 🔗 Cross-repo conflicts (0) 📜 Skill insights (1)

Grey Divider


Action required

1. Broad exclusions scale quadratically ✗ Dismissed 🐞 Bug ➹ Performance
Description
apply_chunk calls IndexSet::shift_remove once per excluded directory, even when an
exclusion-first filter preloads every workspace project into selected. Because each
order-preserving removal shifts later entries, a broad selector such as !./packages/** can turn
recursive filtering from a linear pass into quadratic work on large workspaces.
Code

pnpm/crates/workspace-projects-filter/src/filter.rs[R130-131]

+        for dir in &chunk_selected {
+            selected.shift_remove(dir);
Relevance

●● Moderate

Performance concerns receive mixed treatment; analogous quadratic optimization was recently
rejected, despite accepted scalability fixes elsewhere.

PR-#14794
PR-#15534

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
An exclusion-first filter fills selected with every graph key, after which apply_chunk removes
every matched directory individually with the order-preserving shift_remove operation. The
recursive CLI directly routes user filter selectors through this function, placing the quadratic
case on normal recursive command paths.

pnpm/crates/workspace-projects-filter/src/filter.rs[128-136]
pnpm/crates/workspace-projects-filter/src/filter.rs[161-172]
pnpm/crates/cli/src/cli_args/recursive.rs[447-480]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Broad exclusion chunks repeatedly call `IndexSet::shift_remove`, causing quadratic work as each removal shifts subsequent entries.

## Fix Focus Areas
- pnpm/crates/workspace-projects-filter/src/filter.rs[128-136]

## Recommended Fix
Convert `chunk_selected` into a hash-based membership set and call `selected.retain(...)` once, preserving the remaining projects' order while processing the exclusion in linear time.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Filter speedup is unverified 📜 Skill insight ➹ Performance ⭐ New
Description
apply_chunk now builds an exclusion HashSet and retains selected paths as a performance-oriented
replacement for repeated ordered removals. Because the PR includes no numeric before-and-after
benchmark for realistic large workspaces and alternating inclusion/exclusion chunks, reviewers
cannot verify the claimed improvement or quantify its allocation and hashing costs.
Code

pnpm/crates/workspace-projects-filter/src/filter.rs[R130-131]

+        let excluded: HashSet<PathBuf> = chunk_selected.into_iter().collect();
+        selected.retain(|dir| !excluded.contains(dir));
Relevance

●● Moderate

Recent performance findings are often accepted, but no close precedent establishes mandatory numeric
benchmarks for this optimization.

PR-#14794
PR-#14677

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 3365159 requires measured numbers for performance changes and recommends multiple
runs with realistic project counts. The cited lines show that apply_chunk changes the exclusion
algorithm by building a HashSet and retaining selected paths, while the supplied PR materials
provide no numeric before-and-after benchmark results to establish the benefit or costs.

pnpm/crates/workspace-projects-filter/src/filter.rs[130-131]
pnpm/crates/workspace-projects-filter/src/filter.rs[128-133]
.agents/skills/review-code/references/REVIEW_GUIDE.md[122-134]
Skill: review-code

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new exclusion-retention implementation is presented as a performance improvement, but the PR provides no numeric before-and-after measurements demonstrating the improvement or quantifying its allocation and hashing costs.

## Fix Focus Areas
- pnpm/crates/workspace-projects-filter/src/filter.rs[128-133]

## Recommended Fix
Add a reproducible benchmark comparing the previous and new exclusion implementations with realistic large workspaces, broad exclusion filters, and alternating inclusion/exclusion chunks. Run it multiple times and report numeric timings and variance, where meaningful, in the PR description or committed benchmark documentation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Users get wrong filter guidance ⊘ Outdated 🔗 Cross-repo conflict ≡ Correctness
Description
filterWorkspaceProjects now applies alternating inclusion and exclusion chunks in order, but
pnpm.io's current and version 11 filtering pages still describe multiplicity only as taking every
package that matches any selector. For mixed-polarity filters, especially a later inclusion that
re-adds an earlier exclusion, users of both released lines cannot infer the CLI's new
order-dependent result from the canonical documentation.
Code

.changeset/filter-multiplicity-ordered-exclusion.md[7]

+`--filter` now evaluates selectors in order, so later inclusion filters can re-include packages that an earlier exclusion filter excluded [pnpm/pnpm#9354](https://github.com/pnpm/pnpm/issues/9354).
Relevance

●●● Strong

Recent precedents accept changeset improvements that clearly document user-visible behavior and
usage semantics.

PR-#13915
PR-#15469

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR changes repeated filters to ordered evaluation and explicitly advertises later re-inclusion.
Both pnpm.io pages instead retain the generic multiplicity statement that packages matching any
selector are selected, without documenting polarity order, initial selection, or re-inclusion
semantics.

pnpm -> pnpm.io
.changeset/filter-multiplicity-ordered-exclusion.md[1-7]
pnpm/crates/workspace-projects-filter/src/filter.rs[157-168]
External repo: pnpm/pnpm.io, docs/filtering.md [173-197]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/filtering.md [167-191]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The public semantics of repeated mixed-polarity `--filter` arguments now depend on selector order, but the current and version 11 pnpm.io filtering guides do not explain that behavior.

## Fix Focus Areas
- /cross_repos/pnpm.io/docs/filtering.md[173-197]
- /cross_repos/pnpm.io/versioned_docs/version-11.x/filtering.md[167-191]

## Recommended Fix
Create a coordinated pnpm.io change for both documentation versions. Explain that adjacent selectors of the same polarity are combined, an initial exclusion starts from the whole workspace, and later inclusions can re-include previously excluded projects; include a mixed exclusion/inclusion example.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Mixed filters slow large workspaces 🐞 Bug ➹ Performance
Description
filterWorkspaceProjects now invokes _filterGraph once per polarity chunk, and every invocation
reconstructs the full workspace graph; the Rust implementation likewise rebuilds its reverse graph
in every dependent-bearing chunk. Alternating inclusion and exclusion flags create one chunk per
selector, so recursive and install filtering repeatedly scans all projects and dependency edges
instead of constructing the traversal indexes once.
Code

pnpm11/workspace/projects-filter/src/index.ts[R228-230]

+  for (const chunk of chunks) {
+    // eslint-disable-next-line no-await-in-loop
+    const result = await fg(chunk.selectors)
Relevance

●● Moderate

Performance regressions receive attention, but no close precedent confirms accepting this specific
graph-rebuild optimization.

PR-#14209

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added TypeScript loop calls _filterGraph once for every generated chunk, while _filterGraph
unconditionally calls projectsGraphToGraph and may also call reverseGraph, both of which iterate
the workspace graph. The added Rust loop similarly calls filter_graph per chunk, and that function
constructs reverse_graph anew whenever that chunk includes dependent traversal; both CLIs pass
user-provided filter sequences directly into these paths.

pnpm11/workspace/projects-filter/src/index.ts[228-240]
pnpm11/workspace/projects-filter/src/index.ts[250-272]
pnpm11/workspace/projects-filter/src/index.ts[347-370]
pnpm/crates/workspace-projects-filter/src/filter.rs[165-168]
pnpm/crates/workspace-projects-filter/src/filter.rs[188-196]
pnpm/crates/cli/src/cli_args/recursive.rs[450-474]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Ordered polarity chunks currently invoke the graph-filtering implementation repeatedly, rebuilding workspace traversal indexes for each chunk. Alternating inclusions and exclusions therefore multiply full-workspace setup work in both the TypeScript and Rust implementations.

## Fix Focus Areas
- pnpm11/workspace/projects-filter/src/index.ts[223-240]
- pnpm11/workspace/projects-filter/src/index.ts[250-272]
- pnpm/crates/workspace-projects-filter/src/filter.rs[157-168]
- pnpm/crates/workspace-projects-filter/src/filter.rs[188-196]

## Recommended Fix
Construct the forward workspace graph once per `filterWorkspaceProjects` call and lazily construct its reverse graph at most once, then pass those shared immutable indexes into each chunk evaluation while retaining fresh per-chunk selection state. Apply the equivalent reuse in Rust so `reverse_graph` is not repeated for every dependent-bearing polarity chunk.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

5. Two TypeScript lists omit commas 📘 Rule violation ⚙ Maintainability
Description
SelectorChunk ends its multi-line property list without a comma, and the multi-line Set call
likewise omits one after its argument. Both constructs are newly added inside
filterWorkspaceProjects, leaving the changed TypeScript inconsistent with the required
trailing-comma convention.
Code

pnpm11/workspace/projects-filter/src/index.ts[206]

+    selectors: ProjectSelector[]
Relevance

● Weak

Recent same-rule precedents reject trailing-comma-only style findings in multiline TypeScript
constructs.

PR-#15503
PR-#15416

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 713434 requires the final item in multi-line TypeScript type definitions and
argument lists to end with a trailing comma. The added SelectorChunk interface and Set
construction both omit that comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/workspace/projects-filter/src/index.ts[204-207]
pnpm11/workspace/projects-filter/src/index.ts[223-225]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Two newly added multi-line TypeScript constructs omit required trailing commas: the final `SelectorChunk` property and the argument to the multi-line `Set` constructor.

## Fix Focus Areas
- pnpm11/workspace/projects-filter/src/index.ts[204-207]
- pnpm11/workspace/projects-filter/src/index.ts[223-225]

## Recommended Fix
Add a trailing comma after `selectors: ProjectSelector[]` and after the conditional expression passed to `new Set<ProjectRootDir>()`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 64 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/pnpm.io (sha: e3bc12c9) — View relationship
Review mode: ⚖️ Balanced: This localized runtime change alters filter semantics in a performance-sensitive path, so it warrants a careful single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can choose which labels appear on a finding, and whether they show icons or text

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit a5ebca5

Results up to commit 45f0943 ⚖️ Balanced


🐞 Bugs (1) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (1) 📜 Skill insights (0)


Remediation recommended
1. Users get wrong filter guidance 🔗 Cross-repo conflict ≡ Correctness
Description
filterWorkspaceProjects now applies alternating inclusion and exclusion chunks in order, but
pnpm.io's current and version 11 filtering pages still describe multiplicity only as taking every
package that matches any selector. For mixed-polarity filters, especially a later inclusion that
re-adds an earlier exclusion, users of both released lines cannot infer the CLI's new
order-dependent result from the canonical documentation.
Code

.changeset/filter-multiplicity-ordered-exclusion.md[7]

+`--filter` now evaluates selectors in order, so later inclusion filters can re-include packages that an earlier exclusion filter excluded [pnpm/pnpm#9354](https://github.com/pnpm/pnpm/issues/9354).
Relevance

●●● Strong

Recent precedents accept changeset improvements that clearly document user-visible behavior and
usage semantics.

PR-#13915
PR-#15469

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The PR changes repeated filters to ordered evaluation and explicitly advertises later re-inclusion.
Both pnpm.io pages instead retain the generic multiplicity statement that packages matching any
selector are selected, without documenting polarity order, initial selection, or re-inclusion
semantics.

pnpm -> pnpm.io
.changeset/filter-multiplicity-ordered-exclusion.md[1-7]
pnpm/crates/workspace-projects-filter/src/filter.rs[157-168]
External repo: pnpm/pnpm.io, docs/filtering.md [173-197]
External repo: pnpm/pnpm.io, versioned_docs/version-11.x/filtering.md [167-191]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The public semantics of repeated mixed-polarity `--filter` arguments now depend on selector order, but the current and version 11 pnpm.io filtering guides do not explain that behavior.

## Fix Focus Areas
- /cross_repos/pnpm.io/docs/filtering.md[173-197]
- /cross_repos/pnpm.io/versioned_docs/version-11.x/filtering.md[167-191]

## Recommended Fix
Create a coordinated pnpm.io change for both documentation versions. Explain that adjacent selectors of the same polarity are combined, an initial exclusion starts from the whole workspace, and later inclusions can re-include previously excluded projects; include a mixed exclusion/inclusion example.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Mixed filters slow large workspaces 🐞 Bug ➹ Performance
Description
filterWorkspaceProjects now invokes _filterGraph once per polarity chunk, and every invocation
reconstructs the full workspace graph; the Rust implementation likewise rebuilds its reverse graph
in every dependent-bearing chunk. Alternating inclusion and exclusion flags create one chunk per
selector, so recursive and install filtering repeatedly scans all projects and dependency edges
instead of constructing the traversal indexes once.
Code

pnpm11/workspace/projects-filter/src/index.ts[R228-230]

+  for (const chunk of chunks) {
+    // eslint-disable-next-line no-await-in-loop
+    const result = await fg(chunk.selectors)
Relevance

●● Moderate

Performance regressions receive attention, but no close precedent confirms accepting this specific
graph-rebuild optimization.

PR-#14209

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The added TypeScript loop calls _filterGraph once for every generated chunk, while _filterGraph
unconditionally calls projectsGraphToGraph and may also call reverseGraph, both of which iterate
the workspace graph. The added Rust loop similarly calls filter_graph per chunk, and that function
constructs reverse_graph anew whenever that chunk includes dependent traversal; both CLIs pass
user-provided filter sequences directly into these paths.

pnpm11/workspace/projects-filter/src/index.ts[228-240]
pnpm11/workspace/projects-filter/src/index.ts[250-272]
pnpm11/workspace/projects-filter/src/index.ts[347-370]
pnpm/crates/workspace-projects-filter/src/filter.rs[165-168]
pnpm/crates/workspace-projects-filter/src/filter.rs[188-196]
pnpm/crates/cli/src/cli_args/recursive.rs[450-474]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Ordered polarity chunks currently invoke the graph-filtering implementation repeatedly, rebuilding workspace traversal indexes for each chunk. Alternating inclusions and exclusions therefore multiply full-workspace setup work in both the TypeScript and Rust implementations.

## Fix Focus Areas
- pnpm11/workspace/projects-filter/src/index.ts[223-240]
- pnpm11/workspace/projects-filter/src/index.ts[250-272]
- pnpm/crates/workspace-projects-filter/src/filter.rs[157-168]
- pnpm/crates/workspace-projects-filter/src/filter.rs[188-196]

## Recommended Fix
Construct the forward workspace graph once per `filterWorkspaceProjects` call and lazily construct its reverse graph at most once, then pass those shared immutable indexes into each chunk evaluation while retaining fresh per-chunk selection state. Apply the equivalent reuse in Rust so `reverse_graph` is not repeated for every dependent-bearing polarity chunk.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational
3. Two TypeScript lists omit commas 📘 Rule violation ⚙ Maintainability
Description
SelectorChunk ends its multi-line property list without a comma, and the multi-line Set call
likewise omits one after its argument. Both constructs are newly added inside
filterWorkspaceProjects, leaving the changed TypeScript inconsistent with the required
trailing-comma convention.
Code

pnpm11/workspace/projects-filter/src/index.ts[206]

+    selectors: ProjectSelector[]
Relevance

● Weak

Recent same-rule precedents reject trailing-comma-only style findings in multiline TypeScript
constructs.

PR-#15503
PR-#15416

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 713434 requires the final item in multi-line TypeScript type definitions and
argument lists to end with a trailing comma. The added SelectorChunk interface and Set
construction both omit that comma.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/workspace/projects-filter/src/index.ts[204-207]
pnpm11/workspace/projects-filter/src/index.ts[223-225]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Two newly added multi-line TypeScript constructs omit required trailing commas: the final `SelectorChunk` property and the argument to the multi-line `Set` constructor.

## Fix Focus Areas
- pnpm11/workspace/projects-filter/src/index.ts[204-207]
- pnpm11/workspace/projects-filter/src/index.ts[223-225]

## Recommended Fix
Add a trailing comma after `selectors: ProjectSelector[]` and after the conditional expression passed to `new Set<ProjectRootDir>()`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Results up to commit d299672 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Broad exclusions scale quadratically ✗ Dismissed 🐞 Bug ➹ Performance
Description
apply_chunk calls IndexSet::shift_remove once per excluded directory, even when an
exclusion-first filter preloads every workspace project into selected. Because each
order-preserving removal shifts later entries, a broad selector such as !./packages/** can turn
recursive filtering from a linear pass into quadratic work on large workspaces.
Code

pnpm/crates/workspace-projects-filter/src/filter.rs[R130-131]

+        for dir in &chunk_selected {
+            selected.shift_remove(dir);
Relevance

●● Moderate

Performance concerns receive mixed treatment; analogous quadratic optimization was recently
rejected, despite accepted scalability fixes elsewhere.

PR-#14794
PR-#15534

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
An exclusion-first filter fills selected with every graph key, after which apply_chunk removes
every matched directory individually with the order-preserving shift_remove operation. The
recursive CLI directly routes user filter selectors through this function, placing the quadratic
case on normal recursive command paths.

pnpm/crates/workspace-projects-filter/src/filter.rs[128-136]
pnpm/crates/workspace-projects-filter/src/filter.rs[161-172]
pnpm/crates/cli/src/cli_args/recursive.rs[447-480]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Broad exclusion chunks repeatedly call `IndexSet::shift_remove`, causing quadratic work as each removal shifts subsequent entries.

## Fix Focus Areas
- pnpm/crates/workspace-projects-filter/src/filter.rs[128-136]

## Recommended Fix
Convert `chunk_selected` into a hash-based membership set and call `selected.retain(...)` once, preserving the remaining projects' order while processing the exclusion in linear time.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

…ions (#9354)

When combining multiple `--filter` flags with exclusions and inclusions,
evaluate selectors in ordered polarity chunks so later inclusion filters
can re-include packages that were excluded earlier.

Fixes #9354
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit d299672

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Sep 24, 2026
@codecov-commenter

codecov-commenter commented Sep 24, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.83%. Comparing base (475c869) to head (a5ebca5).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...npm/crates/workspace-projects-filter/src/filter.rs 91.66% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15581   +/-   ##
=======================================
  Coverage   91.82%   91.83%           
=======================================
  Files        1442     1442           
  Lines      194563   194629   +66     
=======================================
+ Hits       178664   178736   +72     
+ Misses      15899    15893    -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit a5ebca5

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit df5b57d into main Sep 24, 2026
44 of 46 checks passed
@zkochan
zkochan deleted the fix-9354 branch September 24, 2026 22:01
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…ions (pnpm#9354) (pnpm#15581)

When combining multiple --filter flags with exclusions and inclusions, evaluate selectors in ordered polarity chunks so later inclusion filters can re-include packages that were excluded earlier.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--filter multiplicity is not additive when using exclusion

2 participants