fix: fly machine wait timeout exceeds API max of 60s (#1619)

The Fly Machines API enforces a [1s, 1m0s] range on
WaitMachineRequest.Timeout. We were passing 90s, which caused an
invalid_argument error and prevented machines from starting.

Lower the default to 60s (the API maximum) and retry up to 3 times
so slow-starting machines still have a full 3-minute window.

Co-authored-by: lab <6723574+louisgv@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
A 2026-02-21 14:00:13 -08:00 committed by GitHub
parent 0569c86ba5
commit 0f59f0e844
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 9 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@openrouter/spawn",
"version": "0.5.21",
"version": "0.5.22",
"type": "module",
"bin": {
"spawn": "cli.js"

View file

@ -533,14 +533,25 @@ async function createMachine(
async function waitForMachineStart(
name: string,
machineId: string,
timeout = 90,
timeout = 60,
retries = 3,
): Promise<void> {
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 <agent>");
throw new Error("Machine start timeout");
}
logInfo("Machine is running");
}
async function cleanupOnFailure(appName: string): Promise<void> {