Repository navigation
fix(pacquet): exec the target from a shim so signal deaths survive - #13745
Conversation
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]>
PR Summary by QodoFix POSIX shims to exec non-shebang targets so signal deaths propagate
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughPOSIX shell shims now use ChangesPOSIX shim signal preservation
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested labels: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (2): Last reviewed commit: "style(pacquet): trim the shim comments t..." | Re-trigger Greptile |
|
|
||
| /// 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. |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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 theexec— it exists solely so the generated shim stays byte-identical to@zkochan/cmd-shim's. Nothing about whatexecdoes; 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).
Code Review by Qodo
1. Historical comment in shim test
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
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]>
|
Code review by qodo was updated up to the latest commit e0c4e0c |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
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 exit128+N, so a target that died onSIGKILLwas reported to the caller as exit code137, and a signal death became indistinguishable from an ordinary exit.@zkochan/cmd-shimexecs on this arm and emits an unreachableexit $?after it. The port kept only the trailing line and a comment read that as deliberate ("upstream still emitsexit $?… 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
globalShimsis off (the setting,PNPM_SHIM_BYPASS, or thePNPM_CONFIG_GLOBAL_SHIMSthatpnpm/setupnow exports) converted signal deaths into exit codes. It surfaced as a TS CI failure on #13675, whereassertPnpmRuns › describes a signal rather than a null exit codereceivedit exited with code 137: Killedinstead of a signal.Related to #13675.
Squash Commit Body
Checklist
already linked to it solves it.
pnpm/port, or the description notes what still needs porting.The TypeScript stack (
@zkochan/cmd-shim) alreadyexecs; this closes the gap.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Verification
a_shim_lets_the_targets_signal_death_reach_the_callerpins the behaviour rather than the template text: it copies a real binary, generates a shim for it, runskill -9 $$through the shim, and assertsstatus.signal() == Some(9). Reverting the one-word change makes it fail (right: Some(9)), so it is a real regression test.pacquet-cmd-shimis 104/104, and theshim/global/binCLI 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 wasexecall 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 itspackageManagerpin to resolve to.Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
SIGKILL, now report the correct termination status instead of a transformed exit code.Tests
execbehavior in shell shims.