Skip to content

Commit 08c08f0

Browse files
committed
fix(mothership): detach only a browser run still going, and retry a failed detach
1 parent 20a3a28 commit 08c08f0

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

‎apps/sim/lib/mothership/request/tools/workflow-client-fallback.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,29 @@ async function detachClientRunAfterWait(params: {
9393
if (row.status !== ASYNC_TOOL_STATUS.running) return
9494
const executionId = getClaimedWorkflowExecutionId(row.claimedBy)
9595
if (!executionId || row.clientWorkflowExecutionId !== executionId) continue
96-
// The claim precedes the run's log; answer running only once the run is readable by its id.
96+
// The claim precedes the run's log: answer running only once the run is readable by its id
97+
// and still going. A run that already ended is reported by its own settlement.
9798
const logged = await getWorkflowExecutionLogStatus(executionId, workflowId).catch(
9899
() => undefined
99100
)
100-
if (!logged) continue
101+
if (logged !== 'running') continue
101102
const status = ASYNC_TOOL_CONFIRMATION_STATUS.background
102-
await settleClientToolCall({
103+
const settled = await settleClientToolCall({
103104
toolCallId,
104105
status,
105106
message: getWorkflowToolCompletionMessage(status),
106107
data: createStructuralWorkflowToolCompletionData(status, workflowId, executionId),
107108
executionId,
108109
guard: { kind: 'open' },
110+
}).catch((error) => {
111+
logger.warn('Could not settle a lapsed browser workflow wait as running; retrying', {
112+
toolCallId,
113+
error: toError(error).message,
114+
})
115+
return undefined
109116
})
110-
return
117+
// A write that failed is retried on the next poll; one another transition beat ends the watch.
118+
if (settled !== undefined) return
111119
}
112120
}
113121

0 commit comments

Comments
 (0)