Skip to content

fix(err): pass the child argv through verbatim - #4206

Closed
MincongZhou wants to merge 1 commit into
rtk-ai:developfrom
MincongZhou:fix/err-preserve-child-argv
Closed

MincongZhou wants to merge 1 commit into
rtk-ai:developfrom
MincongZhou:fix/err-preserve-child-argv

Conversation

@MincongZhou

Copy link
Copy Markdown

Summary

  • rtk err <cmd> [args...] joined its argv into a shell string and handed that to sh -c / cmd /C, which re-split it on whitespace. A quoted argument lost its boundary, so rtk err sh -c 'exit 7' was run as sh -c exit 7 — the one-word script exit with $0=7 — and exited 0. A hard failure was reported as success.
  • A multi-word argv now reaches the child as a vector, the same route rtk proxy already takes, reusing resolved_command + ChildArgExt instead of adding a second quoting path. A lone argument is still a shell string, so rtk err '<cmd> && <cmd>' keeps composing.
  • rtk test flattens its argv the same way in cmds::rust::runner::run_test, but it already routes native expressions through run_passthrough and the issue isolates err, so I left it out to keep the diff in scope. Happy to follow up separately.

Closes #2389

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test
  • Manual testing: rtk <command> output inspected

tests/err_argv_preservation_test.rs is new and fails on unmodified develop:

# develop, unmodified
test failure_inside_a_quoted_child_script_still_fails ... FAILED
test quoted_argument_holding_a_space_arrives_whole ... FAILED
test result: FAILED. 2 passed; 2 failed

# with the change
test result: ok. 4 passed; 0 failed

Manual before/after, rtk 0.48.0 develop @ b748a5f, Linux x86_64. The probe prints its own argc and each argument on stderr, then exits 1:

$ rtk err /tmp/argspy 'a b' c
BEFORE: argc=3  arg=[a] arg=[b] arg=[c]
AFTER:  argc=2  arg=[a b] arg=[c]
$ rtk proxy /tmp/argspy 'a b' c          # reference, unchanged
        argc=2  arg=[a b] arg=[c]

$ rtk err sh -c 'exit 7'
BEFORE: [ok] Command completed successfully (no errors),  exit 0
AFTER:  [FAIL] Command failed (exit code: 7),              exit 7

$ rtk err "sh -c 'exit 9'"               # single argument: shell string
BEFORE: exit 9
AFTER:  exit 9

Full cargo test --all reports the same two guard_integration_test failures before and after this change (git 2.34.1 here), so they are unrelated to it.

`rtk err <cmd> [args...]` joined its argv into one string and handed that to
`sh -c` / `cmd /C`, which re-split it on whitespace. A quoted argument lost its
boundary:

    $ rtk err sh -c 'exit 7'
    # reached sh as: sh -c exit 7

Per POSIX that runs the one-word script `exit` with `$0=7` and exits 0, so a
hard failure was reported as success.

A multi-word argv now reaches the child as a vector, the route `rtk proxy`
already takes, reusing `resolved_command` and `ChildArgExt`. A lone argument is
still a shell string, so `rtk err '<cmd> && <cmd>'` keeps composing.

Closes rtk-ai#2389
@CLAassistant

CLAassistant commented Sep 23, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@bharvey42

Copy link
Copy Markdown

This overlaps with #3505, which fixes the same re-split and uses the same rule: a lone argument stays a shell string, and several arguments go straight to the child as argv. Here's how the two compare, so a reviewer doesn't have to work it out:

I don't mind which one lands. The outcomes I'd like to avoid are this merging and #2389 closing while test and summary still re-split, or both PRs being merged into conflicting code. Two ways to settle it:

  1. Merge fix(exec): stop re-parsing already-parsed argv through a second shell #3505 and move tests/err_argv_preservation_test.rs from here into it, credited to you.
  2. Merge this PR first, and I'll rebase fix(exec): stop re-parsing already-parsed argv through a second shell #3505 on top to extend the same route to test, summary and run.

@MincongZhou, is either of those fine with you?

@MincongZhou

Copy link
Copy Markdown
Author

Thanks for writing this out. Folding child_args (3f285de) back into #3505 was a good catch.

Option 2 works for me. Land this one, then rebase #3505 on top to extend the same route to test, summary and run. Our process-level tests ride along with it, and #3505 can stay the umbrella for the rest.

On the one thing you flagged, #2389 closing while test/summary still re-split: I went back and read the issue and it's narrower than that. Its title is "rtk err re-splits child command argv on whitespace..." and the body only reproduces the err path; it even holds up rtk proxy as already correct, which is exactly the err-vs-proxy gap this PR closes. The summary stray-file case is filed separately as #3185, and test belongs to that same class.

So Closes #2389 is right for this diff and doesn't bury #3185 or the test path. Those stay open for #3505. If you or a maintainer still want #2389 held open as the umbrella, say the word and I'll drop Closes for a plain reference. One line.

If a maintainer would rather take #3505 whole (option 1), moving tests/err_argv_preservation_test.rs over is fine by me. Just tell me which way.

@bharvey42

Copy link
Copy Markdown

Heads-up before we go further with option 2: #4125 (pashifika) covers err, test, summary and run, and KuSh is reviewing it. Scope is accepted and round 2 is done. It uses a different contract from both of ours: positional argv always executes directly, and a script needs --shell or run -c, so rtk err 'a && b' no longer goes through a shell. KuSh closed #3002 in its favour for that reason.

ryanduguid has since Windows-tested #4125 there, alongside both our PRs (#4125 (comment)). Since choosing between the lone-string rule and an explicit --shell is KuSh's call now, I'm closing #3505 in favour of #4125. What you do with #4206 is up to you, of course.

@MincongZhou

Copy link
Copy Markdown
Author

Closing this in favour of #4125, which KuSh merged on 2026-09-26 and which covers err, test, summary and run.

Thanks @bharvey42 for flagging it, and for closing #3505 so we were not both stuck waiting.

Nothing needs carrying over. The argv fix here is a subset of what landed, and the process-level tests in tests/err_argv_preservation_test.rs are covered by tests/run_shell_test.rs in #4125.

The one difference: this PR kept a lone quoted argument as a shell string, so rtk err 'a && b' still composed. #4125 runs positional argv directly and makes a script explicit with --shell or run -c. That is a deliberate breaking change and it went through three review rounds. Nothing to revive here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rtk err re-splits child command argv on whitespace — quoted arguments corrupted, exit codes silently wrong

3 participants