Repository navigation
perf: watch every script's process group with one watchdog - #16490
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (2)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe 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. ChangesProcess-group watchdog
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
Assessment against linked issues
Suggested labels: Merge Risk: ⚪ Minimal · up to 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 ReviewSecurity architecture risk: 🟡 Moderate · up to 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
Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Some tools did not complete. Review the errors below. 🔧 ESLint
pnpm11/exec/npm-lifecycle/src/signals.tsESLint 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.tsESLint 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. Comment |
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
Same-run regression checkHEAD 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.
Integrated-Benchmark Report (Linux)Commit: 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
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
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
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
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
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
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
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
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
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
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
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 storeSame 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.
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
}
]
} |
There was a problem hiding this comment.
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/-pgidprotocol and kill all still-watched groups on EOF. - Replaces the per-child
GroupWatchdogwith a shared, replaceableGroupWatch(Rust, behind a globalMutex) 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
1582dc7 to
53aa906
Compare
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
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]>
|
Code review by qodo was updated up to the latest commit 71d4476 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]>
|
Responses to the Qodo review's summary findings, verified against da07533:
Written by an agent (Claude Code, claude-opus-5-5). |
|
Code review by qodo was updated up to the latest commit da07533 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
There was a problem hiding this comment.
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
|
On the updated Qodo summary for da07533:
Written by an agent (Claude Code, claude-opus-5-5). |
Summary
Closes #16489
pnpm -r runover 50 projects without a terminal starts 1 watchdogshinstead 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: inspawn_childthroughGroupWatchdog::spawn, and in v11'swatchProcessGroup. 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 bareshspawn walksPATH.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 runskill -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 withEPIPE. 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 noopover 50 projects withnoop: true, stdin from/dev/null, no terminal, isolatedHOME). v12 binaries are both built from 50f09c2 withCARGO_PROFILE_RELEASE_LTO=false CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16 cargo build --release --bin pnpm; v11 bundles withpnpm --filter pnpm run compile, with and without the patch.PATHPATHShells 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:
process_tracker::tests::one_watchdog_watches_every_process_groupspawns three children throughspawn_childand counts the watchdogs. Reverted:left: 3, right: 1.one watchdog watches every process groupinexec/npm-lifecycle/test/signals.ts. Reverted:Expected: <= 1, Received: 3.Guarantee of #15564, kept:
SIGKILLed.interrupt::killing_the_process_group_of_pnpm_kills_every_script_of_a_parallel_run(SIGKILLto pnpm's group duringpnpm -r --parallel runover 3 projects ends all 3 scripts); the existinginterrupt::tests pass unchanged.SIGKILLleaves no watched group running, past one that already exited, and a released group survives; a watchdog killed withSIGKILLis replaced and its replacement kills the groups still watched (fails with the replacement removed from the compiledlib/); a runner with a watchdog exits on its own; the existingrun: killing pnpm's process group kills the script behind its shell tooe2e 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 andzsh --emulate shwere checked on Linux. Windows has no watchdog; CI covers that it still compiles.Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version.
pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, Opus 5.5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit