|
1 | 1 | import { createLogger } from '@sim/logger' |
| 2 | +import { interruptibleSleep } from '@sim/utils/helpers' |
2 | 3 | import { generateId } from '@sim/utils/id' |
3 | 4 | import { filterUndefined, isPlainRecord, isRecordLike } from '@sim/utils/object' |
4 | 5 | import { createCopilotWorkspaceApiKey } from '@/lib/api-key/application/create-api-key' |
@@ -277,18 +278,16 @@ async function answerWithinWait( |
277 | 278 | }) |
278 | 279 | const settled = run({ ...lifecycle, executionId, onDispatch: () => markDispatched() }) |
279 | 280 | retainSandboxExecution(settled) |
280 | | - let timer: ReturnType<typeof setTimeout> | undefined |
281 | | - const waited = new Promise<null>((resolve) => { |
282 | | - timer = setTimeout(() => resolve(null), waitMs) |
283 | | - }) |
| 281 | + const stopWaiting = new AbortController() |
| 282 | + const waited = interruptibleSleep(waitMs, stopWaiting.signal).then(() => null) |
284 | 283 | try { |
285 | 284 | const result = await Promise.race([settled, waited]) |
286 | 285 | if (result) return result |
287 | 286 | // Only a run handed to the executor is answered running; one still in preflight settles first. |
288 | 287 | const started = await Promise.race([settled, dispatched]) |
289 | 288 | if (started) return started |
290 | 289 | } finally { |
291 | | - clearTimeout(timer) |
| 290 | + stopWaiting.abort() |
292 | 291 | } |
293 | 292 | logger.info('Workflow tool run outlasted its wait; answering it still running', { |
294 | 293 | toolCallId: context.toolCallId, |
|
0 commit comments