Skip to content

armgit / ruflo

Public Imported from GitHub
0

🌊 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

fix(daa): record performanceScore 0 as a failure, not a 0.8 success (#4427)

Aaditya55cb051880be
diff --git a/v3/@claude-flow/cli/__tests__/daa-agent-adapt-score-4426.test.ts b/v3/@claude-flow/cli/__tests__/daa-agent-adapt-score-4426.test.ts
new file mode 100644
index 0000000000..48918b2d39
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/daa-agent-adapt-score-4426.test.ts
@@ -0,0 +1,71 @@
+/**
+ * #4426: daa_agent_adapt used `(input.performanceScore as number) || 0.8`, so a
+ * failing score of 0, and a missing score, were averaged into successRate and
+ * sent to AgentDB as a 0.8 success. Out-of-range scores were accepted.
+ */
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
+import { mkdtempSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+
+const { bridgeRecordFeedback } = vi.hoisted(() => ({ bridgeRecordFeedback: vi.fn(async () => undefined) }));
+vi.mock('../src/memory/memory-bridge.js', () => ({ bridgeRecordFeedback }));
+
+const originalProjectCwd = process.env.CLAUDE_FLOW_CWD;
+
+async function tools() {
+ const { daaTools } = await import('../src/mcp-tools/daa-tools.js');
+ const get = (name: string) => daaTools.find((t) => t.name === name)!;
+ return {
+ create: (id: string) => get('daa_agent_create').handler({ id }) as Promise<Record<string, any>>,
+ adapt: (input: Record<string, unknown>) => get('daa_agent_adapt').handler(input) as Promise<Record<string, any>>,
+ };
+}
+
+beforeEach(() => {
+ process.env.CLAUDE_FLOW_CWD = mkdtempSync(join(tmpdir(), 'ruflo-4426-'));
+ bridgeRecordFeedback.mockClear();
+});
+afterEach(() => {
+ if (originalProjectCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;
+ else process.env.CLAUDE_FLOW_CWD = originalProjectCwd;
+});
+
+describe('daa_agent_adapt performanceScore (#4426)', () => {
+ it('records a score of 0 as a failure, not a 0.8 success', async () => {
+ const t = await tools();
+ await t.create('a0');
+ const r = await t.adapt({ agentId: 'a0', performanceScore: 0 });
+ // Baseline: performanceScore 0.8, newSuccessRate 0.9, feedback { success: true, quality: 0.8 }.
+ expect(r.success).toBe(true);
+ expect(r.adaptation).toMatchObject({ performanceScore: 0, newSuccessRate: 0.5 });
+ expect(bridgeRecordFeedback).toHaveBeenCalledWith(expect.objectContaining({ success: false, quality: 0 }));
+ });
+
+ it('records no score and no outcome when performanceScore is omitted', async () => {
+ const t = await tools();
+ await t.create('a1');
+ const r = await t.adapt({ agentId: 'a1', feedback: 'tighter prompts' });
+ expect(r.success).toBe(true);
+ expect(r.adaptation).toMatchObject({ performanceScore: null, adaptations: 1, newSuccessRate: 1 });
+ expect(bridgeRecordFeedback).not.toHaveBeenCalled();
+ });
+
+ it.each([5, -1, Number.NaN, '0.9'])('rejects out-of-range or non-numeric score %s without changing the agent', async (score) => {
+ const t = await tools();
+ await t.create('a2');
+ const r = await t.adapt({ agentId: 'a2', performanceScore: score });
+ expect(r.success).toBe(false);
+ expect(r.error).toMatch(/between 0 and 1/);
+ const ok = await t.adapt({ agentId: 'a2', performanceScore: 1 });
+ expect(ok.adaptation).toMatchObject({ adaptations: 1, newSuccessRate: 1 });
+ });
+
+ it('still records a valid score (control)', async () => {
+ const t = await tools();
+ await t.create('a3');
+ const r = await t.adapt({ agentId: 'a3', performanceScore: 0.6 });
+ expect(r.adaptation).toMatchObject({ performanceScore: 0.6, newSuccessRate: 0.8 });
+ expect(bridgeRecordFeedback).toHaveBeenCalledWith(expect.objectContaining({ success: true, quality: 0.6 }));
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/daa-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/daa-tools.ts
index 5729762058..7e316879d4 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/daa-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/daa-tools.ts
@@ -183,27 +183,34 @@ export const daaTools: MCPTool[] = [
return { success: false, error: 'Agent not found' };
}
- const performanceScore = (input.performanceScore as number) || 0.8;
+ // #4426: `|| 0.8` turned a failing 0 (and a missing score) into a 0.8
+ // success. A given score must be in [0, 1]; a missing one records none.
+ const performanceScore = input.performanceScore === undefined ? null : input.performanceScore;
+ if (performanceScore !== null && (typeof performanceScore !== 'number' || !Number.isFinite(performanceScore) || performanceScore < 0 || performanceScore > 1)) {
+ return { success: false, error: 'performanceScore must be a number between 0 and 1' };
+ }
// Update agent metrics
agent.metrics.adaptations++;
- agent.metrics.successRate = (agent.metrics.successRate + performanceScore) / 2;
+ if (performanceScore !== null) agent.metrics.successRate = (agent.metrics.successRate + performanceScore) / 2;
agent.lastActivity = new Date().toISOString();
agent.status = 'active';
saveDAAStore(store);
// Store adaptation feedback in AgentDB for pattern learning (backward compat: JSON store above)
let _storedIn: 'agentdb' | 'json-store' = 'json-store';
- try {
- const bridge = await import('../memory/memory-bridge.js');
- await bridge.bridgeRecordFeedback({
- taskId: `adapt-${agentId}-${agent.metrics.adaptations}`,
- success: performanceScore >= 0.5,
- quality: performanceScore,
- agent: agentId,
- });
- _storedIn = 'agentdb';
- } catch { /* AgentDB not available */ }
+ if (performanceScore !== null) {
+ try {
+ const bridge = await import('../memory/memory-bridge.js');
+ await bridge.bridgeRecordFeedback({
+ taskId: `adapt-${agentId}-${agent.metrics.adaptations}`,
+ success: performanceScore >= 0.5,
+ quality: performanceScore,
+ agent: agentId,
+ });
+ _storedIn = 'agentdb';
+ } catch { /* AgentDB not available */ }
+ }
return {
success: true,