fix(frontend): 链路追踪打开时自动选中有效状态的节点

修复 Provider 组状态提升逻辑,之前仅在 success 时更新组状态,
导致组内有 streaming/failed 等状态的 key 时组仍显示为 available,
自动选择逻辑无法识别有效节点。引入状态优先级机制正确提升组状态,
并扩大 fallback 有效状态范围,避免默认选中未执行的节点。
This commit is contained in:
fawney19
2026-02-11 10:06:59 +08:00
parent 11b0026995
commit 68f5e7e502

View File

@@ -489,9 +489,16 @@ const groupedTimeline = computed<NodeGroup[]>(() => {
currentGroup.retryCount++ currentGroup.retryCount++
currentGroup.endIndex = index currentGroup.endIndex = index
currentGroup.totalLatency += candidate.latency_ms || 0 currentGroup.totalLatency += candidate.latency_ms || 0
// 如果任一尝试成功,更新主状态 // 按优先级提升组状态success > streaming/pending > failed/cancelled/stream_interrupted > skipped > available/unused
if (candidate.status === 'success') { const statusPriority: Record<string, number> = {
currentGroup.primaryStatus = 'success' available: 0, unused: 0, skipped: 1,
failed: 2, cancelled: 2, stream_interrupted: 2,
pending: 3, streaming: 3, success: 4,
}
const currentPriority = statusPriority[currentGroup.primaryStatus] ?? 0
const newPriority = statusPriority[candidate.status] ?? 0
if (newPriority > currentPriority) {
currentGroup.primaryStatus = candidate.status
} }
} else { } else {
// 新建一个组 // 新建一个组
@@ -713,28 +720,29 @@ watch(groupedTimeline, (newGroups) => {
return return
} }
// 查找最后一个有效结果的组(failed 优先于 skipped/available // 查找最后一个有效结果的组(有实际执行过的状态failed/cancelled/stream_interrupted/skipped
// 从后往前找第一个 failed 的组 // 从后往前找第一个有效状态的组
const activeStatuses = ['failed', 'cancelled', 'stream_interrupted', 'skipped']
for (let i = newGroups.length - 1; i >= 0; i--) { for (let i = newGroups.length - 1; i >= 0; i--) {
const group = newGroups[i] const group = newGroups[i]
if (group.primaryStatus === 'failed') { if (activeStatuses.includes(group.primaryStatus)) {
selectedGroupIndex.value = i selectedGroupIndex.value = i
// 选中最后一个失败的尝试(从后往前遍历) // 选中最后一个有效状态的尝试(从后往前遍历)
let failedIdx = -1 let targetIdx = -1
for (let j = group.allAttempts.length - 1; j >= 0; j--) { for (let j = group.allAttempts.length - 1; j >= 0; j--) {
if (group.allAttempts[j].status === 'failed') { if (activeStatuses.includes(group.allAttempts[j].status)) {
failedIdx = j targetIdx = j
break break
} }
} }
selectedAttemptIndex.value = failedIdx >= 0 ? failedIdx : group.allAttempts.length - 1 selectedAttemptIndex.value = targetIdx >= 0 ? targetIdx : group.allAttempts.length - 1
return return
} }
} }
// 都没有则选择最后一个组 // 都没有有效状态,选择第一个组(避免选到末尾的未执行节点)
selectedGroupIndex.value = newGroups.length - 1 selectedGroupIndex.value = 0
selectedAttemptIndex.value = newGroups[newGroups.length - 1].allAttempts.length - 1 selectedAttemptIndex.value = 0
}, { immediate: true }) }, { immediate: true })
// 监听 requestId 变化 // 监听 requestId 变化