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(web): adapt document parsing state for Go ingestion_status (depends on #19533) (#19587)
chanx49efa265fdbb
diff --git a/web/src/constants/knowledge.ts b/web/src/constants/knowledge.tsindex 90f57c5594..227e2b89cf 100644--- a/web/src/constants/knowledge.ts+++ b/web/src/constants/knowledge.ts@@ -45,6 +45,8 @@ export enum RunningStatusOld {}export enum IngestionTaskStatus {+ // Go backend only: no ingestion task exists yet (e.g. freshly uploaded).+ UNSTART = 'UNSTART',CREATED = 'CREATED',SCHEDULED = 'SCHEDULED',RUNNING = 'RUNNING',diff --git a/web/src/hooks/use-document-request.ts b/web/src/hooks/use-document-request.tsindex fff36de160..21ddd73368 100644--- a/web/src/hooks/use-document-request.ts+++ b/web/src/hooks/use-document-request.ts@@ -17,7 +17,7 @@import { useHandleFilterSubmit } from '@/components/list-filter-bar/use-handle-filter-submit';import message from '@/components/ui/message';-import { RunningStatus } from '@/constants/knowledge';+import { IngestionTaskStatus, RunningStatus } from '@/constants/knowledge';import { ResponseType } from '@/interfaces/database/base';import { IReferenceChunk } from '@/interfaces/database/chat';import { IChunk } from '@/interfaces/database/dataset';@@ -48,6 +48,7 @@ import kbService, {uploadDocument,} from '@/services/knowledge-service';import { restAPIv1 } from '@/utils/api';+import { useIsGoBackend } from '@/utils/backend-variant';import { buildChunkHighlights } from '@/utils/document-util';import {keepPreviousData,@@ -388,6 +389,7 @@ export const useSetDocumentStatus = () => {// This hook is used to run a document by its IDsexport const useRunDocument = () => {const queryClient = useQueryClient();+ const isGo = useIsGoBackend();const {data,@@ -404,6 +406,12 @@ export const useRunDocument = () => {run: number;option?: { delete: boolean; apply_kb: boolean };}) => {+ // Optimistically move started documents into an active state so the+ // 5s list polling starts immediately and the row leaves its idle+ // action. Python drives the worker through the legacy run field+ // (RUNNING); Go has no run field and reports the task lifecycle via+ // ingestion_status, so CREATED renders as QUEUED until the next poll+ // observes the real status (SCHEDULED/RUNNING/COMPLETED/...).if (run === 1) {const documentIdSet = new Set(documentIds);queryClient.setQueriesData<{@@ -419,7 +427,9 @@ export const useRunDocument = () => {documentIdSet.has(doc.id)? {...doc,- run: RunningStatus.RUNNING,+ ...(isGo+ ? { ingestion_status: IngestionTaskStatus.CREATED }+ : { run: RunningStatus.RUNNING }),progress: 0,process_duration: 0,process_begin_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),diff --git a/web/src/interfaces/database/dataset.ts b/web/src/interfaces/database/dataset.tsindex f9468c0ed3..c5772dc837 100644--- a/web/src/interfaces/database/dataset.ts+++ b/web/src/interfaces/database/dataset.ts@@ -1,7 +1,7 @@// for the dataset list// The data structures returned by the `datasets` interface and `/api/v1/datasets/{id}` are inconsistent.-import { RunningStatus } from '@/constants/knowledge';+import { IngestionTaskStatus, RunningStatus } from '@/constants/knowledge';import { DataSourceKey } from '@/pages/user-setting/data-source/constant';export interface IConnector {@@ -133,7 +133,10 @@ export interface IKnowledgeFile {process_duration: number;progress: number; // parsing processprogress_msg: string; // parsing log- run: RunningStatus; // parsing status+ // Python backend only. The Go backend removed this field and reports+ // parsing state exclusively through ingestion_status.+ run?: RunningStatus; // parsing status+ ingestion_status?: IngestionTaskStatus;size: number;source_type: string;status: string; // enableddiff --git a/web/src/interfaces/database/document.ts b/web/src/interfaces/database/document.tsindex c1fc05f0ab..16eed6b277 100644--- a/web/src/interfaces/database/document.ts+++ b/web/src/interfaces/database/document.ts@@ -18,7 +18,9 @@ export interface IDocumentInfo {process_duration: number;progress: number;progress_msg: string;- run: RunningStatus;+ // Python backend only. The Go backend removed this field and reports+ // parsing state exclusively through ingestion_status.+ run?: RunningStatus;ingestion_status?: IngestionTaskStatus;size: number;source_type: string;diff --git a/web/src/pages/dataset/dataset/constant.ts b/web/src/pages/dataset/dataset/constant.tsindex b4df261000..96bebd79b3 100644--- a/web/src/pages/dataset/dataset/constant.ts+++ b/web/src/pages/dataset/dataset/constant.ts@@ -18,6 +18,16 @@ export const RunningStatusMap = {color: 'rgba(var(--state-success))',},[RunningStatus.FAIL]: { label: 'FAIL', color: 'rgba(var(--state-error))' },+ // Legacy scheduled state; rendered like the Go queued state.+ [RunningStatus.SCHEDULE]: {+ label: 'SCHEDULE',+ color: 'rgba(var(--state-warning))',+ },+ // Go ingestion only: task enqueued but not started (CREATED/SCHEDULED).+ [RunningStatus.QUEUED]: {+ label: 'QUEUED',+ color: 'rgba(var(--state-warning))',+ },};export * from '@/constants/knowledge';diff --git a/web/src/pages/dataset/dataset/hooks.ts b/web/src/pages/dataset/dataset/hooks.tsindex feb3db5ccd..d0b5866599 100644--- a/web/src/pages/dataset/dataset/hooks.ts+++ b/web/src/pages/dataset/dataset/hooks.ts@@ -1,13 +1,11 @@import { useSetModalState } from '@/hooks/common-hooks';+import { useFetchDocumentsByIds } from '@/hooks/use-document-request';import { IDocumentInfo } from '@/interfaces/database/document';-import { pickByBackend } from '@/utils/backend-variant';import { formatDate, formatSecondsToHumanReadable } from '@/utils/date';import { formatBytes } from '@/utils/file-util';import { useCallback, useMemo, useState } from 'react';import { ILogInfo } from '../process-log-modal';-import { RunningStatus } from './constant';-import { useFetchDocumentsByIds } from '@/hooks/use-document-request';-import { isDocumentQueued } from './utils';+import { getDocumentRunningStatus } from './utils';const PollIntervalMs = 5000;@@ -45,14 +43,9 @@ export const useShowLog = (documents: IDocumentInfo[]) => {processBeginAt: formatDate(source.process_begin_at),chunkNumber: source.chunk_count,duration: formatSecondsToHumanReadable(source.process_duration || 0),- status: pickByBackend({- // The Go backend reports a queued document via ingestion_status- // while the legacy run field stays UNSTART; surface it as QUEUED.- go: isDocumentQueued(source)- ? RunningStatus.QUEUED- : (source.run as RunningStatus),- python: source.run as RunningStatus,- }),+ // Go derives status from ingestion_status (queued included);+ // Python reads the legacy run field.+ status: getDocumentRunningStatus(source),details: source.progress_msg,};}diff --git a/web/src/pages/dataset/dataset/parsing-card.tsx b/web/src/pages/dataset/dataset/parsing-card.tsxindex 0a75b33ef5..b0902e62c4 100644--- a/web/src/pages/dataset/dataset/parsing-card.tsx+++ b/web/src/pages/dataset/dataset/parsing-card.tsx@@ -3,6 +3,7 @@ import { IDocumentInfo } from '@/interfaces/database/document';import { useTranslation } from 'react-i18next';import reactStringReplace from 'react-string-replace';import { RunningStatus, RunningStatusMap } from './constant';+import { getDocumentRunningStatus } from './utils';interface IProps {record: IDocumentInfo;@@ -21,7 +22,9 @@ function Dot({ run }: { run: RunningStatus }) {export const PopoverContent = ({ record }: IProps) => {const { t } = useTranslation();- const label = t(`knowledgeDetails.runningStatus${record.run}`);+ // Go derives state from ingestion_status; Python reads the legacy run.+ const run = getDocumentRunningStatus(record);+ const label = t(`knowledgeDetails.runningStatus${run}`);const replaceText = (text: string) => {// Remove duplicate \n@@ -63,7 +66,7 @@ export const PopoverContent = ({ record }: IProps) => {return (<section><div className="flex gap-2 items-center pb-2">- <Dot run={record.run}></Dot> {label}+ <Dot run={run}></Dot> {label}</div><div className="flex flex-col max-h-[50vh] overflow-auto">{items.map((x, idx) => {@@ -82,13 +85,14 @@ export const PopoverContent = ({ record }: IProps) => {};export function ParsingCard({ record, handleShowLog }: IProps) {+ const run = getDocumentRunningStatus(record);return (<Buttonvariant="ghost"size="icon-xs"onClick={() => handleShowLog?.(record)}>- <Dot run={record.run}></Dot>+ <Dot run={run}></Dot></Button>);}diff --git a/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx b/web/src/pages/dataset/dataset/parsing-status-cell.test.tsxindex f3ab0182b6..79a5146a77 100644--- a/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx+++ b/web/src/pages/dataset/dataset/parsing-status-cell.test.tsx@@ -21,6 +21,15 @@ jest.mock('./use-run-document', () => ({}),}));+// Drive both the useIsGoBackend hook and the pickByBackend payload/status+// adapters from a single mutable flag.+let mockIsGoBackend = false;+jest.mock('@/utils/backend-variant', () => ({+ useIsGoBackend: () => mockIsGoBackend,+ pickByBackend: ({ go, python }: { go: unknown; python: unknown }) =>+ mockIsGoBackend ? go : python,+}));+import { IngestionTaskStatus, RunningStatus } from './constant';import { ParsingStatusCell } from './parsing-status-cell';@@ -30,7 +39,6 @@ const baseRecord = {name: 'doc.pdf',type: 'document',run: RunningStatus.UNSTART,- ingestion_status: IngestionTaskStatus.RUNNING,progress: 0,chunk_count: 0,parser_config: {},@@ -54,10 +62,11 @@ const baseRecord = {chunk_method: 'naive',};-function renderCell(overrides: Record<string, any>) {+function renderCell(overrides: Record<string, any> = {}) {+ const record = { ...baseRecord, ...overrides } as any;return render(React.createElement(ParsingStatusCell, {- record: { ...baseRecord, ...overrides } as any,+ record,showLog: jest.fn(),showChangeParserModal: jest.fn(),}),@@ -65,34 +74,146 @@ function renderCell(overrides: Record<string, any>) {);}+function getSection(container: HTMLElement) {+ return container.querySelector(+ '[data-testid="document-parse-status"]',+ ) as HTMLElement;+}++// IconFontFill renders <use xlink:href="#icon-<name>"/>; jsdom keeps the+// namespaced attribute, so read it instead of relying on a CSS selector.+function hasIconFont(container: HTMLElement, name: string) {+ return Array.from(container.querySelectorAll('svg use')).some((el) => {+ const href = el.getAttribute('xlink:href') ?? el.getAttribute('href') ?? '';+ return href === `#icon-${name}`;+ });+}+describe('ParsingStatusCell', () => {beforeEach(() => {mockRunDocumentByIds.mockClear();mockShowReparseDialog.mockClear();});- it('shows a cancel icon while ingestion runs before the document run state updates', () => {- const { container } = renderCell({- ingestion_status: IngestionTaskStatus.RUNNING,- });+ afterEach(() => {+ mockIsGoBackend = false;+ });++ it('shows a cancel icon while the legacy run state is RUNNING on Python', () => {+ const { container } = renderCell({ run: RunningStatus.RUNNING });expect(container.querySelector('svg.lucide-circle-x')).toBeInTheDocument();+ expect(hasIconFont(container, 'play')).toBe(false);+ // Python never reports STOPPING, so the loading mask must not render.expect(- container.querySelector('use[href="#icon-play"]'),+ screen.queryByTestId('document-stopping-overlay'),).not.toBeInTheDocument();+ expect(getSection(container)).toHaveAttribute('data-state', 'running');});- it('does not expose cancelling as a document status', () => {- const { container } = renderCell({- run: RunningStatus.RUNNING,- ingestion_status: IngestionTaskStatus.STOPPING,- });+ it('shows the play action for an idle Python document', () => {+ const { container } = renderCell({ run: RunningStatus.UNSTART });+ expect(getSection(container)).toHaveAttribute('data-state', 'unstart');+ expect(hasIconFont(container, 'play')).toBe(true);expect(- screen.queryByText('knowledgeDetails.runningStatusStopping'),+ container.querySelector('svg.lucide-circle-x'),).not.toBeInTheDocument();- expect(container.querySelector('svg.lucide-circle-x')).toBeInTheDocument();- expect(container.querySelector('button[disabled]')).toBeInTheDocument();+ });++ describe('Go backend', () => {+ beforeEach(() => {+ mockIsGoBackend = true;+ });++ it('shows the queued chip for CREATED tasks', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.CREATED,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'queued');+ expect(+ screen.getByText('knowledgeDetails.runningStatusQueued'),+ ).toBeInTheDocument();+ });++ it('shows progress and an enabled cancel button while RUNNING', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.RUNNING,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'running');+ expect(+ container.querySelector('svg.lucide-circle-x'),+ ).toBeInTheDocument();+ expect(+ container.querySelector('button[disabled]'),+ ).not.toBeInTheDocument();+ });++ it('masks the progress area with a loading overlay while STOPPING', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.STOPPING,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'stopping');++ // The underlying running row stays visible but reads as disabled:+ // dimmed, flagged as stopping and non-interactive.+ const row = screen.getByTestId('document-processing-row');+ expect(row).toHaveAttribute('data-stopping');+ expect(row).toHaveClass('opacity-50');+ expect(row).toHaveClass('pointer-events-none');++ // The overlay communicates the in-flight cancel with a plain+ // spinner (no status text) and blocks the actions beneath.+ const overlay = screen.getByTestId('document-stopping-overlay');+ expect(overlay).toBeInTheDocument();+ expect(+ screen.queryByText('knowledgeDetails.runningStatusStopping'),+ ).not.toBeInTheDocument();+ expect(overlay.querySelector('.animate-spin')).toBeInTheDocument();++ // Both the progress/log button and the cancel button are disabled.+ const buttons = container.querySelectorAll('button');+ buttons.forEach((button) => expect(button).toBeDisabled());+ });++ it('renders the success state and reparse action for COMPLETED', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.COMPLETED,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'success');+ expect(+ container.querySelector('svg.lucide-circle-x'),+ ).not.toBeInTheDocument();+ });++ it('renders the cancel state for STOPPED', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.STOPPED,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'cancel');+ });++ it('renders the play action for UNSTART without a run field', () => {+ const { container } = renderCell({+ run: undefined,+ ingestion_status: IngestionTaskStatus.UNSTART,+ });+ expect(getSection(container)).toHaveAttribute('data-state', 'unstart');+ expect(hasIconFont(container, 'play')).toBe(true);+ });++ it('treats a missing ingestion_status as idle', () => {+ const { container } = renderCell({ run: undefined });+ expect(getSection(container)).toHaveAttribute('data-state', 'unstart');+ expect(+ container.querySelector('svg.lucide-circle-x'),+ ).not.toBeInTheDocument();+ });});it('runs a chunkless document once without opening the confirmation', () => {diff --git a/web/src/pages/dataset/dataset/parsing-status-cell.tsx b/web/src/pages/dataset/dataset/parsing-status-cell.tsxindex e1efa92314..3c3eb15b80 100644--- a/web/src/pages/dataset/dataset/parsing-status-cell.tsx+++ b/web/src/pages/dataset/dataset/parsing-status-cell.tsx@@ -14,15 +14,21 @@ import {TooltipTrigger,} from '@/components/ui/tooltip';import { IDocumentInfo } from '@/interfaces/database/document';-import { CircleQuestionMark, CircleX, Clock3 } from 'lucide-react';+import { cn } from '@/lib/utils';+import { useIsGoBackend } from '@/utils/backend-variant';+import { CircleQuestionMark, CircleX, Clock3, Loader2 } from 'lucide-react';import { useCallback, useMemo } from 'react';import { useTranslation } from 'react-i18next';-import { DocumentType, IngestionTaskStatus, RunningStatus } from './constant';+import { DocumentType, RunningStatus } from './constant';import { ParsingCard } from './parsing-card';import { ReparseDialog } from './reparse-dialog';import { UseChangeDocumentParserShowType } from './use-change-document-parser';import { useHandleRunDocumentByIds } from './use-run-document';-import { isDocumentProcessing } from './utils';+import {+ getDocumentRunningStatus,+ isDocumentProcessing,+ isDocumentStopping,+} from './utils';const IconMap = {[RunningStatus.UNSTART]: (<IconFontFill name="play" className="text-accent-primary size-[1em]" />@@ -42,6 +48,11 @@ const IconMap = {[RunningStatus.SCHEDULE]: (<IconFontFill name="reparse" className="text-accent-primary" />),+ // QUEUED documents render a dedicated clock button in the processing+ // branch below; this key only keeps the icon map type-exhaustive.+ [RunningStatus.QUEUED]: (+ <IconFontFill name="play" className="text-accent-primary size-[1em]" />+ ),};const ParseStatusStateMap = {@@ -110,20 +121,23 @@ export function ParsingStatusCell({showLog: (record: IDocumentInfo) => void;} & UseChangeDocumentParserShowType) {const { t } = useTranslation();- const { run, progress, chunk_count, id } = record;- const operationIcon = IconMap[run];+ const { progress, chunk_count, id } = record;+ // Go reports state via ingestion_status (run is gone); Python keeps run.+ // Resolve one effective status for the icon, state attribute and labels.+ const effectiveRun = getDocumentRunningStatus(record);+ const operationIcon = IconMap[effectiveRun];const p = Number((progress * 100).toFixed(2));const {handleRunDocumentByIds,+ loading: isRunLoading,visible: reparseDialogVisible,showModal: showReparseDialogModal,hideModal: hideReparseDialogModal,} = useHandleRunDocumentByIds(id);+ const isGo = useIsGoBackend();const isRunning = isDocumentProcessing(record);- const isQueued =- record.ingestion_status === IngestionTaskStatus.CREATED ||- record.ingestion_status === IngestionTaskStatus.SCHEDULED;- const isStopping = record.ingestion_status === IngestionTaskStatus.STOPPING;+ const isQueued = effectiveRun === RunningStatus.QUEUED;+ const isStopping = isDocumentStopping(record);const isZeroChunk = chunk_count === 0;const handleOperationIconClick = (option?: {@@ -159,52 +173,91 @@ export function ParsingStatusCell({<sectionclassName="flex gap-8 items-center"data-testid="document-parse-status"- data-state={isQueued ? 'queued' : (ParseStatusStateMap[run] ?? 'unknown')}+ data-state={+ isQueued+ ? 'queued'+ : isStopping+ ? 'stopping'+ : (ParseStatusStateMap[effectiveRun] ?? 'unknown')+ }>{showParse && (<div className="flex items-center gap-2"><Separator orientation="vertical" className="h-[1em]" />{isRunning ? (- <>- {isQueued ? (+ <div className="relative">+ {/* While STOPPING the underlying running row stays visible+ but reads as disabled: dimmed, non-interactive, with both+ action buttons disabled. The scrim on top carries the+ spinner. */}+ <div+ data-testid="document-processing-row"+ data-stopping={isStopping || undefined}+ className={cn(+ 'flex items-center gap-2',+ isStopping && 'pointer-events-none opacity-50',+ )}+ >+ {isQueued ? (+ <Button+ size="auto"+ variant="static"+ disabled={isStopping}+ onClick={() => handleShowLog(record)}+ >+ <Clock3 className="size-[1em]" />+ {t('knowledgeDetails.runningStatusQueued')}+ </Button>+ ) : (+ <Button+ size="auto"+ variant="static"+ disabled={isStopping}+ onClick={() => handleShowLog(record)}+ >+ <Progress value={p} className="h-1 flex-1 min-w-10" />+ <div className="flex items-center gap-1">+ {p}%+ <span className="inline-flex items-center">+ <CircleQuestionMark className="size-[1em]" />+ </span>+ </div>+ </Button>+ )}+<Button- size="auto"- variant="static"- onClick={() => handleShowLog(record)}+ variant="ghost"+ size="icon-xs"+ disabled={isStopping}+ onClick={handleParseClick}+ data-testid="document-parse-toggle">- <Clock3 className="size-[1em]" />- {t('knowledgeDetails.runningStatusQueued')}+ <CircleX+ color="rgba(var(--state-error))"+ className="size-[1em]"+ /></Button>- ) : (- <Button- size="auto"- variant="static"- onClick={() => handleShowLog(record)}+ </div>++ {/* Go only: STOPPING means a cancel request is in flight but+ the worker has not reached a terminal state yet. The+ translucent scrim keeps the dimmed running row visible+ while the spinner marks the in-flight cancel, until the+ next poll observes STOPPED/FAILED. */}+ {isStopping && (+ <div+ data-testid="document-stopping-overlay"+ className="absolute inset-0 z-10 flex items-center justify-center rounded bg-bg-card/60">- <Progress value={p} className="h-1 flex-1 min-w-10" />- <div className="flex items-center gap-1">- {p}%- <span className="inline-flex items-center">- <CircleQuestionMark className="size-[1em]" />- </span>- </div>- </Button>+ <Loader2 className="size-[1em] animate-spin text-text-disabled" />+ </div>)}-- <Button- variant="ghost"- size="icon-xs"- disabled={isStopping}- onClick={handleParseClick}- data-testid="document-parse-toggle"- >- <CircleX- color="rgba(var(--state-error))"- className="size-[1em]"- />- </Button>- </>+ </div>+ ) : isGo && isRunLoading ? (+ <Button size="auto" variant="static" disabled>+ <Loader2 className="size-[1em] animate-spin" />+ </Button>) : (<><Buttondiff --git a/web/src/pages/dataset/dataset/utils.test.ts b/web/src/pages/dataset/dataset/utils.test.tsindex 5ba5866c1c..0f9dba7bcf 100644--- a/web/src/pages/dataset/dataset/utils.test.ts+++ b/web/src/pages/dataset/dataset/utils.test.ts@@ -1,39 +1,162 @@-import { IDataset } from '@/interfaces/database/dataset';import { FileType, initialParserValues } from '@/pages/agent/constant/pipeline';import { IngestionTaskStatus, RunningStatus } from './constant';import {findFilesMissingParserModels,findMissingParserModel,+ getDocumentRunningStatus,getEffectiveParserSetups,getFileTypeByExtension,+ ingestionStatusToRunningStatus,isDocumentProcessing,+ isDocumentStopping,} from './utils';-describe('isDocumentProcessing', () => {- it('treats a scheduled ingestion task as processing before parsing starts', () => {+// Dispatch on the mutable flag so each scenario can exercise either the+// Go or the Python branch without mounting React.+let mockIsGoBackend = false;+jest.mock('@/utils/backend-variant', () => ({+ pickByBackend: ({ go, python }: { go: unknown; python: unknown }) =>+ mockIsGoBackend ? go : python,+}));++describe('isDocumentStopping', () => {+ it('is true only for the Go STOPPING status', () => {expect(- isDocumentProcessing({- run: RunningStatus.UNSTART,- ingestion_status: IngestionTaskStatus.SCHEDULED,- }),+ isDocumentStopping({ ingestion_status: IngestionTaskStatus.STOPPING }),).toBe(true);+ expect(+ isDocumentStopping({ ingestion_status: IngestionTaskStatus.RUNNING }),+ ).toBe(false);+ expect(isDocumentStopping({ ingestion_status: undefined })).toBe(false);});+});- it.each([- IngestionTaskStatus.CREATED,- IngestionTaskStatus.RUNNING,- IngestionTaskStatus.STOPPING,- ])(- 'treats an active %s ingestion task as processing before document state sync',- (ingestionStatus) => {+describe('isDocumentProcessing', () => {+ afterEach(() => {+ mockIsGoBackend = false;+ });++ describe('Go backend', () => {+ beforeEach(() => {+ mockIsGoBackend = true;+ });++ it.each([+ IngestionTaskStatus.CREATED,+ IngestionTaskStatus.SCHEDULED,+ IngestionTaskStatus.RUNNING,+ IngestionTaskStatus.STOPPING,+ ])('treats active ingestion_status %s as processing', (status) => {+ expect(isDocumentProcessing({ ingestion_status: status })).toBe(true);+ });++ it.each([+ IngestionTaskStatus.UNSTART,+ IngestionTaskStatus.COMPLETED,+ IngestionTaskStatus.FAILED,+ IngestionTaskStatus.STOPPED,+ undefined,+ ])(+ 'treats idle/terminal ingestion_status %s as not processing',+ (status) => {+ expect(isDocumentProcessing({ ingestion_status: status })).toBe(false);+ },+ );++ it('ignores a stale legacy run field on Go responses', () => {+ expect(+ isDocumentProcessing({+ run: RunningStatus.RUNNING,+ ingestion_status: IngestionTaskStatus.COMPLETED,+ }),+ ).toBe(false);+ });+ });++ describe('Python backend', () => {+ beforeEach(() => {+ mockIsGoBackend = false;+ });++ it('treats run=RUNNING as processing', () => {+ expect(isDocumentProcessing({ run: RunningStatus.RUNNING })).toBe(true);+ });++ it.each([+ RunningStatus.UNSTART,+ RunningStatus.CANCEL,+ RunningStatus.DONE,+ RunningStatus.FAIL,+ undefined,+ ])('treats terminal/absent run %s as not processing', (run) => {+ expect(isDocumentProcessing({ run })).toBe(false);+ });++ // Python never serializes ingestion_status; even if a stray field+ // reached the client, it must not influence the run-based result.+ it('ignores ingestion_status because Python never sends it', () => {expect(isDocumentProcessing({- run: RunningStatus.UNSTART,- ingestion_status: ingestionStatus,+ run: RunningStatus.DONE,+ ingestion_status: IngestionTaskStatus.RUNNING,+ }),+ ).toBe(false);+ expect(+ isDocumentProcessing({+ run: RunningStatus.RUNNING,+ ingestion_status: IngestionTaskStatus.STOPPED,}),).toBe(true);- },- );+ });+ });+});++describe('ingestionStatusToRunningStatus', () => {+ it.each([+ [IngestionTaskStatus.CREATED, RunningStatus.QUEUED],+ [IngestionTaskStatus.SCHEDULED, RunningStatus.QUEUED],+ [IngestionTaskStatus.RUNNING, RunningStatus.RUNNING],+ [IngestionTaskStatus.STOPPING, RunningStatus.RUNNING],+ [IngestionTaskStatus.COMPLETED, RunningStatus.DONE],+ [IngestionTaskStatus.FAILED, RunningStatus.FAIL],+ [IngestionTaskStatus.STOPPED, RunningStatus.CANCEL],+ [IngestionTaskStatus.UNSTART, RunningStatus.UNSTART],+ [undefined, RunningStatus.UNSTART],+ ] as const)('maps %s to %s', (status, expected) => {+ expect(ingestionStatusToRunningStatus(status)).toBe(expected);+ });+});++describe('getDocumentRunningStatus', () => {+ afterEach(() => {+ mockIsGoBackend = false;+ });++ it('derives every status from ingestion_status on Go', () => {+ mockIsGoBackend = true;+ expect(+ getDocumentRunningStatus({+ run: undefined,+ ingestion_status: IngestionTaskStatus.STOPPED,+ }),+ ).toBe(RunningStatus.CANCEL);+ expect(+ getDocumentRunningStatus({+ run: RunningStatus.RUNNING,+ ingestion_status: IngestionTaskStatus.COMPLETED,+ }),+ ).toBe(RunningStatus.DONE);+ });++ it('reads the legacy run field on Python', () => {+ expect(getDocumentRunningStatus({ run: RunningStatus.DONE })).toBe(+ RunningStatus.DONE,+ );+ });++ it('falls back to UNSTART when Python omits run', () => {+ expect(getDocumentRunningStatus({})).toBe(RunningStatus.UNSTART);+ });});describe('getFileTypeByExtension', () => {@@ -52,6 +175,12 @@ describe('getFileTypeByExtension', () => {});});+// Minimal structural stand-in for IDataset in these tests. It is declared+// locally (instead of importing the interface) because the esbuild-jest+// babel hoisting pipeline cannot elide imported bindings used only in type+// positions.+type DatasetWithParserConfig = { parser_config: any };+const DefaultSetups = initialParserValues.setups as Record<string, any>[];describe('findMissingParserModel', () => {@@ -132,7 +261,7 @@ describe('getEffectiveParserSetups', () => {audio: { vlm: { llm_id: 'whisper@OpenAI' } },},},- } as unknown as IDataset;+ } as unknown as DatasetWithParserConfig;const setups = getEffectiveParserSetups(knowledgeBase);const audio = setups.find((x) => x.fileFormat === FileType.Audio);expect(audio?.vlm?.llm_id).toBe('whisper@OpenAI');@@ -146,7 +275,7 @@ describe('getEffectiveParserSetups', () => {parser_config: {'TokenChunker:1': { chunk_token_size: 128 },},- } as unknown as IDataset;+ } as unknown as DatasetWithParserConfig;const setups = getEffectiveParserSetups(knowledgeBase);expect(setups).toHaveLength(initialParserValues.setups.length);});diff --git a/web/src/pages/dataset/dataset/utils.ts b/web/src/pages/dataset/dataset/utils.tsindex 5779f83abc..77924c8907 100644--- a/web/src/pages/dataset/dataset/utils.ts+++ b/web/src/pages/dataset/dataset/utils.ts@@ -7,6 +7,7 @@ import {initialParserValues,} from '@/pages/agent/constant/pipeline';import { isStaticParseMethod } from '@/pages/agent/form/parser-form/utils';+import { pickByBackend } from '@/utils/backend-variant';import { getExtension } from '@/utils/document-util';import {getOperatorType,@@ -15,40 +16,148 @@ import {import { cloneDeep } from 'lodash';import { IngestionTaskStatus, RunningStatus } from './constant';-export const isParserRunning = (text: RunningStatus) => {+/** Ingestion statuses that represent an active or canceling parse task on Go. */+const activeIngestionStatuses = new Set<IngestionTaskStatus>([+ IngestionTaskStatus.CREATED,+ IngestionTaskStatus.SCHEDULED,+ IngestionTaskStatus.RUNNING,+ IngestionTaskStatus.STOPPING,+]);++export const isParserRunning = (text?: RunningStatus) => {const isRunning = text === RunningStatus.RUNNING;return isRunning;};-export const isDocumentQueued = (+/**+ * Maps a Go `ingestion_status` value onto the legacy `RunningStatus`+ * vocabulary consumed by the document list UI (icons, dots, labels).+ *+ * - CREATED/SCHEDULED -> QUEUED (task enqueued, worker has not started)+ * - RUNNING/STOPPING -> RUNNING (parse in flight; STOPPING keeps the+ * in-progress presentation with the cancel button disabled)+ * - COMPLETED -> DONE+ * - FAILED -> FAIL+ * - STOPPED -> CANCEL+ * - UNSTART/undefined -> UNSTART+ *+ * @param status - Raw `ingestion_status` from a Go document response.+ * @returns The display/action status used by existing UI components.+ *+ * @example+ * ingestionStatusToRunningStatus(IngestionTaskStatus.COMPLETED);+ * // => RunningStatus.DONE+ */+export const ingestionStatusToRunningStatus = (+ status?: IngestionTaskStatus,+): RunningStatus => {+ switch (status) {+ case IngestionTaskStatus.CREATED:+ case IngestionTaskStatus.SCHEDULED:+ return RunningStatus.QUEUED;+ case IngestionTaskStatus.RUNNING:+ case IngestionTaskStatus.STOPPING:+ return RunningStatus.RUNNING;+ case IngestionTaskStatus.COMPLETED:+ return RunningStatus.DONE;+ case IngestionTaskStatus.FAILED:+ return RunningStatus.FAIL;+ case IngestionTaskStatus.STOPPED:+ return RunningStatus.CANCEL;+ case IngestionTaskStatus.UNSTART:+ default:+ return RunningStatus.UNSTART;+ }+};++/**+ * Returns the effective display/action status of a document.+ *+ * Go derives every status from the real-time `ingestion_status` field+ * (the `run` field is no longer returned). Python keeps reading the+ * legacy `run` field, which is always present on Python responses.+ *+ * @param document - Document (or subset) carrying the raw status fields.+ * @returns The `RunningStatus` to drive icons, dots and labels.+ *+ * @example+ * // Go backend+ * getDocumentRunningStatus({ ingestion_status: IngestionTaskStatus.SCHEDULED });+ * // => RunningStatus.QUEUED+ *+ * @example+ * // Python backend+ * getDocumentRunningStatus({ run: RunningStatus.RUNNING });+ * // => RunningStatus.RUNNING+ */+export const getDocumentRunningStatus = (+ document: Pick<IDocumentInfo, 'run' | 'ingestion_status'>,+): RunningStatus =>+ pickByBackend({+ go: ingestionStatusToRunningStatus(document.ingestion_status),+ python: document.run ?? RunningStatus.UNSTART,+ });++/**+ * Whether a cancel request is currently in flight for the document.+ * Only the Go backend reports STOPPING; Python always returns false.+ *+ * @param document - Document (or subset) carrying `ingestion_status`.+ * @returns `true` while the cancel button must stay disabled.+ *+ * @example+ * isDocumentStopping({ ingestion_status: IngestionTaskStatus.STOPPING });+ * // => true+ */+export const isDocumentStopping = (+ document: Pick<IDocumentInfo, 'ingestion_status'>,+) => document.ingestion_status === IngestionTaskStatus.STOPPING;++// Go: ingestion_status is the only source of truth after the run field+// was removed. Active statuses cover the queued -> running -> stopping+// lifecycle; everything else (including UNSTART and missing status) is+// terminal/idle so polling stops and row actions become available.+const isGoDocumentProcessing = (document: Pick<IDocumentInfo, 'ingestion_status'>,) =>- document.ingestion_status === IngestionTaskStatus.CREATED ||- document.ingestion_status === IngestionTaskStatus.SCHEDULED;--// Go ingestion status can advance before the legacy document run field. The-// Python endpoint omits ingestion_status, so run remains the compatibility path.-// A terminal legacy run status is authoritative: the Go backend may leave-// ingestion_status at STOPPING after a cancel completes, and the document must-// then be treated as not running so its parsing style and restart action work.+ !!document.ingestion_status &&+ activeIngestionStatuses.has(document.ingestion_status);++// Python: ingestion_status is never present on Python responses (the+// Python backend only serializes the legacy run field), so run is the+// only signal — exactly the pre-Go polling contract+// (docs.some(doc => doc.run === RUNNING)).+const isPythonDocumentProcessing = (document: Pick<IDocumentInfo, 'run'>) =>+ isParserRunning(document.run);++/**+ * Whether a document is currently being parsed (queued, running or+ * canceling). Drives the 5s list polling, disabled row actions and the+ * bulk-delete protection.+ *+ * The check is backend-specific: on Go it relies solely on+ * `ingestion_status`, on Python it follows the legacy `run`-based logic.+ *+ * @param document - Document (or subset) carrying the raw status fields.+ * @returns `true` while any parse-related task is in progress.+ *+ * @example+ * // Go backend+ * isDocumentProcessing({ ingestion_status: IngestionTaskStatus.RUNNING });+ * // => true+ *+ * @example+ * // Python backend+ * isDocumentProcessing({ run: RunningStatus.DONE });+ * // => false+ */export const isDocumentProcessing = (document: Pick<IDocumentInfo, 'run' | 'ingestion_status'>,-) => {- if (isParserRunning(document.run)) return true;- if (- document.run === RunningStatus.CANCEL ||- document.run === RunningStatus.DONE ||- document.run === RunningStatus.FAIL- ) {- return false;- }- return (- document.ingestion_status === IngestionTaskStatus.CREATED ||- document.ingestion_status === IngestionTaskStatus.SCHEDULED ||- document.ingestion_status === IngestionTaskStatus.RUNNING ||- document.ingestion_status === IngestionTaskStatus.STOPPING- );-};+) =>+ pickByBackend({+ go: isGoDocumentProcessing(document),+ python: isPythonDocumentProcessing(document),+ });// --- Parser model prerequisite checks -------------------------------------// Audio/video/image files can only be parsed when the matching model is