Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Merge branch 'staging' into fix/mothership-id-key
  • Loading branch information
icecrasher321 committed Mar 25, 2026
commit bce6fdef207010fcae654e4abb948b408dddfdfb
86 changes: 55 additions & 31 deletions apps/sim/lib/copilot/orchestrator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ export async function orchestrateCopilotStream(
messageId,
})
const continuationWorkerId = `sim-resume:${crypto.randomUUID()}`
const withLogContext = (message: string) =>
appendCopilotLogContext(message, {
requestId: context.requestId,
messageId,
})
let claimedToolCallIds: string[] = []
let claimedByWorkerId: string | null = null

Expand Down Expand Up @@ -261,23 +266,33 @@ export async function orchestrateCopilotStream(

if (localPendingPromise) {
localPendingPromises.push(localPendingPromise)
logger.info('Waiting for local async tool completion before retrying resume claim', {
toolCallId,
runId: continuation.runId,
workerId: resumeWorkerId,
})
logger.info(
withLogContext(
'Waiting for local async tool completion before retrying resume claim'
),
{
toolCallId,
runId: continuation.runId,
workerId: resumeWorkerId,
}
)
continue
}

if (durableRow && isTerminalAsyncStatus(durableRow.status)) {
if (durableRow.claimedBy && durableRow.claimedBy !== resumeWorkerId) {
missingToolCallIds.push(toolCallId)
logger.warn('Async tool continuation is waiting on a claim held by another worker', {
toolCallId,
runId: continuation.runId,
workerId: resumeWorkerId,
claimedBy: durableRow.claimedBy,
})
logger.warn(
withLogContext(
'Async tool continuation is waiting on a claim held by another worker'
),
{
toolCallId,
runId: continuation.runId,
workerId: resumeWorkerId,
claimedBy: durableRow.claimedBy,
}
)
continue
}
readyTools.push({
Expand Down Expand Up @@ -338,13 +353,16 @@ export async function orchestrateCopilotStream(
if (missingToolCallIds.length > 0) {
if (resumeRetries < 3) {
resumeRetries++
logger.info('Retrying async resume after some tool calls were not yet ready', {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
retry: resumeRetries,
missingToolCallIds,
})
logger.info(
withLogContext('Retrying async resume after some tool calls were not yet ready'),
{
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
retry: resumeRetries,
missingToolCallIds,
}
)
await new Promise((resolve) => setTimeout(resolve, 250 * resumeRetries))
continue
}
Expand All @@ -366,12 +384,15 @@ export async function orchestrateCopilotStream(
if (readyTools.length === 0) {
if (resumeRetries < 3 && continuation.pendingToolCallIds.length > 0) {
resumeRetries++
logger.info('Retrying async resume because no tool calls were ready yet', {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
retry: resumeRetries,
})
logger.info(
withLogContext('Retrying async resume because no tool calls were ready yet'),
{
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
retry: resumeRetries,
}
)
await new Promise((resolve) => setTimeout(resolve, 250 * resumeRetries))
continue
}
Expand Down Expand Up @@ -403,13 +424,16 @@ export async function orchestrateCopilotStream(

if (claimFailures.length > 0) {
if (newlyClaimedToolCallIds.length > 0) {
logger.info('Releasing async tool claims after claim contention during resume', {
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
newlyClaimedToolCallIds,
claimFailures,
})
logger.info(
withLogContext('Releasing async tool claims after claim contention during resume'),
{
checkpointId: continuation.checkpointId,
runId: continuation.runId,
workerId: resumeWorkerId,
newlyClaimedToolCallIds,
claimFailures,
}
)
await Promise.all(
newlyClaimedToolCallIds.map((toolCallId) =>
releaseCompletedAsyncToolClaim(toolCallId, resumeWorkerId).catch(() => null)
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.