Skip to content

fix(harness,runtime,agent): document generic sh -c opt-in, add exit-127 hint, and skip --model for generic harnesses - #5797

Open
ptone wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
ptone:scion/small-issues-6386
Open

ptone wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
ptone:scion/small-issues-6386

Conversation

@ptone

@ptone ptone commented Nov 28, 2026

Copy link
Copy Markdown
Member

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 that sh -c evaluates 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 --model prepended to their command; the model stays in SCION_MODEL.

Fixes ptone#6386

…27 hint, and skip --model for generic harnesses
@google-cla

google-cla Bot commented Nov 28, 2026

Copy link
Copy Markdown

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.

@gemini-code-assist gemini-code-assist Bot 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.

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.

Comment thread pkg/runtime/common.go
Comment on lines +158 to +160
func looksLikeShellCommand(s string) bool {
return strings.ContainsAny(s, " \t\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.

medium

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.

Suggested change
func looksLikeShellCommand(s string) bool {
return strings.ContainsAny(s, " \t\n&|;<>$`()*?'\"")
}
func looksLikeShellCommand(s string) bool {
return strings.ContainsAny(s, " \t\r\n&|;<>$`()*?'\"~\\{}[]")
}

Comment thread pkg/runtime/common.go
Comment on lines +195 to +201
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),
)
}

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.

medium

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.

Suggested change
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),
)
}

This branch has not been deployed

No deployments
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.

generic harness: task is exec'd as a single argv element, so shell-form tasks fail with 127 and the agent exits silently

1 participant