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(coordination): refuse coordination_sync trigger instead of simulating a sync (#4559)

Aaditya17edaf1b12ee
diff --git a/v3/@claude-flow/cli/__tests__/coordination-sync-trigger-4557.test.ts b/v3/@claude-flow/cli/__tests__/coordination-sync-trigger-4557.test.ts
new file mode 100644
index 0000000000..6aa1a7f16f
--- /dev/null
+++ b/v3/@claude-flow/cli/__tests__/coordination-sync-trigger-4557.test.ts
@@ -0,0 +1,72 @@
+/**
+ * #4557: coordination_sync trigger waited on a simulated 50ms "sync", bumped
+ * syncCount/lastSync, zeroed pendingChanges and returned
+ * { success: true, action: 'synchronized', nodesSync }. No state moved, and it
+ * did this even with no nodes registered. It now refuses and leaves the stored
+ * sync record untouched.
+ */
+import { afterEach, beforeEach, describe, expect, it } from 'vitest';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, 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 sync(input: Record<string, unknown>) {
+ const { coordinationTools } = await import('../src/mcp-tools/coordination-tools.js');
+ return coordinationTools.find((t) => t.name === 'coordination_sync')!.handler(input) as Promise<Record<string, any>>;
+}
+
+beforeEach(() => {
+ scratch = mkdtempSync(join(tmpdir(), 'ruflo-4557-'));
+ process.env.CLAUDE_FLOW_CWD = scratch;
+});
+afterEach(() => {
+ if (originalProjectCwd === undefined) delete process.env.CLAUDE_FLOW_CWD;
+ else process.env.CLAUDE_FLOW_CWD = originalProjectCwd;
+});
+
+describe('coordination_sync trigger (#4557)', () => {
+ it('refuses instead of reporting a simulated synchronization', async () => {
+ const before = await sync({ action: 'status' });
+ const r = await sync({ action: 'trigger', force: true });
+ // Baseline: { success: true, action: 'synchronized', syncCount: 1, nodesSync: 0 }.
+ expect(r.success).toBe(false);
+ expect(r.action).toBe('trigger');
+ expect(String(r.error)).toMatch(/no sync backend/);
+ expect(r).not.toHaveProperty('nodesSync');
+ // (An empty project's default record stamps lastSync with "now" on every load,
+ // so compare the counters trigger used to change.)
+ const after = await sync({ action: 'status' });
+ expect(after.sync).toMatchObject({ syncCount: before.sync.syncCount, pendingChanges: before.sync.pendingChanges });
+ expect(after.sync.syncCount).toBe(0);
+ });
+
+ it('leaves a persisted sync record and status byte-for-byte unchanged', async () => {
+ const dir = join(scratch, '.claude-flow', 'coordination');
+ mkdirSync(dir, { recursive: true });
+ const storePath = join(dir, 'store.json');
+ // Pin lastSync so status is stable across loads.
+ const seeded = { nodes: {}, sync: { lastSync: '2026-01-01T00:00:00.000Z', syncCount: 3, conflicts: 0, pendingChanges: 2 } };
+ writeFileSync(storePath, JSON.stringify(seeded));
+ const fileBefore = readFileSync(storePath);
+ const statusBefore = JSON.stringify((await sync({ action: 'status' })).sync);
+ const r = await sync({ action: 'trigger' });
+ expect(r).toMatchObject({ success: false, syncCount: 3, lastSync: '2026-01-01T00:00:00.000Z' });
+ expect(readFileSync(storePath)).toEqual(fileBefore);
+ expect(JSON.stringify((await sync({ action: 'status' })).sync)).toBe(statusBefore);
+ });
+
+ it('does not persist a sync', async () => {
+ await sync({ action: 'trigger' });
+ const storePath = join(scratch, '.claude-flow', 'coordination', 'store.json');
+ // Baseline: store.json written with syncCount 1 and a fresh lastSync.
+ if (existsSync(storePath)) expect(JSON.parse(readFileSync(storePath, 'utf8')).sync.syncCount).toBe(0);
+ });
+
+ it('leaves status and resolve as they were (control)', async () => {
+ expect(await sync({ action: 'status' })).toMatchObject({ success: true, status: 'synced' });
+ expect(await sync({ action: 'resolve' })).toMatchObject({ success: true, message: 'No conflicts to resolve' });
+ });
+});
diff --git a/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts b/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
index db80abe8d1..929ed27b26 100644
--- a/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
+++ b/v3/@claude-flow/cli/src/mcp-tools/coordination-tools.ts
@@ -317,21 +317,16 @@ export const coordinationTools: MCPTool[] = [
}
if (action === 'trigger') {
- store.sync.syncCount++;
- store.sync.lastSync = new Date().toISOString();
- store.sync.pendingChanges = 0;
-
- // Simulate sync
- await new Promise(resolve => setTimeout(resolve, 50));
-
- saveCoordStore(store);
-
+ // #4557: this waited on a simulated 50ms "sync", bumped syncCount/lastSync
+ // and reported every node synchronized, but no state moves between
+ // nodes. Refuse without touching the stored sync record, as
+ // neural_compress quantize/prune do (#4195, #4423).
return {
- success: true,
- action: 'synchronized',
+ success: false,
+ action: 'trigger',
+ error: 'Synchronization is unavailable: coordination nodes are local records with no sync backend, so nothing would be transferred.',
syncCount: store.sync.syncCount,
- syncedAt: store.sync.lastSync,
- nodesSync: Object.keys(store.nodes).length,
+ lastSync: store.sync.lastSync,
};
}