Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix: show async postprocess duration in trace (#4711)

lsmlhi_25ca96726889bf
diff --git a/docs/assets/postprocess-inclusive-duration.png b/docs/assets/postprocess-inclusive-duration.png
new file mode 100644
index 000000000..63e7b4656
Binary files /dev/null and b/docs/assets/postprocess-inclusive-duration.png differ
diff --git a/frontend/src/components/knowledge-processing-timeline.vue b/frontend/src/components/knowledge-processing-timeline.vue
index b3a92a1d0..4c24cfc93 100644
--- a/frontend/src/components/knowledge-processing-timeline.vue
+++ b/frontend/src/components/knowledge-processing-timeline.vue
@@ -7,6 +7,7 @@ import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledge
import {
groupPostprocessGraphSpans,
knowledgeSpansPayloadHasTrace,
+ postprocessElapsedMs,
summarizePostprocessTasks,
type KnowledgeTraceNode,
} from '@/utils/knowledgeTrace'
@@ -204,11 +205,22 @@ function formatRelativeTime(ts: number): string {
// A skipped stage did not execute. Its tiny bookkeeping interval is not
// processing time, so do not present it as (for example) multimodal time.
-function formatSpanDuration(node: SpanNode): string {
+function formatSpanDuration(node: SpanNode, includeChildren = false): string {
if (node.status === 'skipped' || node.status === 'pending') return '—'
+ if (includeChildren) {
+ const elapsed = postprocessElapsedMs(node, postprocessDisplayNow())
+ if (elapsed !== null) return formatDuration(elapsed)
+ }
return formatDuration(node.duration_ms)
}
+// A terminal parse can leave a stale running child in the last response.
+// Once polling stops, freeze its displayed elapsed time at that response
+// rather than counting indefinitely without fresh worker evidence.
+function postprocessDisplayNow(): number {
+ return shouldPollNow() ? nowTick.value : (lastFetchedAt.value || nowTick.value)
+}
+
function isPolling(status?: string): boolean {
// finalizing is the post-process fan-out window — subspans
// (summary / question / graph.chunk[*]) are still actively producing
@@ -1767,7 +1779,10 @@ const processConfigLines = computed<string[]>(() => {
<span class="kp-running-time">{{ formatDuration(liveElapsedMs(row.node)) }}</span>
</template>
<template v-else>
- {{ formatSpanDuration(row.node) }}
+ <span :title="postprocessElapsedMs(row.node, postprocessDisplayNow()) !== null
+ ? t('knowledgeStages.detail.includingChildren') : undefined">
+ {{ formatSpanDuration(row.node, true) }}
+ </span>
</template>
</div>
@@ -1890,6 +1905,12 @@ const processConfigLines = computed<string[]>(() => {
</template>
</span>
</div>
+ <div v-if="postprocessElapsedMs(selectedRow.node, postprocessDisplayNow()) !== null" class="kp-kv-row">
+ <span class="kp-kv-key">{{ t('knowledgeStages.detail.includingChildren') }}</span>
+ <span class="kp-kv-val kp-mono">
+ {{ formatDuration(postprocessElapsedMs(selectedRow.node, postprocessDisplayNow()) ?? 0) }}
+ </span>
+ </div>
<div v-if="!selectedRow.isRoot && barOffsetMs(selectedRow.node) > 0" class="kp-kv-row">
<span class="kp-kv-key">{{ t('knowledgeStages.detail.offset') }}</span>
<span class="kp-kv-val kp-mono">+{{ formatDuration(barOffsetMs(selectedRow.node)) }}</span>
diff --git a/frontend/src/utils/knowledgeTrace.test.ts b/frontend/src/utils/knowledgeTrace.test.ts
index 318b00cf3..60b483809 100644
--- a/frontend/src/utils/knowledgeTrace.test.ts
+++ b/frontend/src/utils/knowledgeTrace.test.ts
@@ -3,10 +3,39 @@ import test from 'node:test'
import {
groupPostprocessGraphSpans,
+ postprocessElapsedMs,
summarizePostprocessTasks,
type KnowledgeTraceNode,
} from './knowledgeTrace.ts'
+test('postprocess duration follows asynchronous workers instead of enqueue completion', () => {
+ const stage: KnowledgeTraceNode = {
+ name: 'postprocess', kind: 'stage', status: 'done',
+ started_at: '2026-10-25T00:00:00.000Z',
+ finished_at: '2026-10-25T00:00:00.032Z',
+ duration_ms: 32,
+ children: [{
+ name: 'postprocess.wiki', kind: 'subspan', status: 'running',
+ started_at: '2026-10-25T00:00:01.000Z',
+ }],
+ }
+
+ const afterEnqueue = Date.parse('2026-10-25T00:02:00.000Z')
+ assert.equal(postprocessElapsedMs(stage, afterEnqueue), 120_000)
+ assert.equal(stage.duration_ms, 32, 'the stored stage duration still measures enqueue work')
+
+ stage.children![0].status = 'done'
+ stage.children![0].finished_at = '2026-10-25T00:03:00.000Z'
+ assert.equal(postprocessElapsedMs(stage, afterEnqueue + 60_000), 180_000)
+
+ stage.children = [{ name: 'postprocess.wiki', kind: 'subspan', status: 'pending' }]
+ assert.equal(postprocessElapsedMs(stage, afterEnqueue), 120_000,
+ 'queued workers must not make the stage appear complete')
+ stage.children = []
+ assert.equal(postprocessElapsedMs(stage, afterEnqueue), null,
+ 'a stage without asynchronous work keeps its own duration')
+})
+
function graphChunk(index: number, overrides: Partial<KnowledgeTraceNode> = {}): KnowledgeTraceNode {
return {
span_id: `graph-${index}`,
diff --git a/frontend/src/utils/knowledgeTrace.ts b/frontend/src/utils/knowledgeTrace.ts
index c394a4c04..ac495ef00 100644
--- a/frontend/src/utils/knowledgeTrace.ts
+++ b/frontend/src/utils/knowledgeTrace.ts
@@ -49,6 +49,34 @@ function nodeEnd(node: KnowledgeTraceNode): number | null {
return null
}
+/**
+ * The persisted postprocess stage ends after enqueue, while its workers can
+ * continue for minutes. Return the elapsed wall-clock window through the
+ * latest asynchronous descendant for the stage's inclusive display duration.
+ * Keep duration_ms untouched so enqueue time remains available in details.
+ */
+export function postprocessElapsedMs(stage: KnowledgeTraceNode, now: number): number | null {
+ if (stage.name !== 'postprocess') return null
+ const start = timestamp(stage.started_at)
+ if (start === null || !stage.children?.length) return null
+
+ let latest = nodeEnd(stage) ?? start
+ let hasTimedChild = false
+ const visit = (node: KnowledgeTraceNode) => {
+ const childStart = timestamp(node.started_at)
+ const end = node.status === 'running' || node.status === 'pending'
+ ? now
+ : nodeEnd(node)
+ if (end !== null && (childStart !== null || node.status === 'pending')) {
+ latest = Math.max(latest, end)
+ hasTimedChild = true
+ }
+ node.children?.forEach(visit)
+ }
+ stage.children.forEach(visit)
+ return hasTimedChild ? Math.max(0, latest - start) : null
+}
+
function aggregateStatus(nodes: KnowledgeTraceNode[]): string {
if (nodes.some(node => node.status === 'running' || node.status === 'pending')) return 'running'
if (nodes.some(node => node.status === 'failed')) return 'failed'