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: Deleting a pipeline bound to a dataset should not trigger an error when navigating to the file list page of a different dataset. (#21985)
balibabu7a3f8c262e28
diff --git a/web/src/hooks/__tests__/use-document-request-query-keys.test.ts b/web/src/hooks/__tests__/use-document-request-query-keys.test.tsindex 40a756c25f..7f42c251b9 100644--- a/web/src/hooks/__tests__/use-document-request-query-keys.test.ts+++ b/web/src/hooks/__tests__/use-document-request-query-keys.test.ts@@ -20,6 +20,7 @@ import { DocumentKeys } from '../document-query-keys';describe('DocumentKeys', () => {it('matches parameterized document lists with the list prefix', () => {const actual = DocumentKeys.list(+ 'dataset-id','keyword',{ current: 1, pageSize: 30 },{ run: ['1'] },@@ -28,6 +29,18 @@ describe('DocumentKeys', () => {expect(partialMatchKey(actual, DocumentKeys.all())).toBe(true);});+ it('scopes document lists to the dataset id', () => {+ const shared = [+ 'keyword',+ { current: 1, pageSize: 30 },+ { run: ['1'] },+ ] as const;+ const datasetA = DocumentKeys.list('dataset-a', ...shared);+ const datasetB = DocumentKeys.list('dataset-b', ...shared);++ expect(partialMatchKey(datasetA, datasetB)).toBe(false);+ });+it('matches parameterized document filters with the filter prefix', () => {const actual = DocumentKeys.filter('keyword', 'dataset-id');diff --git a/web/src/hooks/document-query-keys.ts b/web/src/hooks/document-query-keys.tsindex 927155ab8d..4b28a59af0 100644--- a/web/src/hooks/document-query-keys.ts+++ b/web/src/hooks/document-query-keys.ts@@ -31,8 +31,22 @@ export const enum DocumentApiAction {export const DocumentKeys = {all: () => [DocumentApiAction.FetchDocumentList] as const,- list: (searchString: string, pagination: unknown, filter: unknown) =>- [...DocumentKeys.all(), searchString, pagination, filter] as const,+ // The dataset id scopes the list: without it two datasets with the same+ // search/pagination/filter share one cache entry, and entering dataset B+ // briefly renders dataset A's documents (firing their per-row requests).+ list: (+ knowledgeId: string | undefined,+ searchString: string,+ pagination: unknown,+ filter: unknown,+ ) =>+ [+ ...DocumentKeys.all(),+ knowledgeId,+ searchString,+ pagination,+ filter,+ ] as const,allFilters: () => [DocumentApiAction.FetchDocumentFilter] as const,filter: (searchString: string, knowledgeId?: string) =>[...DocumentKeys.allFilters(), searchString, knowledgeId] as const,diff --git a/web/src/hooks/use-agent-request.ts b/web/src/hooks/use-agent-request.tsindex dc1385cf54..abe44382a8 100644--- a/web/src/hooks/use-agent-request.ts+++ b/web/src/hooks/use-agent-request.ts@@ -799,6 +799,18 @@ export interface ICanvasVersionRow {alias?: string;}+// Query options shared by useFetchCanvasVersionList and imperative callers+// (queryClient.fetchQuery), so both hit the same cache entry.+export const canvasVersionListQuery = (canvasId?: string) =>+ ({+ queryKey: AgentKeys.canvasVersionList(canvasId),+ queryFn: async (): Promise<ICanvasVersionRow[]> => {+ if (!canvasId) return [];+ const { data } = await agentService.fetchVersionList(canvasId);+ return data?.data ?? [];+ },+ }) as const;+// Lists versions for document status displays. Parser selection uses the// lightweight catalog instead. No initialData so pending and empty differ.export const useFetchCanvasVersionList = (canvasId?: string) => {@@ -807,14 +819,9 @@ export const useFetchCanvasVersionList = (canvasId?: string) => {isFetching: loading,isError,} = useQuery({- queryKey: AgentKeys.canvasVersionList(canvasId),+ ...canvasVersionListQuery(canvasId),gcTime: 0,enabled: !!canvasId,- queryFn: async (): Promise<ICanvasVersionRow[]> => {- if (!canvasId) return [];- const { data } = await agentService.fetchVersionList(canvasId);- return data?.data ?? [];- },});return { data, loading, isError };diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.tsindex 8c046b744e..97b7442e61 100644--- a/web/src/hooks/use-document-request.ts+++ b/web/src/hooks/use-document-request.ts@@ -207,7 +207,12 @@ export const useFetchDocumentList = (loop = true) => {total: number;has_active_tasks?: boolean;}>({- queryKey: DocumentKeys.list(debouncedSearchString, pagination, filterValue),+ queryKey: DocumentKeys.list(+ knowledgeId || id,+ debouncedSearchString,+ pagination,+ filterValue,+ ),initialData: { docs: [], total: 0, has_active_tasks: false },refetchInterval: (query) => {if (!loop) return false;diff --git a/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.test.ts b/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.test.tsdeleted file mode 100644index 6d3e5c519a..0000000000--- a/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.test.ts+++ /dev/null@@ -1,80 +0,0 @@-import { renderHook } from '@testing-library/react';--const mockUseFetchCanvasVersionList = jest.fn();--jest.mock('@/hooks/use-agent-request', () => ({- useFetchCanvasVersionList: (canvasId?: string) =>- mockUseFetchCanvasVersionList(canvasId),-}));--import { useDatasetPipelineMissing } from './use-dataset-pipeline-missing';--const versions = [{ id: 'v1', title: 'newest', created_at: '2026-10-29' }];--describe('useDatasetPipelineMissing', () => {- beforeEach(() => {- mockUseFetchCanvasVersionList.mockReset();- // Mirrors useFetchCanvasVersionList: a disabled query (no canvas id)- // never produces data.- mockUseFetchCanvasVersionList.mockImplementation((canvasId?: string) => ({- data: canvasId ? versions : undefined,- loading: false,- isError: false,- }));- });-- it('stays quiet before the dataset configuration has loaded', () => {- const { result } = renderHook(() => useDatasetPipelineMissing(undefined));-- expect(mockUseFetchCanvasVersionList).toHaveBeenCalledWith(undefined);- expect(result.current).toBe(false);- });-- it('stays disabled for built-in parser datasets', () => {- const { result } = renderHook(() => useDatasetPipelineMissing(''));-- expect(mockUseFetchCanvasVersionList).toHaveBeenCalledWith('');- expect(result.current).toBe(false);- });-- it('stays quiet while the version list is in flight', () => {- mockUseFetchCanvasVersionList.mockReturnValue({- data: undefined,- loading: true,- isError: false,- });- const { result } = renderHook(() => useDatasetPipelineMissing('canvas-1'));-- expect(result.current).toBe(false);- });-- it('flags a pipeline whose version list failed to load (deleted pipeline)', () => {- mockUseFetchCanvasVersionList.mockReturnValue({- data: undefined,- loading: false,- isError: true,- });- const { result } = renderHook(() =>- useDatasetPipelineMissing('deleted-canvas'),- );-- expect(result.current).toBe(true);- });-- it('flags a pipeline with no published versions left', () => {- mockUseFetchCanvasVersionList.mockReturnValue({- data: [],- loading: false,- isError: false,- });- const { result } = renderHook(() => useDatasetPipelineMissing('canvas-1'));-- expect(result.current).toBe(true);- });-- it('stays available while any published version exists', () => {- const { result } = renderHook(() => useDatasetPipelineMissing('canvas-1'));-- expect(result.current).toBe(false);- });-});diff --git a/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.ts b/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.tsdeleted file mode 100644index e0ccc2b066..0000000000--- a/web/src/pages/dataset/dataset/use-dataset-pipeline-missing.ts+++ /dev/null@@ -1,22 +0,0 @@-import { useFetchCanvasVersionList } from '@/hooks/use-agent-request';--// Flags a dataset whose configured pipeline can no longer parse: the version-// list failed to load (the pipeline was deleted or is no longer visible), or-// it loaded empty (no published versions left). Unlike the document-level-// hook there is no pinned version here — any published version keeps the-// dataset parseable. While the list is in flight (or the query is disabled-// because the dataset has not loaded yet) the verdict stays false so the-// upload dialog never warns spuriously.-export const useDatasetPipelineMissing = (pipelineId?: string) => {- const {- data: versions,- loading,- isError,- } = useFetchCanvasVersionList(pipelineId);-- const missing =- !!pipelineId &&- (isError || (!loading && !!versions && versions.length === 0));-- return missing;-};diff --git a/web/src/pages/dataset/dataset/use-upload-document.test.ts b/web/src/pages/dataset/dataset/use-upload-document.test.tsindex a93406079b..3649514e9e 100644--- a/web/src/pages/dataset/dataset/use-upload-document.test.ts+++ b/web/src/pages/dataset/dataset/use-upload-document.test.ts@@ -14,6 +14,7 @@ type Doc = {const mockUpload = jest.fn();const mockRun = jest.fn();const mockWarning = jest.fn();+const mockFetchQuery = jest.fn();// Per-test gap fixtures: pre-upload gaps by file name, and post-upload// document gaps keyed by document name. The real gap detection is covered by@@ -21,13 +22,21 @@ const mockWarning = jest.fn();// which documents the hook auto-parses.let mockUploadGaps: Array<Record<string, unknown>> = [];let mockDocumentGaps: Record<string, Array<Record<string, unknown>>> = {};-let mockPipelineMissing = false;// The warning mock auto-confirms by default so the pre-existing gap tests// keep flowing into the upload; cancellation tests flip this off.let mockAutoConfirmWarning = true;-jest.mock('./use-dataset-pipeline-missing', () => ({- useDatasetPipelineMissing: () => mockPipelineMissing,+// The pipeline-missing check runs imperatively at submit time through+// queryClient.fetchQuery, so the suite stubs the client plus the query+// options factory instead of rendering a provider.+jest.mock('@/hooks/use-agent-request', () => ({+ canvasVersionListQuery: (canvasId: string) => ({+ queryKey: ['canvasVersionList', canvasId],+ }),+}));++jest.mock('@tanstack/react-query', () => ({+ useQueryClient: () => ({ fetchQuery: mockFetchQuery }),}));jest.mock('@/hooks/use-document-request', () => ({@@ -73,9 +82,10 @@ beforeEach(() => {jest.clearAllMocks();mockUploadGaps = [];mockDocumentGaps = {};- mockPipelineMissing = false;mockAutoConfirmWarning = true;mockUpload.mockResolvedValue(uploadOkResponse([makeDoc()]));+ // Default to a live pipeline: the version list resolves non-empty.+ mockFetchQuery.mockResolvedValue([{ id: 'version-1' }]);});// The regression case for the auto-parse bug: an unsupported file type (here@@ -235,7 +245,7 @@ it('auto-parses every document on the no-gap path without a warning modal', asyn// silently parse nothing, so the hook confirms first and drops the auto-parse// on "Continue upload".it('warns and uploads without parsing when the dataset pipeline is missing', async () => {- mockPipelineMissing = true;+ mockFetchQuery.mockResolvedValue([]);const { result } = renderHook(() => useHandleUploadDocument('canvas-1'));await act(async () => {@@ -259,8 +269,32 @@ it('warns and uploads without parsing when the dataset pipeline is missing', asyexpect(mockRun).not.toHaveBeenCalled();});+it('warns when the version list request fails', async () => {+ mockFetchQuery.mockRejectedValue(new Error('request failed'));++ const { result } = renderHook(() => useHandleUploadDocument('canvas-1'));+ await act(async () => {+ await result.current.onDocumentUploadOk({+ fileList: [new File(['x'], 'a.pdf')],+ parseOnCreation: true,+ });+ });++ expect(mockWarning).toHaveBeenCalledTimes(1);+ expect(mockWarning).toHaveBeenCalledWith(+ expect.objectContaining({+ title: 'knowledgeDetails.uploadPipelineDeletedTitle',+ }),+ );+ await waitFor(() => expect(mockUpload).toHaveBeenCalledTimes(1));+ await act(async () => {+ await Promise.resolve();+ });+ expect(mockRun).not.toHaveBeenCalled();+});+it('uploads without a warning when parse-on-creation is off even if the pipeline is missing', async () => {- mockPipelineMissing = true;+ mockFetchQuery.mockResolvedValue([]);const { result } = renderHook(() => useHandleUploadDocument('canvas-1'));await act(async () => {@@ -275,7 +309,7 @@ it('uploads without a warning when parse-on-creation is off even if the pipeline});it('chains the gap warning after the pipeline warning, then uploads without parsing', async () => {- mockPipelineMissing = true;+ mockFetchQuery.mockResolvedValue([]);mockUploadGaps = [{ reason: 'unsupportedType', name: 'deck.pptx', fileType: 'PowerPoint' },];@@ -306,7 +340,7 @@ it('chains the gap warning after the pipeline warning, then uploads without pars});it('does not upload when the pipeline warning is cancelled', async () => {- mockPipelineMissing = true;+ mockFetchQuery.mockResolvedValue([]);mockAutoConfirmWarning = false;const { result } = renderHook(() => useHandleUploadDocument('canvas-1'));diff --git a/web/src/pages/dataset/dataset/use-upload-document.ts b/web/src/pages/dataset/dataset/use-upload-document.tsindex 78f7e7f72d..ed8f6b3914 100644--- a/web/src/pages/dataset/dataset/use-upload-document.ts+++ b/web/src/pages/dataset/dataset/use-upload-document.ts@@ -1,16 +1,17 @@import { UploadFormSchemaType } from '@/components/file-upload-dialog';import { Modal } from '@/components/ui/modal/modal';import { useSetModalState } from '@/hooks/common-hooks';+import { canvasVersionListQuery } from '@/hooks/use-agent-request';import {useRunDocument,useUploadDocument,} from '@/hooks/use-document-request';import { IDocumentInfo } from '@/interfaces/database/document';import { getUnSupportedFilesCount } from '@/utils/document-util';+import { useQueryClient } from '@tanstack/react-query';import { useCallback } from 'react';import { useTranslation } from 'react-i18next';import { buildUploadGapModalContent } from './parser-gap-content';-import { useDatasetPipelineMissing } from './use-dataset-pipeline-missing';import { useParserGapValidation } from './use-parser-gap-validation';import { hasUnsupportedTypeGap } from './utils';@@ -24,7 +25,25 @@ export const useHandleUploadDocument = (pipelineId?: string) => {const { uploadDocument, loading } = useUploadDocument();const { runDocumentByIds } = useRunDocument();const { findParseGaps, findDocumentParseGaps } = useParserGapValidation();- const pipelineMissing = useDatasetPipelineMissing(pipelineId);+ const queryClient = useQueryClient();++ // The dataset's version list only feeds the parse-on-creation warning, so+ // fetch it at submit time instead of on page entry — a dataset whose bound+ // pipeline was deleted should not raise the request (and the global error+ // notification) every time the file list opens. A fetch failure or an empty+ // list means the pipeline can no longer parse.+ const checkPipelineMissing = useCallback(async (): Promise<boolean> => {+ if (!pipelineId) return false;+ try {+ const versions = await queryClient.fetchQuery({+ ...canvasVersionListQuery(pipelineId),+ staleTime: 60_000,+ });+ return versions.length === 0;+ } catch {+ return true;+ }+ }, [pipelineId, queryClient]);const proceedUpload = useCallback(async ({@@ -143,7 +162,7 @@ export const useHandleUploadDocument = (pipelineId?: string) => {// would silently do nothing. Confirm first; on "Continue upload" the// parsing is dropped. The gap check still runs because the backend// reseeds parser configs at upload regardless.- if (values.parseOnCreation && pipelineMissing) {+ if (values.parseOnCreation && (await checkPipelineMissing())) {Modal.warning({title: t('knowledgeDetails.uploadPipelineDeletedTitle'),content: t('knowledgeDetails.uploadPipelineDeletedContent'),@@ -159,7 +178,7 @@ export const useHandleUploadDocument = (pipelineId?: string) => {return validateGapsAndUpload(values);},- [pipelineMissing, validateGapsAndUpload, t],+ [checkPipelineMissing, validateGapsAndUpload, t],);return {