RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.
Go agent-harnessagent-native-databaseagentic-aiagentic-retrievalagentic-searchaiai-agentscontext-enginecontext-engineeringcontext-managementharness-engineeringknowledge-compilationragretrieval-augmented-generationretrieval-harnesssearch-harness
fix(file): keep polling until cleared datasets disappear from the list (#20423)
chanxdec77fefd0cc
diff --git a/web/src/hooks/use-file-request.ts b/web/src/hooks/use-file-request.tsindex cbb1f36961..4f73611f63 100644--- a/web/src/hooks/use-file-request.ts+++ b/web/src/hooks/use-file-request.ts@@ -329,13 +329,17 @@ export const useRenameFile = () => {const LinkedDatasetsPollIntervalMs = 500;const LinkedDatasetsPollMaxAttempts = 6;-// Returns true when every affected file row on the current page carries all the-// newly linked datasets. Rows that are not on the current page, or folder rows-// (which never carry kbs_info), cannot be verified and are treated as done.+// Returns true when every affected file row on the current page matches the+// requested link: the selected datasets are present and, in 'replace' mode, no+// other dataset is left behind — otherwise clearing the selection (empty kbIds)+// would look done on the stale row. Rows that are not on the current page, or+// folder rows (which never carry kbs_info), cannot be verified and are treated+// as done.const areDatasetsLinked = (queryClient: QueryClient,fileIds: string[],kbIds: string[],+ mode: ConnectFileToKnowledgeMode,) => {const cached = queryClient.getQueriesData<IFetchFileListResult>({queryKey: [FileApiAction.FetchFileList],@@ -344,22 +348,27 @@ const areDatasetsLinked = ((file) => fileIds.includes(file.id) && file.type !== 'folder',);if (verifiableFiles.length === 0) return true;- return verifiableFiles.every((file) =>- kbIds.every((kbId) => file.kbs_info?.some((kb) => kb.kb_id === kbId)),- );+ return verifiableFiles.every((file) => {+ const linkedIds = (file.kbs_info ?? []).map((kb) => kb.kb_id);+ return (+ kbIds.every((kbId) => linkedIds.includes(kbId)) &&+ (mode === 'add' || linkedIds.length === kbIds.length)+ );+ });};// Both backends respond to link-to-datasets before the file↔dataset mappings// are written (the conversion runs in the background), so the refetch right-// after success can still see stale kbs_info. Poll until the newly linked-// datasets show up in the list data; give up after a bounded window.+// after success can still see stale kbs_info. Poll until the change shows up in+// the list data; give up after a bounded window.const waitUntilDatasetsLinked = async (queryClient: QueryClient,fileIds: string[],kbIds: string[],+ mode: ConnectFileToKnowledgeMode,) => {for (let attempt = 0; attempt < LinkedDatasetsPollMaxAttempts; attempt++) {- if (areDatasetsLinked(queryClient, fileIds, kbIds)) return;+ if (areDatasetsLinked(queryClient, fileIds, kbIds, mode)) return;await new Promise((resolve) =>setTimeout(resolve, LinkedDatasetsPollIntervalMs),);@@ -398,6 +407,7 @@ export const useConnectToKnowledge = () => {queryClient,params.fileIds,params.kbIds,+ params.mode,);}return data.code;