Skip to content
Merged
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
50 changes: 40 additions & 10 deletions frontend/src/components/usage/CallHistogram.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
<div data-test="usage-call-histogram">
<div class="flex items-center justify-between mb-2">
<h3 class="font-semibold text-sm">Calls per tool</h3>
<span class="text-xs opacity-60">{{ tools.length }} tool{{ tools.length === 1 ? '' : 's' }}</span>
<span class="text-xs opacity-60">{{ charted.length }} tool{{ charted.length === 1 ? '' : 's' }}</span>
</div>
<div v-if="tools.length === 0" class="text-sm opacity-60 py-8 text-center" data-test="usage-call-histogram-empty">
No tool calls in this window.
<div v-if="charted.length === 0" class="text-sm opacity-60 py-8 text-center" data-test="usage-call-histogram-empty">
No completed tool calls in this window.
</div>
<div v-else class="relative" :style="{ height: chartHeight }">
<Bar :data="chartData" :options="chartOptions" />
</div>
<!--
Names that came from failed calls are not a catalog (F22, #1046). They are
named here, once, so they are not hidden either — the Errors & latency
chart below still charts them.
-->
<p
v-if="unresolved.length > 0"
data-test="usage-call-histogram-unresolved"
class="text-xs opacity-50 mt-2"
:title="unresolvedLabels"
>
{{ unresolved.length }} name{{ unresolved.length === 1 ? '' : 's' }} never completed a call
and {{ unresolved.length === 1 ? 'is' : 'are' }} excluded here — see “Errors &amp; latency”.
</p>
</div>
</template>

Expand All @@ -26,22 +40,33 @@ import {
} from 'chart.js'
import type { ChartOptions } from 'chart.js'
import type { UsageToolStat } from '@/types'
import { formatNumber, toolLabel, paletteColor } from '@/utils/usageFormat'
import { formatNumber, partitionUsageTools, toolLabel, paletteColor } from '@/utils/usageFormat'

ChartJS.register(BarElement, CategoryScale, LinearScale, Tooltip, Legend)

const props = defineProps<{ tools: UsageToolStat[] }>()

// This chart answers "what do my agents use". A name that has never once
// completed a call answers nothing about use — it is a typo the agent made or a
// server that was never reachable, and charting it invents a tool catalog out
// of failures (audit finding F22, #1046).
const split = computed(() => partitionUsageTools(props.tools))
const charted = computed(() => split.value.completed)
const unresolved = computed(() => split.value.unresolved)
const unresolvedLabels = computed(() =>
unresolved.value.map(t => toolLabel(t.server, t.tool)).join(', ')
)

// Horizontal bars so long server:tool labels stay readable on high cardinality.
const chartHeight = computed(() => `${Math.max(160, props.tools.length * 28 + 40)}px`)
const chartHeight = computed(() => `${Math.max(160, charted.value.length * 28 + 40)}px`)

const chartData = computed(() => ({
labels: props.tools.map(t => toolLabel(t.server, t.tool)),
labels: charted.value.map(t => toolLabel(t.server, t.tool)),
datasets: [
{
label: 'Calls',
data: props.tools.map(t => t.calls),
backgroundColor: props.tools.map((_, i) => paletteColor(i)),
data: charted.value.map(t => t.calls),
backgroundColor: charted.value.map((_, i) => paletteColor(i)),
borderWidth: 0,
borderRadius: 3,
},
Expand All @@ -57,7 +82,7 @@ const chartOptions = computed<ChartOptions<'bar'>>(() => ({
tooltip: {
callbacks: {
label: (ctx) => {
const t = props.tools[ctx.dataIndex]
const t = charted.value[ctx.dataIndex]
if (!t) return ''
const errPart = t.errors > 0 ? ` · ${formatNumber(t.errors)} errors` : ''
return `${formatNumber(t.calls)} calls${errPart}`
Expand All @@ -66,7 +91,12 @@ const chartOptions = computed<ChartOptions<'bar'>>(() => ({
},
},
scales: {
x: { beginAtZero: true, ticks: { callback: (v) => formatNumber(Number(v)) } },
// Say what the bars measure. An unlabelled axis is guesswork (F22, #1046).
x: {
beginAtZero: true,
title: { display: true, text: 'Calls (cumulative)' },
ticks: { callback: (v) => formatNumber(Number(v)) },
},
y: { ticks: { autoSkip: false, font: { size: 11 } } },
},
}))
Expand Down
43 changes: 34 additions & 9 deletions frontend/src/components/usage/ErrorRateChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,44 @@
No tool calls in this window.
</div>
<template v-else>
<!-- Error rate per tool -->
<!-- Error rate per tool. The bars and the table below measure DIFFERENT
things; each says which (F22, #1046). -->
<p class="text-xs opacity-50 mb-1">Bars: share of calls that failed, per tool.</p>
<div class="relative mb-4" :style="{ height: chartHeight }">
<Bar :data="chartData" :options="chartOptions" />
</div>
<!-- Per-tool p50/p95 latency (FR: tail-latency visibility, T019) -->
<p class="text-xs opacity-50 mb-1">
Table: latency percentiles, read off a fixed histogram — each figure is
the bucket bound the percentile falls in, not a measured duration.
</p>
<div class="overflow-x-auto">
<table class="table table-xs" data-test="usage-latency-table">
<thead>
<tr>
<th>Tool</th>
<th class="text-right">p50</th>
<th class="text-right">p95</th>
<th class="text-right">Err%</th>
<th class="text-right" title="Median latency, bounded by its histogram bucket">p50</th>
<th class="text-right" title="95th-percentile latency, bounded by its histogram bucket">p95</th>
<th class="text-right" title="Share of this tool's calls that failed">Err%</th>
</tr>
</thead>
<tbody>
<tr v-for="t in latencyRows" :key="`${t.server}:${t.tool}`">
<td class="font-mono text-xs truncate max-w-[12rem]">{{ toolLabel(t.server, t.tool) }}</td>
<td class="text-right font-mono text-xs">{{ formatLatency(t.p50_ms) }}</td>
<td class="text-right font-mono text-xs">{{ formatLatency(t.p95_ms) }}</td>
<td class="font-mono text-xs truncate max-w-[12rem]">
{{ toolLabel(t.server, t.tool) }}
<!-- A name that never completed a call has no latency to report
and is not evidence that such a tool exists. -->
<span
v-if="neverCompleted(t)"
data-test="usage-latency-unresolved"
class="opacity-50"
title="Never completed a call — no successful response was ever recorded for this name"
>
·&nbsp;unresolved
</span>
</td>
<td class="text-right font-mono text-xs">{{ formatLatencyBound(t.p50_ms, t.p50_exceeds) }}</td>
<td class="text-right font-mono text-xs">{{ formatLatencyBound(t.p95_ms, t.p95_exceeds) }}</td>
<td class="text-right font-mono text-xs" :class="t.error_rate > 0 ? 'text-error' : 'opacity-60'">
{{ (t.error_rate * 100).toFixed(1) }}%
</td>
Expand All @@ -49,7 +67,7 @@ import {
} from 'chart.js'
import type { ChartOptions } from 'chart.js'
import type { UsageToolStat } from '@/types'
import { formatNumber, formatLatency, toolLabel } from '@/utils/usageFormat'
import { formatNumber, formatLatencyBound, neverCompleted, toolLabel } from '@/utils/usageFormat'

ChartJS.register(BarElement, CategoryScale, LinearScale, Tooltip, Legend)

Expand Down Expand Up @@ -92,7 +110,14 @@ const chartOptions = computed<ChartOptions<'bar'>>(() => ({
},
},
scales: {
x: { beginAtZero: true, max: 100, ticks: { callback: (v) => `${v}%` } },
// The bars are an error RATE and the table beneath them is a latency; with
// no axis title the two read as one chart (F22, #1046).
x: {
beginAtZero: true,
max: 100,
title: { display: true, text: 'Error rate (% of calls)' },
ticks: { callback: (v) => `${v}%` },
},
y: { ticks: { autoSkip: false, font: { size: 11 } } },
},
}))
Expand Down
17 changes: 12 additions & 5 deletions frontend/src/components/usage/ResponseSizeRanking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@ import {
} from 'chart.js'
import type { ChartOptions } from 'chart.js'
import type { UsageToolStat } from '@/types'
import { formatBytes, toolLabel, paletteColor } from '@/utils/usageFormat'
import { formatBytes, partitionUsageTools, toolLabel, paletteColor } from '@/utils/usageFormat'

ChartJS.register(BarElement, CategoryScale, LinearScale, Tooltip, Legend)

const props = defineProps<{ tools: UsageToolStat[] }>()

// Rank by total response bytes descending; drop tools with no sized output.
// Rank by total response bytes descending; drop tools with no sized output, and
// tools that never completed a call. An error message is a response with bytes,
// so without the second filter a name that only ever failed — an agent's typo,
// an unreachable server — ranked as a "token sink" (audit finding F22, #1046).
const ranked = computed(() =>
[...props.tools]
.filter(t => t.total_resp_bytes > 0)
partitionUsageTools(props.tools)
.completed.filter(t => t.total_resp_bytes > 0)
.sort((a, b) => b.total_resp_bytes - a.total_resp_bytes)
)

Expand Down Expand Up @@ -77,7 +80,11 @@ const chartOptions = computed<ChartOptions<'bar'>>(() => ({
},
},
scales: {
x: { beginAtZero: true, ticks: { callback: (v) => formatBytes(Number(v)) } },
x: {
beginAtZero: true,
title: { display: true, text: 'Total response bytes' },
ticks: { callback: (v) => formatBytes(Number(v)) },
},
y: { ticks: { autoSkip: false, font: { size: 11 } } },
},
}))
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/stores/servers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ export const useServersStore = defineStore('servers', () => {
const loaded = ref(false)

// Computed
// Audit finding F27 (#1046): these counts are printed side by side, so they
// have to be answerable as one picture. `disabled` is the count of servers
// switched off AND not already counted as quarantined — the Dashboard rail
// shows both, and a server that was both read as two separate problems. It is
// also asked directly rather than derived as (total − connected − quarantined),
// which mislabelled an enabled-but-unreachable server as "disabled".
const serverCount = computed(() => ({
total: servers.value.length,
connected: servers.value.filter(isServerConnected).length,
enabled: servers.value.filter(s => s.enabled).length,
quarantined: servers.value.filter(s => s.quarantined).length,
disabled: servers.value.filter(s => !s.enabled && !s.quarantined).length,
}))

const connectedServers = computed(() =>
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,13 @@ export interface UsageToolStat {
total_req_bytes: number
avg_req_bytes: number | null
sized_calls: number
// Bucket BOUNDS, not measurements: the true percentile is at or below the
// value, except in the unbounded overflow bucket, where *_exceeds flips it to
// a floor. Render through formatLatencyBound (audit finding F22, #1046).
p50_ms: number
p50_exceeds: boolean
p95_ms: number
p95_exceeds: boolean
last_used: string
}

Expand Down Expand Up @@ -816,6 +821,12 @@ export interface ActivitySummaryResponse {
error_count: number
blocked_count: number
rejected_count: number
// Rows whose status is outside the tool-call vocabulary — a quarantine
// change's action, a policy decision's verdict. Present so that
// success + error + blocked + rejected + other == total_count, which is what
// makes the status tiles a partition instead of four numbers that add up to
// less than the denominator printed beside them (audit finding F2, #1046).
other_count: number
// total_count is how many ROWS the log has in the period; call_count is how
// many of them are calls the user made (the rest — system starts, security
// scans, quarantine auto-approvals, management chatter — are events). The
Expand Down
Loading
Loading