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(swarm): disclose synthetic worker dispatch results (#4456)

ordinary beingc616d4019356
diff --git a/v3/@claude-flow/swarm/__tests__/worker-dispatch-synthetic.test.ts b/v3/@claude-flow/swarm/__tests__/worker-dispatch-synthetic.test.ts
new file mode 100644
index 0000000000..1743a76db4
--- /dev/null
+++ b/v3/@claude-flow/swarm/__tests__/worker-dispatch-synthetic.test.ts
@@ -0,0 +1,73 @@
+/**
+ * #4410 automation scan: all 12 WorkerDispatchService triggers return static
+ * placeholder data. They must identify themselves as synthetic so direct
+ * consumers of the published @claude-flow/swarm package and prompt-injection
+ * helpers cannot present invented counts as real analysis.
+ */
+
+import { describe, expect, it } from 'vitest';
+// Import the TS source explicitly: src/workers/worker-dispatch.js is a stale
+// tracked build artifact that would otherwise shadow the implementation.
+import {
+ WorkerDispatchService,
+ type WorkerInstance,
+ type WorkerTrigger,
+} from '../src/workers/worker-dispatch.ts';
+
+const TRIGGERS: WorkerTrigger[] = [
+ 'ultralearn',
+ 'optimize',
+ 'consolidate',
+ 'predict',
+ 'audit',
+ 'map',
+ 'preload',
+ 'deepdive',
+ 'document',
+ 'refactor',
+ 'benchmark',
+ 'testgaps',
+];
+
+async function waitForCompletion(
+ service: WorkerDispatchService,
+ workerId: string,
+): Promise<WorkerInstance> {
+ const deadline = Date.now() + 5000;
+
+ while (Date.now() < deadline) {
+ const worker = service.getWorker(workerId);
+ if (!worker) throw new Error(`worker ${workerId} disappeared`);
+ if (worker.status === 'completed' && worker.result) return worker;
+ if (worker.status === 'failed') throw worker.error ?? new Error(`worker ${workerId} failed`);
+ if (worker.status === 'cancelled') throw new Error(`worker ${workerId} was cancelled`);
+ await new Promise(resolve => setTimeout(resolve, 5));
+ }
+
+ throw new Error(`worker ${workerId} did not complete in time`);
+}
+
+describe('WorkerDispatchService synthetic-result disclosure (#4410)', () => {
+ it('marks every trigger result as synthetic and labels injected context', async () => {
+ const service = new WorkerDispatchService({ maxConcurrent: TRIGGERS.length });
+ const sessionId = 'synthetic-disclosure-session';
+
+ const workerIds = await Promise.all(
+ TRIGGERS.map(trigger => service.dispatch(trigger, `context for ${trigger}`, sessionId)),
+ );
+ const workers = await Promise.all(
+ workerIds.map(workerId => waitForCompletion(service, workerId)),
+ );
+
+ for (const worker of workers) {
+ expect(worker.result?.success).toBe(true);
+ expect(worker.result?.synthetic).toBe(true);
+ expect(worker.result?.syntheticReason).toContain('No live worker executor');
+ }
+
+ const context = service.getContextForInjection(sessionId);
+ expect(context).toContain('Background Analysis Results');
+ expect(context).toContain('(synthetic placeholders, not real analysis)');
+ expect(context).toContain('(synthetic, not real analysis)');
+ });
+});
diff --git a/v3/@claude-flow/swarm/src/workers/worker-dispatch.ts b/v3/@claude-flow/swarm/src/workers/worker-dispatch.ts
index da044eea43..40d5084239 100644
--- a/v3/@claude-flow/swarm/src/workers/worker-dispatch.ts
+++ b/v3/@claude-flow/swarm/src/workers/worker-dispatch.ts
@@ -94,6 +94,14 @@ export interface WorkerResult {
artifacts?: WorkerArtifact[];
metrics?: WorkerMetrics;
summary?: string;
+ /**
+ * True when this result did not come from real analysis and is only a
+ * deterministic placeholder. Direct consumers (including the published
+ * `@claude-flow/swarm` package) must not present synthetic data as findings.
+ */
+ synthetic?: boolean;
+ /** Human-readable reason the result is synthetic, when `synthetic` is true. */
+ syntheticReason?: string;
}
/**
@@ -137,6 +145,15 @@ export interface DispatchOptions {
callback?: (worker: WorkerInstance) => void;
}
+/**
+ * Every trigger executor below returns a deterministic placeholder. Until a
+ * real executor is wired, results must say so: consumers of the published
+ * package can otherwise mistake invented counts and recommendations for real
+ * analysis (#4410 automation scan).
+ */
+const SYNTHETIC_WORKER_REASON =
+ 'No live worker executor is wired; this is a deterministic placeholder and the work phases are simulated.';
+
// =============================================================================
// Trigger Detection Patterns
// =============================================================================
@@ -538,11 +555,19 @@ export class WorkerDispatchService extends EventEmitter {
if (workers.length === 0) return '';
+ const hasSynthetic = workers.some(w => w.result?.synthetic);
+ const heading = hasSynthetic
+ ? '### Background Analysis Results (synthetic placeholders, not real analysis)'
+ : '### Background Analysis Results';
+
const summaries = workers
- .map(w => `[${w.trigger}] ${w.result?.summary || 'Completed'}`)
+ .map(w => {
+ const provenance = w.result?.synthetic ? ' (synthetic, not real analysis)' : '';
+ return `[${w.trigger}]${provenance} ${w.result?.summary || 'Completed'}`;
+ })
.join('\n');
- return `\n### Background Analysis Results\n${summaries}\n`;
+ return `\n${heading}\n${summaries}\n`;
}
// ===========================================================================
@@ -626,7 +651,12 @@ export class WorkerDispatchService extends EventEmitter {
testgaps: () => this.executeTestgaps(worker),
};
- return executors[worker.trigger]();
+ const result = await executors[worker.trigger]();
+ return {
+ ...result,
+ synthetic: true,
+ syntheticReason: SYNTHETIC_WORKER_REASON,
+ };
}
// ===========================================================================
@@ -1040,12 +1070,12 @@ export class WorkerDispatchService extends EventEmitter {
}
/**
- * Process work phase with minimal overhead
- * Actual task work is performed via worker callbacks and hooks
- * @param ms - Target processing time (capped for performance)
+ * Simulated work phase for placeholder workers.
+ * No real task work is performed here; the delay is capped for tests.
+ * @param ms - Requested simulated duration
*/
private async processWorkPhase(ms: number): Promise<void> {
- // Minimal processing overhead - actual work done via callbacks
+ // Simulated only: actual work would require a real worker executor.
await new Promise(resolve => setTimeout(resolve, Math.min(ms, 10)));
}
}