Skip to content

fix(harness): avoid command substitution in sandbox write parent mkdir (#3850) - #3871

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
chang6666:fix/sandbox-write-windows-hosts
Oct 31, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
chang6666:fix/sandbox-write-windows-hosts

Conversation

@chang6666

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (main @ 1524b31)

Description

Fixes #3850: on Windows hosts, write_file in a Docker sandbox always fails with Failed to write file, because BaseSandboxFilesystem.write() builds its check command with a double-quoted command substitution:

if [ -e '<path>' ]; then echo 'EXISTS'; exit 1; fi; mkdir -p "$(dirname '<path>')" 2>&1

The docker CLI on Windows mangles arguments carrying "...$(...)..." before the container shell sees them, so the shell reports Syntax error: end of file unexpected (exit 2) and write() never reaches its success path.

Change

Compute the parent directory in Java and pass it to mkdir -p as a single-quoted literal:

if [ -e '<path>' ]; then echo 'EXISTS'; exit 1; fi; mkdir -p '<parent>' 2>&1

The generated command now contains no $(...) and no double quotes at all, so this class of Windows-host argument mangling cannot recur.

Why not simply drop the double quotes (the workaround verified in the issue)? An unquoted $(dirname ...) word-splits its output, so parents containing spaces would break on every host — a regression, since paths with spaces are first-class in this codebase (see the existing it's a file.txt heredoc tests). The Java-side parent keeps space-safe quoting and is unit-testable without Docker.

Note: the edit_file half of #3850 (python3 -c "...") was already fixed on main by the heredoc-based edit script; only the write() check command remained affected.

How to test

  • mvn -T1C -pl agentscope-harness -am test — 1590 tests, 0 failures/errors
  • New unit tests in BaseSandboxFilesystemTest assert the write check command carries no double quotes and no command substitution, that a parent with spaces is created via a single-quoted literal, and that root-level files skip the mkdir segment
  • New Linux-gated integration tests exercise write() against a real shell with spaces in the path, plus the existing-file rejection path
  • Manually verified the generated command under sh with a space-containing parent

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test — agentscope-harness module: 1590 tests, 0 failures, 0 errors)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) — no user-facing docs reference the affected command
  • Code is ready for review

chang6666 and others added 2 commits October 30, 2026 23:51
agentscope-ai#3850)

The write() check command wrapped $(dirname ...) in double quotes. The
docker CLI on Windows hosts mangles arguments carrying double-quoted
command substitution before the container shell sees them, so write_file
always failed with a shell syntax error. Dropping the quotes (as move()
already does) would word-split parents containing spaces.

Compute the parent directory in Java and pass it as a single-quoted
literal instead: no command substitution, no double quotes, and
space-safe parent creation on every host.
@jujn
jujn merged commit e190a8d into agentscope-ai:main Oct 31, 2026
4 of 5 checks passed
aMetric added a commit to aMetric/agentscope-java that referenced this pull request Nov 2, 2026
…wn exit codes

The quoted-space command fix for agentscope-ai#3262 / agentscope-ai#3850 is already on `main` (agentscope-ai#3871), so this
branch now carries only the half that is still missing: what the model is told when a
sandbox filesystem mutation fails.

- `write()`, `move()` and `delete()` now append the sandbox's own diagnostic to the
  failure message. Before this, `write()` returned a bare `Failed to write file '<path>'`
  and `move()`/`delete()` embedded the raw stdout/stderr verbatim.
- Raw output is clamped to 500 chars keeping the tail, where shells put the actual error
  line after a command's preamble. The cut backs off one char when it lands on a low
  surrogate so the JSON sent to the model never carries a lone surrogate.
- Mutations fail closed when `execute()` reports no exit status. `exitCode()` is an
  `Integer`, so the previous `result.exitCode() != 0` unboxed a null and threw NPE in
  `move()`/`delete()`, while `write()` treated a null status as success and went on to
  upload.
- `executeFailureMessage()` shares the same detail path, so `ls`/`read`/`edit`/`grep`/
  `glob` inherit the clamp and the explicit `no exit status reported` wording.

Tests: 7 new cases in `BaseSandboxFilesystemTest` (detail carried, clamp, null output,
null exit code for write/move/delete) plus a regression guard asserting no double-quoted
span containing a space is ever generated for `write()` or `move()`. Full
`agentscope-harness` suite: 1601 tests, 0 failures, 37 skipped (Linux/Docker-only).
aMetric added a commit to aMetric/agentscope-java that referenced this pull request Nov 2, 2026
…wn exit codes

The quoted-space command fix for agentscope-ai#3262 / agentscope-ai#3850 is already on `main` (agentscope-ai#3871), so this
branch now carries only the half that is still missing: what the model is told when a
sandbox filesystem mutation fails.

- `write()`, `move()` and `delete()` now append the sandbox's own diagnostic to the
  failure message. Before this, `write()` returned a bare `Failed to write file '<path>'`
  and `move()`/`delete()` embedded the raw stdout/stderr verbatim.
- Raw output is clamped to 500 chars keeping the tail, where shells put the actual error
  line after a command's preamble. The cut backs off one char when it lands on a low
  surrogate so the JSON sent to the model never carries a lone surrogate.
- Mutations fail closed when `execute()` reports no exit status. `exitCode()` is an
  `Integer`, so the previous `result.exitCode() != 0` unboxed a null and threw NPE in
  `move()`/`delete()`, while `write()` treated a null status as success and went on to
  upload.
- `executeFailureMessage()` shares the same detail path, so `ls`/`read`/`edit`/`grep`/
  `glob` inherit the clamp and the explicit `no exit status reported` wording.

Tests: 7 new cases in `BaseSandboxFilesystemTest` (detail carried, clamp, null output,
null exit code for write/move/delete) plus a regression guard asserting no double-quoted
span containing a space is ever generated for `write()` or `move()`. Full
`agentscope-harness` suite: 1601 tests, 0 failures, 37 skipped (Linux/Docker-only).
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
#3850) (#3871)

Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs.

(cherry picked from commit e190a8d)
Backport-review-patch: 12a2c43163f341d54051ed15a416418ee7b1d830
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
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.

[Bug]:docker exec commands with double-quoted $(...) substitution break on Windows hosts — write_file/edit_file in sandbox always fail

2 participants