Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
fix(knowledge): use Promise.allSettled for document dispatch and fix …
…Copilot OAuth context

- Change Promise.all to Promise.allSettled in processDocumentsWithQueue so
  one failed dispatch doesn't abort the entire batch
- Add writeOAuthReturnContext before showing LazyOAuthRequiredModal from
  Copilot tools so useOAuthReturnForWorkflow can handle the return
- Add consumeOAuthReturnContext on modal close to clean up stale context
  • Loading branch information
waleedlatif1 committed Mar 31, 2026
commit 17e5f0f93aeb20fa679a607ccb93359bbfac0fde
19 changes: 17 additions & 2 deletions apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { createLogger } from '@sim/logger'
import { useShallow } from 'zustand/react/shallow'
import { useSession } from '@/lib/auth/auth-client'
import type { OAuthConnectEventDetail } from '@/lib/copilot/tools/client/base-tool'
import { consumeOAuthReturnContext, writeOAuthReturnContext } from '@/lib/credentials/client-state'
import type { OAuthProvider } from '@/lib/oauth'
import { BLOCK_DIMENSIONS, CONTAINER_DIMENSIONS } from '@/lib/workflows/blocks/block-dimensions'
import { TriggerUtils } from '@/lib/workflows/triggers/triggers'
Expand Down Expand Up @@ -478,6 +479,17 @@ const WorkflowContent = React.memo(
const handleOpenOAuthConnect = (event: Event) => {
const detail = (event as CustomEvent<OAuthConnectEventDetail>).detail
if (!detail) return

writeOAuthReturnContext({
origin: 'workflow',
workflowId: workflowIdParam,
displayName: detail.providerName,
providerId: detail.providerId,
preCount: 0,
workspaceId,
requestedAt: Date.now(),
})

setOauthModal({
provider: detail.providerId as OAuthProvider,
serviceId: detail.serviceId,
Expand All @@ -490,7 +502,7 @@ const WorkflowContent = React.memo(
window.addEventListener('open-oauth-connect', handleOpenOAuthConnect as EventListener)
return () =>
window.removeEventListener('open-oauth-connect', handleOpenOAuthConnect as EventListener)
}, [])
}, [workflowIdParam, workspaceId])

const { diffAnalysis, isShowingDiff, isDiffReady, reapplyDiffMarkers, hasActiveDiff } =
useWorkflowDiffStore(
Expand Down Expand Up @@ -4103,7 +4115,10 @@ const WorkflowContent = React.memo(
<Suspense fallback={null}>
<LazyOAuthRequiredModal
isOpen={true}
onClose={() => setOauthModal(null)}
onClose={() => {
consumeOAuthReturnContext()
setOauthModal(null)
}}
provider={oauthModal.provider}
toolName={oauthModal.providerName}
serviceId={oauthModal.serviceId}
Expand Down
22 changes: 20 additions & 2 deletions apps/sim/lib/knowledge/documents/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,27 @@ export async function processDocumentsWithQueue(
}
)

await Promise.all(jobPayloads.map((payload) => dispatchDocumentProcessingJob(payload)))
const results = await Promise.allSettled(
jobPayloads.map((payload) => dispatchDocumentProcessingJob(payload))
)

const failures = results.filter((r): r is PromiseRejectedResult => r.status === 'rejected')
if (failures.length > 0) {
logger.error(`[${requestId}] ${failures.length}/${results.length} document dispatches failed`, {
errors: failures.map((f) =>
f.reason instanceof Error ? f.reason.message : String(f.reason)
),
})
}

logger.info(
`[${requestId}] Document dispatch complete: ${results.length - failures.length}/${results.length} succeeded`
)

if (failures.length === results.length) {
throw new Error(`All ${failures.length} document processing dispatches failed`)
}

logger.info(`[${requestId}] All documents dispatched for processing`)
return
}

Expand Down
Loading