Skip to content

Commit ce3a282

Browse files
fix: Add custom retry delay support for startVM API calls (#156)
* Add custom retry delay support for startVM API calls - Added retryDelay parameter to startVm method with default 200ms - Sandbox creation: uses 200ms delay (preserves existing behavior) - Sandbox restart: uses 1000ms delay for better stability - Sandbox resume: uses 500ms delay for hibernated sandboxes - Connection fallbacks: use 200ms delay for reconnection scenarios 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * add explicit retry in build * use merged options object instead --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent d386bda commit ce3a282

4 files changed

Lines changed: 14 additions & 9 deletions

File tree

src/API.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import type {
4848
VmCreateSessionData,
4949
VmShutdownData,
5050
VmUpdateSpecsData,
51-
VmStartData,
51+
VmStartRequest,
5252
VmUpdateSpecs2Data,
5353
PreviewHostListData,
5454
PreviewHostCreateData,
@@ -111,6 +111,10 @@ export interface APIOptions {
111111
instrumentation?: (request: Request) => Promise<Response>;
112112
}
113113

114+
export interface StartVmOptions extends VmStartRequest {
115+
retryDelay?: number;
116+
}
117+
114118
export class API {
115119
private client: Client;
116120

@@ -353,7 +357,8 @@ export class API {
353357
return handleResponse(response, `Failed to update specs for VM ${id}`);
354358
}
355359

356-
async startVm(id: string, data?: VmStartData["body"]) {
360+
async startVm(id: string, options?: StartVmOptions) {
361+
const { retryDelay = 200, ...data } = options || {};
357362
const response = await retryWithDelay(
358363
() =>
359364
vmStart({
@@ -362,7 +367,7 @@ export class API {
362367
body: data,
363368
}),
364369
3,
365-
200
370+
retryDelay
366371
);
367372
const handledResponse = handleResponse(
368373
response,

src/Sandbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export class Sandbox {
127127
) {
128128
const client = await SandboxClient.create(
129129
session,
130-
async () => this.getSession(await this.api.startVm(this.id), customSession),
130+
async () => this.getSession(await this.api.startVm(this.id, { retryDelay: 200 }), customSession),
131131
undefined,
132132
this.tracer
133133
);
@@ -241,7 +241,7 @@ export class Sandbox {
241241
client ||
242242
SandboxClient.create(
243243
session,
244-
async () => this.getSession(await this.api.startVm(this.id), customSession),
244+
async () => this.getSession(await this.api.startVm(this.id, { retryDelay: 200 }), customSession),
245245
undefined,
246246
this.tracer
247247
)

src/Sandboxes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Sandboxes {
8888

8989
const startResponse = await this.api.startVm(
9090
sandbox.id,
91-
getStartOptions(opts)
91+
{ ...getStartOptions(opts), retryDelay: 200 } // Keep 200ms delay for creation
9292
);
9393

9494
return new Sandbox(sandbox.id, this.api, startResponse, this.tracer);
@@ -108,7 +108,7 @@ export class Sandboxes {
108108
"sandboxes.resume",
109109
{ "sandbox.id": sandboxId },
110110
async () => {
111-
const startResponse = await this.api.startVm(sandboxId);
111+
const startResponse = await this.api.startVm(sandboxId, { retryDelay: 500 }); // Use 500ms delay for resume
112112
return new Sandbox(sandboxId, this.api, startResponse, this.tracer);
113113
}
114114
);
@@ -162,7 +162,7 @@ export class Sandboxes {
162162
}
163163

164164
try {
165-
const startResponse = await this.api.startVm(sandboxId, opts);
165+
const startResponse = await this.api.startVm(sandboxId, { ...opts, retryDelay: 1000 }); // Use 1000ms delay for restart
166166

167167
return new Sandbox(sandboxId, this.api, startResponse, this.tracer);
168168
} catch (e) {

src/bin/commands/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export const buildCommand: yargs.CommandModule<
187187
spinner.start(updateSpinnerMessage(index, "Starting sandbox..."));
188188

189189
const startResponse = await withCustomError(
190-
api.startVm(id),
190+
api.startVm(id, { retryDelay: 200 }),
191191
"Failed to start sandbox at all"
192192
);
193193
let sandboxVM = new Sandbox(id, api, startResponse);

0 commit comments

Comments
 (0)