Skip to content

fix(e2b): fail calls when snapshots cannot be restored - #3609

Merged
jujn merged 8 commits into
agentscope-ai:mainfrom
chcodex:fix/e2b-snapshot-restore-failure
Oct 19, 2026
Merged

jujn merged 8 commits into
agentscope-ai:mainfrom
chcodex:fix/e2b-snapshot-restore-failure

Conversation

@chcodex

@chcodex chcodex commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

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.)

Verification

  • mvn -T1 -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b -am test — passed (1,245 Harness tests, 10 skipped; 129 E2B tests).
  • mvn -T1 -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b spotless:check — passed.

@chcodex
chcodex marked this pull request as draft October 16, 2026 09:27
@codecov

codecov Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...io/agentscope/extensions/sandbox/e2b/E2bRetry.java 25.00% 1 Missing and 2 partials ⚠️
.../agentscope/extensions/sandbox/e2b/E2bSandbox.java 92.30% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

chcodex and others added 6 commits October 16, 2026 17:45
A sandbox created from the template cannot hold the workspace this session
had, yet the TAR / no-snapshot path left the persisted workspace-ready flag
set. start() then probed the fresh sandbox, found the workspace root and
applied ephemeral entries only, so the TAR archive was never restored and the
empty workspace was written back on the next stop. Clear the workspace-ready
flags on every template-created path, keeping them only for the sandbox
created from the native snapshot.

Also stop relabeling existing SandboxExceptions (e.g. a missing API key) as
snapshot restore failures, and tighten the signatures of
createSandboxForRestore()/peekNativeSnapshot() to what they actually throw.
tarResumeHydratesSnapshotWhenPreviousWorkspaceWasReady asserted an exact
request count and a per-request order, so harmless hydrate refinements
(merging the temp-file cleanup into the extract, extra validation calls)
would fail it without any semantic change. Serve responses through a
Dispatcher keyed by path, drain all requests, and assert what the fix
guarantees: the template create happened, the archive was uploaded and
unpacked, workspace setup ran, and no workspace-preserved probe ran.
Collect the requests start() issued by reading the server-side count once
instead of looping on a one-second read timeout. The timeout loop made every
caller wait a full second and made the collected set depend on inter-request
timing; start() issues its requests synchronously, so the count is final. Also
assert the request set is non-empty before indexing it.
@chcodex
chcodex marked this pull request as ready for review October 18, 2026 11:28
@chcodex

chcodex commented Oct 18, 2026

Copy link
Copy Markdown
Contributor Author

@jujn @Buktal Please take a look

@jujn
jujn merged commit 9ea0540 into agentscope-ai:main Oct 19, 2026
6 checks passed
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
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 9ea0540)
Backport-review-patch: fb2278d693ba0fc2e41d416f900b9dd773fd0851
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.

3 participants