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:
@@ -4,6 +4,7 @@ import { MessagePlugin } from 'tdesign-vue-next'
|
|||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledgeDetails } from '@/api/knowledge-base/index'
|
import { getKnowledgeSpans, reparseKnowledge, cancelKnowledgeParse, getKnowledgeDetails } from '@/api/knowledge-base/index'
|
||||||
import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace'
|
import { knowledgeSpansPayloadHasTrace } from '@/utils/knowledgeTrace'
|
||||||
|
import { resolveTimelineHeaderStatus } from '@/utils/knowledgeProcessingStatus'
|
||||||
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'
|
import type { KnowledgeProcessOverrides } from '@/types/knowledgeProcess'
|
||||||
|
|
||||||
interface SpanNode {
|
interface SpanNode {
|
||||||
@@ -373,8 +374,13 @@ async function fetchSpans(opts: { manual?: boolean } = {}) {
|
|||||||
}
|
}
|
||||||
for (const stage of data.value.trace?.children || []) autoExpand(stage)
|
for (const stage of data.value.trace?.children || []) autoExpand(stage)
|
||||||
expandedRows.value = expanded
|
expandedRows.value = expanded
|
||||||
const traceStatus = data.value.trace?.status || data.value.parse_status || 'running'
|
const latestAttempt = data.value.latest_attempt || data.value.attempt || 0
|
||||||
attemptStatuses.set(data.value.attempt, traceStatus)
|
const tabStatus = resolveTimelineHeaderStatus({
|
||||||
|
parseStatus: data.value.parse_status,
|
||||||
|
traceStatus: data.value.trace?.status,
|
||||||
|
isLatestAttempt: data.value.attempt === latestAttempt,
|
||||||
|
}) || 'running'
|
||||||
|
attemptStatuses.set(data.value.attempt, tabStatus)
|
||||||
ensureAttemptStatuses()
|
ensureAttemptStatuses()
|
||||||
emit('update:hasSpans', knowledgeSpansPayloadHasTrace(data.value))
|
emit('update:hasSpans', knowledgeSpansPayloadHasTrace(data.value))
|
||||||
} else {
|
} else {
|
||||||
@@ -411,7 +417,11 @@ function ensureAttemptStatuses() {
|
|||||||
getKnowledgeSpans(props.knowledgeId, n)
|
getKnowledgeSpans(props.knowledgeId, n)
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
if (res?.success && res.data?.trace) {
|
if (res?.success && res.data?.trace) {
|
||||||
attemptStatuses.set(n, res.data.trace.status || res.data.parse_status || 'running')
|
attemptStatuses.set(n, resolveTimelineHeaderStatus({
|
||||||
|
parseStatus: res.data.parse_status,
|
||||||
|
traceStatus: res.data.trace?.status,
|
||||||
|
isLatestAttempt: n === latest,
|
||||||
|
}) || 'running')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => { })
|
.catch(() => { })
|
||||||
@@ -1128,36 +1138,18 @@ const viewingLatestAttempt = computed<boolean>(() => {
|
|||||||
return active === latest
|
return active === latest
|
||||||
})
|
})
|
||||||
|
|
||||||
// Project the knowledge-level parse_status onto the trace-span status
|
|
||||||
// vocabulary localizedStatus() speaks, so the header badge reads the
|
|
||||||
// same whether it comes from the root span or from parse_status.
|
|
||||||
// 'finalizing' keeps its own label ("优化中") to match the doc card.
|
|
||||||
function parseStatusToTraceStatus(s?: string): string {
|
|
||||||
switch (s) {
|
|
||||||
case 'completed':
|
|
||||||
return 'done'
|
|
||||||
case 'processing':
|
|
||||||
return 'running'
|
|
||||||
case 'finalizing':
|
|
||||||
return 'finalizing'
|
|
||||||
default:
|
|
||||||
return s || ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The authoritative status for the header badge. During the async
|
// The authoritative status for the header badge. During the async
|
||||||
// post-pipeline window (summary / question / graph / wiki), the latest
|
// post-pipeline window (summary / question / graph / wiki), the latest
|
||||||
// attempt's ROOT span closes — so trace.status reads 'done' — while
|
// attempt's ROOT span closes — so trace.status reads 'done' — while
|
||||||
// those subspans keep running and the row is still 'finalizing'.
|
// those subspans can still be running or can later make the knowledge fail.
|
||||||
// Trusting trace.status there flashes "已完成" mid-wiki even though the
|
// The latest knowledge row is therefore authoritative for ALL statuses,
|
||||||
// doc card (and LIVE badge) still say "优化中". Prefer parse_status while
|
// including terminal ones. Historical attempts keep their own root status.
|
||||||
// it is non-terminal on the latest attempt so all three agree.
|
|
||||||
const headerStatus = computed(() => {
|
const headerStatus = computed(() => {
|
||||||
const parseStatus = data.value?.parse_status
|
return resolveTimelineHeaderStatus({
|
||||||
if (viewingLatestAttempt.value && isPolling(parseStatus)) {
|
parseStatus: data.value?.parse_status,
|
||||||
return parseStatusToTraceStatus(parseStatus)
|
traceStatus: data.value?.trace?.status,
|
||||||
}
|
isLatestAttempt: viewingLatestAttempt.value,
|
||||||
return data.value?.trace?.status || parseStatusToTraceStatus(parseStatus)
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const headerStatusText = computed(() => {
|
const headerStatusText = computed(() => {
|
||||||
@@ -1182,6 +1174,10 @@ const headerStatusTheme = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const showLastError = computed(() =>
|
||||||
|
Boolean(data.value?.last_error && data.value?.parse_status === 'failed'),
|
||||||
|
)
|
||||||
|
|
||||||
const stagesStatDisplay = computed(() => {
|
const stagesStatDisplay = computed(() => {
|
||||||
const total = stages.value.length
|
const total = stages.value.length
|
||||||
const doneCount = stages.value.filter((s) => s.status === 'done').length
|
const doneCount = stages.value.filter((s) => s.status === 'done').length
|
||||||
@@ -1235,7 +1231,7 @@ watch(
|
|||||||
() => {
|
() => {
|
||||||
emit('update:summary', {
|
emit('update:summary', {
|
||||||
totalMs: totalMs.value,
|
totalMs: totalMs.value,
|
||||||
status: data.value?.trace?.status || data.value?.parse_status || '',
|
status: headerStatus.value,
|
||||||
stageIndex: currentStageIndex.value,
|
stageIndex: currentStageIndex.value,
|
||||||
stageTotal: stages.value.length,
|
stageTotal: stages.value.length,
|
||||||
stageLabel: currentStageLabel.value,
|
stageLabel: currentStageLabel.value,
|
||||||
@@ -1486,6 +1482,22 @@ const processConfigLines = computed<string[]>(() => {
|
|||||||
}}</span>
|
}}</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div v-if="showLastError && data?.last_error" class="kp-last-error" role="alert">
|
||||||
|
<div class="kp-last-error-bar" />
|
||||||
|
<div class="kp-last-error-body">
|
||||||
|
<div class="kp-last-error-row">
|
||||||
|
<span class="kp-last-error-glyph">!</span>
|
||||||
|
<span class="kp-last-error-title">{{ localizedErrorTitle(data.last_error.error_code) }}</span>
|
||||||
|
<span v-if="data.last_error.error_code" class="kp-last-error-code kp-mono">{{ data.last_error.error_code
|
||||||
|
}}</span>
|
||||||
|
</div>
|
||||||
|
<div class="kp-last-error-suggestion">{{ localizedErrorSuggestion(data.last_error.error_code) }}</div>
|
||||||
|
<div v-if="data.last_error.error_message" class="kp-last-error-raw kp-mono">{{
|
||||||
|
data.last_error.error_message }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ============== BODY (Waterfall) ============== -->
|
<!-- ============== BODY (Waterfall) ============== -->
|
||||||
@@ -1588,22 +1600,6 @@ const processConfigLines = computed<string[]>(() => {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-if="data?.last_error && data?.parse_status === 'failed'" class="kp-last-error">
|
|
||||||
<div class="kp-last-error-bar" />
|
|
||||||
<div class="kp-last-error-body">
|
|
||||||
<div class="kp-last-error-row">
|
|
||||||
<span class="kp-last-error-glyph">!</span>
|
|
||||||
<span class="kp-last-error-title">{{ localizedErrorTitle(data.last_error.error_code) }}</span>
|
|
||||||
<span v-if="data.last_error.error_code" class="kp-last-error-code kp-mono">{{ data.last_error.error_code
|
|
||||||
}}</span>
|
|
||||||
</div>
|
|
||||||
<div class="kp-last-error-suggestion">{{ localizedErrorSuggestion(data.last_error.error_code) }}</div>
|
|
||||||
<div v-if="data.last_error.error_message" class="kp-last-error-raw kp-mono">{{
|
|
||||||
data.last_error.error_message }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
@@ -2058,7 +2054,7 @@ const processConfigLines = computed<string[]>(() => {
|
|||||||
transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
|
transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.kp-attempt:hover {
|
.kp-attempt:not(.kp-attempt-active):hover {
|
||||||
background: var(--td-bg-color-secondarycontainer);
|
background: var(--td-bg-color-secondarycontainer);
|
||||||
border-color: var(--td-text-color-placeholder);
|
border-color: var(--td-text-color-placeholder);
|
||||||
color: var(--td-text-color-primary);
|
color: var(--td-text-color-primary);
|
||||||
@@ -2070,7 +2066,14 @@ const processConfigLines = computed<string[]>(() => {
|
|||||||
border-color: var(--td-brand-color);
|
border-color: var(--td-brand-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.kp-attempt-active .kp-attempt-glyph {
|
.kp-attempt-active:hover {
|
||||||
|
background: var(--td-brand-color);
|
||||||
|
color: var(--td-text-color-anti);
|
||||||
|
border-color: var(--td-brand-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.kp-attempt-active .kp-attempt-glyph,
|
||||||
|
.kp-attempt-active:hover .kp-attempt-glyph {
|
||||||
color: var(--td-text-color-anti) !important;
|
color: var(--td-text-color-anti) !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2614,9 +2617,9 @@ const processConfigLines = computed<string[]>(() => {
|
|||||||
background: var(--td-text-color-placeholder);
|
background: var(--td-text-color-placeholder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Last error block */
|
/* Last error block — pinned in the header so long trace trees don't bury it */
|
||||||
.kp-last-error {
|
.kp-last-error {
|
||||||
margin: 14px 20px 4px;
|
margin: 10px 0 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
background: var(--td-error-color-light);
|
background: var(--td-error-color-light);
|
||||||
border-radius: var(--td-radius-medium);
|
border-radius: var(--td-radius-medium);
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
@@ -680,16 +680,18 @@ func (h *KnowledgeHandler) GetKnowledgeSpans(c *gin.Context) {
|
|||||||
|
|
||||||
rows := []types.KnowledgeProcessingSpan{}
|
rows := []types.KnowledgeProcessingSpan{}
|
||||||
currentAttempt := 0
|
currentAttempt := 0
|
||||||
|
latestAttempt := 0
|
||||||
if h.spanRepo != nil {
|
if h.spanRepo != nil {
|
||||||
if requestedAttempt == 0 {
|
latest, lerr := h.spanRepo.LatestAttempt(ctx, knowledge.ID)
|
||||||
latest, lerr := h.spanRepo.LatestAttempt(ctx, knowledge.ID)
|
if lerr != nil {
|
||||||
if lerr != nil {
|
logger.Warnf(ctx, "spans LatestAttempt failed for %s: %v", knowledge.ID, lerr)
|
||||||
logger.Warnf(ctx, "spans LatestAttempt failed for %s: %v", knowledge.ID, lerr)
|
|
||||||
} else {
|
|
||||||
currentAttempt = latest
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
|
latestAttempt = latest
|
||||||
|
}
|
||||||
|
if requestedAttempt > 0 {
|
||||||
currentAttempt = requestedAttempt
|
currentAttempt = requestedAttempt
|
||||||
|
} else {
|
||||||
|
currentAttempt = latestAttempt
|
||||||
}
|
}
|
||||||
if currentAttempt > 0 {
|
if currentAttempt > 0 {
|
||||||
rows, err = h.spanRepo.ListByAttempt(ctx, knowledge.ID, currentAttempt)
|
rows, err = h.spanRepo.ListByAttempt(ctx, knowledge.ID, currentAttempt)
|
||||||
@@ -713,6 +715,8 @@ func (h *KnowledgeHandler) GetKnowledgeSpans(c *gin.Context) {
|
|||||||
|
|
||||||
resp := gin.H{
|
resp := gin.H{
|
||||||
"knowledge_id": knowledge.ID,
|
"knowledge_id": knowledge.ID,
|
||||||
|
"attempt": currentAttempt,
|
||||||
|
"latest_attempt": latestAttempt,
|
||||||
"parse_status": knowledge.ParseStatus,
|
"parse_status": knowledge.ParseStatus,
|
||||||
"current_attempt": currentAttempt,
|
"current_attempt": currentAttempt,
|
||||||
"current_stage": currentStageName,
|
"current_stage": currentStageName,
|
||||||
@@ -720,10 +724,27 @@ func (h *KnowledgeHandler) GetKnowledgeSpans(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
if lastErr != nil {
|
if lastErr != nil {
|
||||||
resp["last_error"] = gin.H{
|
resp["last_error"] = gin.H{
|
||||||
"stage": lastErr.Name,
|
"stage": lastErr.Name,
|
||||||
"code": lastErr.ErrorCode,
|
"code": lastErr.ErrorCode,
|
||||||
"message": lastErr.ErrorMessage,
|
"message": lastErr.ErrorMessage,
|
||||||
"finished_at": lastErr.FinishedAt,
|
"name": lastErr.Name,
|
||||||
|
"error_code": lastErr.ErrorCode,
|
||||||
|
"error_message": lastErr.ErrorMessage,
|
||||||
|
"finished_at": lastErr.FinishedAt,
|
||||||
|
}
|
||||||
|
} else if currentAttempt == latestAttempt && knowledge.ParseStatus == types.ParseStatusFailed && knowledge.ErrorMessage != "" {
|
||||||
|
// The knowledge row can be failed by recovery/dead-letter paths after
|
||||||
|
// the main root span has already closed. Surface that authoritative
|
||||||
|
// failure reason instead of leaving the detail drawer with a red status
|
||||||
|
// but no explanation.
|
||||||
|
resp["last_error"] = gin.H{
|
||||||
|
"stage": "knowledge_processing",
|
||||||
|
"code": "UNKNOWN",
|
||||||
|
"message": knowledge.ErrorMessage,
|
||||||
|
"name": "knowledge_processing",
|
||||||
|
"error_code": "UNKNOWN",
|
||||||
|
"error_message": knowledge.ErrorMessage,
|
||||||
|
"finished_at": knowledge.UpdatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
|||||||
Reference in New Issue
Block a user