fix(knowledge): align processing timeline status with knowledge row

Latest attempt tabs and header now trust parse_status over a closed root span, surface recovery failures via last_error, and keep attempt hover styles from washing out the active tab.
This commit is contained in:
wizardchen
2026-07-14 16:40:49 +08:00
committed by lyingbug
parent 41975abcc5
commit fc03e4862d
4 changed files with 155 additions and 61 deletions
@@ -0,0 +1,36 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import {
parseStatusToTimelineStatus,
resolveTimelineHeaderStatus,
} from './knowledgeProcessingStatus.ts'
test('latest attempt uses failed knowledge status even when root span is done', () => {
assert.equal(resolveTimelineHeaderStatus({
parseStatus: 'failed',
traceStatus: 'done',
isLatestAttempt: true,
}), 'failed')
})
test('latest attempt keeps finalizing distinct from a completed root span', () => {
assert.equal(resolveTimelineHeaderStatus({
parseStatus: 'finalizing',
traceStatus: 'done',
isLatestAttempt: true,
}), 'finalizing')
})
test('historical attempt keeps its own root status', () => {
assert.equal(resolveTimelineHeaderStatus({
parseStatus: 'failed',
traceStatus: 'done',
isLatestAttempt: false,
}), 'done')
})
test('parse status maps completed and processing into timeline vocabulary', () => {
assert.equal(parseStatusToTimelineStatus('completed'), 'done')
assert.equal(parseStatusToTimelineStatus('processing'), 'running')
})
@@ -0,0 +1,34 @@
export type TimelineStatusInput = {
parseStatus?: string
traceStatus?: string
isLatestAttempt: boolean
}
/**
* Convert the knowledge-level parse status to the span status vocabulary used
* by the processing timeline.
*/
export function parseStatusToTimelineStatus(status?: string): string {
switch (status) {
case 'completed':
return 'done'
case 'processing':
return 'running'
default:
return status || ''
}
}
/**
* The knowledge row is authoritative for the latest attempt. The root span
* only describes the main parse pipeline and may already be `done` while
* asynchronous enrichment is still running or has subsequently failed.
* Historical attempts have no matching knowledge-row snapshot, so they keep
* their own persisted root-span status.
*/
export function resolveTimelineHeaderStatus(input: TimelineStatusInput): string {
if (input.isLatestAttempt) {
return parseStatusToTimelineStatus(input.parseStatus) || input.traceStatus || ''
}
return input.traceStatus || parseStatusToTimelineStatus(input.parseStatus)
}