🌊 The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(performance): report recorded latency/throughput, not fixed figures (#4556)
Aaditya6c0d58d01098
diff --git a/v3/@claude-flow/cli/__tests__/performance-metrics-samples-4554.test.ts b/v3/@claude-flow/cli/__tests__/performance-metrics-samples-4554.test.tsnew file mode 100644index 0000000000..afe458cae9--- /dev/null+++ b/v3/@claude-flow/cli/__tests__/performance-metrics-samples-4554.test.ts@@ -0,0 +1,88 @@+/**+ * #4554: performance_metrics returned fixed latency/throughput literals+ * (current 45ms, p95 150ms, 1250 ops/s) and, for the default metric 'all',+ * labelled the response _real: true even with no samples recorded.+ * They now come from the samples performance_report stores (ADR-093 F8),+ * or are reported as unavailable.+ */+import { afterEach, beforeEach, describe, expect, it } from 'vitest';+import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join } from 'node:path';++const originalProjectCwd = process.env.CLAUDE_FLOW_CWD;+let scratch: string;++async function tool(name: string) {+ const { performanceTools } = await import('../src/mcp-tools/performance-tools.js');+ const t = performanceTools.find((c) => c.name === name)!;+ return (input: Record<string, unknown> = {}) => t.handler(input) as Promise<Record<string, any>>;+}++function seedSamples(latencies: number[], operations: number[]) {+ const dir = join(scratch, '.claude-flow', 'performance');+ mkdirSync(dir, { recursive: true });+ const metrics = latencies.map((avg, i) => ({+ timestamp: new Date(Date.UTC(2026, 0, 1, 0, i)).toISOString(),+ cpu: { usage: 10, cores: 4 },+ memory: { used: 100, total: 1000, heap: 10 },+ latency: { avg, p50: avg, p95: avg, p99: avg },+ throughput: { requests: i + 1, operations: operations[i] },+ errors: { count: 0, rate: 0 },+ }));+ writeFileSync(join(dir, 'metrics.json'), JSON.stringify({ metrics, benchmarks: {}, version: '3.0.0' }));+}++beforeEach(() => {+ scratch = mkdtempSync(join(tmpdir(), 'ruflo-4554-'));+ process.env.CLAUDE_FLOW_CWD = scratch;+});+afterEach(() => {+ if (originalProjectCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;+ else process.env.CLAUDE_FLOW_CWD = originalProjectCwd;+});++describe('performance_metrics latency/throughput (#4554)', () => {+ it('reports latency and throughput as unavailable when no samples exist, and all is not _real', async () => {+ const r = await (await tool('performance_metrics'))();+ // Baseline: _real true with latency { current: 45, p95: 150, ... } and throughput current 1250.+ expect(r._real).toBe(false);+ expect(r.metrics.latency).toMatchObject({ available: false, samples: 0, _real: false, unit: 'ms' });+ expect(r.metrics.latency.current).toBeUndefined();+ expect(r.metrics.throughput).toMatchObject({ available: false, samples: 0, _real: false, unit: 'ops/s' });+ expect(r.metrics.cpu._real).toBe(true);+ });++ it('returns a null value, not a fixed figure, for a single unavailable metric', async () => {+ const r = await (await tool('performance_metrics'))({ metric: 'latency', aggregation: 'p95' });+ expect(r).toMatchObject({ _real: false, metric: 'latency', value: null, unit: 'ms' });+ });++ it('aggregates the recorded samples', async () => {+ seedSamples([10, 20, 30], [2, 4, 6]);+ const t = await tool('performance_metrics');+ const all = await t();+ expect(all._real).toBe(true);+ expect(all.metrics.latency).toMatchObject({ current: 30, avg: 20, min: 10, max: 30, samples: 3, _real: true, unit: 'ms' });+ expect(all.metrics.throughput).toMatchObject({ current: 6, avg: 4, min: 2, max: 6, samples: 3, _real: true });+ const maxLatency = await t({ metric: 'latency', aggregation: 'max' });+ expect(maxLatency).toMatchObject({ _real: true, value: 30 });+ });++ it('does not claim _real for all when only some figures were measured', async () => {+ // Samples with latency but no throughput reading (e.g. an older store shape).+ seedSamples([10, 20], [Number.NaN, Number.NaN]);+ const all = await (await tool('performance_metrics'))();+ expect(all.metrics.latency).toMatchObject({ samples: 2, _real: true });+ expect(all.metrics.throughput).toMatchObject({ available: false, samples: 0, _real: false });+ expect(all._real).toBe(false);+ });++ it('picks up the sample performance_report records', async () => {+ await (await tool('performance_report'))();+ const r = await (await tool('performance_metrics'))();+ expect(r.metrics.latency).toMatchObject({ samples: 1, _real: true });+ expect(Number.isFinite(r.metrics.latency.current)).toBe(true);+ expect(r.metrics.latency.current).not.toBe(45);+ });+});diff --git a/v3/@claude-flow/cli/src/mcp-tools/performance-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/performance-tools.tsindex c197891103..37353fa132 100644--- a/v3/@claude-flow/cli/src/mcp-tools/performance-tools.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/performance-tools.ts@@ -660,6 +660,15 @@ export const performanceTools: MCPTool[] = [const cpuStats = calcStats(cpuHistory, cpuPercent);const memStats = calcStats(memHistory, memUsedMB);+ // #4554: latency/throughput used to be fixed literals (45ms, 1250 ops/s).+ // Report the samples performance_report records (ADR-093 F8), or say none exist.+ const sampled = (values: number[], unit: string) => {+ const real = values.filter(n => Number.isFinite(n));+ return real.length === 0+ ? { available: false, unit, samples: 0, _real: false, _note: 'No samples recorded yet: run performance_report to record one.' }+ : { ...calcStats(real, real[real.length - 1]), unit, samples: real.length, _real: true };+ };+const allMetrics = {cpu: {...cpuStats,@@ -678,31 +687,13 @@ export const performanceTools: MCPTool[] = [unit: 'MB',_real: true,},- latency: {- current: 45,- avg: 52,- min: 15,- max: 250,- p50: 48,- p95: 150,- p99: 220,- unit: 'ms',- },- throughput: {- current: 1250,- avg: 1100,- min: 500,- max: 2000,- p50: 1050,- p95: 1800,- p99: 1950,- unit: 'ops/s',- },+ latency: sampled(history.map(m => m.latency?.avg), 'ms'),+ throughput: sampled(history.map(m => m.throughput?.operations), 'ops/s'),};if (metric === 'all') {return {- _real: true,+ _real: Object.values(allMetrics).every(m => m._real),metrics: allMetrics,aggregation,historySize: history.length,@@ -712,9 +703,9 @@ export const performanceTools: MCPTool[] = [const selectedMetric = allMetrics[metric as keyof typeof allMetrics];return {- _real: ['cpu', 'memory'].includes(metric),+ _real: selectedMetric._real,metric,- value: selectedMetric[aggregation as keyof typeof selectedMetric],+ value: (selectedMetric as Record<string, unknown>)[aggregation] ?? null,unit: selectedMetric.unit,details: selectedMetric,timestamp: new Date().toISOString(),