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(neural): refuse neural_compress prune instead of deleting every pattern (#4428)

Aadityaf6c6a32432e7
diff --git a/v3/@claude-flow/cli/__tests__/neural-compress-persistence-4195.test.ts b/v3/@claude-flow/cli/__tests__/neural-compress-persistence-4195.test.ts
index 8bd439a4be..203ee64e7b 100644
--- a/v3/@claude-flow/cli/__tests__/neural-compress-persistence-4195.test.ts
+++ b/v3/@claude-flow/cli/__tests__/neural-compress-persistence-4195.test.ts
@@ -44,3 +44,37 @@ describe('neural_compress quantize persistence (#4195)', () => {
expect(JSON.parse(readFileSync(storePath, 'utf8')).patterns.p1.embedding).toEqual([0.25, -0.5, 1]);
});
});
+
+describe('neural_compress prune (#4423)', () => {
+ it.each([{ targetSize: 0.1 }, { targetSize: 1 }, {}])('refuses %o and leaves models.json byte-identical', async (input) => {
+ const scratch = mkdtempSync(join(tmpdir(), 'ruflo-4423-'));
+ process.env.CLAUDE_FLOW_CWD = scratch;
+ const neuralDir = join(scratch, '.claude-flow', 'neural');
+ mkdirSync(neuralDir, { recursive: true });
+ const storePath = join(neuralDir, 'models.json');
+ // usageCount 0 is what neural_train writes; nothing in the neural store increments it.
+ const pattern = (id: string, usageCount: number) => ({
+ id, name: id, type: 'test', embedding: [0.25, -0.5, 1],
+ metadata: {}, createdAt: '2026-01-01T00:00:00.000Z', usageCount,
+ });
+ writeFileSync(storePath, JSON.stringify({ models: {}, patterns: { fresh: pattern('fresh', 0), merged: pattern('merged', 2) }, version: '3.0.0' }, null, 2));
+ const originalBytes = readFileSync(storePath);
+
+ const { neuralTools } = await import('../src/mcp-tools/neural-tools.js');
+ const tool = neuralTools.find((candidate) => candidate.name === 'neural_compress')!;
+ const result = await tool.handler({ method: 'prune', ...input }) as Record<string, unknown>;
+
+ // Baseline: success true, the usageCount-0 pattern deleted and the deletion saved.
+ expect(result.success).toBe(false);
+ expect(String(result.error)).toMatch(/do not record usage/);
+ expect(result).toMatchObject({ patternsRemoved: 0, patternsBefore: 2, patternsAfter: 2 });
+ expect(readFileSync(storePath)).toEqual(originalBytes);
+ });
+
+ it('no longer documents targetSize as a 0-1 size reduction', async () => {
+ const { neuralTools } = await import('../src/mcp-tools/neural-tools.js');
+ const tool = neuralTools.find((candidate) => candidate.name === 'neural_compress')!;
+ const schema = tool.inputSchema as { properties: { targetSize: { description: string } } };
+ expect(schema.properties.targetSize.description).not.toMatch(/reduction|0-1/);
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
index b62714473f..43d10eb88f 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/neural-tools.ts
@@ -957,7 +957,7 @@ export const neuralTools: MCPTool[] = [
properties: {
modelId: { type: 'string', description: 'Model ID to compress' },
method: { type: 'string', enum: ['quantize', 'prune', 'distill'], description: 'Compression method' },
- targetSize: { type: 'number', description: 'Target size reduction (0-1)' },
+ targetSize: { type: 'number', description: 'Not used: quantize (#4195) and prune (#4423) are unavailable, and distill merges by similarity' },
},
},
handler: async (input) => {
@@ -965,7 +965,6 @@ export const neuralTools: MCPTool[] = [
const store = loadNeuralStore();
const method = (input.method as string) || 'quantize';
- const targetReduction = (input.targetSize as number) || 0.5;
const patterns = Object.values(store.patterns);
if (patterns.length === 0) {
@@ -996,21 +995,18 @@ export const neuralTools: MCPTool[] = [
await ensureEmbeddings();
if (method === 'prune') {
- // Prune patterns with low usage count below threshold (targetReduction as min usage)
- const threshold = targetReduction;
- const toRemove: string[] = [];
- for (const [id, pattern] of Object.entries(store.patterns)) {
- if ((pattern.usageCount || 0) < threshold) toRemove.push(id);
- }
- for (const id of toRemove) delete store.patterns[id];
- saveNeuralStore(store);
+ // #4423: prune deleted patterns with usageCount below targetSize, but
+ // nothing in the neural store records usage (patterns are written with
+ // 0 and only max-merged), so any targetSize > 0, including the old 0.5
+ // default, deleted and persisted every pattern. Refuse until usage is
+ // tracked, the same way quantize refuses (#4195). The store is untouched.
return {
- success: true, _real: true, method,
- embeddingProvider: embeddingServiceName,
- threshold,
- patternsRemoved: toRemove.length,
+ success: false,
+ error: 'Pruning is unavailable: neural patterns do not record usage, so there is no signal to choose which to remove.',
+ method,
+ patternsRemoved: 0,
patternsBefore: beforeCount,
- patternsAfter: Object.keys(store.patterns).length,
+ patternsAfter: beforeCount,
};
}