Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/request-attempt-timeline.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
### English

- The request log detail draws each failover attempt on a shared timeline, so a slow or failed account reads as a bar instead of a row of numbers.

### 中文

- 请求日志详情把每一次故障转移画在同一条时间轴上,慢账号和失败账号一眼就能看出来,不再只是一行数字。
201 changes: 201 additions & 0 deletions frontend/src/components/logview/RequestTimeline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
import { useLayoutEffect, useRef, useState } from 'react'
import { formatLatency } from '@/lib/format'
import { prefersReducedMotion } from '@/lib/motion'
import type { RequestAttempt, RequestLog } from '@/api/logs'

/*
* Request timeline for one logged call.
*
* The bar layout — a span as wide as it took, placed where it started, with the
* axis rescaling when the run outgrows it — follows affectui "Trace Waterfall"
* (components/trace-waterfall-clean.tsx), https://github.com/flohoeller/affectui
*
* MIT License
* Copyright (c) 2026 Florian Höller (adfects)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Local changes: the spans are this console's request attempts (account, status,
* latency) rather than an agent trace tree; colors come from the console status
* tokens instead of the original indigo/teal kind palette; the axis and bars
* ease with the console's 220ms motion instead of a 720ms rescale.
*/

const RESCALE_MS = 220

type Translate = (key: string, vars?: Record<string, string | number>) => string

type Span = {
id: string
index: number
name: string
detail: string
start: number
end: number
tone: 'success' | 'warning' | 'danger' | 'muted'
latency?: number | null
}

const TONES = {
success: 'var(--success)',
warning: 'var(--warning)',
danger: 'var(--danger)',
muted: 'var(--muted)',
} as const

function toneOf(status: string): Span['tone'] {
if (status === 'ok') return 'success'
if (status === 'streaming' || status === 'started' || status === 'incomplete') return 'warning'
if (status === 'error' || status === 'canceled' || status === 'failover') return 'danger'
return 'muted'
}

function spansOf(log: RequestLog, nameOf: (accountId?: string) => string): Span[] {
const origin = Date.parse(log.created_at)
const base = Number.isFinite(origin) ? origin : 0
const attempts = [...(log.attempts ?? [])].sort((a, b) => a.attempt_index - b.attempt_index)
return attempts.map((attempt) => spanOf(attempt, base, nameOf))
}

function spanOf(attempt: RequestAttempt, base: number, nameOf: (accountId?: string) => string): Span {
const started = Date.parse(attempt.started_at)
const start = Number.isFinite(started) ? Math.max(0, started - base) : 0
const latency = attempt.latency_ms
const finished = attempt.finished_at ? Date.parse(attempt.finished_at) : NaN
const end = Number.isFinite(finished)
? Math.max(start, finished - base)
: start + (latency != null && latency > 0 ? latency : 0)
const detail = [attempt.error_kind, attempt.http_status ? String(attempt.http_status) : '']
.filter(Boolean)
.join(' · ')
return {
id: attempt.id,
index: attempt.attempt_index,
name: nameOf(attempt.account_id),
detail,
start,
end: Math.max(start, end),
tone: toneOf(attempt.status),
latency,
}
}

/** Smallest axis that fits the run, rounded up to a readable step. */
function rangeFor(end: number) {
const target = Math.max(end, 1)
const steps = [1, 2, 5]
let magnitude = 1
for (let i = 0; i < 8; i += 1) {
for (const step of steps) {
const range = step * magnitude
if (range >= target) return range
}
magnitude *= 10
}
return target
}

function useAxis(range: number) {
const [shown, setShown] = useState(range)
const from = useRef(range)
useLayoutEffect(() => {
if (prefersReducedMotion() || from.current === range) {
from.current = range
setShown(range)
return
}
const start = from.current
const began = performance.now()
let frame = 0
const tick = (now: number) => {
const t = Math.min(1, (now - began) / RESCALE_MS)
const eased = 1 - (1 - t) ** 3
setShown(start + (range - start) * eased)
if (t < 1) frame = requestAnimationFrame(tick)
else from.current = range
}
frame = requestAnimationFrame(tick)
return () => cancelAnimationFrame(frame)
}, [range])
return shown
}

export function RequestTimeline({
log,
nameOf,
t,
}: {
log: RequestLog
nameOf: (accountId?: string) => string
t: Translate
}) {
const spans = spansOf(log, nameOf)
const end = spans.reduce((max, span) => Math.max(max, span.end), 0)
const axis = useAxis(rangeFor(end * 1.08))
const ticks = [0, 0.5, 1].map((share) => ({ share, label: formatLatency(axis * share) }))

if (spans.length === 0) return null

return (
<div className="space-y-2">
<div className="relative h-4">
{ticks.map((tick) => (
<span
key={tick.share}
className="mono absolute top-0 -translate-x-1/2 text-caption text-muted first:translate-x-0 last:-translate-x-full"
style={{ left: `${tick.share * 100}%` }}
>
{tick.label}
</span>
))}
</div>
<ol className="space-y-1.5">
{spans.map((span, index) => {
const width = Math.max(0, span.end - span.start)
const left = axis > 0 ? (span.start / axis) * 100 : 0
const size = axis > 0 ? Math.max((width / axis) * 100, 0.8) : 0
return (
<li key={span.id} className="grid grid-cols-[9rem_minmax(0,1fr)] items-center gap-3">
<div className="min-w-0">
<div className="truncate text-caption font-medium text-foreground">
<span className="mono mr-1.5 text-muted">#{span.index || index + 1}</span>
{span.name}
</div>
{span.detail ? <div className="mono truncate text-caption text-muted">{span.detail}</div> : null}
</div>
<div className="relative h-2 rounded-full bg-surface-secondary">
<span
className="absolute inset-y-0 rounded-full"
style={{
left: `${left}%`,
width: `${Math.min(size, 100 - left)}%`,
background: TONES[span.tone],
transition: prefersReducedMotion() ? undefined : `left ${RESCALE_MS}ms, width ${RESCALE_MS}ms`,
}}
title={formatLatency(span.latency ?? width)}
/>
</div>
</li>
)
})}
</ol>
<p className="text-caption text-muted">{t('logsTimelineHint')}</p>
</div>
)
}
2 changes: 2 additions & 0 deletions frontend/src/i18n/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ export const messages: Record<Lang, Dict> = {
logsRouting_sticky: 'Session sticky',
logsRouting_sticky_escape: 'Session escape',
logsNoAttempts: 'No attempt details.',
logsTimelineHint: 'Each bar starts when that attempt did and is as wide as it took.',
logsStreamDiagnostics: 'Stream diagnostics',
logsMessageShape: 'Message shape',
logsMessageCount: 'Messages',
Expand Down Expand Up @@ -1744,6 +1745,7 @@ export const messages: Record<Lang, Dict> = {
logsRouting_sticky: '会话粘性',
logsRouting_sticky_escape: '粘性逃逸',
logsNoAttempts: '没有尝试详情。',
logsTimelineHint: '每条从该次尝试开始的时刻起算,长短即耗时。',
logsStreamDiagnostics: '流诊断',
logsMessageShape: '消息结构',
logsMessageCount: '消息数',
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/LogsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { FilterToggle } from '@/components/ui/FilterToggle'
import { ListPager, type PageSize } from '@/components/ui/ListPager'
import { PageAlert } from '@/components/ui/PageAlert'
import { LogsPageSkeleton, LogsRequestListSkeleton, LogsRuntimeListSkeleton, SkeletonBlock } from '@/components/ui/PageSkeletons'
import { RequestTimeline } from '@/components/logview/RequestTimeline'
import { LatencyStats } from '@/components/ui/LatencyStats'
import { computeOutputTokensPerSecond, formatBytes, formatLatency, formatTokensPerSecond } from '@/lib/format'
import { SearchBar } from '@/components/ui/SearchBar'
Expand Down Expand Up @@ -1095,6 +1096,13 @@ export function LogsPage() {
title={t('logsAttempts')}
aside={selected.attempts?.length ? <span className="mono text-caption text-muted">{selected.attempts.length}</span> : null}
>
{selected.attempts?.length ? (
<RequestTimeline
log={selected}
t={t}
nameOf={(accountId) => (accountId ? (accountNameById.get(accountId) || accountId) : '—')}
/>
) : null}
{selected.attempts?.length ? (
<div className="divide-y divide-separator overflow-hidden rounded-lg bg-surface-secondary">
{selected.attempts.map((attempt) => (
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading