Skip to content

Commit c5e7f17

Browse files
waleedlatif1claude
andcommitted
fix(kb): poll for connector documents after initial sync without requiring refresh
Add time-bounded polling for newly created connectors awaiting their first sync. Previously, documents only appeared after a manual page refresh because the frontend stopped polling before the sync started. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d5a3ce2 commit c5e7f17

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

apps/sim/app/workspace/[workspaceId]/knowledge/[id]/base.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import {
6262
type TagDefinition,
6363
useKnowledgeBaseTagDefinitions,
6464
} from '@/hooks/kb/use-knowledge-base-tag-definitions'
65-
import { useConnectorList } from '@/hooks/queries/kb/connectors'
65+
import { isConnectorSyncingOrPending, useConnectorList } from '@/hooks/queries/kb/connectors'
6666
import type { DocumentTagFilter } from '@/hooks/queries/kb/knowledge'
6767
import {
6868
useBulkDocumentOperation,
@@ -272,7 +272,7 @@ export function KnowledgeBase({
272272
} = useKnowledgeBase(id)
273273

274274
const { data: connectors = [], isLoading: isLoadingConnectors } = useConnectorList(id)
275-
const hasSyncingConnectors = connectors.some((c) => c.status === 'syncing')
275+
const hasSyncingConnectors = connectors.some(isConnectorSyncingOrPending)
276276
const hasSyncingConnectorsRef = useRef(hasSyncingConnectors)
277277
hasSyncingConnectorsRef.current = hasSyncingConnectors
278278

apps/sim/hooks/queries/kb/connectors.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ async function fetchConnectorDetail(
8888
return result.data
8989
}
9090

91+
/** Stop polling for initial sync after 2 minutes */
92+
const PENDING_SYNC_WINDOW_MS = 2 * 60 * 1000
93+
94+
/**
95+
* Checks if a connector is syncing or awaiting its first sync within the allowed window
96+
*/
97+
export function isConnectorSyncingOrPending(connector: ConnectorData): boolean {
98+
if (connector.status === 'syncing') return true
99+
return (
100+
connector.status === 'active' &&
101+
!connector.lastSyncAt &&
102+
Date.now() - new Date(connector.createdAt).getTime() < PENDING_SYNC_WINDOW_MS
103+
)
104+
}
105+
91106
export function useConnectorList(knowledgeBaseId?: string) {
92107
return useQuery({
93108
queryKey: connectorKeys.list(knowledgeBaseId),
@@ -97,8 +112,8 @@ export function useConnectorList(knowledgeBaseId?: string) {
97112
placeholderData: keepPreviousData,
98113
refetchInterval: (query) => {
99114
const connectors = query.state.data
100-
const hasSyncing = connectors?.some((c) => c.status === 'syncing')
101-
return hasSyncing ? 3000 : false
115+
if (!connectors?.length) return false
116+
return connectors.some(isConnectorSyncingOrPending) ? 3000 : false
102117
},
103118
})
104119
}

0 commit comments

Comments
 (0)