fix(sdk-typescript): surface snapshot-from-sandbox capture failures#35
Open
mu-hashmi wants to merge 1 commit into
Open
fix(sdk-typescript): surface snapshot-from-sandbox capture failures#35mu-hashmi wants to merge 1 commit into
mu-hashmi wants to merge 1 commit into
Conversation
…andbox
`_experimental_createSnapshot` previously watched only the sandbox state,
which reverts to its previous value on both success and failure of a
snapshot-from-sandbox capture. A failed capture was therefore reported as
success and the snapshot 404'd forever.
Wait on the snapshot record instead: resolve when it reaches `active`,
throw with the record's `errorReason` when it reaches `error`/`build_failed`.
The capture route now documents the 409 duplicate-name response, propagated
into the generated clients.
Compatibility with servers that only insert the record after a successful
capture ("legacy API" in the code) is handled by two guards:
- The record and the sandbox-state revert land in separate steps, so a poll
can observe the reverted sandbox before the record exists. Re-read the
record a few times, spaced out and bounded by the caller timeout, before
declaring the capture failed.
- Such servers have no accept-time duplicate check, so polling by name could
resolve against a pre-existing same-name snapshot. Reject records whose
createdAt predates the capture initiation beyond a 5-minute skew allowance.
Sandbox gains an optional SnapshotsApi constructor argument (defaulted from
the API-targeted client config) so the poller hits the Daytona API rather
than the toolbox proxy.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sandbox._experimental_createSnapshot()used to watch only the sandboxstate. A snapshot-from-sandbox capture reverts the sandbox to its previous
state on both success and failure, so a failed capture was reported to
the caller as success while the snapshot never materialized (404 forever).
This PR makes the SDK wait on the snapshot record instead:
active.DaytonaErrorcarrying the record'serrorReasonwhen it reacheserror/build_failed.409when a snapshot with that namealready exists for the organization; the response is propagated into the
generated Go / Java / Python clients.
Sandboxtakes an optionalSnapshotsApi(defaulted from the API-targetedclient configuration, since the sandbox's own config is repurposed to point
at the toolbox proxy) so the poller queries the Daytona API directly.
Compatibility with servers that create the record only after success
The code refers to these as the "legacy API" path — a server that inserts
the snapshot record only after a successful capture, rather than up front
when the capture is accepted. Two guards keep the poller correct against
them:
in separate steps, so a poll can observe the reverted sandbox before the
record lands. After seeing the sandbox leave
snapshottingwith no recordyet, re-read the record up to 3 times, 500 ms apart, bounded by the caller
timeout, before declaring the capture failed.
check, so polling by name could resolve against a pre-existing same-name
snapshot while the real capture is still running. Reject any polled record
whose
createdAtpredates the capture initiation beyond a 5-minuteclock-skew allowance.
Behavior changes worth noting
DaytonaErrorwith the realerror reason, instead of a silent success.
409from the capture route.
Test plan
nx test sdk-typescript— 16 suites / 215 tests green (adds coveragefor success, capture failure, build failure, the legacy grace-read
recovery and timeout paths, stale-record rejection, clock-skew tolerance,
and the default
SnapshotsApiwiring).tsc --verbatimModuleSyntax) green.eslint sdk-typescript/src/**/*.ts— no new errors.yarn generate:api-client— generated client drift limited to theadditive
409response (Go/Java/Python).nx run sdk-typescript:docs— regenerated SDK reference reflects thenew constructor argument and method contract.
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by cubic
Fixes silent successes when capturing a snapshot from a sandbox by polling the snapshot record until it’s active and surfacing real failures via
DaytonaError. Also documents duplicate-name409and propagates it to generated clients.Bug Fixes
_experimental_createSnapshotnow waits on the snapshot record: resolves atactive; throwsDaytonaErrorwitherrorReasonaterror/build_failed.snapshotting; reject stale records created before the capture (5‑minute skew tolerance).Sandboxconstructor accepts optionalSnapshotsApi(defaults to an API-targeted client) so polling hits the Daytona API, not the toolbox proxy.Dependencies
409for duplicate snapshot names.api-client-go,api-client-java,api-client-python,api-client-python-async) include the409response.SnapshotsApiarg and the snapshot method’s behavior.Written for commit 67cbad8. Summary will update on new commits.