From a163bab32f75b19d5b769a4d3795c539b032b089 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Sun, 20 Sep 2026 12:19:04 +0800 Subject: [PATCH] feat(knowledge): rework the parse timeline panel's layout and failure card MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The processing-pipeline drawer presented a failed parse worst-side-up. The error card printed the error code twice (headline plus a solid red pill), gave the most prominent line to the generic "check the logs" filler, and left the one line that explains the failure — the backend's own message — last, smallest and greyest. Around it, the waterfall left roughly half the panel blank, ruled its time axis at 0/124/247/371/494ms (the raw total cut in four), flung a ROOT/STAGE label to the far right of every name cell, and drew the stages that an upstream failure had abandoned as pending rows with dashed stubs pinned to the track edge. Error card - Headline says which stage broke; the code appears once, as a quiet chip. The backend message is promoted to the card's primary line. - Retry moves into the card, next to the reason, and loses the brand-green outline it wore against a red failure. It stays in the toolbar only when a failure carries no last_error. - The headline no longer uses --td-error-color on the card's own error tint, which measured around 3:1 in both themes. Waterfall - Axis ticks round onto a 1/2/2.5/5 x 10^n step, and bars are positioned against the rounded axis maximum so bars and ruler cannot disagree. Gridlines mark each tick behind the bars. - Kind labels are reserved for `generation` spans instead of stamping ROOT/STAGE/SPAN on every row via margin-left:auto. - Depth is carried by indent guides rather than three near-identical row tints that read as banding. - Stages abandoned by an upstream failure say "not run" and recede. Layout and interaction - The detail panel opens on load, on the failed span or the root, so the panel is not half empty and the rows are discoverably clickable. It stays closed once the user closes it. - The waterfall is content-sized (capped at 60%) and the detail absorbs the remainder, instead of a fixed 50/50 that clipped rows mid-height. - The dot-joined meta sentence becomes label/value stats; the panel name moves to an overline above the filename. Axis math moves to utils/traceAxis.ts with unit tests. New i18n keys are added to all five locales; three keys left unreferenced by this change are removed. --- .../knowledge-processing-timeline.vue | 605 +++++++++++++----- frontend/src/i18n/locales/en-US.ts | 12 +- frontend/src/i18n/locales/ja-JP.ts | 12 +- frontend/src/i18n/locales/ko-KR.ts | 12 +- frontend/src/i18n/locales/ru-RU.ts | 12 +- frontend/src/i18n/locales/zh-CN.ts | 12 +- frontend/src/utils/traceAxis.test.ts | 77 +++ frontend/src/utils/traceAxis.ts | 83 +++ 8 files changed, 659 insertions(+), 166 deletions(-) create mode 100644 frontend/src/utils/traceAxis.test.ts create mode 100644 frontend/src/utils/traceAxis.ts diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue index e87d62b7..e9c89079 100644 --- a/frontend/src/components/knowledge-processing-timeline.vue +++ b/frontend/src/components/knowledge-processing-timeline.vue @@ -11,6 +11,7 @@ import { type KnowledgeTraceNode, } from '@/utils/knowledgeTrace' import { resolveTimelineHeaderStatus } from '@/utils/knowledgeProcessingStatus' +import { axisGridStepPct, buildAxisTicks, computeTraceAxis } from '@/utils/traceAxis' import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess' type SpanNode = KnowledgeTraceNode @@ -92,6 +93,10 @@ const refreshing = ref(false) const selectedAttempt = ref(undefined) const expandedRows = ref>(new Set(['__root__'])) const selectedSpanId = ref(null) +// Guards the one-shot auto-selection below. Cleared once the panel has +// opened itself, or the moment the user closes it — a 2s poll must never +// reopen a panel the user just dismissed. +const autoSelectPending = ref(true) const expandedJsonKeys = ref>(new Set()) const nowTick = ref(Date.now()) const detailTab = ref<'overview' | 'input' | 'output' | 'metadata' | 'raw'>('overview') @@ -385,6 +390,9 @@ async function fetchSpans(opts: { manual?: boolean } = {}) { attemptStatuses.set(data.value.attempt, tabStatus) ensureAttemptStatuses() emit('update:hasSpans', knowledgeSpansPayloadHasTrace(data.value)) + // flatRows is derived from data.value; wait for it to recompute + // before picking a row out of it. + nextTick(autoSelectSpan) } else { emit('update:hasSpans', false) } @@ -462,6 +470,7 @@ async function onRetry() { selectedAttempt.value = undefined attemptStatuses.clear() selectedSpanId.value = null + autoSelectPending.value = true await fetchSpans() } catch { // ignore @@ -503,6 +512,7 @@ function onAttemptChange(n: number) { if (Number.isNaN(n)) return selectedAttempt.value = n selectedSpanId.value = null + autoSelectPending.value = true // New attempt: forget per-row user choices so the auto-expand // rule re-evaluates cleanly against the new attempt's tree. userToggledRows.value = new Set() @@ -519,6 +529,7 @@ watch( currentKnowledgeFileType.value = '' expandedRows.value = new Set(['__root__']) selectedSpanId.value = null + autoSelectPending.value = true attemptStatuses.clear() userToggledRows.value = new Set() fetchSpans() @@ -528,7 +539,7 @@ watch( function onKeydown(ev: KeyboardEvent) { if (ev.key === 'Escape' && selectedSpanId.value) { - selectedSpanId.value = null + closeDetail() } } @@ -686,25 +697,21 @@ const totalMs = computed(() => { const showRuler = computed(() => totalMs.value >= 50) -const rulerTicks = computed(() => { - if (!showRuler.value) return [] as { left: string; label: string }[] - const total = totalMs.value - const fmt = (ms: number) => formatDuration(ms) - return [ - { left: '0%', label: fmt(0) }, - { left: '25%', label: fmt(total * 0.25) }, - { left: '50%', label: fmt(total * 0.5) }, - { left: '75%', label: fmt(total * 0.75) }, - { left: '100%', label: fmt(total) }, - ] -}) +// ---------- Time axis ---------- +// See utils/traceAxis: the ruler is a rounded 1/2/2.5/5 axis, and every +// bar is positioned against axis.maxMs rather than the raw total so the +// bars and the ruler above them cannot disagree. +const timeAxis = computed(() => computeTraceAxis(totalMs.value)) +const axisMaxMs = computed(() => timeAxis.value.maxMs) +const gridStepPct = computed(() => axisGridStepPct(timeAxis.value)) +const rulerTicks = computed(() => (showRuler.value ? buildAxisTicks(timeAxis.value) : [])) // "Now" position on the waterfall scale, used to draw the live cursor // while polling so the user can see time advancing even when the running // stage's bar grows slowly toward the right edge. const nowMarkerPct = computed(() => { - if (!isLive.value || !t0.value || !totalMs.value) return null - const pct = ((nowTick.value - t0.value) / totalMs.value) * 100 + if (!isLive.value || !t0.value || !axisMaxMs.value) return null + const pct = ((nowTick.value - t0.value) / axisMaxMs.value) * 100 return Math.max(0, Math.min(100, pct)) }) @@ -781,7 +788,7 @@ const selectedRow = computed(() => { const detailOpen = computed(() => selectedSpanId.value !== null && selectedRow.value !== null) function barStyle(node: SpanNode): Record { - const total = totalMs.value + const total = axisMaxMs.value if (!total || t0.value === null) return { display: 'none' } const start = nodeStart(node) if (start === null) return { display: 'none' } @@ -816,7 +823,7 @@ function descendantMaxEnd(node: SpanNode): number | null { } function wrapStyle(node: SpanNode): Record | null { - const total = totalMs.value + const total = axisMaxMs.value if (!total || t0.value === null) return null const start = nodeStart(node) if (start === null) return null @@ -843,7 +850,7 @@ function wrapDurationMs(node: SpanNode): number { } function barOffsetPct(node: SpanNode): number | null { - const total = totalMs.value + const total = axisMaxMs.value if (!total || t0.value === null) return null const start = nodeStart(node) if (start === null) return null @@ -866,6 +873,20 @@ function isPlaceholder(node: SpanNode): boolean { return !node.span_id && !node.started_at } +// The trace has reached a terminal state and nothing is still ticking. +const traceTerminal = computed( + () => isHardTerminal(data.value?.parse_status) && !traceActive.value, +) + +// A synthesized stage still marked 'pending' on a finished trace never +// ran and never will — docreader failed, so chunking/embedding/... were +// abandoned. v1 rendered them as ordinary pending rows with a dashed +// stub pinned to the right edge of the track, which reads as leftover +// rendering junk. Say "not run" in words and let the row recede. +function isNotRun(node: SpanNode): boolean { + return traceTerminal.value && node.status === 'pending' && isPlaceholder(node) +} + function isRowExpanded(key: string): boolean { return expandedRows.value.has(key) } @@ -921,6 +942,22 @@ function selectRow(row: FlatRow) { function closeDetail() { selectedSpanId.value = null + autoSelectPending.value = false +} + +// v1 opened with nothing selected, so a short trace showed a handful of +// rows above half a panel of white space, and nothing suggested the rows +// were clickable at all. Open on the span the reader came for: the one +// that failed, or the root (whose detail is the stage breakdown). +function autoSelectSpan() { + if (props.compact) return + if (!autoSelectPending.value || selectedSpanId.value) return + const rows = flatRows.value + if (rows.length === 0) return + const failed = rows.find((r) => !r.isRoot && r.node.status === 'failed') + selectedSpanId.value = (failed || rows[0]).key + detailTab.value = 'overview' + autoSelectPending.value = false } function isObjectWithKeys(v: any): boolean { @@ -957,10 +994,13 @@ function rowLabel(row: FlatRow): string { return row.node.name } +// v1 stamped ROOT / STAGE / SPAN on every row and flung the label to the +// far right of the name column with margin-left:auto, which opened a +// ~200px gap mid-row and told the reader nothing that indentation hadn't +// already said. Only `generation` (an LLM/VLM call) is worth a chip. function rowKindLabel(row: FlatRow): string { - if (row.isRoot) return 'root' - if (row.isStage) return 'stage' - return row.node.kind || 'span' + if (row.isRoot || row.isStage) return '' + return row.node.kind === 'generation' ? 'generation' : '' } function jsonExpandKey(section: string, key: string): string { @@ -1178,6 +1218,38 @@ const showLastError = computed(() => Boolean(data.value?.last_error && data.value?.parse_status === 'failed'), ) +const failedStage = computed( + () => stages.value.find((s) => s.status === 'failed') || null, +) + +// v1's headline was localizedErrorTitle(code), which falls back to the +// raw code when no translation exists — so the card printed +// DOCREADER_PARSE_FAILED as its title AND again as the chip beside it, +// while the one line that actually explains the failure +// ("Unsupported file type: htm") sat at the bottom in 11px grey mono. +// The headline now says WHERE it broke, the code appears exactly once, +// and the message is promoted to the card's primary line. +const errorHeadline = computed(() => { + const err = data.value?.last_error + const localized = localizedErrorTitle(err?.error_code) + if (localized && localized !== err?.error_code) return localized + // Prefer a stage row that actually carries the failure; fall back to + // the span name the backend recorded on last_error, which covers a + // failure raised before any stage span opened. + const name = failedStage.value?.name + || (STAGES as readonly string[]).find((n) => n === err?.name) + if (name) { + return t('knowledgeStages.stageFailed', { stage: t(`knowledgeStages.stage.${name}`) }) + } + return t('knowledgeStages.status.failed') +}) + +// Retry stays reachable from the toolbar when a failure has no +// last_error payload to hang the in-card button off. +const showToolbarRetry = computed( + () => data.value?.parse_status === 'failed' && !showLastError.value, +) + const stagesStatDisplay = computed(() => { const total = stages.value.length const completedCount = stages.value.filter( @@ -1202,38 +1274,70 @@ const postprocessTaskStats = computed(() => summarizePostprocessTasks(data.value?.trace), ) -const headMetaParts = computed(() => { +interface HeadStat { + key: string + label: string + value: string + mono: boolean + note?: boolean +} + +// v1 glued five unrelated facts into one dot-separated grey sentence — +// "处理流水线 · 总耗时 494ms · 当前阶段 1/5 · 第 1 次尝试" — which reads +// as a run-on and buries the numbers among the words. Label/value pairs +// with the numbers in tabular mono scan in one pass instead. The panel's +// own name moves out of the sentence and onto the overline above the +// title, where it belongs. +const headStats = computed(() => { if (!data.value) return [] - const parts: string[] = [t('knowledgeStages.title')] + const out: HeadStat[] = [] if (totalMs.value > 0) { - parts.push(t('knowledgeStages.total', { d: formatDuration(totalMs.value) })) + out.push({ + key: 'duration', + label: t('knowledgeStages.stat.duration'), + value: formatDuration(totalMs.value), + mono: true, + }) } const st = stagesStatDisplay.value - parts.push(`${st.label} ${st.value}`) + out.push({ key: 'stages', label: st.label, value: st.value, mono: true }) + 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, - })) + out.push({ + key: 'tasks', + label: t('knowledgeStages.stat.tasks'), + value: t('knowledgeStages.stat.tasksValue', { + running: postprocess.running, + failed: postprocess.failed, + completed: postprocess.completed, + }), + mono: false, + note: postprocess.running > 0 || postprocess.failed > 0, + }) } if (attemptTabs.value.length === 0 && data.value.current_attempt) { - parts.push(t('knowledgeStages.attempt', { n: data.value.current_attempt })) + out.push({ + key: 'attempt', + label: t('knowledgeStages.stat.attempt'), + value: `#${data.value.current_attempt}`, + mono: true, + }) } if (lastFetchedAt.value && isLive.value) { let updated = formatRelativeTime(lastFetchedAt.value) if (!lastFetchOk.value) { updated += ` (${t('knowledgeStages.fetchFailedShort')})` } - parts.push(`${t('knowledgeStages.head.updated')} ${updated}`) + out.push({ + key: 'updated', + label: t('knowledgeStages.head.updated'), + value: updated, + mono: false, + note: !lastFetchOk.value, + }) } - return parts + return out }) const primaryHeadTitle = computed(() => props.docTitle || t('knowledgeStages.title')) @@ -1430,21 +1534,26 @@ const processConfigLines = computed(() => {
-

{{ primaryHeadTitle }}

- - {{ headerStatusText }} - - - - {{ t('knowledgeStages.live') }} - +
+
{{ t('knowledgeStages.title') }}
+
+

{{ primaryHeadTitle }}

+ + {{ headerStatusText }} + + + + {{ t('knowledgeStages.live') }} + +
+