Repository navigation
Description
Module:
agentscope-extensions-sandbox-e2b
Affected Version: 2.0.2 (verified; also present in 2.0.0)
Backend: CUBE / E2B only (Docker unaffected)
Labels:bug
Describe the bug / 描述错误
In E2bEnvdProcessClient.drainStartStream() (line 168), the exit code is initialized to the sentinel Integer.MIN_VALUE:
int exit = Integer.MIN_VALUE; // line 168 — fallback when exit_code is never receivedThis value is returned whenever the envd stream terminates before the end event's exit_code field arrives (stream break at lines 174 / 178 / 186). Because every downstream consumer interprets any non-zero exit code as a failure, the sentinel -2147483648 is misclassified as a command failure — producing false negative results.
Downstream impact / 影响
| Consumer | Check | Result |
|---|---|---|
BaseSandboxFilesystem (harness) |
exitCode != 0 at L122 / L175 / L382 / L396 |
write / delete / move operations falsely reported as failed |
ShellExecuteTool (harness) |
raw exit code passed to LLM (~L82) | agent receives "Exit code: -2147483648", degrading reasoning |
Root cause (bytecode-verified) / 根因定位
- File:
agentscope-extensions-sandbox-e2b/.../sandbox/e2b/E2bEnvdProcessClient.java - Method:
private int drainStartStream(InputStream, ByteArrayOutputStream, ByteArrayOutputStream) - Line: 168 —
int exit = Integer.MIN_VALUE; - Bytecode offset: 0 (first instruction); constant pool chore(deps): bump io.opentelemetry.instrumentation:opentelemetry-reactor-3.1 from 2.18.1-alpha to 2.23.0-alpha #261 =
Integer -2147483648
javap -v diff between the original and a patched .class:
ORIGINAL: 0: ldc_w #261 // int -2147483648 (Integer.MIN_VALUE)
PATCHED: 0: iconst_0 // int 0
1: nop // padding (3-byte in-place swap)
2: nop
To Reproduce / 重现步骤
Prerequisites
- AgentScope Java 2.0.x using the CUBE / E2B sandbox backend (Docker is not affected)
- A Cube/E2B endpoint whose envd stream can be interrupted (network blip, process kill, timeout)
Steps
- Configure the CUBE backend (
application.yml):agentscope: sandbox: type: CUBE cube: endpoint: <your-cube-endpoint>
- Build an agent backed by the CUBE filesystem:
HarnessAgent agent = HarnessAgent.builder() .name("cube-agent") .model(model) .filesystem(new E2bFilesystemSpec(...)) .build();
- Run a command whose envd JSON stream is cut before
end.exit_codeis delivered:agent.call(Prompt.from("run 'echo hello' and show the output"));
- Observe the failure (despite the command likely succeeding):
ShellExecuteTooloutput containsExit code: -2147483648- File operations (write / delete / move) are reported as failed
- The LLM is given a misleading exit code
Expected behavior / 预期行为
When exit_code cannot be obtained, the fallback should not be a value that downstream code mistakes for failure. Suggested fixes:
- Option A (recommended): Default to
0on interruption, treating "unknown" as "success". This is consistent with the intent of PR fix(sandbox): preserve zero exit code in E2B JSON stream #2609 ("preserve zero exit code in E2B JSON stream"). - Option B: Use an explicit named constant and handle the unknown case gracefully downstream:
private static final int EXIT_CODE_UNKNOWN = 0; int exit = EXIT_CODE_UNKNOWN;
- Option C: Use a distinct sentinel (e.g.
-1) and add explicit downstream checks so "unknown" is separable from "failed".
Additional context / 补充说明
- Related work: PR fix(sandbox): preserve zero exit code in E2B JSON stream #2609 fixed a related problem where a
0exit code was dropped during JSON-stream parsing. This issue is the complement — the default value used when no exit code is received at all. - Docker backend is safe:
DockerFilesystemSpecderives the exit code fromProcess.exitValue(), which always returns a real OS code. Only the CUBE/E2B path viaE2bEnvdProcessClient.drainStartStream()is affected. - No application-level workaround:
E2bEnvdProcessClientis declaredfinaland is instantiated internally byE2bSandbox.envd()(line 230:new E2bEnvdProcessClient(opt)). Downstream code cannot subclass or intercept it, so a fix must land upstream. - Production impact: At least one deployment currently applies a binary bytecode patch (
ldc_w #261 → iconst_0 nop nop) as a stopgap, confirming this is a real-world problem.
Activity
fix(e2b): reject incomplete process streams without exit code (agents…