(args: Args, deadline: number)
| 176 | } |
| 177 | |
| 178 | async function waitUntilIdle(args: Args, deadline: number): Promise<void> { |
| 179 | let attempt = 0; |
| 180 | while (Date.now() < deadline) { |
| 181 | attempt++; |
| 182 | try { |
| 183 | const runs = await Agent.listRuns(args.agentId, { |
| 184 | runtime: "cloud", |
| 185 | limit: 1, |
| 186 | }); |
| 187 | const status = runs.items[0]?.status; |
| 188 | log(`idle-check ${attempt}: status=${status ?? "(no runs)"}`); |
| 189 | if (status !== "running") return; |
| 190 | } catch (err) { |
| 191 | const msg = err instanceof Error ? err.message : String(err); |
| 192 | log(`idle-check ${attempt}: Agent.listRuns failed: ${msg}`); |
| 193 | } |
| 194 | await sleep(args.pollMs); |
| 195 | } |
| 196 | log(`idle-wait exhausted after ${args.maxWaitMs / 1000}s; giving up`); |
| 197 | process.exit(4); |
| 198 | } |
| 199 | |
| 200 | async function sendWithBusyRetry(args: Args, deadline: number): Promise<void> { |
| 201 | let attempt = 0; |
no test coverage detected