Repository navigation
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
Suggest supplementary test |
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR improves the Connect protocol frame parsing in E2bEnvdProcessClient by properly handling end-stream frames (flag 0x02), compressed frames (flag 0x01), and unknown flags — replacing the previous naive flags != 0x00 check. It also adds SLF4J debug logging for better diagnosability and a clean parseEndStreamResponse() / EndStreamMessage record for end-stream error parsing. The changes are well-scoped and align with the Connect protocol specification. A few minor robustness gaps were identified around defensive null handling and a silently-swallowed exception that should be addressed for consistency with the new logging additions.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
AgentScopeJavaBot
left a comment
There was a problem hiding this comment.
🤖 AI Review
This PR improves the Connect protocol frame parsing in E2bEnvdProcessClient by properly handling end-stream frames (flag 0x02), compressed frames (flag 0x01), and unknown flags — replacing the previous naive flags != 0x00 check. It also adds SLF4J debug logging for better diagnosability and a clean parseEndStreamResponse() / EndStreamMessage record for end-stream error parsing. The changes are well-scoped and align with the Connect protocol specification. A few minor robustness gaps were identified around defensive null handling and a silently-swallowed exception that should be addressed for consistency with the new logging additions.
(inline comments could not be attached — line numbers fell outside PR hunks. See archived report.)
- Parse EndStreamResponse (flags & 0x02) per Connect protocol spec - Use getField() instead of hasField() for proto3 scalar exit_code - Proto3 omits default values (0) from wire; getField() returns default - Extract EndEvent.error to stderr (signal-killed processes) - Fix JSON codec: always set end event when end node exists - Parsed error field from JSON (proto3_optional) - Reject compressed frames (flags & 0x01) with explicit error - Skip reserved flag bits (flags & 0xFC) - Add debug logging for frame processing diagnostics - Add 7 unit tests covering exit_code=0, EndStreamResponse, error field - Add integration test: signal-killed process via runShell + threads - Add evidence comments referencing Connect spec, Python SDK, Go handler
- Replace base64 shell transfers with HTTP multipart upload (uploadFile) and GET download (downloadFile) via E2B Filesystem REST API - Rewrite doHydrateWorkspace: chunked Python base64 -> uploadFile + tar xf - Rewrite doPersistWorkspace: protobuf streaming -> tar file + downloadFile - Add E2bSandboxFilesystem: override uploadFiles/downloadFiles to use REST API, avoiding 33% base64 overhead and 512KB stdout truncation bug - Add createFilesystem() factory on SandboxFilesystemSpec for custom fs impl - Add E2bSandboxFilesystemTest: 6 unit tests covering delegation, error handling, and fallback to super for non-E2B sandboxes
9240999 to
0f18e9f
Compare
- Use import java.util.Arrays instead of inline fully qualified name - Restore connectFrame() to delegate to encodeUnaryEnvelope() so existing tests exercise production envelope encoding
|
@jujn Enough test cases have been added |
|
io.agentscope.extensions.sandbox.e2b.E2bEnvdProcessClient#uploadFile url paramters should add username or set default default username parameter value |
# Conflicts: # agentscope-harness/src/main/java/io/agentscope/harness/agent/HarnessAgent.java
|
Thanks @MABIY for the review! Weve added the |
|
@jujn @chickenlj Hello, I have some PRs, including the current one, which has been pending for a long time. Can you help me review them? If you have any questions, please give me some guidance. |
Thanks for your contribution. A little big, I'll review it when I have time. |
|
Looking forward to merging it soon. |
|
this bug need fix in code. |
Filesystem upload/download previously used https://sandbox.{domain} with E2b-Sandbox-Id/Port header routing, which self-hosted gateways reject (400 bad request). Reuse envdHost() so both calls go directly to https://{port}-{sandboxId}.{domain} like runShell does.
|
@jujn @chickenlj Hi, this PR has been open for about a month. Just wanted to check if there are any blocking concerns or areas you'd like us to improve that have caused the delay in merging? Also, this PR contains two relatively independent parts (streaming response parsing fix + Filesystem REST API migration). Would you recommend splitting it into smaller PRs for easier review? e.g.:
Happy to split if you prefer — just let us know your suggestion. Thanks! |
- agentscope-ai#2196: pass username query param in e2b filesystem REST calls (filesUrl helper plus URL assertions and workspace state setup) - agentscope-ai#2555: drop dead snapshot-timestamp helpers from E2bPlatformHttp, restore coverage tests plus InputStream close fix - agentscope-ai#2976: reliable e2b exec timeout with server-side kill (callTimeout plus readTimeout(0), Connect-Timeout-Ms header, interrupt-bit handling) plus its tests - E2bEnvdProcessClientTest: align three stale drain tests with the merged upstream agentscope-ai#2828 reject-without-exit-code behavior
|
This PR currently conflicts with git fetch origin
git rebase origin/main
# resolve conflicts, then:
git push --force-with-leaseThis is a one-time reminder. Feel free to @mention me for a re-review after conflicts are resolved. Automated notification by github-manager-bot |
Fixes #3338 Split from #2196 (standalone: based on current `main`, no dependency on `fix/e2b-envd-client`). ## What Harden `E2bEnvdProcessClient.drainStartStream` Connect streaming parsing: - Parse end-stream envelopes (flags `0x02`) as `EndStreamMessage` JSON: throw `SandboxRuntimeException(WORKSPACE_START_ERROR)` on error, break cleanly otherwise. - `error` key presence alone signals failure (mirrors Python SDK `ServerStreamParser`); falls back to raw error JSON when code/message are absent. - Reject compressed frames (`0x01`) with `IOException`; skip reserved flag bits (`0xFC`). - Message-Length per spec: 4-byte unsigned big-endian (drop erroneous `& 0x7FFFFFFF` mask). - Read proto3 `exit_code` via `getField()` so exit 0 is no longer misreported; always retain `end` event even when sub-fields are empty. - Forward `EndEvent.error` (e.g. `signal: killed`, `exit status N`) to stderr. - Extract `buildEnvdRequest` to share header construction (no behavior change).
Closes #3339. Split from #2196. Stacked on #3341 (A: envd process streaming parsing fix). Own change is the top commit only; diff shrinks to 2 files once #3341 merges. Scope: add E2bEnvdProcessClient.uploadFile (multipart POST) and downloadFile (GET) against /files, routed via envdHost(); keep E2b-Sandbox-Id/Port/X-Access-Token/Authorization headers. Plus unit tests. --------- Co-authored-by: jujn <[email protected]>
…3] (#3344) Fixes #3340 Split from #2196 (stacked on #3339's scope: only the top commit is new). ## What - `E2bSandbox implements SandboxFileTransfer` (`supportsFileTransfer` accepts absolute paths only; relative paths fall back to the exec strategy). - Workspace persist/hydrate use the Filesystem REST API for tar transfer (single upload + `tar xf` / single tar + download), replacing shell+base64. - Temp tar files in the sandbox are removed best-effort after transfer (success and failure paths). - No custom filesystem subclass; default `SandboxBackedFilesystem` is used. --------- Co-authored-by: jujn <[email protected]>
Take the merged agentscope-ai#2196 splits as authoritative for e2b files: [1/3] hardened envd streaming parsing, [2/3] Filesystem REST transfer, [3/3] SandboxFileTransfer routing. Local-only behavior preserved on top: - e2b exec server-side kill (Connect-Timeout-Ms, readTimeout(0), interrupt-bit handling); timeout<=0 keeps the historical no-client-timeout path used by the opt-in live-sandbox test - E2bSandbox volume support (early-return archiving, volumeMounts create param) adapted to the new tar/transfer helpers with WorkspaceSpec-root lookups (local state has no getWorkspaceRoot) - BaseSandboxFilesystem native edit + transfer fallback (local agentscope-ai#2398); dropped upstream python-first edit and its tests - FilesystemTool norm() follows upstream namespace-aware normalize(path, ctx); the local absolute-path skip is retired (verified unnecessary under the new architecture) - WorkspaceContextMiddleware local prompt tests moved to the WorkspaceContextMaterials registry (JEV redesign)
Summary
Fix E2B envd
process.Process/Startserver-streaming response parsing and replace shell+base64 file transfers with native binary HTTP via the E2B Filesystem REST API.Root Cause
sint32 exit_code = 1is a regular proto3 scalar field (not proto3_optional, not oneof). When exit code is 0, the field is omitted from both protobuf binary wire format and JSON output (proto3 default-value omission). The original code usedDynamicMessage.hasField()to check presence — returnsfalsefor default values — causing exit code 0 to be treated as "no exit code received", resulting inexitCode = -2147483648(Integer.MIN_VALUE).Changes — Streaming Response Parsing
EndStreamMessage, throw on error, break cleanly on successIOExceptionhasField()+getField()withgetField()forexit_codeevent.event.end.exit_codeerrorfieldevent.event.end.errordirectly& 0x7FFFFFFFstrippedbuildEnvdRequest()extracted — deduplicate envd request header constructionrunShellanddrainStartStreamChanges — Filesystem REST API
Replace shell+base64 file transfers (33% overhead, 512KB truncation) with native binary HTTP.
E2bEnvdProcessClient.javauploadFile()(POST multipart) +downloadFile()(GET). RefactoredbuildFilesystemRequest()to share headers without hardcoding HTTP method.E2bSandbox.javauploadFile()+tar xf. doPersistWorkspace(): protobuf streaming → tar file +downloadFile()GET. Added publicuploadFile()/downloadFile()delegates.E2bSandboxFilesystem.javauploadFiles()/downloadFiles()to use REST API. Falls back tosuperfor non-E2B sandboxes (test mocks).E2bFilesystemSpec.javacreateFilesystem()→new E2bSandboxFilesystem().SandboxFilesystemSpec.javacreateFilesystem()default method returningSandboxBackedFilesystem().HarnessAgent.javanew SandboxBackedFilesystem()→sandboxFilesystemSpec.createFilesystem().Fix: route filesystem calls through the envd host subdomain
uploadFile/downloadFilepreviously usedhttps://sandbox.{domain}withE2b-Sandbox-Id/E2b-Sandbox-Portheader routing. Self-hosted gateways only recognize the{port}-{sandboxId}.{domain}subdomain and rejected these calls with400 {"error":"bad request"}. Both calls now reuseenvdHost()(https://{ENVD_PORT}-{sandboxId}.{domain}), the same subdomain pattern asrunShell's process calls — compatible with both the official E2B environment and self-hosted gateways. TheE2b-Sandbox-Id/E2b-Sandbox-Port/X-Access-Token/Authorizationheaders are kept unchanged: the official envd filesystem API may still require the access token, and self-hosted gateways route by subdomain and ignore them.E2bEnvdProcessClient.javafilesystemHost()removed;uploadFile()/downloadFile()callenvdHost(state)directly.E2bEnvdProcessClientTest.javafilesystemHost*tests renamed toenvdHost*; assertions updated tohttps://49983-test-id.custom.com/https://49983-test-id.e2b.app; upload/download URL assertions updated tohttps://49983-test-id.e2b.app/files?path=.Performance (before → after)
tar xfTests
Unit Tests — Streaming Parsing (
E2bEnvdProcessClientTest) — 14 testsendStreamResponseWithErrorThrowsSandboxRuntimeExceptionendStreamResponseWithoutErrorBreaksCleanly{}→ clean breakexitCodeZeroDefaultWhenOmittedend:{}(exitCode omitted) → exit=0 (proto3 default via getField)exitCodeNonZeroend:{exitCode:42}→ exit=42endEventErrorWrittenToStderrend:{error:"signal: 9"}→ stderr contains errorcompressedFrameThrowsIOExceptionreservedFlagsFrameIsSkippedUnit Tests — Filesystem (
E2bSandboxFilesystemTest) — 6 testsuploadFiles_delegatesToE2bSandboxE2bSandbox.uploadFile()uploadFiles_returnsFailureOnExceptionFileUploadResponse.errordownloadFiles_delegatesToE2bSandboxE2bSandbox.downloadFile()downloadFiles_returnsFailureOnExceptionFileDownloadResponse.erroruploadFiles_fallsBackToSuperWhenNotE2bSandboxSandboxBackedFilesystemfallbackdownloadFiles_fallsBackToSuperWhenNotE2bSandboxIntegration Tests (
E2bEnvdProcessClientIntegrationTest) — 2 tests (require-DE2B_API_KEY)captureRawConnectFramessignalKillViaRunShellsleep 120; Thread B kills viakillall; verifies EndEvent.error captured to stderrTest Plan