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
15 changes: 14 additions & 1 deletion cmd/mcpproxy/activity_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,8 @@ func runActivitySummary(cmd *cobra.Command, _ []string) error {
// Table output
period := getStringField(summary, "period")
totalCount := getIntField(summary, "total_count")
callCount := getIntField(summary, "call_count")
callErrorCount := getIntField(summary, "call_error_count")
successCount := getIntField(summary, "success_count")
errorCount := getIntField(summary, "error_count")
blockedCount := getIntField(summary, "blocked_count")
Expand All @@ -1808,9 +1810,20 @@ func runActivitySummary(cmd *cobra.Command, _ []string) error {
blockedPct = float64(blockedCount) / float64(totalCount) * 100
}

// "Total Calls" used to print total_count, which counts every activity
// record — security scans, quarantine auto-approvals, system starts — so the
// CLI, the Web UI's Usage tab and the tray all reported different totals for
// the same window (audit finding F1, #1046). Events and calls are separate
// rows now, and the call row is the number every other surface shows.
callErrorPct := float64(0)
if callCount > 0 {
callErrorPct = float64(callErrorCount) / float64(callCount) * 100
}

fmt.Printf("%-15s %s\n", "METRIC", "VALUE")
fmt.Printf("%-15s %s\n", strings.Repeat("-", 15), strings.Repeat("-", 20))
fmt.Printf("%-15s %d\n", "Total Calls", totalCount)
fmt.Printf("%-15s %d\n", "Total Events", totalCount)
fmt.Printf("%-15s %d (%.1f%% failed)\n", "Calls", callCount, callErrorPct)
fmt.Printf("%-15s %d (%.1f%%)\n", "Successful", successCount, successPct)
fmt.Printf("%-15s %d (%.1f%%)\n", "Errors", errorCount, errorPct)
fmt.Printf("%-15s %d (%.1f%%)\n", "Blocked", blockedCount, blockedPct)
Expand Down
5 changes: 4 additions & 1 deletion docs/cli/activity-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@ Activity Summary (last 24h)

METRIC VALUE
─────── ─────
Total Calls 150
Total Events 150
Calls 128 (3.9% failed)
Successful 142 (94.7%)
Errors 5 (3.3%)
Blocked 3 (2.0%)
Expand All @@ -384,6 +385,8 @@ database:query 15 calls
{
"period": "24h",
"total_count": 150,
"call_count": 128,
"call_error_count": 5,
"success_count": 142,
"error_count": 5,
"blocked_count": 3,
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/components/ActivityWidget.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@

<!-- Summary Stats Row -->
<div v-if="summary" class="stats stats-horizontal bg-base-200 mb-4">
<!-- Rows in the window; only some of them are calls (F1, #1046). -->
<div class="stat py-2 px-4">
<div class="stat-title text-xs">Today</div>
<div class="stat-title text-xs">Events (24h)</div>
<div class="stat-value text-lg">{{ summary.total_count }}</div>
</div>
<div class="stat py-2 px-4">
<div class="stat-title text-xs">Calls</div>
<div class="stat-value text-lg">{{ summary.call_count }}</div>
</div>
<div class="stat py-2 px-4">
<div class="stat-title text-xs">Success</div>
<!-- Success is the norm — it gets no colour, so Errors can have it. -->
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,12 @@ export interface UsageAggregateResponse {
tools: UsageToolStat[]
other?: UsageOtherBucket | null // present only when list truncated to top-N
timeline: UsageTimeBucket[]
// Headline counts for the window, computed server-side as the sum of the
// timeline above. NOT a sum of `tools`: that list is lifetime-cumulative,
// upstream-only and truncated to top-N. Same population as
// ActivitySummaryResponse.call_count (audit finding F1, #1046).
total_calls: number
total_errors: number
}

export type UsageWindow = '24h' | '7d' | 'all'
Expand Down Expand Up @@ -807,6 +813,14 @@ export interface ActivitySummaryResponse {
error_count: number
blocked_count: number
rejected_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
// Usage tab counts the second population, so the header must label the two
// apart or the same instance reports different totals on two screens
// (audit finding F1/F24, #1046).
call_count: number
call_error_count: number
top_servers?: ActivityTopServer[]
top_tools?: ActivityTopTool[]
start_time: string
Expand Down
45 changes: 40 additions & 5 deletions frontend/src/utils/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,19 @@ export const shortId = (id: string): string => (id.length > 8 ? `…${id.slice(-

/** One segment of the compact counts strip. */
export interface CompactSummaryPart {
key: 'total' | 'error' | 'blocked' | 'rejected'
key: 'total' | 'calls' | 'error' | 'blocked' | 'rejected'
label: string
tone: StatusTone
/** Status value this segment filters to; '' clears the status filter. */
status: string
/** False for segments that describe the list without narrowing it. */
filterable: boolean
}

interface ActivitySummaryCounts {
total_count?: number
/** Calls the user made — the population the Usage tab counts (F1, #1046). */
call_count?: number
error_count?: number
blocked_count?: number
rejected_count?: number
Expand All @@ -365,30 +369,59 @@ interface ActivitySummaryCounts {
const plural = (n: number, one: string, many: string): string => `${n} ${n === 1 ? one : many}`

/**
* Compact counts strip, e.g. "54 calls · 6 errors · 1 blocked". The total is
* always present and muted; a zero attention count is omitted entirely rather
* than rendered as a reassuring "0 errors" that costs a line of scanning.
* Compact counts strip, e.g. "70 events · 42 calls · 6 errors · 1 blocked".
*
* "Events" and "calls" are two different questions and this strip used to print
* the first under the second's name: the header read "70 calls" for a window
* whose rows included security scans, quarantine auto-approvals and a system
* start, while the Usage tab — counting only calls — read 42 for the same 24
* hours (audit finding F1/F24, #1046). The event total is the paginator's
* denominator, so it stays; it just says what it is, and the call count that
* matches the Usage tab sits beside it.
*
* A zero attention count is omitted entirely rather than rendered as a
* reassuring "0 errors" that costs a line of scanning.
*/
export const compactSummaryParts = (
summary?: ActivitySummaryCounts | null
): CompactSummaryPart[] => {
if (!summary) return []

const total = summary.total_count ?? 0
const calls = summary.call_count
// Every row is a call: one segment, and it can say so.
const allRowsAreCalls = calls === total

const parts: CompactSummaryPart[] = [
{
key: 'total',
label: plural(summary.total_count ?? 0, 'call', 'calls'),
label: allRowsAreCalls
? plural(total, 'call', 'calls')
: plural(total, 'event', 'events'),
tone: 'muted',
status: '',
filterable: true,
},
]

// No status selects "calls", so this segment describes rather than filters.
if (calls !== undefined && !allRowsAreCalls) {
parts.push({
key: 'calls',
label: plural(calls, 'call', 'calls'),
tone: 'muted',
status: '',
filterable: false,
})
}

if ((summary.error_count ?? 0) > 0) {
parts.push({
key: 'error',
label: plural(summary.error_count as number, 'error', 'errors'),
tone: 'error',
status: 'error',
filterable: true,
})
}
if ((summary.blocked_count ?? 0) > 0) {
Expand All @@ -397,6 +430,7 @@ export const compactSummaryParts = (
label: `${summary.blocked_count} blocked`,
tone: 'warning',
status: 'blocked',
filterable: true,
})
}
if ((summary.rejected_count ?? 0) > 0) {
Expand All @@ -405,6 +439,7 @@ export const compactSummaryParts = (
label: `${summary.rejected_count} rejected`,
tone: 'neutral',
status: 'rejected',
filterable: true,
})
}

Expand Down
32 changes: 32 additions & 0 deletions frontend/src/utils/usageFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ export function formatLatency(ms: number | null | undefined): string {
return `${Math.round(ms)} ms`
}

/** The window's headline counts, as the Usage tiles print them. */
export interface UsageHeadline {
calls: number
errors: number
/** Percentage, one decimal, as a string — "0.0" when the window is empty. */
errorRate: string
}

/**
* Headline counts for the selected window.
*
* These come from the response, not from summing `tools`. Summing `tools`
* client-side was the Usage half of audit finding F1 (#1046): that list is
* lifetime-cumulative (the window only filters which tools appear), counts
* upstream tools only (so mcpproxy's own retrieve_tools and describe_tool calls
* vanished), and is truncated to top-N (so a high-cardinality log silently lost
* the tail). The result was a "Tool calls" tile that disagreed with the
* "Activity over time" chart printed directly beneath it AND with the Activity
* Log. `total_calls` / `total_errors` are the sum of that same chart.
*/
export function usageHeadline(
data?: { total_calls?: number; total_errors?: number } | null
): UsageHeadline {
const calls = data?.total_calls ?? 0
const errors = data?.total_errors ?? 0
return {
calls,
errors,
errorRate: calls > 0 ? ((errors / calls) * 100).toFixed(1) : '0.0',
}
}

/** A short, readable label for a (server, tool) pair. */
export function toolLabel(server: string, tool: string): string {
return `${server}:${tool}`
Expand Down
18 changes: 17 additions & 1 deletion frontend/src/views/Activity.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<template v-for="(part, idx) in summaryParts" :key="part.key">
<span v-if="idx > 0" class="text-base-content/25" aria-hidden="true">·</span>
<button
v-if="part.filterable"
type="button"
:data-test="`activity-compact-${part.key}`"
:class="[
Expand All @@ -61,6 +62,15 @@
>
{{ part.label }}
</button>
<!-- No status filters to "calls", so this one only reports. -->
<span
v-else
:data-test="`activity-compact-${part.key}`"
:class="['text-sm', summaryToneClass(part.tone)]"
title="Calls the user made in the last 24h — the same count the Usage tab shows. The rest of the rows are events: security scans, quarantine changes, system start."
>
{{ part.label }}
</span>
</template>
</div>

Expand Down Expand Up @@ -146,8 +156,14 @@
:aria-pressed="filterStatus === ''"
@click="filterStatus = ''"
>
<div class="stat-title">Total (24h)</div>
<!--
Rows in the window, not calls: the status tiles beside it are a split
of this, and a security scan or a quarantine auto-approval is one of
these and not one of those (F1/F24, #1046).
-->
<div class="stat-title">Events (24h)</div>
<div class="stat-value text-2xl">{{ summary.total_count }}</div>
<div class="stat-desc">{{ summary.call_count }} calls</div>
</button>
<button
type="button"
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/views/Usage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,20 @@
<div class="stat-value text-success">{{ formatNumber(data.tokens_saved) }}</div>
<div class="stat-desc">{{ data.tokens_saved_percentage.toFixed(1) }}% reduction via BM25 discovery</div>
</div>
<div class="stat">
<div class="stat-title">Tool calls</div>
<div class="stat-value">{{ formatNumber(totalCalls) }}</div>
<!--
Calls and errors come from the response, which counts the same
population as the Activity Log's own header — see usageHeadline for why
summing `tools` here was wrong (F1, #1046).
-->
<div class="stat" data-test="usage-calls-tile">
<div class="stat-title">Calls</div>
<div class="stat-value">{{ formatNumber(headline.calls) }}</div>
<div class="stat-desc">{{ data.tools.length }} active tool{{ data.tools.length === 1 ? '' : 's' }} ({{ windowLabel }})</div>
</div>
<div class="stat">
<div class="stat" data-test="usage-errors-tile">
<div class="stat-title">Errors</div>
<div class="stat-value" :class="totalErrors > 0 ? 'text-error' : ''">{{ formatNumber(totalErrors) }}</div>
<div class="stat-desc">{{ overallErrorRate }}% overall error rate</div>
<div class="stat-value" :class="headline.errors > 0 ? 'text-error' : ''">{{ formatNumber(headline.errors) }}</div>
<div class="stat-desc">{{ headline.errorRate }}% overall error rate</div>
</div>
</div>

Expand Down Expand Up @@ -122,7 +127,7 @@
import { ref, computed, onMounted, onUnmounted } from 'vue'
import api from '@/services/api'
import type { UsageAggregateResponse, UsageWindow, UsageSort, UsageStatus } from '@/types'
import { formatNumber } from '@/utils/usageFormat'
import { formatNumber, usageHeadline } from '@/utils/usageFormat'
import CallHistogram from '@/components/usage/CallHistogram.vue'
import ResponseSizeRanking from '@/components/usage/ResponseSizeRanking.vue'
import ErrorRateChart from '@/components/usage/ErrorRateChart.vue'
Expand Down Expand Up @@ -151,12 +156,7 @@ const windowLabel = computed(() => {
}
})

const totalCalls = computed(() => data.value?.tools.reduce((s, t) => s + t.calls, 0) ?? 0)
const totalErrors = computed(() => data.value?.tools.reduce((s, t) => s + t.errors, 0) ?? 0)
const overallErrorRate = computed(() => {
const c = totalCalls.value
return c > 0 ? ((totalErrors.value / c) * 100).toFixed(1) : '0.0'
})
const headline = computed(() => usageHeadline(data.value))

const isEmpty = computed(() => {
if (!data.value) return false
Expand Down
5 changes: 4 additions & 1 deletion frontend/tests/unit/activity-compact-view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ vi.mock('@/services/api', () => {
ok({
period: '24h',
total_count: 54,
call_count: 42,
success_count: 47,
error_count: 6,
blocked_count: 1,
Expand Down Expand Up @@ -104,7 +105,9 @@ describe('Activity Log — compact header', () => {

const strip = wrapper.find('[data-test="activity-compact-summary"]')
expect(strip.exists()).toBe(true)
expect(strip.text()).toContain('54 calls')
// Rows in the window are events; only 42 of them are calls (F1, #1046).
expect(strip.text()).toContain('54 events')
expect(strip.text()).toContain('42 calls')
expect(strip.text()).toContain('6 errors')
expect(strip.text()).toContain('1 blocked')
// Zero rejected never earns a segment.
Expand Down
Loading
Loading