Repository navigation
fix(harness,runtime,agent): document generic sh -c opt-in, add exit-127 hint, and skip --model for generic harnesses - #5797
Conversation
…27 hint, and skip --model for generic harnesses
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
There was a problem hiding this comment.
Code Review
This pull request introduces explicit shell-form opt-in (using sh -c) for generic and declarative-generic harnesses, while maintaining the safer exec form as the default. It also ensures that the --model flag is not prepended to command arguments for generic or shell-based harnesses, while still keeping SCION_MODEL in their environment. The review feedback highlights two valuable improvements: expanding the looksLikeShellCommand helper to detect additional shell metacharacters (such as tildes, backslashes, and brackets) and refactoring the exit-127 hint logic to prevent premature shell termination when set -e is active.
| func looksLikeShellCommand(s string) bool { | ||
| return strings.ContainsAny(s, " \t\n&|;<>$`()*?'\"") | ||
| } |
There was a problem hiding this comment.
The looksLikeShellCommand helper checks for common shell metacharacters, but it currently misses several important ones such as backslashes (\\), tildes (~), carriage returns (\r), and globbing/brace expansion characters ([, ], {, }). Adding these ensures that tasks using tilde expansion (e.g., ~/script.sh), backslash escapes, or globbing are correctly identified as shell-form commands, triggering the exit-127 hint if they fail in exec form.
| func looksLikeShellCommand(s string) bool { | |
| return strings.ContainsAny(s, " \t\n&|;<>$`()*?'\"") | |
| } | |
| func looksLikeShellCommand(s string) bool { | |
| return strings.ContainsAny(s, " \t\r\n&|;<>$`()*?'\"~\\{}[]") | |
| } |
| if len(harnessArgs) == 1 && cfg.Task != "" && harnessArgs[0] == cfg.Task && looksLikeShellCommand(cfg.Task) { | ||
| line = fmt.Sprintf( | ||
| `%s; scion_rc=$?; if [ "$scion_rc" -eq 127 ]; then printf '%%s\n' %s >&2; fi; (exit "$scion_rc")`, | ||
| line, | ||
| shellQuote(genericExecForm127Hint), | ||
| ) | ||
| } |
There was a problem hiding this comment.
If the executing shell environment has set -e (errexit) enabled, the shell will immediately terminate upon the failure of the command line (exit code 127), preventing the subsequent scion_rc=$? and the if block from ever executing. To make this robust under set -e, we can run the command as part of an OR list (||), which prevents immediate shell termination and safely captures the exit status.
| if len(harnessArgs) == 1 && cfg.Task != "" && harnessArgs[0] == cfg.Task && looksLikeShellCommand(cfg.Task) { | |
| line = fmt.Sprintf( | |
| `%s; scion_rc=$?; if [ "$scion_rc" -eq 127 ]; then printf '%%s\n' %s >&2; fi; (exit "$scion_rc")`, | |
| line, | |
| shellQuote(genericExecForm127Hint), | |
| ) | |
| } | |
| if len(harnessArgs) == 1 && cfg.Task != "" && harnessArgs[0] == cfg.Task && looksLikeShellCommand(cfg.Task) { | |
| line = fmt.Sprintf( | |
| `scion_rc=0; %s || scion_rc=$?; if [ "$scion_rc" -eq 127 ]; then printf '%%s\n' %s >&2; fi; (exit "$scion_rc")`, | |
| line, | |
| shellQuote(genericExecForm127Hint), | |
| ) | |
| } |
Generic-harness tasks run in exec form, so shell-form task strings fail with exit 127. As the maintainer decided, there's no implicit shell: templates that want shell semantics opt in explicitly with
command.base: ["sh", "-c"](or the equivalent args). That's now documented, with a caution thatsh -cevaluates all task text, so opt in only for trusted task sources. An exit-127 hint points at the opt-in. Also, harnesses that don't accept--model(generic, shell, shell-based declarative) no longer get--modelprepended to their command; the model stays inSCION_MODEL.Fixes ptone#6386