From b4b7509e3aea779031561619e875b9a55fc26d03 Mon Sep 17 00:00:00 2001 From: zhangzherui Date: Tue, 28 Jul 2026 10:57:58 +0800 Subject: [PATCH] fix(frontend): clarify processing timeline status --- .../knowledge-processing-timeline.vue | 18 ++++++ frontend/src/i18n/locales/en-US.ts | 4 +- frontend/src/i18n/locales/ko-KR.ts | 4 +- frontend/src/i18n/locales/zh-CN.ts | 4 +- frontend/src/utils/knowledgeTrace.test.ts | 52 +++++++++++++++- frontend/src/utils/knowledgeTrace.ts | 60 +++++++++++++++++++ 6 files changed, 138 insertions(+), 4 deletions(-) diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue index d5d0c70c..d406501d 100644 --- a/frontend/src/components/knowledge-processing-timeline.vue +++ b/frontend/src/components/knowledge-processing-timeline.vue @@ -6,6 +6,7 @@ import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledge import { groupPostprocessGraphSpans, knowledgeSpansPayloadHasTrace, + summarizePostprocessTasks, type KnowledgeTraceNode, } from '@/utils/knowledgeTrace' import { resolveTimelineHeaderStatus } from '@/utils/knowledgeProcessingStatus' @@ -1197,6 +1198,10 @@ const stagesStatDisplay = computed(() => { } }) +const postprocessTaskStats = computed(() => + summarizePostprocessTasks(data.value?.trace), +) + const headMetaParts = computed(() => { if (!data.value) return [] const parts: string[] = [t('knowledgeStages.title')] @@ -1205,6 +1210,19 @@ const headMetaParts = computed(() => { } const st = stagesStatDisplay.value parts.push(`${st.label} ${st.value}`) + const postprocess = postprocessTaskStats.value + if (postprocess.total > 0) { + parts.push(t('knowledgeStages.head.postprocessTasks', { + running: postprocess.running, + failed: postprocess.failed, + completed: postprocess.completed, + })) + } + if (data.value.parse_status === 'completed' && postprocess.running > 0) { + parts.push(t('knowledgeStages.head.completedWithActiveTrace', { + n: postprocess.running, + })) + } if (attemptTabs.value.length === 0 && data.value.current_attempt) { parts.push(t('knowledgeStages.attempt', { n: data.value.current_attempt })) } diff --git a/frontend/src/i18n/locales/en-US.ts b/frontend/src/i18n/locales/en-US.ts index 3f70ca0c..3bcd007a 100755 --- a/frontend/src/i18n/locales/en-US.ts +++ b/frontend/src/i18n/locales/en-US.ts @@ -898,8 +898,10 @@ export default { head: { duration: 'Duration', stages: 'Stages', - stagesDone: 'Stages completed', + stagesDone: 'Main stages', stagesProgress: 'Current stage', + postprocessTasks: 'Postprocess: {running} running / {failed} failed / {completed} completed', + completedWithActiveTrace: 'Processing completed, but {n} trace task(s) remain active', stage: 'Stage', status: 'Status', attempt: 'Attempt', diff --git a/frontend/src/i18n/locales/ko-KR.ts b/frontend/src/i18n/locales/ko-KR.ts index 5a67d290..2ef7ff1c 100755 --- a/frontend/src/i18n/locales/ko-KR.ts +++ b/frontend/src/i18n/locales/ko-KR.ts @@ -902,8 +902,10 @@ export default { head: { duration: "소요시간", stages: "단계", - stagesDone: "완료된 단계", + stagesDone: "주요 단계", stagesProgress: "현재 단계", + postprocessTasks: "후처리: 실행 중 {running} / 실패 {failed} / 완료 {completed}", + completedWithActiveTrace: "처리는 완료되었지만 {n}개의 Trace 작업이 아직 활성 상태입니다", stage: "단계", status: "상태", attempt: "시도", diff --git a/frontend/src/i18n/locales/zh-CN.ts b/frontend/src/i18n/locales/zh-CN.ts index 90ce5831..c4265e80 100755 --- a/frontend/src/i18n/locales/zh-CN.ts +++ b/frontend/src/i18n/locales/zh-CN.ts @@ -900,8 +900,10 @@ export default { head: { duration: "总耗时", stages: "阶段", - stagesDone: "已完成阶段", + stagesDone: "主流程阶段", stagesProgress: "当前阶段", + postprocessTasks: "后台任务:运行中 {running} / 失败 {failed} / 已完成 {completed}", + completedWithActiveTrace: "处理已完成,但仍有 {n} 个 Trace 任务处于活动状态", stage: "阶段", status: "状态", attempt: "尝试", diff --git a/frontend/src/utils/knowledgeTrace.test.ts b/frontend/src/utils/knowledgeTrace.test.ts index 89ad0879..318b00cf 100644 --- a/frontend/src/utils/knowledgeTrace.test.ts +++ b/frontend/src/utils/knowledgeTrace.test.ts @@ -1,7 +1,11 @@ import assert from 'node:assert/strict' import test from 'node:test' -import { groupPostprocessGraphSpans, type KnowledgeTraceNode } from './knowledgeTrace.ts' +import { + groupPostprocessGraphSpans, + summarizePostprocessTasks, + type KnowledgeTraceNode, +} from './knowledgeTrace.ts' function graphChunk(index: number, overrides: Partial = {}): KnowledgeTraceNode { return { @@ -107,3 +111,49 @@ test('leaves postprocess unchanged when it has no graph chunks', () => { assert.equal(groupPostprocessGraphSpans(stage), stage) }) + +test('summarizes asynchronous postprocess leaf tasks', () => { + const trace: KnowledgeTraceNode = { + name: 'root', + kind: 'root', + status: 'done', + children: [ + { + name: 'postprocess', + kind: 'stage', + status: 'done', + children: [ + { name: 'postprocess.summary', kind: 'subspan', status: 'done' }, + { name: 'postprocess.question', kind: 'subspan', status: 'running' }, + { + name: 'postprocess.graph', + kind: 'group', + status: 'failed', + children: [ + { name: 'postprocess.graph.chunk[0]', kind: 'subspan', status: 'failed' }, + { name: 'postprocess.graph.chunk[1]', kind: 'subspan', status: 'pending' }, + ], + }, + ], + }, + ], + } + + assert.deepEqual(summarizePostprocessTasks(trace), { + running: 2, + failed: 1, + completed: 1, + other: 0, + total: 4, + }) +}) + +test('returns an empty postprocess summary when no trace is available', () => { + assert.deepEqual(summarizePostprocessTasks(undefined), { + running: 0, + failed: 0, + completed: 0, + other: 0, + total: 0, + }) +}) diff --git a/frontend/src/utils/knowledgeTrace.ts b/frontend/src/utils/knowledgeTrace.ts index 9ce1ba08..c394a4c0 100644 --- a/frontend/src/utils/knowledgeTrace.ts +++ b/frontend/src/utils/knowledgeTrace.ts @@ -23,6 +23,14 @@ export interface KnowledgeTraceNode { children?: KnowledgeTraceNode[] } +export interface PostprocessTaskSummary { + running: number + failed: number + completed: number + other: number + total: number +} + const graphChunkName = /^postprocess\.graph\.chunk\[(\d+)\]$/ function timestamp(value?: string | null): number | null { @@ -105,3 +113,55 @@ export function groupPostprocessGraphSpans( return { ...stage, children: groupedChildren } } + +/** + * Counts leaf postprocess spans so the UI can distinguish the five main + * pipeline stages from asynchronous enrichment work. + */ +export function summarizePostprocessTasks( + trace?: KnowledgeTraceNode, +): PostprocessTaskSummary { + const summary: PostprocessTaskSummary = { + running: 0, + failed: 0, + completed: 0, + other: 0, + total: 0, + } + if (!trace) return summary + + const postprocess = trace.name === 'postprocess' + ? trace + : (trace.children || []).find(child => child.name === 'postprocess') + if (!postprocess) return summary + + const countLeaves = (node: KnowledgeTraceNode) => { + const children = node.children || [] + if (children.length > 0) { + children.forEach(countLeaves) + return + } + + summary.total++ + switch (node.status) { + case 'running': + case 'pending': + case 'processing': + case 'finalizing': + summary.running++ + break + case 'failed': + summary.failed++ + break + case 'done': + case 'completed': + summary.completed++ + break + default: + summary.other++ + } + } + + ;(postprocess.children || []).forEach(countLeaves) + return summary +}