Skip to content

update snapshot restore and sandbox snapshot APIs - #13

Merged
steven-passynkov merged 2 commits into
mainfrom
snapshot-restore-api
Apr 22, 2026
Merged

update snapshot restore and sandbox snapshot APIs#13
steven-passynkov merged 2 commits into
mainfrom
snapshot-restore-api

Conversation

@steven-passynkov

@steven-passynkov steven-passynkov commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added killSandboxAfter parameter for snapshot creation
  • Refactor
    • Snapshot creation now accessed via sandbox instance method instead of client-level API
    • Snapshot restore operation renamed from resume to restore

@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@steven-passynkov has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 40 minutes and 22 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 40 minutes and 22 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 56c3c2e0-4d29-407b-b309-6044e4a051e2

📥 Commits

Reviewing files that changed from the base of the PR and between 2a5519e and d836fc5.

📒 Files selected for processing (1)
  • src/models/index.ts
📝 Walkthrough

Walkthrough

The changes reorganize snapshot-related functionality by moving snapshot creation from the client-level snapshots API to the sandbox instance method, renaming the resume operation to restore across the snapshots service, and migrating the CreateSnapshotParams schema definition from the snapshot module to the sandbox module with corresponding type export updates.

Changes

Cohort / File(s) Summary
Snapshot API Restructuring
src/services/snapshots.ts, tests/services/snapshots.test.ts
Removed create() and pause() methods from SnapshotsClient; renamed resume() to restore() with endpoint change from /v1/snapshot/resume to /v1/snapshot/restore and parameter type ResumeSnapshotParamsRestoreSnapshotParams. Tests updated to reflect these method removals and endpoint changes.
Sandbox-level Snapshot Creation
src/client/sandbox.ts, src/services/sandboxes.ts, tests/services/sandboxes-client.test.ts
Added Sandbox.createSnapshot() instance method forwarding to SandboxesClient.createSnapshot(), which creates new API endpoint POST /v1/sandbox/{sandboxId}/snapshot/create with parameter validation and response normalization. New tests validate the endpoint structure and input validation (name constraints).
Schema and Type Migration
src/models/sandbox.ts, src/models/snapshot.ts, src/models/index.ts
Migrated createSnapshotParamsSchema and CreateSnapshotParams type from snapshot.ts to sandbox.ts; renamed resumeSnapshotParamsSchema and ResumeSnapshotParams to restoreSnapshotParamsSchema and RestoreSnapshotParams in snapshot.ts. Updated re-exports in models/index.ts to reflect these movements.
Public Export Surface
src/index.ts
Updated exported types: moved CreateSnapshotParams position and replaced ResumeSnapshotParams with RestoreSnapshotParams in the public API surface.
Example and Client Test Updates
examples/snapshots.ts, tests/client/client-sandbox.test.ts
Updated snapshot creation call from client.snapshots.create() to sandbox.createSnapshot() and restore call from client.snapshots.resume() to client.snapshots.restore(). Added mock and type assertions for new Sandbox.createSnapshot() method and updated expected return type for Sandbox.addMount().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Use params objects for service APIs #11: Modifies Sandbox client class to add/convert methods accepting params objects, similar pattern to the addition of Sandbox.createSnapshot().
  • Init fixes #3: Touches snapshot and sandbox API surface changes, including snapshot-related service methods and schema reorganization.

Poem

🐰 Snapshots find a brand new home,
From client lands to sandbox's loam—
Resume becomes restore's delight,
Methods hop into their rightful sight,
A warren reorganized just right! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately summarizes the main changes: updating snapshot restore operations and sandbox snapshot creation APIs across the codebase.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch snapshot-restore-api

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 and usage tips.

@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

🧹 Nitpick comments (2)
src/client/sandbox.ts (1)

221-226: Add explicit return type for API consistency.

Other instance methods on Sandbox declare explicit return types (e.g., pause(): Promise<this>, addMount(...): Promise<ObjectStorageMountSummary>). createSnapshot relies on inference, which leaks the SandboxesClient.createSnapshot return type through and is inconsistent with the surrounding style. Consider annotating : Promise<SnapshotData> (importing SnapshotData from @/models/index.js).

♻️ Proposed change
   async createSnapshot(
     params: CreateSnapshotParams = {},
     options?: { timeout?: number },
-  ) {
+  ): Promise<SnapshotData> {
     return this.client.sandboxes.createSnapshot(this.id, params, options);
   }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/client/sandbox.ts` around lines 221 - 226, The createSnapshot method on
the Sandbox class lacks an explicit return type; update its signature to return
Promise<SnapshotData> and add an import for SnapshotData from
"@/models/index.js" so the method matches the style of other instance methods
(e.g., pause(): Promise<this>, addMount(): Promise<ObjectStorageMountSummary>)
and no longer leaks the SandboxesClient.createSnapshot inferred type.
tests/services/snapshots.test.ts (1)

27-36: Consider asserting the HTTP methods too.

The path/body coverage is good; adding method checks would catch regressions where restore/delete accidentally switch verbs.

Test hardening diff
   assert.equal(calls[0]?.path, "/v1/snapshot/restore");
+  assert.equal(calls[0]?.init.method, "POST");
   assert.deepEqual(jsonOf(calls[0]!), {
     snapshot_name: "snap-c",
     auto_pause: true,
     timeout: 12,
   });
   assert.equal(restored.templateId, "tpl-1");
   assert.equal(calls[1]?.path, "/v1/snapshot/snap-1");
+  assert.equal(calls[1]?.init.method, "DELETE");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/services/snapshots.test.ts` around lines 27 - 36, The test currently
asserts request paths and bodies for client.restore and client.delete but not
HTTP methods; update the assertions around restored = await client.restore(...)
and await client.delete(...) to also check calls[0]?.method is "POST" (or the
expected verb used by SnapshotService.restore) and calls[1]?.method is "DELETE"
(or the expected verb used by SnapshotService.delete") so the test verifies both
path/body and HTTP verb for calls[0] and calls[1].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/models/index.ts`:
- Around line 33-39: The module re-exports listSnapshots schemas but forgot to
re-export restoreSnapshotParamsSchema alongside the RestoreSnapshotParams type;
update src/models/index.ts to export restoreSnapshotParamsSchema from
"@/models/snapshot.js" (similar to listSnapshotsParamsSchema) so consumers and
services (e.g., code using restoreSnapshotParamsSchema and
RestoreSnapshotParams) can import the validation schema and type consistently.

---

Nitpick comments:
In `@src/client/sandbox.ts`:
- Around line 221-226: The createSnapshot method on the Sandbox class lacks an
explicit return type; update its signature to return Promise<SnapshotData> and
add an import for SnapshotData from "@/models/index.js" so the method matches
the style of other instance methods (e.g., pause(): Promise<this>, addMount():
Promise<ObjectStorageMountSummary>) and no longer leaks the
SandboxesClient.createSnapshot inferred type.

In `@tests/services/snapshots.test.ts`:
- Around line 27-36: The test currently asserts request paths and bodies for
client.restore and client.delete but not HTTP methods; update the assertions
around restored = await client.restore(...) and await client.delete(...) to also
check calls[0]?.method is "POST" (or the expected verb used by
SnapshotService.restore) and calls[1]?.method is "DELETE" (or the expected verb
used by SnapshotService.delete") so the test verifies both path/body and HTTP
verb for calls[0] and calls[1].
🪄 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: 36cdf0bc-a1a9-436f-a27b-3c91d88eafb7

📥 Commits

Reviewing files that changed from the base of the PR and between 5bab52e and 2a5519e.

📒 Files selected for processing (11)
  • examples/snapshots.ts
  • src/client/sandbox.ts
  • src/index.ts
  • src/models/index.ts
  • src/models/sandbox.ts
  • src/models/snapshot.ts
  • src/services/sandboxes.ts
  • src/services/snapshots.ts
  • tests/client/client-sandbox.test.ts
  • tests/services/sandboxes-client.test.ts
  • tests/services/snapshots.test.ts

Comment thread src/models/index.ts Outdated
@steven-passynkov
steven-passynkov merged commit f9637d3 into main Apr 22, 2026
1 check 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.

1 participant