Skip to content

fix(pacquet): exec the target from a shim so signal deaths survive - #13745

Merged
zkochan merged 2 commits into
mainfrom
fix-shim-exec
Aug 9, 2026
Merged

zkochan merged 2 commits into
mainfrom
fix-shim-exec

Conversation

@zkochan

@zkochan zkochan commented Aug 9, 2026 •

Copy link
Copy Markdown
Member

Summary

A shim generated for a target with no interpreter — a managed runtime binary, or any bin without a shebang — ran the target as a child of the shell and then exit $?. A child killed by a signal makes the shell exit 128+N, so a target that died on SIGKILL was reported to the caller as exit code 137, and a signal death became indistinguishable from an ordinary exit.

@zkochan/cmd-shim execs on this arm and emits an unreachable exit $? after it. The port kept only the trailing line and a comment read that as deliberate ("upstream still emits exit $? … for parity with non-execve POSIX shells"). It is not deliberate — this restores parity rather than diverging from it, which is also why there is no TypeScript-side change.

The context-aware global shims widened the blast radius: their fallback re-enters the shim body with dispatch disabled, and that is exactly this arm. So any global runtime bin invoked while globalShims is off (the setting, PNPM_SHIM_BYPASS, or the PNPM_CONFIG_GLOBAL_SHIMS that pnpm/setup now exports) converted signal deaths into exit codes. It surfaced as a TS CI failure on #13675, where assertPnpmRuns › describes a signal rather than a null exit code received it exited with code 137: Killed instead of a signal.

Related to #13675.

Squash Commit Body

A shim for a target with no interpreter — a managed runtime binary, or any
bin without a shebang — ran the target as a child of the shell and exited
with `$?`. A child killed by a signal makes the shell exit 128+N, so the
caller saw exit code 137 where the target had died on SIGKILL, and could no
longer tell a signal from an exit code.

`@zkochan/cmd-shim` execs on this arm and emits an unreachable `exit $?`
after it; the port kept only the trailing line and read it as deliberate.
Restore the `exec`, and keep the vestigial `exit $?` so the two stacks'
shims stay byte-identical.

The context-aware global shims made this reachable in more places: their
fallback re-enters the shim body with dispatch disabled, which is exactly
this arm, so any global runtime bin run with `globalShims` off converted
signal deaths into exit codes.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting.
    The TypeScript stack (@zkochan/cmd-shim) already execs; this closes the gap.
  • 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.
  • Updated the documentation if needed.

Verification

a_shim_lets_the_targets_signal_death_reach_the_caller pins the behaviour rather than the template text: it copies a real binary, generates a shim for it, runs kill -9 $$ through the shim, and asserts status.signal() == Some(9). Reverting the one-word change makes it fail (right: Some(9)), so it is a real regression test.

pacquet-cmd-shim is 104/104, and the shim / global / bin CLI suites are 120/120. The two existing template assertions were updated — note both already carried the message "no-runtime arm must exec the target directly", so the intent was exec all along; only the assertion had been pinned to the wrong body.

Release note

The shim body is written at link time, so this reaches a machine only once a pnpm carrying the fix rewrites the shim. Existing installs keep the old body until pnpm self-update, pnpm runtime set -g, or a global install re-links it. #13675 cannot go green until a release with this fix exists for its packageManager pin to resolve to.


Written by an agent (Claude Code, claude-opus-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

    • POSIX command shims now preserve signal-based termination behavior when launching interpreterless targets.
    • Commands terminated by signals, such as SIGKILL, now report the correct termination status instead of a transformed exit code.
  • Tests

    • Added coverage for signal handling and exec behavior in shell shims.

A shim for a target with no interpreter — a managed runtime binary, or any
bin without a shebang — ran the target as a child of the shell and exited
with `$?`. A child killed by a signal makes the shell exit 128+N, so the
caller saw exit code 137 where the target had died on SIGKILL, and could no
longer tell a signal from an exit code.

`@zkochan/cmd-shim` execs on this arm and emits an unreachable `exit $?`
after it; the port kept only the trailing line and read it as deliberate.
Restore the `exec`, and keep the vestigial `exit $?` so the two stacks'
shims stay byte-identical.

The context-aware global shims made this reachable in more places: their
fallback re-enters the shim body with dispatch disabled, which is exactly
this arm, so any global runtime bin run with `globalShims` off converted
signal deaths into exit codes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings August 9, 2026 19:48

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Fix POSIX shims to exec non-shebang targets so signal deaths propagate

🐞 Bug fix 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Restore exec in POSIX shims when the target has no interpreter/shebang.
• Preserve signal termination semantics (avoid 128+N exit-code translation by shells).
• Add Unix regression test and ship a patch changeset for pacquet.
Diagram

graph TD
  A["pacquet cmd-shim (Rust)"] --> B["Generated POSIX shim"] --> C{"Target has\nno shebang?"}
  C -->|Yes| D["exec target"] --> E(("Caller"))
  C -->|No| F["Run via interpreter"] --> E

  subgraph Legend
    direction LR
    _proc([Process step]) ~~~ _dec{"Decision"} ~~~ _term((Caller))
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Translate 128+N back into a signal (self-kill) instead of exec
  • ➕ Could avoid using exec if a shell environment required post-processing
  • ➕ Might allow additional shim bookkeeping after the child exits
  • ➖ Shell- and platform-specific edge cases (signals, job control, traps)
  • ➖ Hard to do correctly and portably across POSIX shells
  • ➖ Still risks mismatches with upstream @zkochan/cmd-shim behavior
2. Use a small native wrapper for the no-interpreter path
  • ➕ Precise control over signal forwarding/exit status
  • ➕ Avoids shell portability quirks
  • ➖ Adds build/distribution complexity and per-platform binaries
  • ➖ Moves away from upstream byte-identical shim bodies
  • ➖ Overkill for a one-line behavioral parity fix

Recommendation: Keep the PR’s approach: emitting exec for the no-interpreter arm is the simplest, most portable way to preserve signal semantics and restores parity with upstream cmd-shim. Retaining the (unreachable) exit $? for byte-identical output is reasonable to minimize cross-stack drift.

Files changed (3) +46 / -5

Bug fix (2) +11 / -3
shim-exec-preserves-signals.mdAdd changeset documenting POSIX shim signal-preservation fix +5/-0

Add changeset documenting POSIX shim signal-preservation fix

• Introduces a patch changeset for 'pacquet' describing the restored 'exec' behavior for no-shebang/no-interpreter targets and why it matters (signal deaths vs 128+N exit codes).

.changeset/shim-exec-preserves-signals.md

shim.rsExec no-runtime targets in generated POSIX shims +6/-3

Exec no-runtime targets in generated POSIX shims

• Updates the POSIX shim generator to 'exec' the target when no interpreter/runtime is present, preventing shells from converting signal deaths into '128+N' exit codes. Expands inline comments to clarify the signal semantics and the intentional (unreachable) trailing 'exit $?' for upstream byte-identical parity.

pnpm/crates/cmd-shim/src/shim.rs

Tests (1) +35 / -2
tests.rsAdjust shim-body assertions and add Unix signal-propagation regression test +35/-2

Adjust shim-body assertions and add Unix signal-propagation regression test

• Updates existing tests to expect 'exec' in the no-runtime/no-prog branches. Adds a Unix-only test that runs a generated shim against a real executable and verifies 'SIGKILL' is observed as a signal (no numeric exit code), ensuring the regression can’t return.

pnpm/crates/cmd-shim/src/shim/tests.rs

@coderabbitai

coderabbitai Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: e10f56eb-72bf-4bea-b5bf-00b77c296f82

📥 Commits

Reviewing files that changed from the base of the PR and between b101c4e and e0c4e0c.

📒 Files selected for processing (2)
  • pnpm/crates/cmd-shim/src/shim.rs
  • pnpm/crates/cmd-shim/src/shim/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/cmd-shim/src/shim.rs
  • pnpm/crates/cmd-shim/src/shim/tests.rs

📝 Walkthrough

Walkthrough

POSIX shell shims now use exec for interpreterless targets. Tests verify the generated command paths and confirm that signal-based termination status reaches the caller unchanged. A patch changeset documents the behavior.

Changes

POSIX shim signal preservation

Layer / File(s) Summary
Restore exec in the shell-shim fallback
pnpm/crates/cmd-shim/src/shim.rs
The fallback replaces the shell process with the target through exec while preserving runtime arguments and trailing exit handling.
Validate generated shim behavior
pnpm/crates/cmd-shim/src/shim/tests.rs, .changeset/shim-exec-preserves-signals.md
Tests require exec in no-runtime paths and verify that a target terminated by SIGKILL preserves its signal status. The changeset documents the patch.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • pnpm/pnpm#13411: Both PRs modify POSIX shell-shim generation and its tests, but address different behaviors.
  • pnpm/pnpm#13731: Both PRs modify shell-shim generation and fallback dispatch behavior.

Suggested labels: product: pacquet

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-shim-exec

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.

@greptile-apps

greptile-apps Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Reviews (2): Last reviewed commit: "style(pacquet): trim the shim comments t..." | Re-trigger Greptile

Comment thread pnpm/crates/cmd-shim/src/shim/tests.rs Outdated
Comment on lines +742 to +745

/// A caller must be able to tell "the target died on a signal" from "the
/// target exited with a code". Only holds if the shim `exec`s the target:
/// a shell that waits on it converts a signal death into exit code 128+N.

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.

P2 Remove duplicated behavior commentary

This doc comment restates the signal-versus-exit-code behavior already expressed by the descriptive test name, setup, and assertions, while the related implementation comment similarly narrates the adjacent exec and unreachable exit. The duplicated prose adds maintenance cost and can drift from the executable behavior.

Context Used: Comments and docs in code are suspicious. Is test ... (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in e0c4e0c — and it matches this repo's own comment rule, so thanks for catching it.

Both comments shrank to what the code cannot say on its own:

  • The implementation comment now only explains why an unreachable exit $? is emitted after the exec — it exists solely so the generated shim stays byte-identical to @zkochan/cmd-shim's. Nothing about what exec does; the test pins that.
  • The test's doc comment is down to one sentence of why the test exists (a waiting shell surfaces the death as exit code 128+N, indistinguishable from an ordinary exit) instead of restating the assertions.

The remaining inline comment in the test is kept deliberately: it explains why the fixture copies a real binary rather than writing a script, which is not evident from std::fs::copy("/bin/sh", …) — a script would carry a shebang and take a different arm of the generator entirely.


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

@qodo-code-review

qodo-code-review Bot commented Aug 9, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2) 📜 Skill insights (0)

Grey Divider


Remediation recommended

1. Historical comment in shim test 📘 Rule violation ⚙ Maintainability ⭐ New
Description
The new doc comment describes what a “waiting shell would” do (a prior/hypothetical implementation)
rather than documenting the current contract and why the current behavior matters. This violates the
rule against historical/temporal implementation comments and can become misleading as the code
evolves.
Code

pnpm/crates/cmd-shim/src/shim/tests.rs[R743-744]

+/// A waiting shell would surface the death as exit code 128+N, which the
+/// caller cannot tell from an ordinary exit.
Relevance

●●● Strong

Team often accepts rewriting/removing temporal/hypothetical test doc comments to be contract-focused
and non-historical.

PR-#13734
PR-#13652

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 772199 requires comments to describe current behavior rather than historical
implementations. The added doc comment explicitly describes the alternative “waiting shell” behavior
(“would surface the death as exit code 128+N”), which is not the current behavior being tested.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cmd-shim/src/shim/tests.rs[743-744]

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 newly added doc comment explains behavior in terms of a historical/hypothetical implementation (“A waiting shell would…”), which violates the guideline to document current behavior.

## Issue Context
This is in a new test documenting shim behavior around signal propagation. The intent should be stated as the current contract (what the shim must do/guarantee) rather than describing the prior non-`exec` approach.

## Fix Focus Areas
- pnpm/crates/cmd-shim/src/shim/tests.rs[743-744]

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



Informational

2. Misleading exec comment 🐞 Bug ⚙ Maintainability ⭐ New
Description
In generate_sh_shim(), the comment claims the trailing exit $? is unreachable after exec, but
it is reachable when exec fails (e.g., missing or non-executable target), which can mislead future
changes around error behavior.
Code

pnpm/crates/cmd-shim/src/shim.rs[R341-343]

+        // The trailing `exit $?` is unreachable after the `exec`. It is
+        // emitted anyway because upstream emits it, which is what keeps
+        // the two stacks' shims byte-identical.
Relevance

●● Moderate

Mixed precedent on comment-accuracy edits in cmd-shim; some accepted, but a similar “fix misleading
comment” was rejected.

PR-#13536
PR-#13644

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The updated comment asserts unreachability, but the shim string emitted in this branch includes
exec ... followed by exit $?; in POSIX sh, a failed exec returns to the shell, so the
following exit $? can run.

pnpm/crates/cmd-shim/src/shim.rs[341-347]

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 comment says the trailing `exit $?` is unreachable after `exec`, but that is only true when `exec` succeeds. If `exec` fails, the shell continues and can execute the `exit $?` line.

## Issue Context
This change is documentation-only but can cause future contributors to incorrectly assume the shim cannot observe/propagate `exec` failure status.

## Fix Focus Areas
- pnpm/crates/cmd-shim/src/shim.rs[341-343]

## Suggested change
Adjust the comment to something like:
- “The trailing `exit $?` is unreachable if `exec` succeeds; it remains reachable if `exec` fails. It is emitted anyway because upstream emits it, keeping the two stacks’ shims byte-identical.”

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


3. pnpm missing in changeset 📘 Rule violation § Compliance
Description
The new changeset declares a bump for pacquet but does not include an entry for the pnpm
package. This violates the repo requirement that changesets explicitly declare a pnpm bump type.
Code

.changeset/shim-exec-preserves-signals.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Team often rejects adding pnpm entry when changeset bumps only pacquet, despite bot compliance
prompts.

PR-#13739
PR-#13734
PR-#13707

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires every changeset to include an explicit pnpm entry with a valid
bump type. The added changeset file only lists "pacquet": patch in its front-matter, so pnpm is
missing.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/shim-exec-preserves-signals.md[1-3]

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 front-matter is missing a `pnpm` entry.

## Issue Context
Compliance requires each changeset to explicitly declare the `pnpm` package and a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/shim-exec-preserves-signals.md[1-3]

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


Grey Divider

Context used
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can ask Qodo to dismiss a finding you disagree with, with your reason on record

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit e0c4e0c ⚖️ Balanced

Results up to commit b101c4e ⚖️ Balanced


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


Informational
1. pnpm missing in changeset 📘 Rule violation § Compliance
Description
The new changeset declares a bump for pacquet but does not include an entry for the pnpm
package. This violates the repo requirement that changesets explicitly declare a pnpm bump type.
Code

.changeset/shim-exec-preserves-signals.md[R1-3]

+---
+"pacquet": patch
+---
Relevance

● Weak

Team often rejects adding pnpm entry when changeset bumps only pacquet, despite bot compliance
prompts.

PR-#13739
PR-#13734
PR-#13707

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713436 requires every changeset to include an explicit pnpm entry with a valid
bump type. The added changeset file only lists "pacquet": patch in its front-matter, so pnpm is
missing.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/shim-exec-preserves-signals.md[1-3]

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 front-matter is missing a `pnpm` entry.

## Issue Context
Compliance requires each changeset to explicitly declare the `pnpm` package and a valid bump type (`patch`/`minor`/`major`).

## Fix Focus Areas
- .changeset/shim-exec-preserves-signals.md[1-3]

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


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.

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Aug 9, 2026
@github-actions

github-actions Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     11.4±0.05ms    32.8 MB/sec    1.00     11.4±0.05ms    32.8 MB/sec
packument/parse                                  1.00     35.5±0.34µs  1868.6 MB/sec    1.00     35.6±0.14µs  1864.2 MB/sec
tarball/download_dependency                      1.01      2.3±0.06ms  1912.8 KB/sec    1.00      2.2±0.07ms  1930.5 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.05    175.3±8.06ms 91.3 KElem/sec    1.00    166.5±4.63ms 96.1 KElem/sec
workspace_resolution/hoist_heavy                 1.00    237.9±0.94ms        ? ?/sec    1.04   247.4±10.16ms        ? ?/sec

@codecov-commenter

codecov-commenter commented Aug 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.10%. Comparing base (7ddb297) to head (e0c4e0c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13745   +/-   ##
=======================================
  Coverage   88.10%   88.10%           
=======================================
  Files         622      622           
  Lines      101098   101098           
=======================================
+ Hits        89075    89077    +2     
+ Misses      12023    12021    -2     

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

The signal-versus-exit-code behaviour is pinned by the test, so neither
comment needs to narrate it. What survives is the part the code cannot
show: why an unreachable `exit $?` is emitted at all, and why the fixture
copies a binary rather than writing a script.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 9, 2026 19:55

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 was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

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

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

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

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants