fix(timeline): track fetch attempts and surface silent polling failures
User reported: spinner spinning + "更新于 X 秒前" continuously growing without bound while parsing is in progress. The auto-poll loop IS firing every 2s, but lastFetchedAt only updated on success — so when the API returns success=false or errors, the caption silently aged while the visible state suggested live polling. - Move lastFetchedAt update into the finally block so it tracks attempts (success or failure). The caption now bounces back to "刚刚 / 1s 前 / 刚刚" every poll cycle, matching the spinner's visual cadence. - Track failedAttempts and lastFetchOk: when the last attempt failed the timestamp shows in muted italic; when 2+ consecutive attempts fail a small "⚠ 刷新失败" pill appears next to it with a tooltip explaining the situation. - New i18n keys fetchFailed / fetchFailedShort in zh-CN/en-US/ko-KR. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -66,6 +66,13 @@ 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 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
|
||||
// indicator the user sees a spinning auto-refresh icon while the
|
||||
// caption ages without explanation.
|
||||
const failedAttempts = ref<number>(0)
|
||||
const lastFetchOk = ref<boolean>(true)
|
||||
|
||||
const attemptStatuses = reactive<Map<number, string>>(new Map())
|
||||
|
||||
@@ -132,11 +139,12 @@ async function fetchSpans(opts: { manual?: boolean } = {}) {
|
||||
if (!props.knowledgeId) return
|
||||
if (opts.manual) refreshing.value = true
|
||||
if (!data.value) loading.value = true
|
||||
let attemptOk = false
|
||||
try {
|
||||
const res: any = await getKnowledgeSpans(props.knowledgeId, selectedAttempt.value)
|
||||
if (res?.success && res.data) {
|
||||
data.value = res.data as SpansResponse
|
||||
lastFetchedAt.value = Date.now()
|
||||
attemptOk = true
|
||||
if (selectedAttempt.value === undefined) {
|
||||
selectedAttempt.value = data.value.attempt
|
||||
}
|
||||
@@ -151,6 +159,18 @@ async function fetchSpans(opts: { manual?: boolean } = {}) {
|
||||
} catch (e) {
|
||||
emit('update:hasSpans', false)
|
||||
} finally {
|
||||
// Track every attempt, not just successful ones — otherwise a
|
||||
// failing endpoint would leave "更新于 X 秒前" frozen forever while
|
||||
// the spinner spins. The user explicitly reported this confusing
|
||||
// behavior. Pair with failedAttempts to render a "fetch failed"
|
||||
// hint when consecutive errors pile up.
|
||||
lastFetchedAt.value = Date.now()
|
||||
lastFetchOk.value = attemptOk
|
||||
if (attemptOk) {
|
||||
failedAttempts.value = 0
|
||||
} else {
|
||||
failedAttempts.value += 1
|
||||
}
|
||||
loading.value = false
|
||||
refreshing.value = false
|
||||
}
|
||||
@@ -951,10 +971,21 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
|
||||
<!-- "Updated X ago" — always visible. While polling it
|
||||
stays small (1-2s); after parsing finishes it shows
|
||||
staleness when a user reopens the drawer hours later
|
||||
("更新于 3 小时前") so they know to hit refresh. -->
|
||||
("更新于 3 小时前") so they know to hit refresh. When
|
||||
consecutive fetches are failing we surface that —
|
||||
otherwise the caption would silently age while the
|
||||
spinner kept spinning. -->
|
||||
<div v-if="lastFetchedAt" class="kp-stat kp-stat-end">
|
||||
<span class="kp-stat-label">{{ t('knowledgeStages.head.updated') }}</span>
|
||||
<span class="kp-stat-val">{{ formatRelativeTime(lastFetchedAt) }}</span>
|
||||
<span
|
||||
class="kp-stat-val"
|
||||
:class="{ 'kp-stat-val-stale': !lastFetchOk }"
|
||||
>{{ formatRelativeTime(lastFetchedAt) }}</span>
|
||||
<span
|
||||
v-if="failedAttempts > 1"
|
||||
class="kp-stat-fail"
|
||||
:title="t('knowledgeStages.fetchFailed', { n: failedAttempts })"
|
||||
>⚠ {{ t('knowledgeStages.fetchFailedShort') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1542,6 +1573,28 @@ const stageBreakdown = computed<StageRowSummary[]>(() => {
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
/* Stale value styling — "更新于" goes muted/strikethrough-ish when the
|
||||
last fetch attempt failed, signaling that the timestamp may not
|
||||
reflect fresh server state. */
|
||||
.kp-stat-val-stale {
|
||||
color: var(--td-text-color-placeholder);
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* Inline "fetch failed" hint that lives next to "更新于". Surfaces
|
||||
silent polling failures (network errors, success=false responses)
|
||||
so the user knows the loop is running but not landing data. */
|
||||
.kp-stat-fail {
|
||||
margin-left: 6px;
|
||||
font-size: 11px;
|
||||
color: var(--td-error-color);
|
||||
background: var(--td-error-color-light);
|
||||
padding: 1px 6px;
|
||||
border-radius: var(--td-radius-default);
|
||||
letter-spacing: 0.02em;
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.kp-stat-num { color: var(--td-text-color-primary); }
|
||||
.kp-stat-slash { color: var(--td-text-color-placeholder); margin: 0 1px; }
|
||||
|
||||
|
||||
@@ -403,6 +403,8 @@ export default {
|
||||
liveTooltip: 'Parsing in progress — auto-refreshes every 2s',
|
||||
autoRefreshOn: 'Auto-refreshing',
|
||||
autoRefreshOff: 'Auto-refresh stopped',
|
||||
fetchFailed: 'Last {n} refreshes failed — data may be stale, click refresh to retry',
|
||||
fetchFailedShort: 'fetch failed',
|
||||
viewTrace: 'View trace',
|
||||
justNow: 'just now',
|
||||
secondsAgo: '{n}s ago',
|
||||
|
||||
@@ -409,6 +409,8 @@ export default {
|
||||
liveTooltip: "파싱 진행 중 — 2초마다 자동 새로고침",
|
||||
autoRefreshOn: "자동 새로고침 중",
|
||||
autoRefreshOff: "자동 새로고침 중지됨",
|
||||
fetchFailed: "최근 {n}회 새로고침 실패 — 데이터가 오래되었을 수 있습니다, 새로고침 버튼을 눌러 재시도하세요",
|
||||
fetchFailedShort: "새로고침 실패",
|
||||
viewTrace: "Trace 보기",
|
||||
justNow: "방금",
|
||||
secondsAgo: "{n}초 전",
|
||||
|
||||
@@ -406,6 +406,8 @@ export default {
|
||||
liveTooltip: "解析进行中,每 2 秒自动刷新一次",
|
||||
autoRefreshOn: "自动刷新中",
|
||||
autoRefreshOff: "已停止自动刷新",
|
||||
fetchFailed: "最近 {n} 次刷新都失败了,数据可能已过期,点击刷新按钮重试",
|
||||
fetchFailedShort: "刷新失败",
|
||||
viewTrace: "查看 Trace",
|
||||
justNow: "刚刚",
|
||||
secondsAgo: "{n} 秒前",
|
||||
|
||||
Reference in New Issue
Block a user