Skip to content

fix(daytona): omit resource fields when creating sandbox from snapshot - #2427

Open
pratikshabelwate05 wants to merge 1 commit into
agentscope-ai:mainfrom
pratikshabelwate05:fix/daytona-snapshot-resources
Open

fix(daytona): omit resource fields when creating sandbox from snapshot#2427
pratikshabelwate05 wants to merge 1 commit into
agentscope-ai:mainfrom
pratikshabelwate05:fix/daytona-snapshot-resources

Conversation

@pratikshabelwate05

Copy link
Copy Markdown

Bug Description

DaytonaHttp#createSandbox always includes cpu, memory, and disk in the request body because DaytonaSandboxClientOptions initializes them to non-null defaults (1, 1, 3). When a snapshot is specified, the Daytona API rejects these resource parameters:

Cannot specify Sandbox resources when using a snapshot

Fixes #2421

Root Cause

DaytonaSandboxClientOptions defines:

private Integer cpu = 1;
private Integer memory = 1;
private Integer disk = 3;

DaytonaHttp#createSandbox only skips each field when it is null. Since the defaults are non-null, they are always serialized — even in snapshot mode, where the Daytona API does not allow resource parameters.

Fix

Guard cpu/memory/disk behind !useSnapshot so they are only included for image-based sandbox creation. The non-snapshot path is unchanged.

boolean useSnapshot = opt.getSnapshotId() != null && !opt.getSnapshotId().isBlank();
// ...
if (!useSnapshot) {
    if (opt.getCpu() != null) body.put("cpu", opt.getCpu());
    if (opt.getMemory() != null) body.put("memory", opt.getMemory());
    if (opt.getDisk() != null) body.put("disk", opt.getDisk());
}

This corresponds to Option A from the issue.

How to Verify

  1. mvn test -pl agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-daytona -Dtest=DaytonaHttpCreateSandboxTest
  2. Both tests pass — createSandbox_withSnapshot_omitsCpuMemoryDisk and createSandbox_withImage_includesCpuMemoryDisk

Test Plan

  • Added regression test for this bug (DaytonaHttpCreateSandboxTest)
  • Existing tests still pass (mvn spotless:check + mvn test for the module)
  • Manual verification of the fix (MockWebServer asserts the request body shape for both snapshot and image modes)

Risk Assessment

Low — the change only removes fields from the request body in snapshot mode. The image-based path is byte-for-byte identical to before. No public API changes.

DaytonaSandboxClientOptions initializes cpu=1, memory=1, disk=3 as
non-null defaults. DaytonaHttp#createSandbox only skipped each field
when null, so the defaults were always serialized into the request
body -- even when a snapshot was specified. The Daytona API rejects
resource parameters together with a snapshot (HTTP 400: 'Cannot
specify Sandbox resources when using a snapshot').

Guard cpu/memory/disk behind !useSnapshot so they are only sent for
image-based sandbox creation. The non-snapshot path is unchanged.

Adds DaytonaHttpCreateSandboxTest to lock in both paths.

Closes agentscope-ai#2421
@gemini-code-assist

Copy link
Copy Markdown

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@CLAassistant

CLAassistant commented Jul 27, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@oss-maintainer oss-maintainer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review — Approved ✅

Overall: Correct fix for #2421. The PR properly omits resource fields (cpu, memory, disk) when creating a sandbox from a snapshot, which aligns with the Daytona API's requirement that resource parameters cannot be specified together with a snapshot.

Key Changes:

  1. Modified DaytonaSandboxClientOptions to conditionally serialize resource fields
  2. When a snapshot is specified, resource fields are omitted from the request body
  3. Added comprehensive test coverage for the snapshot creation scenario

Code Quality:

  • ✅ Clean implementation with proper null checks
  • ✅ Good test coverage
  • ✅ Follows existing code patterns

CI Status: ✅ All checks passed

Verdict: Well-implemented fix that correctly addresses the reported issue.

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.

DaytonaSandboxClient: Using snapshot to create sandbox fails because cpu/memory/disk default values are always sent

3 participants