Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(knowledge): skip sync and document processing when KB is deleted#4327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
cd52b8e19eb8a1dfae79aFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -156,19 +156,51 @@ export async function dispatchSync( | ||
| const connectorRows = await db | ||
| .select({ | ||
| knowledgeBaseId: knowledgeConnector.knowledgeBaseId, | ||
| connectorArchivedAt: knowledgeConnector.archivedAt, | ||
| connectorDeletedAt: knowledgeConnector.deletedAt, | ||
| workspaceId: knowledgeBase.workspaceId, | ||
| userId: knowledgeBase.userId, | ||
| kbDeletedAt: knowledgeBase.deletedAt, | ||
| }) | ||
| .from(knowledgeConnector) | ||
| .innerJoin(knowledgeBase, eq(knowledgeBase.id, knowledgeConnector.knowledgeBaseId)) | ||
| .where(eq(knowledgeConnector.id, connectorId)) | ||
| .limit(1) | ||
| const row = connectorRows[0] | ||
| if (!row) { | ||
| logger.warn(`Skipping sync dispatch: connector not found`, { connectorId, requestId }) | ||
| return | ||
| } | ||
| if (row.kbDeletedAt) { | ||
| logger.warn(`Skipping sync dispatch: knowledge base is deleted`, { | ||
| connectorId, | ||
| knowledgeBaseId: row.knowledgeBaseId, | ||
| requestId, | ||
| }) | ||
| await db | ||
| .update(knowledgeConnector) | ||
| .set({ | ||
| status: 'error', | ||
| nextSyncAt: null, | ||
| lastSyncError: 'Knowledge base deleted', | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(knowledgeConnector.id, connectorId)) | ||
| return | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| if (row.connectorArchivedAt || row.connectorDeletedAt) { | ||
| logger.warn(`Skipping sync dispatch: connector is archived or deleted`, { | ||
| connectorId, | ||
| requestId, | ||
| }) | ||
| return | ||
| } | ||
| const tags = [`connectorId:${connectorId}`] | ||
| if (row?.knowledgeBaseId) tags.push(`knowledgeBaseId:${row.knowledgeBaseId}`) | ||
| if (row?.workspaceId) tags.push(`workspaceId:${row.workspaceId}`) | ||
| if (row?.userId) tags.push(`userId:${row.userId}`) | ||
| if (row.knowledgeBaseId) tags.push(`knowledgeBaseId:${row.knowledgeBaseId}`) | ||
| if (row.workspaceId) tags.push(`workspaceId:${row.workspaceId}`) | ||
| if (row.userId) tags.push(`userId:${row.userId}`) | ||
| await knowledgeConnectorSync.trigger( | ||
| { | ||
| @@ -261,7 +293,8 @@ export async function executeSync( | ||
| .limit(1) | ||
| if (connectorRows.length === 0) { | ||
| throw new Error(`Connector not found: ${connectorId}`) | ||
| logger.warn(`Skipping sync: connector ${connectorId} not found, archived, or deleted`) | ||
| return { ...result, error: 'connector_unavailable' } | ||
| } | ||
| const connector = connectorRows[0] | ||
| @@ -278,7 +311,19 @@ export async function executeSync( | ||
| .limit(1) | ||
| if (kbRows.length === 0) { | ||
| throw new Error(`Knowledge base not found: ${connector.knowledgeBaseId}`) | ||
| logger.warn( | ||
| `Skipping sync: knowledge base ${connector.knowledgeBaseId} is deleted (connector ${connectorId})` | ||
| ) | ||
| await db | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .update(knowledgeConnector) | ||
| .set({ | ||
| status: 'error', | ||
| nextSyncAt: null, | ||
| lastSyncError: 'Knowledge base deleted', | ||
| updatedAt: new Date(), | ||
| }) | ||
| .where(eq(knowledgeConnector.id, connectorId)) | ||
| return { ...result, error: 'knowledge_base_deleted' } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| const userId = kbRows[0].userId | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -386,7 +386,20 @@ export async function processDocumentAsync( | ||
| .limit(1) | ||
| if (kb.length === 0) { | ||
| throw new Error(`Knowledge base not found: ${knowledgeBaseId}`) | ||
| logger.warn( | ||
| `[${documentId}] Skipping document processing: knowledge base ${knowledgeBaseId} is deleted` | ||
| ) | ||
| await db | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .update(document) | ||
| .set({ | ||
| processingStatus: 'failed', | ||
| processingError: 'Knowledge base deleted', | ||
| processingCompletedAt: new Date(), | ||
| }) | ||
| .where( | ||
| and(eq(document.id, documentId), isNull(document.archivedAt), isNull(document.deletedAt)) | ||
| ) | ||
| return | ||
| } | ||
waleedlatif1 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| await db | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.