Repository navigation
fix(xargs): exit 123 when any invocation fails, like GNU - #223
Conversation
d631e85 to
2e453cf
Compare
|
@strandly-the-agent Please review this PR |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Verdict: approve once the timeout status is fixed. I compared the new status rules with GNU xargs 4.9.0 and they match. Two 🟡 inline, nothing blocking:
- 🟡 A timeout inside xargs now exits 123.
Shell::timeoutdocumentsstatus = 1(src/shell.rs:1015-1017). Withtimeout = 1,echo 2 | xargs sleepgives 1 on main and 123 on this PR. There's a fix suggestion inline; I tested it and it gives 1 again. - 🟡
xargs_status_not_foundalso passes on main, so no test checks the new stop-on-127. The stronger test inline passes here and fails on main.
CI: the FAILURE rollup comes from run 43316065263, which was cancelled and superseded by rerun 43316066805. That rerun was still in progress and had no failed jobs when I checked. This PR didn't cause it.
✅ What I verified
- Head
2e453cf.cargo test --workspace --all-targets: 2207 passed, 0 failed. - New tests with main's
xargs.rsswapped in: 6 of 7 fail (with the strengthenedxargs_status_not_found). Onlyxargs_status_all_succeedpasses, as expected. On the PR head, all 7 pass. - Against GNU 4.9.0:
- A failure in the middle, at the end, or under
-Igives 123. - 255 gives 124, and the abort message is byte-identical to GNU's.
- A missing command gives 127 with one error. main printed it twice.
- All runs succeeding gives 0.
- A failure in the middle, at the end, or under
set -e,||andifaround xargs behave like bash with GNU xargs (exit 123, theelsebranch sees 123).- Callers:
tests/differential/cases/xargs_*.sh,tests/command_fallback.rs:274andtests/command_check.rs:425still pass. No docs or tool descriptions mention xargs status. - Timeout repro, with
[limits] timeout = 1:strands-shell --config t.toml -c 'echo 2 | xargs sleep'gives main rc=1, PR rc=123, and PR + suggestion rc=1. The 123 only reaches the final status when xargs is the last command. Every limit check (src/exec.rs:2163-2201) returns 1, so a limit status never collides withstops(). - Process: an advanced-tier adversarial pass timed out at 900s. I re-ran it, scoped to limits and
set -e, and it finished; the timeout finding comes from that run.
Appendix — non-blocking (4)
- ⚪ 126/127 deviation (documented):
run_scriptalso returns 126 when it can't open or read a script (src/exec.rs:160-178). Soxargs -n 1 shstops at a missing script, where GNU carries on and returns 123. The trade-off seems fine to me. A test pinning0\n127\n7→ stops at 127 would stop a later change from flipping it without anyone noticing. - ⚪ Pre-existing, not filed:
exit Nisn't masked to 8 bits ((exit 256); echo $?prints 256). Practically unreachable. - ⚪ Pre-existing:
printf '' | xargs falsereturns 0. GNU, without-r, runs the command once and returns 123. - ⚪ With
-I X X …, the abort message names the unsubstitutedX(cmd_args[0]). Contrived.
|
@strandly-the-agent Please review this PR Both findings are fixed in bd2c189. Timeout results stay at the documented status 1 across normal, -n, and -I paths. The missing-command test now asserts exactly one diagnostic, and I verified it fails if stop-on-127 is removed. The timeout regression failed before the fix and passes now. Full workspace tests, fmt, clippy, doc tests, and warning-denied docs pass, along with seven GNU comparisons and three CLI timeout cases. The documented 126/127 trade-off and the pre-existing empty-input behavior remain as described. |
strandly-the-agent
left a comment
There was a problem hiding this comment.
Approve. I checked both findings at bd2c189 and both are fixed. I found nothing new in the fix.
- ✅ Timeout status: the
check_limits()guard is atsrc/builtins/xargs.rs:147-149.xargs_status_timeoutcovers the default,-nand-Ipaths. When I removed the guard, the test failed with[123, 123, 123]against[1, 1, 1]. - ✅ Stop-on-127:
xargs_status_not_foundnow asserts a single diagnostic. When I removed 127 fromstops(), the test failed.
CI on bd2c189 was still pending when I checked: the Windows Node jobs had passed and the rest were queued.
✅ What I verified
cargo test --workspace --all-targetsatbd2c189: 2208 passed, 0 failed. That's one more than before, the new timeout test.- Both mutation checks above were reverted afterwards, and the worktree is clean.
- Attacking the fix:
- If the deadline expires during a final run that exits 0, xargs now returns 1. That matches the shell's own check after a successful command (
src/exec.rs:2162-2167), so it's consistent rather than a regression. - The guard runs on the parent
proc, whose depth has already passedcheck_limits, so only the deadline can trigger it. - The 200 ms test deadline isn't flaky. If CI is slow enough for the deadline to hit before xargs runs,
execute_itemstill returns 1 with the same message, and the whole xargs filter ran in 0.64 s.
- If the deadline expires during a final run that exits 0, xargs now returns 1. That matches the shell's own check after a successful command (
- The 126/127 trade-off and the empty-input behaviour are unchanged, as you noted. They're still non-blocking.
Description
xargs returned the status of its last run only, so a failure in the middle got lost. With files
aandband nonosuch, on main:GNU xargs exits 123 there. Now xargs follows GNU's rules: 123 if any run failed, and if the command exits 255 it stops and exits 124. With this change the example above prints 123. One difference from GNU: a command that itself exits 126 or 127 stops xargs here, while GNU only stops when the command can't be run, because inside the shell those two cases return the same status.
I compared each case against GNU xargs on Linux and added tests that fail on main and pass with the change. This doesn't touch option parsing or stderr forwarding, and it merges cleanly with #208 and #213.
Related Issues
Part of #207
Documentation PR
N/A
Type of Change
Bug fix
Testing
How have you tested the change? Verify that the changes do not break functionality or introduce new warnings.
cargo test --workspace --all-targets,pytest tests/python,npm test)cargo fmtandcargo clippyChecklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.