Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(dataset): poll ingestion log while parsing and stop after terminal (#20206)

chanxc51e414e807f
diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.ts
index c7f5032c1f..d229097b50 100644
--- a/web/src/hooks/use-document-request.ts
+++ b/web/src/hooks/use-document-request.ts
@@ -328,9 +328,16 @@ export const useFetchDocumentList = (loop = true) => {
};
};
+type RefetchInterval =
+ | number
+ | false
+ | ((query: {
+ state: { data?: { docs: IDocumentInfo[]; total: number } };
+ }) => number | false);
+
export const useFetchDocumentsByIds = (
ids: string[],
- options?: { enabled?: boolean; refetchInterval?: number | false },
+ options?: { enabled?: boolean; refetchInterval?: RefetchInterval },
) => {
const { id: datasetId } = useParams();
const { enabled, refetchInterval } = options ?? {};
diff --git a/web/src/pages/dataset/dataset/hooks.ts b/web/src/pages/dataset/dataset/hooks.ts
index 598f6b6603..aecd78ca3e 100644
--- a/web/src/pages/dataset/dataset/hooks.ts
+++ b/web/src/pages/dataset/dataset/hooks.ts
@@ -6,6 +6,7 @@ import { useIsGoBackend } from '@/utils/backend-variant';
import { formatDate, formatSecondsToHumanReadable } from '@/utils/date';
import { formatBytes } from '@/utils/file-util';
import { useQuery } from '@tanstack/react-query';
+import { RunningStatus } from '@/constants/knowledge';
import { useCallback, useMemo, useState } from 'react';
import { useParams } from 'react-router';
import { listDataPipelineLogDocument } from '@/services/knowledge-service';
@@ -29,13 +30,32 @@ export const useShowLog = (documents: IDocumentInfo[]) => {
const datasetId = knowledgeId || routeId;
const isGoBackend = useIsGoBackend();
+ const isTerminal = (doc?: IDocumentInfo) => {
+ const status = doc && getDocumentRunningStatus(doc);
+ return (
+ status === RunningStatus.DONE ||
+ status === RunningStatus.FAIL ||
+ status === RunningStatus.CANCEL
+ );
+ };
+
// When the modal is visible, poll the document directly by ID so progress_msg
// updates (e.g. "Indexing done") are captured even if the parent list no longer
// polls (isLoop became false before the final message) or the record fell off
- // the current paginated page.
+ // the current paginated page. Stop polling once the run reaches a terminal
+ // status, otherwise the modal keeps requesting forever.
const { documents: liveDocs } = useFetchDocumentsByIds(
record?.id ? [record.id] : [],
- { enabled: visible, refetchInterval: PollIntervalMs },
+ {
+ enabled: visible,
+ refetchInterval: (query) => {
+ const doc =
+ query.state.data?.docs[0] ??
+ documents.find((item: IDocumentInfo) => item.id === record?.id) ??
+ record;
+ return isTerminal(doc) ? false : PollIntervalMs;
+ },
+ },
);
const liveDoc = liveDocs?.[0];
const sourceDoc =
@@ -48,7 +68,7 @@ export const useShowLog = (documents: IDocumentInfo[]) => {
const { data: documentLog } = useQuery<IFileLogList>({
queryKey: DocumentLogKeys.queued(datasetId, sourceDoc?.id),
enabled: visible && isGoBackend && !!datasetId && !!sourceDoc?.id,
- refetchInterval: PollIntervalMs,
+ refetchInterval: isTerminal(sourceDoc) ? false : PollIntervalMs,
queryFn: async () => {
const { data: res = {} } = await listDataPipelineLogDocument(
datasetId || '',
diff --git a/web/src/pages/dataset/ingestion-message-hooks.ts b/web/src/pages/dataset/ingestion-message-hooks.ts
index f325b9a20b..5865cc71a2 100644
--- a/web/src/pages/dataset/ingestion-message-hooks.ts
+++ b/web/src/pages/dataset/ingestion-message-hooks.ts
@@ -10,6 +10,11 @@ import { useEffect, useRef, useState } from 'react';
const PollIntervalMs = 5000;
+// Module-level constant: an inline default object would get a new identity on
+// every render and, being a polling-effect dependency, would reset the
+// interval before it ever fires.
+const DefaultParams: IngestionMessageParams = { limit: 200 };
+
export const IngestionMessageKeys = {
messages: (datasetId: string | undefined, logId: string | undefined) =>
['ingestionMessages', datasetId, logId] as const,
@@ -19,7 +24,7 @@ export const useIngestionMessages = (
datasetId: string | undefined,
logId: string | undefined,
enabled: boolean,
- params: IngestionMessageParams = { limit: 200 },
+ params: IngestionMessageParams = DefaultParams,
) => {
const queryClient = useQueryClient();
const isGoBackend = useIsGoBackend();