fix: preserve span input/metadata, auto-expand subspans, force-arm poll
Three fixes in response to user feedback: 1. Span input disappearing on End/Fail The Upsert's DoUpdates always listed input/output/metadata, so calls that only set output (EndSpan) or only set error_* (FailSpan) wrote NULL into input/metadata, clobbering whatever Begin had recorded. Build the column list dynamically: skip input/output/metadata when the incoming row's value is nil. nil now means "preserve existing" (matches user's intuition "Begin recorded it, End shouldn't erase it"). 2. Subspans not auto-expanded Stages with children (multimodal.image[*], postprocess.summary, postprocess.question, postprocess.graph.chunk[*]) required a click on the ▸ caret to surface — easy to miss. On the FIRST successful fetch per (knowledgeId × attempt), auto-expand any stage that has children. Subsequent polls honor whatever the user has collapsed, so manual collapse mid-parse stays collapsed. 3. Auto-poll still not firing Force-arm the polling interval in onMounted regardless of state. The per-tick callback decides whether to actually fetch based on current parse_status — so the loop can never get stranded waiting on a status transition that already happened. Added a console.debug when the interval arms, so we can verify from DevTools console that polling is actually running. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,11 @@ const expandedJsonKeys = ref<Set<string>>(new Set())
|
||||
const nowTick = ref(Date.now())
|
||||
const detailTab = ref<'overview' | 'input' | 'output' | 'metadata' | 'raw'>('overview')
|
||||
const lastFetchedAt = ref<number>(0)
|
||||
// Tracks whether we've completed our FIRST successful fetch for the
|
||||
// current knowledgeId. After that, the user owns expandedRows — we
|
||||
// don't re-auto-expand on every poll (would un-collapse rows the user
|
||||
// intentionally collapsed mid-parse).
|
||||
let firstLoadDone = false
|
||||
// Tracks consecutive fetch failures so the "更新于" caption can surface
|
||||
// staleness. When the parse_status is mid-flight but every fetch is
|
||||
// hitting an error, the loop keeps going silently — without this
|
||||
@@ -144,6 +149,7 @@ function ensurePolling() {
|
||||
if (unmounted) return
|
||||
if (props.autoPoll === false) return
|
||||
if (pollTimer) return
|
||||
console.debug('[KnowledgeTimeline] arming poll interval', { knowledgeId: props.knowledgeId, every: POLL_INTERVAL_MS })
|
||||
pollTimer = setInterval(() => {
|
||||
// Guard against overlapping fetches AND state changes that have
|
||||
// since flipped status out of polling. Keeps the loop conservative.
|
||||
@@ -153,7 +159,14 @@ function ensurePolling() {
|
||||
}
|
||||
if (fetchInFlight) return
|
||||
const status = data.value?.parse_status
|
||||
if (!status || !isPolling(status)) {
|
||||
if (!status) {
|
||||
// First fetch hasn't completed yet — give it another tick to
|
||||
// settle. Common when the drawer opens against a slow network.
|
||||
return
|
||||
}
|
||||
if (!isPolling(status)) {
|
||||
// Terminal state: stop the interval. The watcher will re-arm
|
||||
// it if status flips back to polling (e.g. user triggers reparse).
|
||||
clearTimer()
|
||||
return
|
||||
}
|
||||
@@ -176,6 +189,21 @@ async function fetchSpans(opts: { manual?: boolean } = {}) {
|
||||
if (selectedAttempt.value === undefined) {
|
||||
selectedAttempt.value = data.value.attempt
|
||||
}
|
||||
// First-load auto-expand: surface any stage that already has
|
||||
// subspans (multimodal.image[i], postprocess.summary, etc.) so
|
||||
// users don't have to click ▸ on every stage to discover them.
|
||||
// Only runs once per (knowledgeId × attempt) — subsequent polls
|
||||
// honor whatever the user has collapsed.
|
||||
if (!firstLoadDone) {
|
||||
const expanded = new Set<string>(['__root__'])
|
||||
for (const stage of data.value.trace?.children || []) {
|
||||
if ((stage.children || []).length > 0) {
|
||||
expanded.add(stage.span_id || `stage:${stage.name}`)
|
||||
}
|
||||
}
|
||||
expandedRows.value = expanded
|
||||
firstLoadDone = true
|
||||
}
|
||||
const traceStatus = data.value.trace?.status || data.value.parse_status || 'running'
|
||||
attemptStatuses.set(data.value.attempt, traceStatus)
|
||||
ensureAttemptStatuses()
|
||||
@@ -286,6 +314,8 @@ function onAttemptChange(n: number) {
|
||||
if (Number.isNaN(n)) return
|
||||
selectedAttempt.value = n
|
||||
selectedSpanId.value = null
|
||||
// Re-trigger auto-expand on the new attempt's stages.
|
||||
firstLoadDone = false
|
||||
fetchSpans()
|
||||
}
|
||||
|
||||
@@ -297,6 +327,7 @@ watch(
|
||||
expandedRows.value = new Set(['__root__'])
|
||||
selectedSpanId.value = null
|
||||
attemptStatuses.clear()
|
||||
firstLoadDone = false
|
||||
fetchSpans()
|
||||
},
|
||||
)
|
||||
@@ -328,6 +359,13 @@ function onKeydown(ev: KeyboardEvent) {
|
||||
|
||||
onMounted(() => {
|
||||
fetchSpans()
|
||||
// Arm the polling interval unconditionally — the per-tick callback
|
||||
// decides whether to actually fetch based on current parse_status.
|
||||
// This way the loop can never get stranded waiting on a status
|
||||
// transition that already happened. The callback self-clears when
|
||||
// status reaches a terminal state, and the watcher re-arms if it
|
||||
// flips back to polling.
|
||||
ensurePolling()
|
||||
// Tick at 1Hz; running bars and "next refresh" countdown depend on it.
|
||||
nowTimer = setInterval(() => {
|
||||
nowTick.value = Date.now()
|
||||
|
||||
Reference in New Issue
Block a user