Repository navigation
fix(sandbox): keep Kubernetes wrap newlines around command - #3204
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Minimal, correct fix for the heredoc/#-comment breakage in the Kubernetes sandbox exec path: the closing ) is moved onto its own line, so a command whose last line is a heredoc terminator (or ends in a trailing comment / line continuation) is no longer glued to ). Verdict: approve — the two items below are non-blocking.
I replayed both wrap shapes against dash and bash with the same grammar the runtime uses (sh -c '<cd> && (<command>)'). The new shape fixes exactly the class reported in #3198 and also repairs two shapes the old wrap broke — a command ending in # comment and one ending in a trailing \ — with no behaviour change for single-line commands, trailing newlines, multi-line if/fi blocks, background &, or commands containing quoted parens. So this is a strict improvement, not a swap of one broken case for another.
Scope is right too: the wrap only exists in KubernetesSandbox.doExec — Docker passes sh -c <command> with -w <workspaceRoot>, AgentRun hands the command to mcp.exec, Daytona and E2b take a cwd — so the "only the Kubernetes backend changes" claim in the description holds. Repo-wide grep finds no remaining consumer of the old single-line shape outside the two places this PR updates. CI is green (build ubuntu/windows, Check Module Sync, Check License, codecov patch) and license/cla is signed.
Findings
- [Warning]
KubernetesSandbox.java:92— a null/blankcommandstill reaches the shell and fails as an opaque syntax error under both the old and the new shape; not a regression, just an opportunity to make the contract explicit while this line is open. - [Info]
KubernetesSandboxTest.java:96—assertTrue(!…)→assertFalse(…), and consider pinning the two additional shapes the newline wrap repairs (trailing#comment, trailing\) so a future refactor of the wrap cannot silently re-break them.
Suggestions
If you want the blank-command guard, the narrow version keeps the exception type the harness already maps:
String wrapped =
"cd " + shellQuote(k8sState.getWorkspaceRoot()) + " && (\n" + command + "\n)";→
if (command == null || command.isBlank()) {
throw new SandboxException.ExecException(2, "", "empty command rejected by KubernetesSandbox");
}
String wrapped =
"cd " + shellQuote(k8sState.getWorkspaceRoot()) + " && (\n" + command + "\n)";A @ParameterizedTest over the last line of the payload (heredoc terminator, # comment, trailing \, plain command) would cover the whole class in one place.
Automated review by github-manager-bot
| throws Exception { | ||
| String wrapped = "cd " + shellQuote(k8sState.getWorkspaceRoot()) + " && (" + command + ")"; | ||
| String wrapped = | ||
| "cd " + shellQuote(k8sState.getWorkspaceRoot()) + " && (\n" + command + "\n)"; |
There was a problem hiding this comment.
[Warning] Non-blocking, but worth deciding on while this line is open. The new shape still produces a shell syntax error for a null/blank command — cd '/workspace' && (\n\n) fails with syntax error near unexpected token ')' in both dash and bash. That is unchanged from the old wrap, so it is not a regression; it just means an empty command surfaces as an opaque sh parse error instead of a clear failure.
Since this PR is the one that owns the wrap shape, a cheap guard would make the contract explicit:
if (command == null || command.isBlank()) {
throw new SandboxException.ExecException(2, "", "empty command rejected before exec");
}(Or simply skip the subshell for blank input.) Happy to see this handled in a follow-up — it does not affect the fix here.
There was a problem hiding this comment.
Applied: null/blank command now throws SandboxException.ExecException(2, "", "empty command rejected by KubernetesSandbox") before the wrap.
| assertEquals("cd '/workspace' && (\n" + command + "\n)", wrapped); | ||
| // Closing ')' must not glue onto the heredoc terminator. | ||
| assertTrue(wrapped.endsWith("\nEOF\n)")); | ||
| assertTrue(!wrapped.contains("EOF)")); |
There was a problem hiding this comment.
[Info] Two small test nits:
assertTrue(!wrapped.contains("EOF)"))reads better asassertFalse(...)— the failure message then states the positive condition that broke.- The newline wrap actually repairs more than the heredoc case:
echo hi # note(the old form let the#comment swallow the closing)) and a command ending in a trailing\continuation both failed before and pass now. Those two shapes are the reason I would not switch to a;-appending variant instead. Consider folding them into this test (a@ParameterizedTestover last-line payloads would keep it compact) so the broader guarantee is pinned and a later refactor of the wrap cannot silently re-break them.
There was a problem hiding this comment.
Applied: switched to assertFalse, and expanded into a @ParameterizedTest over last-line payloads (heredoc terminator / # comment / trailing \ / plain) asserting the closing ) stays on its own line. Also added doExecRejectsNullOrBlankCommand.
Address oss-maintainer review on agentscope-ai#3204: guard null/blank command before wrap, use assertFalse, and parameterize last-line wrap shapes (heredoc / comment / trailing \ / plain).
|
Applied review feedback from @oss-maintainer on
|
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Re-reviewed the new commit since my approval (0d96e96 → fee113e): the incremental change rejects null/blank commands in KubernetesSandbox.doExec with a clear ExecException (stderr message) and converts the newline-wrapping assertions into a parameterized test covering heredoc, trailing-comment, trailing-backslash and plain commands. The wrap contract (closing paren on its own line) is now asserted generically instead of the heredoc-only case. All 6 checks pass on this head. LGTM — the added guard makes failed-exec surfacing unambiguous and the test matrix covers the previously fragile edge cases.
Automated review by github-manager-bot
|
Thanks for the review! I didn’t realize you had merge access 😄 |
AgentScope-Java Version
2.0.3-SNAPSHOT (based on upstream/main at 6c8ccc5)
Description
KubernetesSandbox.doExecwrapped commands ascd <root> && (command)with the closing)concatenated onto the last line of the command. When that last line was a heredoc terminator (e.g.EOF), the shell sawEOF)instead ofEOF, so the delimiter never matched and dash reportedSyntax error: end of file unexpected (expecting ")").This change puts the subshell delimiters on their own lines:
Only the Kubernetes backend wraps this way; Docker / local / AgentRun paths are unchanged.
Closes #3198
Verification
mvn spotless:apply/mvn spotless:checkfor the changed sandbox-kubernetes module: passedmvn -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-kubernetes -am test -Dtest=KubernetesSandboxTest: 11 tests, 0 failuresdoExecKeepsClosingParenOffHeredocTerminatorLineChecklist