Skip to content

Commit 8ae2f01

Browse files
committed
refactor(mothership): settle a browser-claimed workflow tool from its log status alone
1 parent 3b8825a commit 8ae2f01

2 files changed

Lines changed: 13 additions & 23 deletions

File tree

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

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
import { createLogger } from '@sim/logger'
2-
import { ASYNC_TOOL_CONFIRMATION_STATUS } from '@/lib/mothership/async-runs/lifecycle'
1+
import {
2+
ASYNC_TOOL_CONFIRMATION_STATUS,
3+
isTerminalAsyncStatus,
4+
} from '@/lib/mothership/async-runs/lifecycle'
35
import {
46
completeClientWorkflowToolCall,
57
detachAsyncToolCall,
@@ -10,12 +12,7 @@ import {
1012
getWorkflowToolCompletionMessage,
1113
getWorkflowToolConfirmationStatus,
1214
} from '@/lib/mothership/tools/workflow-tools'
13-
import {
14-
getTrustedWorkflowToolExecution,
15-
hasWorkflowExecutionLog,
16-
} from '@/lib/workflows/executor/execution-state'
17-
18-
const logger = createLogger('CopilotWorkflowClientSettlement')
15+
import { getWorkflowExecutionLogStatus } from '@/lib/workflows/executor/execution-state'
1916

2017
interface ReportClientWorkflowToolParams {
2118
toolCallId: string
@@ -40,17 +37,10 @@ export async function reportSettledClientWorkflowTool({
4037
executionId,
4138
workflowId,
4239
}: ReportClientWorkflowToolParams): Promise<void> {
43-
const execution = await getTrustedWorkflowToolExecution(executionId, workflowId, toolCallId)
44-
if (!execution && (await hasWorkflowExecutionLog(executionId, workflowId))) {
45-
logger.warn('Settled client workflow execution has no trusted log; leaving it to the client', {
46-
toolCallId,
47-
executionId,
48-
workflowId,
49-
})
50-
return
51-
}
40+
const logStatus = await getWorkflowExecutionLogStatus(executionId, workflowId)
41+
if (logStatus !== undefined && !isTerminalAsyncStatus(logStatus)) return
5242

53-
const executionStatus = execution?.status ?? 'failed'
43+
const executionStatus = logStatus ?? 'failed'
5444
const status = getWorkflowToolConfirmationStatus(executionStatus)
5545
const message = getWorkflowToolCompletionMessage(status)
5646
const data = createStructuralWorkflowToolCompletionData(status, workflowId, executionId)

‎apps/sim/lib/workflows/executor/execution-state.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ export async function getExecutionStateForWorkflow(
136136
return extractExecutionStateFromRow(row)
137137
}
138138

139-
/** Whether an execution ever started its workflow log, whatever state that log is in now. */
140-
export async function hasWorkflowExecutionLog(
139+
/** The status of an execution's workflow log, or `undefined` when it never started one. */
140+
export async function getWorkflowExecutionLogStatus(
141141
executionId: string,
142142
workflowId: string
143-
): Promise<boolean> {
143+
): Promise<string | undefined> {
144144
const [row] = await db
145-
.select({ id: workflowExecutionLogs.id })
145+
.select({ status: workflowExecutionLogs.status })
146146
.from(workflowExecutionLogs)
147147
.where(
148148
and(
@@ -151,7 +151,7 @@ export async function hasWorkflowExecutionLog(
151151
)
152152
)
153153
.limit(1)
154-
return Boolean(row)
154+
return row?.status
155155
}
156156

157157
/** Loads a terminal workflow result only when its server-persisted Copilot binding matches. */

0 commit comments

Comments
 (0)