Skip to content

fix(core): honor resources.disk_gb on sandbox create#2

Merged
ezynda3 merged 2 commits into
mainfrom
fix/1-honor-disk-gb
Jun 29, 2026
Merged

fix(core): honor resources.disk_gb on sandbox create#2
ezynda3 merged 2 commits into
mainfrom
fix/1-honor-disk-gb

Conversation

@ezynda3

@ezynda3 ezynda3 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Description

POST /v1/sandboxes accepted resources.disk_gb (it was in openapi.yaml and ResourcesDTO), but the value was silently dropped — only cpu and memory_mb were ever applied, so every sandbox got the image's default writable-overlay size. A client following the OpenAPI contract could request more scratch space and get a default-sized overlay with no error or warning.

This wires disk_gb through to the SDK's WithOCIUpperSize option, converting the API unit (GiB) to the SDK unit (MiB). The option is only applied when disk_gb > 0, so omitting it still falls back to the image default.

Verified live against /dev/kvm: creating with disk_gb: 32 now reports upper_size_mib: 32768 in /inspect (was 4096), and omitting it keeps the 4096 default.

Changes

  • internal/core/service.go — add DiskGB to CreateParams; map it to msb.WithOCIUpperSize(uint32(p.DiskGB)*1024) when > 0. Extract the CreateParams → []msb.SandboxOption mapping into a pure, side-effect-free buildCreateOptions helper so it's unit-testable without booting a microVM.
  • internal/api/handlers.go — pass req.Resources.DiskGB into core.CreateParams.
  • internal/core/service_test.go — new regression tests for the GiB→MiB conversion, the unset/default case, and the combined CPU/memory/disk mapping.
  • openapi.yaml — clarify the disk_gb description to match actual behavior (writable overlay upper size in GiB; zero = image default).

Testing

  • go test -race ./... — pass
  • golangci-lint run ./... — 0 issues
  • Manual end-to-end on a KVM host: disk_gb: 32upper_size_mib: 32768; no disk_gb4096. MicroVM integration paths aren't exercised in CI (no /dev/kvm).

Wire contract

Additive / backward-compatible. No DTO shape change — ResourcesDTO.disk_gb already existed in both dto.go and openapi.yaml; this only makes the previously-ignored field functional. dto.go and openapi.yaml remain in lockstep.

Fixes #1

Summary by CodeRabbit

  • New Features

    • Added support for setting writable overlay disk size when creating a sandbox.
    • Improved create behavior to better determine the working directory before returning the instance.
  • Bug Fixes

    • Disk size values are now consistently passed through from the API to sandbox creation.
    • Clarified disk size behavior so a value of 0 continues to use the image default.
  • Documentation

    • Updated the disk size description to better explain how it is applied.

- thread DiskGB through CreateParams and the create handler so the
  requested writable-overlay size is no longer silently dropped
- map disk_gb (GiB) to the SDK's WithOCIUpperSize (MiB) with unit
  conversion; only applied when > 0 so the image default still wins
- extract the CreateParams -> SandboxOption mapping into a pure
  buildCreateOptions helper and cover it with unit tests
- clarify the disk_gb description in openapi.yaml to match behavior

Fixes #1
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@ezynda3, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 47 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cdcda3fe-b7ca-4277-99bf-1279ed113af4

📥 Commits

Reviewing files that changed from the base of the PR and between aa6712d and 86e125a.

📒 Files selected for processing (2)
  • internal/core/service.go
  • internal/core/service_test.go
📝 Walkthrough

Walkthrough

resources.disk_gb was accepted by the API but silently dropped. This PR adds DiskGB to core.CreateParams, maps it in handleCreate, extracts a buildCreateOptions helper in Service.Create that appends msb.WithOCIUpperSize(DiskGB*1024) when non-zero, and adds unit tests and an updated OpenAPI description.

disk_gb end-to-end wiring

Layer / File(s) Summary
CreateParams.DiskGB field and handler mapping
internal/core/service.go, internal/api/handlers.go
CreateParams.DiskGB comment clarifies it is the writable overlay upper size in GiB; handleCreate now sets DiskGB: req.Resources.DiskGB when building CreateParams.
buildCreateOptions helper and Service.Create refactor
internal/core/service.go
Service.Create delegates option construction to buildCreateOptions(p, image); the helper conditionally appends msb.WithOCIUpperSize(uint32(p.DiskGB * 1024)) and returns the completed opts slice.
Unit tests and OpenAPI description
internal/core/service_test.go, openapi.yaml
Three tests cover GiB→MiB conversion, zero-DiskGB behavior, and CPU/memory/image mapping. OpenAPI disk_gb description updated to document overlay semantics and the 0 = image default behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 A disk_gb field sat lonely and bare,
Accepted in JSON but lost in thin air.
Now GiB turns to MiB with a swift multiply,
The overlay grows big — no more silent goodbye!
Hops of delight as the sandbox expands right! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning service.go also changes sandbox timing, caching, and workdir resolution, which are unrelated to making resources.disk_gb work. Move those behavioral changes to a separate PR unless they are required for the disk_gb fix.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly states the main change: honoring resources.disk_gb during sandbox creation.
Linked Issues check ✅ Passed The PR threads disk_gb from the API into core and applies it via OCI upper-size with the correct GiB-to-MiB conversion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1-honor-disk-gb

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/core/service.go`:
- Around line 190-193: Validate p.DiskGB in the service path before calling
msb.WithOCIUpperSize: reject negative values explicitly and add an upper-bound
check to prevent uint32 overflow when converting GiB to MiB. Update the logic in
the disk size handling block to fail fast for invalid disk_gb inputs instead of
silently skipping them or wrapping the converted size, and keep the existing
conversion only for values safely within range.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3582705f-1e96-400c-a48a-7f31795ed985

📥 Commits

Reviewing files that changed from the base of the PR and between 09c9a36 and aa6712d.

📒 Files selected for processing (4)
  • internal/api/handlers.go
  • internal/core/service.go
  • internal/core/service_test.go
  • openapi.yaml

Comment thread internal/core/service.go Outdated
- reject negative disk_gb instead of silently skipping it
- add an upper bound (maxDiskGB) so the GiB->MiB conversion can't
  overflow the uint32 WithOCIUpperSize takes
- return an error from buildCreateOptions and propagate it from Create
  so invalid input fails fast rather than booting a misconfigured box
- cover the negative, overflow, and max in-range cases with unit tests
@ezynda3 ezynda3 merged commit 9c4d6ae into main Jun 29, 2026
3 checks passed
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.

resources.disk_gb is silently ignored on POST /v1/sandboxes

1 participant