diff --git a/cli/package.json b/cli/package.json index 8d686fb3..b2fe677a 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "@openrouter/spawn", - "version": "0.5.21", + "version": "0.5.22", "type": "module", "bin": { "spawn": "cli.js" diff --git a/cli/src/fly/fly.ts b/cli/src/fly/fly.ts index 4e68be94..add0b39a 100644 --- a/cli/src/fly/fly.ts +++ b/cli/src/fly/fly.ts @@ -533,14 +533,25 @@ async function createMachine( async function waitForMachineStart( name: string, machineId: string, - timeout = 90, + timeout = 60, + retries = 3, ): Promise { - logStep(`Waiting for machine to start (timeout: ${timeout}s)...`); - const resp = await flyApi( - "GET", - `/apps/${name}/machines/${machineId}/wait?state=started&timeout=${timeout}`, - ); - if (hasError(resp)) { + for (let attempt = 1; attempt <= retries; attempt++) { + logStep( + `Waiting for machine to start (timeout: ${timeout}s, attempt ${attempt}/${retries})...`, + ); + const resp = await flyApi( + "GET", + `/apps/${name}/machines/${machineId}/wait?state=started&timeout=${timeout}`, + ); + if (!hasError(resp)) { + logInfo("Machine is running"); + return; + } + if (attempt < retries) { + logWarn(`Machine not ready yet, retrying...`); + continue; + } const data = parseJson(resp); logError( `Machine did not reach 'started' state: ${data?.error || "timeout"}`, @@ -548,7 +559,6 @@ async function waitForMachineStart( logError("Try a new region: FLY_REGION=ord spawn fly "); throw new Error("Machine start timeout"); } - logInfo("Machine is running"); } async function cleanupOnFailure(appName: string): Promise {