|
6 | 6 | type AsyncTerminalCompletionSnapshot, |
7 | 7 | getTerminalConfirmationStatus, |
8 | 8 | isAsyncTerminalConfirmationStatus, |
| 9 | + isTerminalAsyncStatus, |
9 | 10 | } from '@/lib/mothership/async-runs/lifecycle' |
10 | 11 | import { replaceTerminalAsyncToolCallResult } from '@/lib/mothership/async-runs/repository' |
11 | 12 | import { MothershipStreamV1ToolOutcome } from '@/lib/mothership/generated/mothership-stream-v1' |
@@ -42,6 +43,7 @@ import { |
42 | 43 | getHumanPauseResumeUrl, |
43 | 44 | getTrustedWorkflowToolExecution, |
44 | 45 | getWorkflowExecutionCopilotToolCallId, |
| 46 | + getWorkflowExecutionLogStatus, |
45 | 47 | } from '@/lib/workflows/executor/execution-state' |
46 | 48 | import type { ResolvedSecretTraceRegistry } from '@/executor/utils/resolved-secret-trace-registry' |
47 | 49 |
|
@@ -376,21 +378,33 @@ export async function waitForWorkflowToolCompletion({ |
376 | 378 | completion.data.status === WORKFLOW_TOOL_PAUSED_STATUS |
377 | 379 | ) { |
378 | 380 | // Re-read rather than trust the confirmation; a run resumed since then reads as finished. |
379 | | - const [resumeUrl, boundToolCallId] = await Promise.all([ |
| 381 | + const [resumeUrl, boundToolCallId, logStatus] = await Promise.all([ |
380 | 382 | getHumanPauseResumeUrl(executionId, workflowId), |
381 | 383 | getWorkflowExecutionCopilotToolCallId(executionId, workflowId), |
| 384 | + getWorkflowExecutionLogStatus(executionId, workflowId), |
382 | 385 | ]).catch((error) => { |
383 | 386 | logger.warn('Failed to read paused workflow tool execution', { |
384 | 387 | toolCallId, |
385 | 388 | workflowId, |
386 | 389 | executionId, |
387 | 390 | error: getErrorMessage(error), |
388 | 391 | }) |
389 | | - return [null, undefined] as const |
| 392 | + return [null, undefined, undefined] as const |
390 | 393 | }) |
391 | | - if (resumeUrl && boundToolCallId === toolCallId) { |
392 | | - toolRegistry?.markIncomplete('client-tool-completion-deferred') |
393 | | - return buildPausedWorkflowToolCompletion(workflowId, executionId, resumeUrl) |
| 394 | + if (boundToolCallId === toolCallId) { |
| 395 | + if (resumeUrl) { |
| 396 | + toolRegistry?.markIncomplete('client-tool-completion-deferred') |
| 397 | + return buildPausedWorkflowToolCompletion(workflowId, executionId, resumeUrl) |
| 398 | + } |
| 399 | + // The person answered before this read and the resumed run has no result yet. |
| 400 | + if (logStatus !== undefined && !isTerminalAsyncStatus(logStatus)) { |
| 401 | + toolRegistry?.markIncomplete('client-tool-completion-deferred') |
| 402 | + return structuralWorkflowCompletion( |
| 403 | + ASYNC_TOOL_CONFIRMATION_STATUS.background, |
| 404 | + workflowId, |
| 405 | + executionId |
| 406 | + ) |
| 407 | + } |
394 | 408 | } |
395 | 409 | } |
396 | 410 |
|
|
0 commit comments