Repository navigation
Conversation
|
u010143241 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
Changes Docker sandbox command execution from sh -c to sh -s (stdin pipe), solving Windows command-line length limits, UTF-8 escaping issues, and process argument exposure. Well-scoped change (2 files, +108/-12) with comprehensive tests. Clean implementation, no issues found.
This comment was marked as abuse.
This comment was marked as abuse.
oss-maintainer
left a comment
There was a problem hiding this comment.
Summary
Streams the shell program into docker exec -i ... sh -s instead of embedding it in sh -c <command>, which is the right fix for the host argv limits and quoting problems with agent-generated scripts, and the helper extraction + integration-test gate are sensible. Findings above are about the unbounded stdin write (the one real risk), stdin re-direction semantics for nested commands, and the fact that the unit tests do not cover the wiring they appear to cover.
Note: the license/cla check is still pending, so this review is a COMMENT only — please sign the CLA (see reminder) before a maintainer looks at merging.
Automated review by github-manager-bot
| drainer.shutdown(); | ||
|
|
||
| try (OutputStream stdin = process.getOutputStream()) { | ||
| writeShellProgram(stdin, command); |
There was a problem hiding this comment.
[Warning] writeShellProgram runs on the calling thread before process.waitFor(timeoutSeconds, ...), so the per-call timeout does not bound the stdin write. For a large shell program (this PR's own test uses ~100 KB) the pipe fills once docker exec -i stops draining it — e.g. the daemon is slow, the exec is failing/retrying, or the container is being killed — and stdin.write(...) can block long past timeoutSeconds while the output drainers just sit idle. Writing stdin from the same drainer executor (or a dedicated single-use future bounded by timeoutSeconds) keeps the documented timeout guarantee; the current shape turns a bounded doExec into a potentially unbounded one.
| } | ||
|
|
||
| static List<String> buildExecCommand(String containerId, String workspaceRoot) { | ||
| return List.of("docker", "exec", "-i", "-w", workspaceRoot, containerId, "sh", "-s"); |
There was a problem hiding this comment.
[Info] Adding -i also re-points the container's stdin at the script, so any command inside the program that reads stdin (git, mysql, ssh, a bare read, cat with no file) now consumes the remaining script bytes instead of hitting an immediate EOF like it did with the previous sh -c form. For agent-generated tool calls that is a silent truncation risk. If the goal is only to keep argv small, docker exec -i <cid> sh -s -- </dev/null-style redirection is not possible from the host side, so either document the caveat in the class javadoc above or drain the script into a file first (sh -c 'cat > /tmp/x && sh /tmp/x') — otherwise worth a comment noting the tradeoff was considered.
| } | ||
|
|
||
| static void writeShellProgram(OutputStream stdin, String command) throws IOException { | ||
| stdin.write(command.getBytes(StandardCharsets.UTF_8)); |
There was a problem hiding this comment.
[Info] No trailing newline is appended. sh -s executes the last line without one in practice (dash/bash both handle EOF-without-LF), but callers building a program by concatenation are one printf away from a silently dropped final command; stdin.write((command + "\n").getBytes(...)) costs nothing and makes the byte-for-byte assertion in the test explicit about what the shell actually receives.
| ByteArrayOutputStream stdin = new ByteArrayOutputStream(); | ||
| DockerSandbox.writeShellProgram(stdin, script); | ||
|
|
||
| assertEquals(8, command.size()); |
There was a problem hiding this comment.
[Warning] Both unit tests exercise the two new static helpers directly — no process is started — so they would still pass if doExec forgot to call writeShellProgram or kept the old sh -c argument list; the only test that covers the real wiring is @EnabledIfEnvironmentVariable(AGENTSCOPE_DOCKER_INTEGRATION), which CI never runs. A cheap way to close the gap without Docker: spawn sh -s locally through the same code path (or expose the write behind a small seam) and assert stdout/exit code, so the regression this PR fixes stays fixed.
Summary
docker exec -i ... sh -sWhy
docker exec ... sh -c <command>puts the complete shell program in the WindowsCreateProcessargument list. Complex nested quoting can be corrupted, and large filesystem scripts can exceed the host command-line limit.The public Sandbox API and command semantics remain unchanged; only the Docker CLI transport changes.
Tests
mvn -pl agentscope-harness spotless:check test -Dtest=DockerSandboxCommandTest,BaseSandboxFilesystemTest,HarnessAgentDistributedSandboxTest -Dsurefire.failIfNoSpecifiedTests=falseAGENTSCOPE_DOCKER_INTEGRATION=true mvn -pl agentscope-harness test -Dtest=DockerSandboxCommandTest$(dirname ...), paths with spaces, and a 100KB shell program2.0.1-SNAPSHOTCloses #2135.
Addresses #1560.