Skip to content

Commit 984387e

Browse files
committed
fix(mothership): key resumes by orchestration id
1 parent f94be08 commit 984387e

File tree

1 file changed

+9
-1
lines changed
  • apps/sim/lib/copilot/orchestrator

1 file changed

+9
-1
lines changed

apps/sim/lib/copilot/orchestrator/index.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export async function orchestrateCopilotStream(
123123
runId,
124124
messageId: typeof payloadMsgId === 'string' ? payloadMsgId : crypto.randomUUID(),
125125
})
126+
const continuationWorkerId = `sim-resume:${crypto.randomUUID()}`
126127
let claimedToolCallIds: string[] = []
127128
let claimedByWorkerId: string | null = null
128129

@@ -198,7 +199,7 @@ export async function orchestrateCopilotStream(
198199
for (;;) {
199200
claimedToolCallIds = []
200201
claimedByWorkerId = null
201-
const resumeWorkerId = continuation.runId || context.runId || context.messageId
202+
const resumeWorkerId = continuationWorkerId
202203
const readyTools: ReadyContinuationTool[] = []
203204
const localPendingPromises: Promise<unknown>[] = []
204205
const missingToolCallIds: string[] = []
@@ -213,6 +214,7 @@ export async function orchestrateCopilotStream(
213214
logger.info('Waiting for local async tool completion before retrying resume claim', {
214215
toolCallId,
215216
runId: continuation.runId,
217+
workerId: resumeWorkerId,
216218
})
217219
continue
218220
}
@@ -223,6 +225,7 @@ export async function orchestrateCopilotStream(
223225
logger.warn('Async tool continuation is waiting on a claim held by another worker', {
224226
toolCallId,
225227
runId: continuation.runId,
228+
workerId: resumeWorkerId,
226229
claimedBy: durableRow.claimedBy,
227230
})
228231
continue
@@ -278,6 +281,7 @@ export async function orchestrateCopilotStream(
278281
logger.info('Retrying async resume after some tool calls were not yet ready', {
279282
checkpointId: continuation.checkpointId,
280283
runId: continuation.runId,
284+
workerId: resumeWorkerId,
281285
retry: resumeRetries,
282286
missingToolCallIds,
283287
})
@@ -295,6 +299,7 @@ export async function orchestrateCopilotStream(
295299
logger.info('Retrying async resume because no tool calls were ready yet', {
296300
checkpointId: continuation.checkpointId,
297301
runId: continuation.runId,
302+
workerId: resumeWorkerId,
298303
retry: resumeRetries,
299304
})
300305
await new Promise((resolve) => setTimeout(resolve, 250 * resumeRetries))
@@ -323,6 +328,7 @@ export async function orchestrateCopilotStream(
323328
logger.info('Releasing async tool claims after claim contention during resume', {
324329
checkpointId: continuation.checkpointId,
325330
runId: continuation.runId,
331+
workerId: resumeWorkerId,
326332
newlyClaimedToolCallIds,
327333
claimFailures,
328334
})
@@ -337,6 +343,7 @@ export async function orchestrateCopilotStream(
337343
logger.info('Retrying async resume after claim contention', {
338344
checkpointId: continuation.checkpointId,
339345
runId: continuation.runId,
346+
workerId: resumeWorkerId,
340347
retry: resumeRetries,
341348
claimFailures,
342349
})
@@ -359,6 +366,7 @@ export async function orchestrateCopilotStream(
359366
logger.info('Resuming async tool continuation', {
360367
checkpointId: continuation.checkpointId,
361368
runId: continuation.runId,
369+
workerId: resumeWorkerId,
362370
toolCallIds: readyTools.map((tool) => tool.toolCallId),
363371
})
364372

0 commit comments

Comments
 (0)