Repository navigation
fix(e2b): restore NATIVE_SNAPSHOT sessions with a single sandbox - #3562
Merged
Merged
Conversation
## What's wrong A session holding a restorable native snapshot created the sandbox twice: `E2bSandbox.start()` called `ensureSandbox()` first, which created one from the configured template, and only then did the base start logic hydrate the snapshot and create a second sandbox from the snapshot id, killing the first. A restore cost four platform calls and two cold starts instead of one. If that second create failed, the first sandbox was never deleted and leaked. ## What changes Decide the source before creating, instead of creating and rebuilding: - `peekNativeSnapshotId()` reads the native snapshot id out of the persisted archive — a bounded 4096-byte read, only in `NATIVE_SNAPSHOT` mode, returning null on any failure so it degrades exactly like an unrestorable snapshot. - `createSandboxForRestore()` creates straight from that snapshot when one is present and degrades to the original template when the snapshot cannot be created from, so a bad snapshot no longer fails `start()` and nothing is left behind to delete. - `createdFromSnapshotId` records the snapshot the live sandbox was built from, so the hydrate that follows in the same start no longer rebuilds it; it is cleared when the sandbox was connected or built from the template. - `shutdown()` clears the sandbox id after a successful kill, so the next resume does not spend a guaranteed-404 connect on a dead id. ## Verification - `mvn -T1 -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b -am test` → 109 tests in the module, 1245 in harness, spotless clean. - `E2bSandboxRecoveryTest` pins the single create, the hydrate short-circuit and its negative path, the template fallbacks, the snapshot-create failure without a leak, the reconnect-failure path, and the shutdown id handling. - `E2bNativeSnapshotRestoreIntegrationTest` (opt-in, `E2B_API_KEY`) exercises the live service: the snapshot id is accepted as the create template, the workspace comes back, and the replaced sandbox is really deleted. Fixes agentscope-ai#3555
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
@oss-maintainer please review this PR. |
jujn
approved these changes
Oct 15, 2026
jujn
pushed a commit
that referenced
this pull request
Oct 19, 2026
## Summary - Treat only confirmed-missing native snapshots (HTTP 404 or `isRestorable() == false`) as cold starts, with an explicit warning. - Fail the current call on snapshot-store/read/restorability errors, corrupt references, and non-404 snapshot creation failures, without mutating session state — the next call retries the same snapshot instead of silently starting empty. - Hydrate the persisted TAR archive whenever a sandbox is recreated from the template: a template-created sandbox can never hold the previous workspace, so the workspace-ready flags are now cleared on every template path. Previously a resume whose persisted state still marked the workspace ready skipped the archive and overwrote it with an empty workspace on the next stop. - Carry platform HTTP status codes in typed exceptions and base retries on those codes (408/429/502/503); 404 is never retried. - Keep the successful restore path to a single sandbox creation and reuse the peeked archive (`restoreCount() == 1`). - Document the failure behavior in English and Chinese. Related: follow-up to #3562; related closed issue #3555. (Not using `Fixes #3555` because it is closed.)
chcodex
added a commit
to chcodex/agentscope-java
that referenced
this pull request
Oct 20, 2026
…ntscope-ai#3562) A session holding a restorable native snapshot created the sandbox twice: `E2bSandbox.start()` called `ensureSandbox()` first, which created one from the configured template, and only then did the base start logic hydrate the snapshot and create a second sandbox from the snapshot id, killing the first. A restore cost four platform calls and two cold starts instead of one. If that second create failed, the first sandbox was never deleted and leaked. Fixes agentscope-ai#3555 --------- Co-authored-by: jujn <[email protected]> (cherry picked from commit e7bfda1)
chcodex
added a commit
to chcodex/agentscope-java
that referenced
this pull request
Oct 20, 2026
…#3609) - Treat only confirmed-missing native snapshots (HTTP 404 or `isRestorable() == false`) as cold starts, with an explicit warning. - Fail the current call on snapshot-store/read/restorability errors, corrupt references, and non-404 snapshot creation failures, without mutating session state — the next call retries the same snapshot instead of silently starting empty. - Hydrate the persisted TAR archive whenever a sandbox is recreated from the template: a template-created sandbox can never hold the previous workspace, so the workspace-ready flags are now cleared on every template path. Previously a resume whose persisted state still marked the workspace ready skipped the archive and overwrote it with an empty workspace on the next stop. - Carry platform HTTP status codes in typed exceptions and base retries on those codes (408/429/502/503); 404 is never retried. - Keep the successful restore path to a single sandbox creation and reuse the peeked archive (`restoreCount() == 1`). - Document the failure behavior in English and Chinese. Related: follow-up to agentscope-ai#3562; related closed issue agentscope-ai#3555. (Not using `Fixes agentscope-ai#3555` because it is closed.) (cherry picked from commit 9ea0540)
chickenlj
pushed a commit
that referenced
this pull request
Nov 13, 2026
Reuse the selected native snapshot restore source so recovery does not create a redundant sandbox; retain legacy TAR and platform contracts. (cherry picked from commit e7bfda1) Constraint: No AgentScope Service or SDK migration Confidence: high Scope-risk: narrow Not-tested: Live provider integration and Java 17 runtime
5 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
A session holding a restorable native snapshot created the sandbox twice:
E2bSandbox.start()calledensureSandbox()first, which created one from the configured template, and only then did the base start logic hydrate the snapshot and create a second sandbox from the snapshot id, killing the first. A restore cost four platform calls and two cold starts instead of one. If that second create failed, the first sandbox was never deleted and leaked.Fixes #3555