Skip to content

perf: watch every script's process group with one watchdog - #16490

Merged
zkochan merged 4 commits into
pnpm:mainfrom
altaywtf:perf/single-group-watchdog
Oct 1, 2026
Merged

zkochan merged 4 commits into
pnpm:mainfrom
altaywtf:perf/single-group-watchdog

Conversation

@altaywtf

@altaywtf altaywtf commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #16489

pnpm -r run over 50 projects without a terminal starts 1 watchdog sh instead of 50, and costs 36% fewer instructions on pnpm v12 and 23% fewer on pnpm v11. A script's process group still dies when pnpm is killed.

Root cause. #15564 (first in 12.7.0 and 11.28.0) starts sh -c "trap '' INT TERM HUP; read -r _ || kill -9 -$1" for every child that leads its own process group: in spawn_child through GroupWatchdog::spawn, and in v11's watchProcessGroup. Every script run without a terminal leads its own group, and in v12 so does every script of a concurrent recursive run. v12 also blocked on reaping each watchdog, and on macOS each bare sh spawn walks PATH.

Fix. One watchdog per pnpm process, started with the first group. pnpm writes +<pgid> to its stdin when it starts watching a group and -<pgid> once it is done with it. End of input means pnpm died, and the watchdog runs kill -9 -<pgid> for every group still listed. The watchdog keeps the groups in one space-delimited string, so a release costs two pattern expansions, not a loop over every group. pnpm keeps the watched leaders too, so a watchdog that died is replaced and takes over the groups still watched. v12 replaces it on the next write, which fails with EPIPE. v11 replaces it as soon as it exits, because Node reports the failed write too late. In v11 the watchdog and its pipe are unref'd, so they never keep pnpm alive.

Before/after (macOS arm64, median of 5, instructions retired by the pnpm process, pnpm -r run noop over 50 projects with noop: true, stdin from /dev/null, no terminal, isolated HOME). v12 binaries are both built from 50f09c2 with CARGO_PROFILE_RELEASE_LTO=false CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 cargo build --release --bin pnpm; v11 bundles with pnpm --filter pnpm run compile, with and without the patch.

watchdog shells instructions, 50-entry PATH instructions, 96-entry PATH
v12 main 50 825M 1,169M
v12 this PR 1 529M 587M
v12.6.0 (last good) 0 547M
v11 main 50 5.35G
v11 this PR 1 4.13G
v11.27.1 (last good) 0 3.91G

Shells are counted by each script listing the watchdogs whose parent is its pnpm (the issue's repro). Instructions: /usr/bin/time -l sh -c 'exec pnpm -r run noop </dev/null >/dev/null 2>&1'.

Tests, each failing with the patch reverted in the working tree:

  • v12: process_tracker::tests::one_watchdog_watches_every_process_group spawns three children through spawn_child and counts the watchdogs. Reverted: left: 3, right: 1.
  • v11: one watchdog watches every process group in exec/npm-lifecycle/test/signals.ts. Reverted: Expected: <= 1, Received: 3.

Guarantee of #15564, kept:

  • v12 unit: dropping the watch kills every group still watched, past one that already exited, and leaves a released group alone; a replacement watchdog takes over the groups of one that was SIGKILLed.
  • v12 e2e: new interrupt::killing_the_process_group_of_pnpm_kills_every_script_of_a_parallel_run (SIGKILL to pnpm's group during pnpm -r --parallel run over 3 projects ends all 3 scripts); the existing interrupt:: tests pass unchanged.
  • v11: a runner killed with SIGKILL leaves no watched group running, past one that already exited, and a released group survives; a watchdog killed with SIGKILL is replaced and its replacement kills the groups still watched (fails with the replacement removed from the compiled lib/); a runner with a watchdog exits on its own; the existing run: killing pnpm's process group kills the script behind its shell too e2e passes on the patched bundle.

Ran locally on macOS: pnpm test:rust -p pnpm-executor (137 passed), pnpm test:rust -p pnpm-cli -E 'test(interrupt::) | test(run::) | test(exec::)' (154 passed), pnpm --filter @pnpm/exec.npm-lifecycle test (80 passed, 7 skipped), scoped clippy with --deny warnings, rustfmt, rustdoc, eslint, typos, cspell.

Unverified: Linux instruction counts (the code path is the same; CI runs the tests there), and busybox running the watchdog script, which uses only POSIX sh (case, ${var#pattern}, ${var%%pattern}). dash, bash and zsh --emulate sh were checked on Linux. Windows has no watchdog; CI covers that it still compiles.

Squash Commit Body

Without a controlling terminal, and in a concurrent recursive run of
pnpm v12, each script pnpm starts leads a process group of its own.
Since pnpm/pnpm#15564 a `sh` stood watch over each such group so that
it dies with pnpm. That doubled the processes a recursive run starts:
`pnpm -r run` over 50 projects started 100 shells, and on macOS each
bare `sh` spawn also walked PATH.

One watchdog per pnpm process now watches every group. It starts with
the first group pnpm creates. pnpm writes `+<pgid>` to its stdin when
it starts watching a group and `-<pgid>` once it is done with it. End
of input means pnpm died, and the watchdog kills every group still
listed, so the guarantee of pnpm/pnpm#15564 holds for any number of
concurrent groups. The watchdog keeps the groups in one string, so a
release costs two pattern expansions rather than a loop over every
group. A watchdog that died is replaced and takes over the groups
still watched: pacquet on its next write, pnpm v11 as soon as it exits.

Both runners change: pacquet's GroupWatch behind spawn_child, and
watchProcessGroup in pnpm v11's npm-lifecycle, whose watchdog and pipe
are unref'd so they never keep pnpm alive.

Closes pnpm/pnpm#16489

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.

Written by an agent (Claude Code, Opus 5.5).


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
    • Scripts run without a terminal now share one watchdog per pnpm command instead of starting a separate shell for each script.
    • If pnpm is killed, the watchdog ends the process groups of all scripts still running. Script groups that have already been released are left alone.
    • Recursive, parallel scripts are also stopped when pnpm’s process group is forcibly terminated, preventing child scripts from continuing to run afterward.

@altaywtf
altaywtf requested a review from zkochan as a code owner October 1, 2026 15:46
Copilot AI balanced review requested due to automatic review settings October 1, 2026 15:46
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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

🧰 Additional context used
📚 Code guidelines (2)
AGENTS.md — auto-discovered
pnpm/AGENTS.md — auto-discovered

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: 23abe1e5-b03f-4760-a185-ae490bfd58ce

📥 Commits

Reviewing files that changed from the base of the PR and between 71d4476 and da07533.

📒 Files selected for processing (4)
  • pnpm/crates/executor/src/process_tracker/group_watchdog.rs
  • pnpm/crates/executor/src/process_tracker/tests.rs
  • pnpm11/exec/npm-lifecycle/src/signals.ts
  • pnpm11/exec/npm-lifecycle/test/signals.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm/crates/executor/src/process_tracker/tests.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The Rust executor and npm-lifecycle package now use one watchdog shell to track multiple script process groups. The watchdog kills groups that remain watched when its input closes. Tests cover watchdog reuse, release, replacement, and shutdown of parallel scripts.

Changes

Process-group watchdog

Layer / File(s) Summary
Shared watchdog behavior
pnpm/crates/executor/src/process_tracker/group_watchdog.rs, pnpm11/exec/npm-lifecycle/src/signals.ts, pnpm11/exec/npm-lifecycle/test/*
The Rust and TypeScript watchdogs accept commands to watch and release process groups. The TypeScript watchdog restarts if it exits while groups remain watched. Tests cover multiple groups, runner shutdown, watchdog replacement, and runner exit.
Executor integration and shutdown validation
pnpm/crates/executor/src/process_tracker.rs, pnpm/crates/executor/src/process_tracker/tests.rs, pnpm/crates/cli/tests/suite/interrupt.rs, .changeset/one-process-group-watchdog.md
The Rust executor stores whether each child group is watched and releases the group after waiting. Tests cover shared watchdog use, group release, replacement, and parallel script shutdown. The changeset records patch releases and the watchdog update.

Priority: ➖ Normal

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

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant Executor as pnpm executor
  participant GroupWatch
  participant Watchdog as shared watchdog shell
  participant Groups as process groups
  Executor->>GroupWatch: register or release a process-group leader
  GroupWatch->>Watchdog: send +pgid or -pgid
  Watchdog->>Groups: kill groups still watched when input closes
Loading

Assessment against linked issues

Objective Addressed Explanation
[#16489] Avoid starting a separate watchdog shell for every script while still ending watched process groups when pnpm is killed. ✅

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

Merge Risk: ⚪ Minimal · up to da075

This change replaces a per-script watchdog shell with one watchdog per pnpm process, while still ending script process groups if pnpm is killed. No actionable merge-blocking risk was identified. The one open point is that behavior under dash and busybox shells was not run.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to da075

Sharing one watchdog reduces process overhead, but also makes cleanup depend on one process. Recovery does not cover every failure state, so one watchdog failure can leave multiple scripts running after pnpm is killed. The inspected paths do not demonstrate new privilege escalation or externally controlled kill targets.

Retained concerns

  • Medium · reliability · inferred: A single failed shared watchdog can leave every active watched group without parent-death cleanup. Rust recovery requires another registration; TypeScript handles signal exits but not all startup or non-signal failure paths. If pnpm is subsequently killed before recovery, multiple scripts may outlive it. The base confined an individual watchdog failure to its own group.
Security review details

Security Blast Radius

  • inferred — The correlated cleanup-failure scope is every concurrently watched process group within one pnpm process, potentially spanning multiple workspace scripts. The inspected source does not establish cross-tenant, remote-service or datastore exposure.

Trust Boundaries and Controls

  • inferred — The observed boundary remains an internal parent-to-watchdog pipe. No attacker-controlled path from lifecycle script arguments or output to kill-target selection was demonstrated. The public TypeScript function's numeric input existed before this PR, so direct misuse alone does not establish a newly introduced attack path.

Resilience and Maintainability Implications

  • inferred — The retained concern is loss of failure containment for lifecycle cleanup, not a verified sandbox escape. Group replay restores ownership on supported replacement paths, but a populated leader list alone cannot enforce cleanup when no live watchdog remains.

Hardening Proposals

  • proposed — Define an explicit degraded state for loss of the shared cleanup channel. Use bounded recovery independent of new registrations, or a deliberate fail-closed policy for owned groups, and validate parent interruption during failed replacement and non-signal watchdog failure.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.

Warning

Some tools did not complete. Review the errors below.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

pnpm11/exec/npm-lifecycle/src/signals.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

pnpm11/exec/npm-lifecycle/test/signals.ts

ESLint skipped: the matched ESLint configuration already failed (missing-dependency).


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 added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 1, 2026
@codecov-commenter

codecov-commenter commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.21%. Comparing base (9cb11fd) to head (da07533).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...tes/executor/src/process_tracker/group_watchdog.rs 96.87% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##             main   #16490    +/-   ##
========================================
  Coverage   92.20%   92.21%            
========================================
  Files        1528     1530     +2     
  Lines      205703   205836   +133     
========================================
+ Hits       189671   189812   +141     
+ Misses      16032    16024     -8     

☔ 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.

@github-actions

github-actions Bot commented Oct 1, 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 2617.91 ms 2794.48 ms 6.7% 130.90 ms Inconclusive (overlapping samples)
isolated-fresh-restore-cold-cache-cold-store pnpr 1807.69 ms 1687.60 ms -6.6% 90.38 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pacquet 349.11 ms 342.05 ms -2.0% 17.46 ms Within tolerance
isolated-fresh-restore-hot-cache-hot-store pnpr 319.13 ms 337.39 ms 5.7% 15.96 ms Inconclusive (overlapping samples)
isolated-repeat-install-hot-cache-hot-store pacquet 15.24 ms 14.82 ms -2.8% 2.00 ms Within tolerance
isolated-repeat-install-hot-cache-hot-store pnpr 16.46 ms 15.31 ms -7.0% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pacquet 8.91 ms 9.50 ms 6.6% 2.00 ms Within tolerance
isolated-repeat-install-cold-cache-hot-store pnpr 11.44 ms 11.61 ms 1.5% 2.00 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pacquet 3188.97 ms 3151.14 ms -1.2% 159.45 ms Within tolerance
isolated-fresh-install-cold-cache-cold-store pnpr 1753.73 ms 1775.18 ms 1.2% 87.69 ms Within tolerance
isolated-fresh-install-hot-cache-hot-store pacquet 665.77 ms 838.69 ms 26.0% 33.29 ms Inconclusive (overlapping samples)
isolated-fresh-install-hot-cache-hot-store pnpr 396.70 ms 402.89 ms 1.6% 19.83 ms Within tolerance
isolated-fresh-install-cold-cache-hot-store pacquet 1753.47 ms 1873.92 ms 6.9% 87.67 ms Inconclusive (overlapping samples)
isolated-fresh-install-cold-cache-hot-store pnpr 404.85 ms 371.35 ms -8.3% 20.24 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pacquet 356.65 ms 348.74 ms -2.2% 17.83 ms Within tolerance
isolated-fresh-resolve-hot-cache-offline pnpr 115.02 ms 119.51 ms 3.9% 5.75 ms Within tolerance
isolated-peer-heavy-resolve-hot-cache-offline pacquet 266.21 ms 257.72 ms -3.2% 13.31 ms Within tolerance
isolated-linked-workspace-resolve-hot-cache-offline pacquet 220.96 ms 225.63 ms 2.1% 11.05 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pacquet 4715.49 ms 4509.60 ms -4.4% 235.77 ms Within tolerance
isolated-fresh-restore-cold-cache-cold-store-cold-pnpr pnpr 4492.82 ms 4754.06 ms 5.8% 224.64 ms Inconclusive (overlapping samples)
gvs-fresh-restore-hot-cache-hot-store pacquet 193.25 ms 185.49 ms -4.0% 9.66 ms Within tolerance
gvs-fresh-restore-hot-cache-hot-store pnpr 173.39 ms 197.04 ms 13.6% 8.67 ms Inconclusive (overlapping samples)

Integrated-Benchmark Report (Linux)

Commit: da075332dc1e

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.740 ± 0.183 2.443 2.972 1.55 ± 0.19
pacquet@main 2.640 ± 0.150 2.454 2.916 1.50 ± 0.18
pnpr@HEAD 1.810 ± 0.248 1.594 2.271 1.02 ± 0.18
pnpr@main 1.766 ± 0.182 1.434 1.989 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.73950658708,
      "stddev": 0.1831624119939991,
      "median": 2.7944774499799996,
      "user": 2.3445122199999995,
      "system": 2.2458336200000004,
      "min": 2.44331441348,
      "max": 2.97184443248
    },
    {
      "command": "pacquet@main",
      "mean": 2.64025247918,
      "stddev": 0.15038430527922766,
      "median": 2.61791251298,
      "user": 2.1392969199999996,
      "system": 2.0485990199999997,
      "min": 2.4543592794799998,
      "max": 2.91601606948
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.8100686655799998,
      "stddev": 0.2480529472355309,
      "median": 1.6875982079800003,
      "user": 2.4390368199999997,
      "system": 2.4135804199999997,
      "min": 1.59393560248,
      "max": 2.27061433748
    },
    {
      "command": "pnpr@main",
      "mean": 1.76600374378,
      "stddev": 0.1824738824729931,
      "median": 1.8076881719800002,
      "user": 2.27205872,
      "system": 2.23929752,
      "min": 1.4340447554800002,
      "max": 1.9885554844800002
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 343.3 ± 25.5 295.3 379.5 1.05 ± 0.13
pacquet@main 347.5 ± 22.4 313.8 382.9 1.06 ± 0.13
pnpr@HEAD 342.3 ± 15.9 324.1 372.4 1.05 ± 0.11
pnpr@main 327.3 ± 32.5 281.1 384.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34331635748,
      "stddev": 0.025518049898785568,
      "median": 0.34205014348,
      "user": 0.3973968,
      "system": 0.7860971999999999,
      "min": 0.29528465498,
      "max": 0.37950168298000003
    },
    {
      "command": "pacquet@main",
      "mean": 0.34751302348,
      "stddev": 0.022368477723408543,
      "median": 0.34910992998,
      "user": 0.42581620000000003,
      "system": 0.8041437,
      "min": 0.31380569998,
      "max": 0.38293782698
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.34231550478000006,
      "stddev": 0.015911712436539834,
      "median": 0.33738832898000004,
      "user": 0.39912630000000004,
      "system": 0.716191,
      "min": 0.32412717898,
      "max": 0.37244474298
    },
    {
      "command": "pnpr@main",
      "mean": 0.32734873508,
      "stddev": 0.03253981080872267,
      "median": 0.31912944298,
      "user": 0.37434700000000004,
      "system": 0.6883766999999998,
      "min": 0.28105633198,
      "max": 0.38403155198
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 15.7 ± 3.2 10.9 23.2 1.00
pacquet@main 16.0 ± 2.8 11.6 23.3 1.02 ± 0.27
pnpr@HEAD 15.8 ± 2.6 9.8 25.0 1.01 ± 0.27
pnpr@main 17.2 ± 3.1 11.7 24.3 1.09 ± 0.30
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.01570582162477611,
      "stddev": 0.003233227686197662,
      "median": 0.014815554580000001,
      "user": 0.008909844477611943,
      "system": 0.00834874253731343,
      "min": 0.01089526708,
      "max": 0.02323523808
    },
    {
      "command": "pacquet@main",
      "mean": 0.016027368859999995,
      "stddev": 0.0027612574812539547,
      "median": 0.015237168580000002,
      "user": 0.0079774913,
      "system": 0.00962268,
      "min": 0.01155232208,
      "max": 0.023259928080000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.01579394096023952,
      "stddev": 0.0026282498273640658,
      "median": 0.01531274708,
      "user": 0.008345626227544907,
      "system": 0.009006026946107783,
      "min": 0.00983397408,
      "max": 0.025037011080000005
    },
    {
      "command": "pnpr@main",
      "mean": 0.0171574808524138,
      "stddev": 0.003137150150576437,
      "median": 0.016462339080000003,
      "user": 0.009183726206896552,
      "system": 0.009553468965517243,
      "min": 0.011743880080000001,
      "max": 0.02430154308
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 9.5 ± 1.0 7.6 12.7 1.00
pacquet@main 9.6 ± 1.8 7.5 18.0 1.01 ± 0.22
pnpr@HEAD 11.8 ± 1.6 9.1 18.2 1.24 ± 0.22
pnpr@main 11.6 ± 2.2 8.4 22.9 1.22 ± 0.27
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.009481702015639103,
      "stddev": 0.0010293054222631057,
      "median": 0.009495776260000002,
      "user": 0.005468441954887219,
      "system": 0.004796424962406015,
      "min": 0.007554333260000001,
      "max": 0.01267345526
    },
    {
      "command": "pacquet@main",
      "mean": 0.009555709264854372,
      "stddev": 0.0018019372910446775,
      "median": 0.00891105976,
      "user": 0.005753358252427182,
      "system": 0.004556670388349514,
      "min": 0.007500833260000001,
      "max": 0.017983935260000004
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.011801220134999998,
      "stddev": 0.001644900209861523,
      "median": 0.01161043576,
      "user": 0.0069046165217391325,
      "system": 0.005760305217391301,
      "min": 0.009084596260000001,
      "max": 0.018204610260000004
    },
    {
      "command": "pnpr@main",
      "mean": 0.011563446974285723,
      "stddev": 0.0021876045525769426,
      "median": 0.011443919260000001,
      "user": 0.006457381674876846,
      "system": 0.006026557339901476,
      "min": 0.00840858926,
      "max": 0.02289253726
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.113 ± 0.261 2.754 3.484 1.76 ± 0.18
pacquet@main 3.215 ± 0.178 2.957 3.487 1.82 ± 0.14
pnpr@HEAD 1.827 ± 0.130 1.672 2.002 1.03 ± 0.09
pnpr@main 1.768 ± 0.097 1.651 1.945 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.1131821224400005,
      "stddev": 0.26056409027471616,
      "median": 3.1511389421400002,
      "user": 3.1722575799999997,
      "system": 2.7666675199999995,
      "min": 2.75439748114,
      "max": 3.48445898114
    },
    {
      "command": "pacquet@main",
      "mean": 3.2153410901399995,
      "stddev": 0.17811503820126082,
      "median": 3.1889676531399997,
      "user": 3.26596378,
      "system": 2.8502603199999994,
      "min": 2.95735397814,
      "max": 3.48709466014
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.82724896014,
      "stddev": 0.1298149535050066,
      "median": 1.77518083714,
      "user": 2.04737958,
      "system": 2.17497072,
      "min": 1.67160266714,
      "max": 2.0016356311399996
    },
    {
      "command": "pnpr@main",
      "mean": 1.76771680694,
      "stddev": 0.09697728420057325,
      "median": 1.7537272961400001,
      "user": 2.03215678,
      "system": 2.26518412,
      "min": 1.6513804011400002,
      "max": 1.94513246414
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 784.7 ± 124.0 589.1 957.1 1.96 ± 0.32
pacquet@main 664.4 ± 57.8 558.5 760.5 1.66 ± 0.16
pnpr@HEAD 409.7 ± 36.2 339.9 470.6 1.03 ± 0.10
pnpr@main 399.5 ± 15.5 373.7 427.1 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.7846814350200002,
      "stddev": 0.12396511246056485,
      "median": 0.8386878065200001,
      "user": 1.14061072,
      "system": 1.1808481599999998,
      "min": 0.5891256060200001,
      "max": 0.9571038770200001
    },
    {
      "command": "pacquet@main",
      "mean": 0.6643742196200001,
      "stddev": 0.057783305297614156,
      "median": 0.6657699395200001,
      "user": 0.9672156200000002,
      "system": 0.9600667599999999,
      "min": 0.5584888360200001,
      "max": 0.76045514402
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.40971556492000005,
      "stddev": 0.03620739508310952,
      "median": 0.4028889950200001,
      "user": 0.39327612,
      "system": 0.7646072599999999,
      "min": 0.33986123902000004,
      "max": 0.47058663702000003
    },
    {
      "command": "pnpr@main",
      "mean": 0.39951940792,
      "stddev": 0.015517645909009234,
      "median": 0.3966999750200001,
      "user": 0.37759692,
      "system": 0.73683526,
      "min": 0.3737287690200001,
      "max": 0.42709533102
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.916 ± 0.236 1.742 2.563 5.21 ± 0.66
pacquet@main 1.765 ± 0.038 1.716 1.833 4.80 ± 0.17
pnpr@HEAD 0.368 ± 0.011 0.347 0.381 1.00
pnpr@main 0.409 ± 0.024 0.374 0.453 1.11 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.9162379622199996,
      "stddev": 0.23570683876195683,
      "median": 1.87392371792,
      "user": 1.39404746,
      "system": 1.3517262799999998,
      "min": 1.74196586392,
      "max": 2.56282682192
    },
    {
      "command": "pacquet@main",
      "mean": 1.7651688237199994,
      "stddev": 0.038017221851442316,
      "median": 1.75347192392,
      "user": 1.17096246,
      "system": 1.20338478,
      "min": 1.71579099092,
      "max": 1.83314566492
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.36775935362,
      "stddev": 0.010601331814625066,
      "median": 0.37135157192,
      "user": 0.34617415999999995,
      "system": 0.7791942799999999,
      "min": 0.34732291392,
      "max": 0.38058118692
    },
    {
      "command": "pnpr@main",
      "mean": 0.40859669802000004,
      "stddev": 0.023872074209071174,
      "median": 0.40485216092,
      "user": 0.40120746,
      "system": 0.8984330799999999,
      "min": 0.37437885992,
      "max": 0.45297925892
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 342.6 ± 33.3 289.6 386.0 2.99 ± 0.32
pacquet@main 351.6 ± 24.3 320.8 391.6 3.07 ± 0.25
pnpr@HEAD 119.5 ± 5.9 105.2 133.6 1.04 ± 0.07
pnpr@main 114.5 ± 5.2 102.7 124.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34263358066,
      "stddev": 0.03327149987741056,
      "median": 0.34874293426,
      "user": 0.35487761999999995,
      "system": 0.15271618,
      "min": 0.28963612676,
      "max": 0.38596552276
    },
    {
      "command": "pacquet@main",
      "mean": 0.35163559576,
      "stddev": 0.024262193394696024,
      "median": 0.35664701226,
      "user": 0.35268411999999993,
      "system": 0.15057497999999997,
      "min": 0.32075153176,
      "max": 0.39157774476
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.1195362722,
      "stddev": 0.005923239801096371,
      "median": 0.11951134976000001,
      "user": 0.05738238,
      "system": 0.02592044,
      "min": 0.10522273976000002,
      "max": 0.13359665776
    },
    {
      "command": "pnpr@main",
      "mean": 0.11449810084333334,
      "stddev": 0.0051817465364234596,
      "median": 0.11502146326000001,
      "user": 0.054742428333333315,
      "system": 0.023253379999999994,
      "min": 0.10271642676,
      "max": 0.12447519576
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 258.7 ± 25.6 225.0 295.2 1.00
pacquet@main 272.6 ± 33.5 221.1 331.2 1.05 ± 0.17
pnpm@HEAD 4175.7 ± 358.1 3475.6 4711.3 16.14 ± 2.11
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2586500868133334,
      "stddev": 0.025595486863440826,
      "median": 0.25771713748,
      "user": 0.2763671711111111,
      "system": 0.047443351111111115,
      "min": 0.22504635348000002,
      "max": 0.29520851648
    },
    {
      "command": "pacquet@main",
      "mean": 0.27262605870222223,
      "stddev": 0.03346019491650418,
      "median": 0.26621304648000005,
      "user": 0.2825502822222222,
      "system": 0.05792390666666666,
      "min": 0.22110033848000002,
      "max": 0.33115230948
    },
    {
      "command": "pnpm@HEAD",
      "mean": 4.1757134180355555,
      "stddev": 0.3581298580210141,
      "median": 4.226442061479999,
      "user": 6.604258171111111,
      "system": 0.43493023999999997,
      "min": 3.47555990648,
      "max": 4.71129272448
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 227.6 ± 11.3 210.6 246.4 1.02 ± 0.08
pacquet@main 223.9 ± 14.5 208.8 259.8 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.22762362821,
      "stddev": 0.011270282154615003,
      "median": 0.22562823996000003,
      "user": 0.18271701666666665,
      "system": 0.08851877666666665,
      "min": 0.21057782846000003,
      "max": 0.24642115246000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.22389053462666667,
      "stddev": 0.014475396975979892,
      "median": 0.22096379196000004,
      "user": 0.18788776666666665,
      "system": 0.07933235999999999,
      "min": 0.20879838146000002,
      "max": 0.25975504946
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.560 ± 0.175 4.391 4.824 1.00
pacquet@main 4.700 ± 0.203 4.430 5.055 1.03 ± 0.06
pnpr@HEAD 4.680 ± 0.447 3.901 5.132 1.03 ± 0.11
pnpr@main 4.601 ± 0.780 3.646 6.101 1.01 ± 0.18
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.55978006248,
      "stddev": 0.1751146565154893,
      "median": 4.50959769458,
      "user": 1.55907186,
      "system": 1.50968996,
      "min": 4.39121044208,
      "max": 4.82379728108
    },
    {
      "command": "pacquet@main",
      "mean": 4.699906102280001,
      "stddev": 0.20335336234664378,
      "median": 4.71548621458,
      "user": 1.9703441599999998,
      "system": 1.87911876,
      "min": 4.43010925508,
      "max": 5.05543158308
    },
    {
      "command": "pnpr@HEAD",
      "mean": 4.68039155678,
      "stddev": 0.44748558623576046,
      "median": 4.75405537508,
      "user": 2.53980386,
      "system": 2.44737756,
      "min": 3.90058584108,
      "max": 5.13235106808
    },
    {
      "command": "pnpr@main",
      "mean": 4.601437323779999,
      "stddev": 0.7795983396931105,
      "median": 4.49282484658,
      "user": 2.3361855599999997,
      "system": 2.32745976,
      "min": 3.6457072570799998,
      "max": 6.10090840908
    }
  ]
}

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 193.1 ± 32.3 161.2 292.6 1.12 ± 0.24
pacquet@main 205.0 ± 37.0 155.6 273.3 1.19 ± 0.26
pnpr@HEAD 202.7 ± 49.3 143.9 303.3 1.18 ± 0.32
pnpr@main 172.3 ± 22.0 143.1 223.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.19307026334571428,
      "stddev": 0.032311259947419665,
      "median": 0.18548758006000002,
      "user": 0.23209212857142858,
      "system": 0.1812709742857143,
      "min": 0.16116691806000003,
      "max": 0.29263339206
    },
    {
      "command": "pacquet@main",
      "mean": 0.2049955111266667,
      "stddev": 0.036975208775817295,
      "median": 0.19324990006000003,
      "user": 0.25111089999999997,
      "system": 0.17496232666666664,
      "min": 0.15563297106,
      "max": 0.27334529706
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.20272218756000004,
      "stddev": 0.04934180955097719,
      "median": 0.19703983506000003,
      "user": 0.23002320000000004,
      "system": 0.17272686,
      "min": 0.14388141706000002,
      "max": 0.30331762006
    },
    {
      "command": "pnpr@main",
      "mean": 0.1723201835933334,
      "stddev": 0.02201707645675148,
      "median": 0.17338861706000003,
      "user": 0.1958818333333333,
      "system": 0.16868852666666667,
      "min": 0.14313857606000002,
      "max": 0.22301530906000003
    }
  ]
}

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.

Copilot review overview

🔵 Needs a closer look

It is reliability-sensitive process/signal management (process groups, SIGKILL, pipe EOF, concurrency, and a POSIX shell script) spanning two languages, whose correctness depends on cross-platform test runs that cannot be verified in this environment.

Review effort: Balanced
Findings: None

What changed in this PR

This PR fixes a performance regression introduced by the per-group process watchdog added in #15564. Previously, every script that led its own process group (any script run without a terminal, plus every script of a concurrent recursive run in v12) spawned a dedicated sh watchdog, doubling the process count of a recursive run. The PR replaces that with a single long-lived watchdog per pnpm process that multiplexes all groups over one pipe, using a +<pgid>/-<pgid> stdin protocol; end-of-input (pnpm death) makes the watchdog kill -9 every group still listed. The change is mirrored across the Rust v12 CLI (pnpm/) and the TypeScript v11 CLI (pnpm11/).

Changes:

  • Rewrites the watchdog shell script to track multiple process groups via a +pgid/-pgid protocol and kill all still-watched groups on EOF.
  • Replaces the per-child GroupWatchdog with a shared, replaceable GroupWatch (Rust, behind a global Mutex) and a module-level single watchdog lifeline (TypeScript, unref'd so it never keeps pnpm alive).
  • Adds unit tests (v11 + v12), a new v12 parallel-run e2e test, a test fixture, and a changeset.
File Description
pnpm/​crates/​executor/​src/​process_tracker/​group_watchdog.rs New GroupWatch managing one shared watchdog with replace-on-death and the multi-group shell script.
pnpm/​crates/​executor/​src/​process_tracker.rs spawn_child now records a watched: bool instead of owning a GroupWatchdog; releases via module functions.
pnpm/​crates/​executor/​src/​process_tracker/​tests.rs Unit tests for single-watchdog multiplexing, drop-kills-all, and watchdog replacement.
pnpm/​crates/​cli/​tests/​suite/​interrupt.rs New e2e test: SIGKILL to pnpm's group ends every script of a parallel run.
pnpm11/​exec/​npm-lifecycle/​src/​signals.ts Mirrors the Rust change: shared watchdogLifeline, +/- protocol, unref'd watchdog and pipe.
pnpm11/​exec/​npm-lifecycle/​test/​signals.ts Unit tests for single-watchdog, kill-on-death, and self-exit.
pnpm11/​exec/​npm-lifecycle/​test/​fixtures/​watchdog/​watch.mjs Test fixture driving watchProcessGroup from a standalone runner.
.changeset/​one-process-group-watchdog.md Changeset targeting @pnpm/exec.npm-lifecycle, pnpm, and pacquet.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Without a controlling terminal, and in a concurrent recursive run of
pnpm v12, each script pnpm starts leads a process group of its own.
Since #15564 a `sh` stood watch over each such group so that
it dies with pnpm. That doubled the processes a recursive run starts:
`pnpm -r run` over 50 projects started 100 shells, and on macOS each
bare `sh` spawn also walked PATH.

One watchdog per pnpm process now watches every group. It starts with
the first group pnpm creates. pnpm writes `+<pgid>` to its stdin when
it starts watching a group and `-<pgid>` once it is done with it. End
of input means pnpm died, and the watchdog kills every group still
listed, so the guarantee of #15564 holds for any number of
concurrent groups. A watchdog that died is replaced on the next watch
and takes over the groups still watched.

Both runners change: pacquet's GroupWatch behind spawn_child, and
watchProcessGroup in pnpm v11's npm-lifecycle, whose watchdog and pipe
are unref'd so they never keep pnpm alive.

Closes #16489
Copilot AI balanced review requested due to automatic review settings October 1, 2026 18:24
@zkochan
zkochan force-pushed the perf/single-group-watchdog branch from 1582dc7 to 53aa906 Compare October 1, 2026 18:24
@qodo-code-review

qodo-code-review Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. The restart test can fail before restart ✗ Dismissed
Description
The replacement test takes a single listWatchdogs() snapshot immediately after the runner writes
watching, without establishing that its spawned watchdog is visible to ps. If the shell has not
appeared in that snapshot, killed is undefined and process.kill() throws even though the
production fix is present.
Code

pnpm11/exec/npm-lifecycle/test/signals.ts[R195-196]

+    const [killed] = listWatchdogs(runner.pid!)
+    process.kill(killed, 'SIGKILL')
Relevance

●●● Strong

The test has a real process-discovery race; historical watchdog reviews accept fixes that make
lifecycle tests robust.

PR-#15119

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The rule requires the regression test to pass with the fix present. The fixture announces readiness
after requesting an asynchronous spawn, whereas the test immediately takes one process-list snapshot
and passes its possibly absent PID to process.kill().

pnpm11/exec/npm-lifecycle/test/fixtures/watchdog/watch.mjs[9-13]
pnpm11/exec/npm-lifecycle/test/signals.ts[193-196]
pnpm11/exec/npm-lifecycle/test/signals.ts[233-239]
pnpm11/exec/npm-lifecycle/src/signals.ts[409-416]
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 replacement regression test can inspect the process list before the first watchdog appears and fail without testing replacement.

## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/test/signals.ts[193-197]
- pnpm11/exec/npm-lifecycle/test/signals.ts[223-234]

## Recommended Fix
Poll with a deadline until exactly one initial watchdog is visible before killing it. Fail explicitly if none appears, then check that a different watchdog replaces it.

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


2. A missing watchdog passes the group test ✗ Dismissed
Description
The new TypeScript test accepts started.length of zero because it asserts only
toBeLessThanOrEqual(1). If the runner starts no watchdog at all, the assertion passes despite
three groups being watched, so the test does not verify the process it is meant to count.
Code

pnpm11/exec/npm-lifecycle/test/signals.ts[164]

+    expect(started.length).toBeLessThanOrEqual(1)
Relevance

●●● Strong

The assertion permits zero watchdogs, so strengthening it is a deterministic test-correctness fix.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The rule requires an assertion of the changed effect. The test counts newly started watchdogs but
permits a count of zero.

pnpm11/exec/npm-lifecycle/test/signals.ts[157-164]
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 multi-group test passes when no watchdog starts.

## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/test/signals.ts[157-165]

## Recommended Fix
Assert that exactly one new watchdog starts for the three groups.

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



Remediation recommended

3. Shutdown can target the wrong script group 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The watchdog's ${groups%% "$group" *} expansion lacks the leading-space boundary needed to make
the comment's claim that a release removes one group true. With groups equal to  1234 34 ,
releasing 34 leaves  12  instead of  1234 , so the same error affects shutdown in both the
Rust and TypeScript implementations.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[47]

+        *" $group "*) groups="${groups%% "$group" *} ${groups#* "$group" }" ;;
Relevance

●●● Strong

The expansion can remove a suffix-matching ID; this is a deterministic correctness bug in watchdog
group tracking.

PR-#15564

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed comment says a release cuts one watched ID out, but the changed expansion can match a
suffix of another ID. Both implementations use the same expansion, and their final loops act on the
resulting list.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[37-52]
pnpm11/exec/npm-lifecycle/src/signals.ts[351-357]

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

## Issue description
Releasing a group can truncate an earlier group ID that ends with the same digits, leaving the wrong group in the watchdog's shutdown list.

## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[46-48]
- pnpm11/exec/npm-lifecycle/src/signals.ts[351-353]

## Recommended Fix
Anchor the prefix expansion to the space before the complete group ID in both scripts. Add a regression case that releases `34` while `1234` remains watched.

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

Dismiss ↗ | View ↗


4. One changeset mixes both release lines 📘 Rule violation § Compliance
Description
The new changeset puts the v11 pnpm bump and the v12 pacquet bump in the same file. Because this
PR changes both implementations, the package-specific release entries cannot be maintained
independently under the checklist's separate-changeset requirement.
Code

.changeset/one-process-group-watchdog.md[R3-4]

+"pnpm": patch
+"pacquet": patch
Relevance

●●● Strong

Recent changeset precedents explicitly require separate pnpm and pacquet files.

PR-#15316
PR-#15895

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist explicitly calls for separate files when a PR touches both stacks. This single new
file lists both pnpm and pacquet.

Rule 713436: Changesets for pnpm v11 vs v12 (pacquet) must target the correct package and bump type
.changeset/one-process-group-watchdog.md[1-7]

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 changeset combines v11 and v12 package bumps although both implementations change.

## Fix Focus Areas
- .changeset/one-process-group-watchdog.md[1-7]

## Recommended Fix
Create separate changesets: one for the v11 TypeScript packages with patch bumps, and one for pacquet.

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

Dismiss ↗ | View ↗


5. Two test comments describe old behavior ✓ Resolved
Description
The new comments say that a shell per watched group or child doubled the processes a recursive run
starts. They sit above tests of the current single-watchdog behavior, leaving historical
implementation detail in source comments rather than describing the current guarantee.
Code

pnpm11/exec/npm-lifecycle/test/signals.ts[156]

+// A sh per watched group doubled the processes a recursive run starts.
Relevance

●●● Strong

Recent precedent accepts requests to rewrite comments describing historical behavior into current
invariants.

PR-#15854

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Both added comments refer to the former per-child shell behavior in the past tense, which the rule
excludes from inline comments.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm11/exec/npm-lifecycle/test/signals.ts[156-157]
pnpm/crates/executor/src/process_tracker/tests.rs[47-50]

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 new test comments describe the former per-group watchdog implementation.

## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/test/signals.ts[156-156]
- pnpm/crates/executor/src/process_tracker/tests.rs[47-48]

## Recommended Fix
Remove the historical clauses or describe only the current single-watchdog guarantee.

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


View medium (4)
6. Earlier scripts outlive a failed restart 🐞 Bug ☼ Reliability
Description
GroupWatch::start_watchdog removes the dead watchdog before attempting a fallible replacement,
while watch removes only the newly added leader if that attempt fails. If replacement spawning or
replaying leaders fails, previously watched groups have no watchdog to kill them when pnpm dies,
although the newly spawned child is terminated.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R129-132]

+        if let Some(mut dead) = self.watchdog.take() {
+            let _ = dead.process.wait();
+        }
+        let Some(mut watchdog) = GroupWatchdog::spawn()? else {
Relevance

●● Moderate

Failure-path reliability concern is specific and substantive; no closely matching team precedent was
found.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The old watchdog is taken before the fallible spawn and replay, but the failure path pops only the
most recently appended leader. The caller's error path terminates only that newest child.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[93-107]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[126-140]
pnpm/crates/executor/src/process_tracker.rs[179-190]

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

## Issue description
A failed watchdog restart leaves earlier groups recorded but no longer protected.
## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[93-107]
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-140]
## Recommended Fix
On replacement failure, explicitly handle every previously watched group rather than only the newest child; do not retain groups as protected when no working watchdog exists.

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

Dismiss ↗ | View ↗


7. Large parallel runs stall on group updates ✓ Resolved
Description
The watchdog script copies its growing positional-parameter list for every added group and
repeatedly rebuilds it while removing a group. Runs with many concurrent scripts therefore incur
quadratic work while adding groups and potentially cubic work while releasing them; the Rust runner
also scans its leader list and writes updates under a global mutex.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R46-49]

+        if [ -z "$released" ] && [ "$group" = "${line#-}" ]; then
+          released=1
+        else
+          set -- "$@" "$group"
Relevance

●● Moderate

Performance concern is plausible, but no close precedent addresses this retained watchdog algorithm.

PR-#15564

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Each addition copies all existing shell arguments; each removal loops over them and copies the
remaining arguments again at every iteration. Both runners send these updates for every watched
child, and Rust also linearly searches its leader vector on release.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[111-122]
pnpm/crates/executor/src/process_tracker.rs[223-229]
pnpm11/exec/npm-lifecycle/src/signals.ts[340-360]

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 shared watchdog repeatedly copies its group list, making large parallel runs increasingly expensive.
## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[111-118]
- pnpm11/exec/npm-lifecycle/src/signals.ts[340-360]
## Recommended Fix
Use group bookkeeping that avoids rebuilding the entire shell argument list for each removal, update the duplicated script in both runners, and benchmark large concurrent runs. Avoid a linear search for every Rust-side release.

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


8. Unrelated running scripts get killed 🐞 Bug ☼ Reliability
Description
In GroupWatch::start_watchdog, a failing watchdog.watch(leader)? returns early and drops the
local GroupWatchdog, closing its stdin. That is the same end-of-input signal that pnpm's death
sends, so a still-live sh runs kill -9 on every group it was already told about. The trigger is
any write failure while re-registering leaders after a watchdog died; it hits all concurrent scripts
of a parallel run, while self.leaders still lists them as watched.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R136-139]

+        for &leader in &self.leaders {
+            watchdog.watch(leader)?;
+        }
+        self.watchdog = Some(watchdog);
Relevance

●● Moderate

Potential watchdog-drop hazard is serious, but lacks a closely matching acceptance or rejection
precedent.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
GroupWatchdog has no Drop impl, so dropping it drops the lifeline pipe, and the field's own
comment says end of input means pnpm is gone. The script's final loop kills every group it was told
about. The old watchdog was already removed by self.watchdog.take(), and watch only pops the new
leader.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-141]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[146-151]

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

## Issue description
In `start_watchdog`, an error from `watchdog.watch(leader)?` drops the new watchdog with its pipe open. The `sh` sees end of input and kills every group it was already told about, which are other running scripts.

## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-141]

## Recommended Fix
Build all `+<pgid>` lines into one buffer and write it with a single `write_all`. On error, call `watchdog.process.kill()` and `watchdog.process.wait()` before the watchdog is dropped, so a dead `sh` cannot run its kill loop. Leave `self.leaders` intact so the next `watch` call retries.

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

Dismiss ↗ | View ↗


9. Scripts lose protection after a watchdog dies ✓ Resolved
Description
watchProcessGroup writes to any non-null watchdogLifeline, but the dead watchdog's exit
handler clears that reference only when its event runs and does not restart it. If a new lifecycle
child starts after the shell dies but before that handler runs, its watch is written to the dead
pipe; absent a later watch, neither it nor the previously watched groups has a replacement watchdog.
Code

pnpm11/exec/npm-lifecycle/src/signals.ts[R389-394]

+  if (watchdogLifeline == null) {
+    watchdogLifeline = startWatchdog()
+    watchdogLifeline.write(watchedLeaders.map((watched) => `+${watched}\n`).join(''))
+  } else {
+    watchdogLifeline.write(`+${leader}\n`)
+  }
Relevance

●● Moderate

Race semantics are plausible, but historical evidence does not directly establish team treatment.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The active-leader list is replayed only when a watch starts a new watchdog. An exit merely clears
the lifeline, so a write made before that asynchronous exit handler runs is not replayed.

pnpm11/exec/npm-lifecycle/src/signals.ts[369-371]
pnpm11/exec/npm-lifecycle/src/signals.ts[387-401]
pnpm11/exec/npm-lifecycle/src/signals.ts[411-426]
pnpm11/exec/npm-lifecycle/src/runScript.ts[94-103]

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

## Issue description
A watch can be written to a dead watchdog before its exit event is handled, leaving active groups unprotected.
## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/src/signals.ts[388-401]
- pnpm11/exec/npm-lifecycle/src/signals.ts[418-426]
## Recommended Fix
Track watchdog termination and failed stdin writes, and promptly start a replacement that replays every still-watched leader rather than waiting for another group to be added.

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


Grey Divider

Context sources
✅ Compliance rules (platform): 63 rules
✅ Skills: review-code
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This push changes process-group watchdog lifecycle and shell signaling logic in both Rust and TypeScript, creating real performance and process-kill correctness risks across multiple paths.

Grey Divider

Tip of the day
💡 Did you know, you can keep summaries lean with Findings visible per group, which tucks the rest behind a View link

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous reviews

Review updated until commit da07533

Results up to commit 53aa906 🧠 Deep


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


Action required
1. A missing watchdog passes the group test ✗ Dismissed
Description
The new TypeScript test accepts started.length of zero because it asserts only
toBeLessThanOrEqual(1). If the runner starts no watchdog at all, the assertion passes despite
three groups being watched, so the test does not verify the process it is meant to count.
Code

pnpm11/exec/npm-lifecycle/test/signals.ts[164]

+    expect(started.length).toBeLessThanOrEqual(1)
Relevance

●●● Strong

The assertion permits zero watchdogs, so strengthening it is a deterministic test-correctness fix.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The rule requires an assertion of the changed effect. The test counts newly started watchdogs but
permits a count of zero.

pnpm11/exec/npm-lifecycle/test/signals.ts[157-164]
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 multi-group test passes when no watchdog starts.

## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/test/signals.ts[157-165]

## Recommended Fix
Assert that exactly one new watchdog starts for the three groups.

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



Remediation recommended
2. One changeset mixes both release lines 📘 Rule violation § Compliance
Description
The new changeset puts the v11 pnpm bump and the v12 pacquet bump in the same file. Because this
PR changes both implementations, the package-specific release entries cannot be maintained
independently under the checklist's separate-changeset requirement.
Code

.changeset/one-process-group-watchdog.md[R3-4]

+"pnpm": patch
+"pacquet": patch
Relevance

●●● Strong

Recent changeset precedents explicitly require separate pnpm and pacquet files.

PR-#15316
PR-#15895

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist explicitly calls for separate files when a PR touches both stacks. This single new
file lists both pnpm and pacquet.

Rule 713436: Changesets for pnpm v11 vs v12 (pacquet) must target the correct package and bump type
.changeset/one-process-group-watchdog.md[1-7]

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 changeset combines v11 and v12 package bumps although both implementations change.

## Fix Focus Areas
- .changeset/one-process-group-watchdog.md[1-7]

## Recommended Fix
Create separate changesets: one for the v11 TypeScript packages with patch bumps, and one for pacquet.

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

Dismiss ↗ | View ↗


3. Two test comments describe old behavior ✓ Resolved
Description
The new comments say that a shell per watched group or child doubled the processes a recursive run
starts. They sit above tests of the current single-watchdog behavior, leaving historical
implementation detail in source comments rather than describing the current guarantee.
Code

pnpm11/exec/npm-lifecycle/test/signals.ts[156]

+// A sh per watched group doubled the processes a recursive run starts.
Relevance

●●● Strong

Recent precedent accepts requests to rewrite comments describing historical behavior into current
invariants.

PR-#15854

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Both added comments refer to the former per-child shell behavior in the past tense, which the rule
excludes from inline comments.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm11/exec/npm-lifecycle/test/signals.ts[156-157]
pnpm/crates/executor/src/process_tracker/tests.rs[47-50]

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 new test comments describe the former per-group watchdog implementation.

## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/test/signals.ts[156-156]
- pnpm/crates/executor/src/process_tracker/tests.rs[47-48]

## Recommended Fix
Remove the historical clauses or describe only the current single-watchdog guarantee.

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


4. Earlier scripts outlive a failed restart 🐞 Bug ☼ Reliability
Description
GroupWatch::start_watchdog removes the dead watchdog before attempting a fallible replacement,
while watch removes only the newly added leader if that attempt fails. If replacement spawning or
replaying leaders fails, previously watched groups have no watchdog to kill them when pnpm dies,
although the newly spawned child is terminated.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R129-132]

+        if let Some(mut dead) = self.watchdog.take() {
+            let _ = dead.process.wait();
+        }
+        let Some(mut watchdog) = GroupWatchdog::spawn()? else {
Relevance

●● Moderate

Failure-path reliability concern is specific and substantive; no closely matching team precedent was
found.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The old watchdog is taken before the fallible spawn and replay, but the failure path pops only the
most recently appended leader. The caller's error path terminates only that newest child.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[93-107]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[126-140]
pnpm/crates/executor/src/process_tracker.rs[179-190]

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

## Issue description
A failed watchdog restart leaves earlier groups recorded but no longer protected.
## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[93-107]
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-140]
## Recommended Fix
On replacement failure, explicitly handle every previously watched group rather than only the newest child; do not retain groups as protected when no working watchdog exists.

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

Dismiss ↗ | View ↗


View medium (3)
5. Unrelated running scripts get killed 🐞 Bug ☼ Reliability
Description
In GroupWatch::start_watchdog, a failing watchdog.watch(leader)? returns early and drops the
local GroupWatchdog, closing its stdin. That is the same end-of-input signal that pnpm's death
sends, so a still-live sh runs kill -9 on every group it was already told about. The trigger is
any write failure while re-registering leaders after a watchdog died; it hits all concurrent scripts
of a parallel run, while self.leaders still lists them as watched.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R136-139]

+        for &leader in &self.leaders {
+            watchdog.watch(leader)?;
+        }
+        self.watchdog = Some(watchdog);
Relevance

●● Moderate

Potential watchdog-drop hazard is serious, but lacks a closely matching acceptance or rejection
precedent.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
GroupWatchdog has no Drop impl, so dropping it drops the lifeline pipe, and the field's own
comment says end of input means pnpm is gone. The script's final loop kills every group it was told
about. The old watchdog was already removed by self.watchdog.take(), and watch only pops the new
leader.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-141]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[146-151]

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

## Issue description
In `start_watchdog`, an error from `watchdog.watch(leader)?` drops the new watchdog with its pipe open. The `sh` sees end of input and kills every group it was already told about, which are other running scripts.

## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[128-141]

## Recommended Fix
Build all `+<pgid>` lines into one buffer and write it with a single `write_all`. On error, call `watchdog.process.kill()` and `watchdog.process.wait()` before the watchdog is dropped, so a dead `sh` cannot run its kill loop. Leave `self.leaders` intact so the next `watch` call retries.

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

Dismiss ↗ | View ↗


6. Large parallel runs stall on group updates ✓ Resolved
Description
The watchdog script copies its growing positional-parameter list for every added group and
repeatedly rebuilds it while removing a group. Runs with many concurrent scripts therefore incur
quadratic work while adding groups and potentially cubic work while releasing them; the Rust runner
also scans its leader list and writes updates under a global mutex.
Code

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[R46-49]

+        if [ -z "$released" ] && [ "$group" = "${line#-}" ]; then
+          released=1
+        else
+          set -- "$@" "$group"
Relevance

●● Moderate

Performance concern is plausible, but no close precedent addresses this retained watchdog algorithm.

PR-#15564

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Each addition copies all existing shell arguments; each removal loops over them and copies the
remaining arguments again at every iteration. Both runners send these updates for every watched
child, and Rust also linearly searches its leader vector on release.

pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
pnpm/crates/executor/src/process_tracker/group_watchdog.rs[111-122]
pnpm/crates/executor/src/process_tracker.rs[223-229]
pnpm11/exec/npm-lifecycle/src/signals.ts[340-360]

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 shared watchdog repeatedly copies its group list, making large parallel runs increasingly expensive.
## Fix Focus Areas
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[36-55]
- pnpm/crates/executor/src/process_tracker/group_watchdog.rs[111-118]
- pnpm11/exec/npm-lifecycle/src/signals.ts[340-360]
## Recommended Fix
Use group bookkeeping that avoids rebuilding the entire shell argument list for each removal, update the duplicated script in both runners, and benchmark large concurrent runs. Avoid a linear search for every Rust-side release.

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


7. Scripts lose protection after a watchdog dies ✓ Resolved
Description
watchProcessGroup writes to any non-null watchdogLifeline, but the dead watchdog's exit
handler clears that reference only when its event runs and does not restart it. If a new lifecycle
child starts after the shell dies but before that handler runs, its watch is written to the dead
pipe; absent a later watch, neither it nor the previously watched groups has a replacement watchdog.
Code

pnpm11/exec/npm-lifecycle/src/signals.ts[R389-394]

+  if (watchdogLifeline == null) {
+    watchdogLifeline = startWatchdog()
+    watchdogLifeline.write(watchedLeaders.map((watched) => `+${watched}\n`).join(''))
+  } else {
+    watchdogLifeline.write(`+${leader}\n`)
+  }
Relevance

●● Moderate

Race semantics are plausible, but historical evidence does not directly establish team treatment.

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The active-leader list is replayed only when a watch starts a new watchdog. An exit merely clears
the lifeline, so a write made before that asynchronous exit handler runs is not replayed.

pnpm11/exec/npm-lifecycle/src/signals.ts[369-371]
pnpm11/exec/npm-lifecycle/src/signals.ts[387-401]
pnpm11/exec/npm-lifecycle/src/signals.ts[411-426]
pnpm11/exec/npm-lifecycle/src/runScript.ts[94-103]

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

## Issue description
A watch can be written to a dead watchdog before its exit event is handled, leaving active groups unprotected.
## Fix Focus Areas
- pnpm11/exec/npm-lifecycle/src/signals.ts[388-401]
- pnpm11/exec/npm-lifecycle/src/signals.ts[418-426]
## Recommended Fix
Track watchdog termination and failed stdin writes, and promptly start a replacement that replays every still-watched leader rather than waiting for another group to be added.

ⓘ 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.

A failed write is replaced by starting a new watchdog, and the old one
was reaped while pnpm still held its pipe open. A watchdog that refused
writes without exiting would then never see end of input, and the
reap would block forever under the global group-watch lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 71d4476

@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.

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.

Copilot review overview

🔵 Needs a closer look

It reworks safety-critical process-group, signal, and SIGKILL-survival behavior across two language stacks using global mutable state and a hand-written POSIX shell state machine, which warrants final human sign-off even though no concrete defect was found.

Review effort: Balanced
Findings: None

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.

Copilot review overview

🔵 Needs a closer look

It changes signal handling, process-group kill -9 semantics, a process-global watchdog, and POSIX shell portability (explicitly unverified on dash/busybox/Linux), which is safety-critical and warrants human review.

Review effort: Balanced
Findings: None

Releasing a group rebuilt the positional parameters once per group
still watched, so the watchdog shell spent 2 to 8 seconds of CPU on a
run with 500 concurrent groups. A space-delimited string cut with two
pattern expansions does the same in about 10ms.

pnpm v11 now replaces a watchdog killed while groups are watched as
soon as it exits. A watch written to the dead pipe before the exit
event fails asynchronously and would otherwise be lost.

The v11 single-watchdog test now asserts exactly one watchdog rather
than at most one new one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 1, 2026 18:50
@zkochan

zkochan commented Oct 1, 2026

Copy link
Copy Markdown
Member

Responses to the Qodo review's summary findings, verified against da07533:

  • A missing watchdog passes the group test. Fixed in da07533. See the inline thread.
  • Two test comments describe old behavior. Fixed in da07533. The Rust doc comment now states the current guarantee, and the v11 history comment is gone.
  • Large parallel runs stall on group updates. Confirmed and fixed in da07533. With 500 concurrent groups, the old script spent 2.2s (dash) and 7.8s (bash) of CPU. The watchdog now keeps the groups in one space-delimited string and cuts a released one out with two pattern expansions. That takes about 0.01s, and dash, bash and zsh --emulate sh produce the same results. The Rust-side Vec scan under the mutex holds one entry per running script and is not a cost worth changing.
  • Scripts lose protection after a watchdog dies. Fixed for v11 in da07533. Node reports a write to a dead pipe asynchronously, so a watch written before the exit event was lost. A watchdog killed by a signal while groups are watched is now replaced at once, and the replacement takes over every watched group. The new test a killed watchdog is replaced and takes over every group still watched fails with the replacement removed from the compiled lib/. Rust gets EPIPE synchronously on the next write and replaces the watchdog there.
  • One changeset mixes both release lines. Declined. AGENTS.md allows one changeset for both lines when the same note applies. Both lines started a sh per group before this change and start one per pnpm process after it.
  • Earlier scripts outlive a failed restart / Unrelated running scripts get killed. Declined. Both need a write to a freshly spawned, live sh to fail. A pipe write fails only with EPIPE, which means the reader is already gone and cannot kill anything. A spawn failure leaves nothing to fall back to, and the next watch retries. 71d4476 also kills a replaced watchdog before reaping it, so reaping can never block on one that still runs.

Written by an agent (Claude Code, claude-opus-5-5).

@qodo-code-review

Copy link
Copy Markdown

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

@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.

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.

Copilot review overview

🔵 Needs a closer look

It reworks process-group signal/lifecycle management via a shared mutable global, unsafe FFI, and a hand-written POSIX sh protocol in both the Rust and TypeScript CLIs, where subtle errors orphan or mis-kill processes, so it warrants final human review despite being well-tested.

Review effort: Balanced
Findings: None

@zkochan

zkochan commented Oct 1, 2026

Copy link
Copy Markdown
Member

On the updated Qodo summary for da07533:

  • Shutdown can target the wrong script group. Not a bug. In ${groups%% "$group" *} the space after %% is part of the pattern, so it matches only a whole space-delimited ID. Watching 1234 and 34 and then releasing 34 leaves 1234 under dash, bash and zsh --emulate sh, in either order. Watching 341 and 34 and releasing 34 leaves 341.
  • The restart test can fail before restart. Answered in the inline thread. spawn returns only after the watchdog has exec'd.
  • One changeset mixes both release lines and Earlier scripts outlive a failed restart. Unchanged since the previous round. See my earlier comment.

Written by an agent (Claude Code, claude-opus-5-5).

@zkochan
zkochan merged commit 88bf5e4 into pnpm:main Oct 1, 2026
85 of 87 checks passed
@altaywtf
altaywtf deleted the perf/single-group-watchdog branch October 2, 2026 04:35
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.

Every script run without a terminal starts a second sh since 12.7.0 and 11.28.0

4 participants