Skip to content

fix(sdk-typescript): poll the snapshot record in _experimental_createSnapshot#5000

Open
mu-hashmi wants to merge 5 commits into
mainfrom
feat/sdk-snapshot-record-polling
Open

fix(sdk-typescript): poll the snapshot record in _experimental_createSnapshot#5000
mu-hashmi wants to merge 5 commits into
mainfrom
feat/sdk-snapshot-record-polling

Conversation

@mu-hashmi

@mu-hashmi mu-hashmi commented Jun 11, 2026

Copy link
Copy Markdown
Collaborator

TL;DR: _experimental_createSnapshot now polls the snapshot record (not sandbox state), so failed captures throw with the record's errorReason instead of reporting success for a snapshot that doesn't exist.

Description

The helper previously polled sandbox state and treated any exit from SNAPSHOTTING as success. A silently failed capture (#4990) therefore RESOLVED with a snapshot name that 404s forever.

Now it polls the record by name until terminal: active resolves; error/build_failed throw a DaytonaError carrying the record's errorReason. Terminal-state handling mirrors SnapshotService.create.

  • Legacy-server compatibility (pre-feat(api): create the snapshot record at capture start and mark it error on failure #4999 APIs create no record until success): a 404 is tolerated while the sandbox is still SNAPSHOTTING; once the sandbox reverts with no record, ONE grace re-read closes the server-side persist/revert straddle before reporting the legacy silent revert as a failure.
  • Constructor: Sandbox gains an optional snapshotsApi parameter. When omitted (direct constructors in the wild), it is default-instantiated from the same pre-proxy Configuration the other APIs use - captured before the constructor repoints clientConfig to the toolbox proxy. No breaking change; everyone gets record polling.
  • Refresh semantics: after a successful capture the local sandbox data is refreshed best-effort - a refresh failure logs and is swallowed, never rejecting a successful snapshot.

Known, labeled limitation: against PRE-#4999 servers, a pre-existing ACTIVE record with the same name yields a false success - pre-existing failure class, fixed server-side by #4999's accept-time 409.

Review guide

Suggested order:

  1. libs/sdk-typescript/src/Sandbox.ts - waitForSnapshotComplete loop (risk center: terminal mapping + legacy fallback), then the constructor default.
  2. libs/sdk-typescript/src/Daytona.ts - wiring of the new param at construction sites.
  3. __tests__/Sandbox.test.ts - the six snapshot-wait specs document the contract.
    Mechanical: apps/docs typedoc regen (generated; CI diffs it), test-file import fix (nx module-boundary rule counts CJS require of a buildable lib as lazy-loading).

Commit map

Commit What Why it exists
bf500c9 poll the record in _experimental_createSnapshot implementation (plan)
1fc4ca9 typedoc regen implementation (generated)
cfc34c4 snapshotsApi optional + success-path refresh Copilot + cubic review (valid)
679c299 never reject a successful capture on refresh failure cubic review (valid)
91cdee1 static api-client import in test CI module-boundary failure fix

Related PRs

Part of #4990. Pairs with #4999 (record exists from accept time); mergeable independently thanks to the legacy fallback. Python SDK has the same bug plus an unenforced-timeout defect - deliberately out of scope, follow-up issue to come.

Validation

  • nx test sdk-typescript: 15 suites / 202 tests green, incl.: success gated on the record (polled twice), error rejects with errorReason, build_failed rejects, 404-tolerance while snapshotting, grace re-read recovery, legacy hard-fail once reverted with no record, default SnapshotsApi instantiation, success + refresh-throws still resolves.
  • CI typecheck mirror (tsc --verbatimModuleSyntax) clean; prettier clean; typedoc regenerated in-PR.
  • All CI checks green on 91cdee1. (One E2E run failed on the nuxt runtime harness's silent npm install - infra flake, passed on rerun, tracked in ci: nuxt runtime-compat harness fails silently on transient npm errors #5008.)

Closes #4992

…shot

Signed-off-by: Muhammad Hashmi <mhashmi@berkeley.edu>
Signed-off-by: Muhammad Hashmi <mhashmi@berkeley.edu>
@nx-cloud

nx-cloud Bot commented Jun 11, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 91cdee1

Command Status Duration Result
nx e2e:cleanup daytona-e2e ✅ Succeeded <1s View ↗
nx run sdk-typescript:test:runtime ✅ Succeeded 2m 12s View ↗
nx run-many --target=test:e2e --all --nxBail=true ✅ Succeeded 6m 29s View ↗
nx e2e daytona-e2e ✅ Succeeded <1s View ↗
nx run-many --target=build --projects=api,runne... ✅ Succeeded 6s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-11 05:20:32 UTC

@mu-hashmi mu-hashmi marked this pull request as ready for review June 11, 2026 03:32
Copilot AI review requested due to automatic review settings June 11, 2026 03:32

Copilot AI 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.

Pull request overview

This PR fixes a correctness gap in the TypeScript SDK’s Sandbox._experimental_createSnapshot by polling the snapshot record (via SnapshotsApi.getSnapshot) to determine success/failure, rather than inferring success from the sandbox leaving SNAPSHOTTING (which could previously mask silent capture failures).

Changes:

  • Update _experimental_createSnapshot to poll the snapshot record to terminal states (active => success, error/build_failed => throw with errorReason), with legacy-server 404 tolerance + one grace re-read.
  • Plumb a SnapshotsApi instance into Sandbox construction (via Daytona.create/get/list and _experimental_fork).
  • Add focused unit tests for success/failure/legacy behaviors and regenerate the docs page to reflect the new behavior/signature.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
libs/sdk-typescript/src/Sandbox.ts Implements record-based polling and adds snapshotsApi dependency to Sandbox.
libs/sdk-typescript/src/Daytona.ts Instantiates and threads SnapshotsApi through Sandbox creation and SnapshotService.
libs/sdk-typescript/src/tests/Sandbox.test.ts Adds tests covering record polling and legacy 404/grace behaviors.
apps/docs/src/content/docs/en/typescript-sdk/sandbox.mdx Updates generated docs to reflect constructor signature and updated snapshot behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 144 to 150
constructor(
sandboxDto: SandboxDto | SandboxListItemDto,
private readonly clientConfig: Configuration,
private readonly axiosInstance: AxiosInstance,
private readonly sandboxApi: SandboxApi,
private readonly snapshotsApi: SnapshotsApi,
) {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in cfc34c4: snapshotsApi is optional; when omitted the constructor default-instantiates SnapshotsApi from the same configuration used for the other APIs (captured before the toolbox-proxy repoint), so direct constructors keep working and still get record polling.

@cubic-dev-ai cubic-dev-ai 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.

2 issues found across 4 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread libs/sdk-typescript/src/Sandbox.ts Outdated
Comment thread libs/sdk-typescript/src/Sandbox.ts
…fter capture

Signed-off-by: Muhammad Hashmi <mhashmi@berkeley.edu>

@cubic-dev-ai cubic-dev-ai 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.

1 issue found across 3 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread libs/sdk-typescript/src/Sandbox.ts Outdated
…lure

Signed-off-by: Muhammad Hashmi <mhashmi@berkeley.edu>
Copilot AI review requested due to automatic review settings June 11, 2026 04:23

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Signed-off-by: Muhammad Hashmi <mhashmi@berkeley.edu>
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.

sdk: _experimental_createSnapshot should poll the snapshot record, not sandbox state

2 participants