🌊 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(flywheel): compute receipt statistics from encoded scale-12 values (ruflo#3072)
ruva38647e1f90f
diff --git a/v3/@claude-flow/cli/__tests__/flywheel-receipt.test.ts b/v3/@claude-flow/cli/__tests__/flywheel-receipt.test.tsindex 1dbc40ca22..2e6e2f90b3 100644--- a/v3/@claude-flow/cli/__tests__/flywheel-receipt.test.ts+++ b/v3/@claude-flow/cli/__tests__/flywheel-receipt.test.ts@@ -122,6 +122,34 @@ describe('flywheel receipt protocol', () => {expect(verifyFlywheelReceipt(receipt, new Set([key.publicKeyPem])).valid).toBe(true);});+ it('verifies receipts whose scores need more than twelve decimals (encoded round-trip)', () => {+ const key = keys();+ // Mean of a heterogeneous per-task corpus; not representable at scale 12.+ // Stored as "0.768708333333", so a verifier recomputes from that value —+ // the producer must have used it too, or relativeLift shifts by one ULP+ // and an honest receipt reports "statistical decision does not recompute".+ const candidateScore = 0.7687083333333332;+ const heldOutDeltas = [0.2687083333333332, 0.26870833333333326, 0.2687083333333333, 0.2687083333333331];+ const receipt = createFlywheelReceipt({+ baselineRef: policyCandidateId({ alpha: 0.5 }),+ candidatePolicy: { alpha: 0.3 },+ safetyEnvelopeRef: 'sha256:safety',+ corpusVersion: 'corpus-v1',+ corpusHash: 'sha256:corpus',+ baselineScore: 0.5,+ candidateScore,+ heldOutDeltas,+ frozenAnchorRegression: 0,+ gates: { heldOut: true },+ bootstrapIterations: 500,+ ...key,+ });+ expect(receipt.payload.candidateScore).toBe('0.768708333333');+ const verification = verifyFlywheelReceipt(receipt, new Set([key.publicKeyPem]));+ expect(verification.errors).toEqual([]);+ expect(verification.valid).toBe(true);+ });+it('rejects small relative lifts even when every held-out delta is positive', () => {const { privateKeyPem, publicKeyPem } = keys();const receipt = createFlywheelReceipt({diff --git a/v3/@claude-flow/cli/src/services/flywheel-receipt.ts b/v3/@claude-flow/cli/src/services/flywheel-receipt.tsindex fbd7f5eddf..343c371d2c 100644--- a/v3/@claude-flow/cli/src/services/flywheel-receipt.ts+++ b/v3/@claude-flow/cli/src/services/flywheel-receipt.ts@@ -323,11 +323,19 @@ export function createFlywheelReceipt(input: CreateReceiptInput): FlywheelEvaluaconst evaluationRunId = input.evaluationRunId ?? uuidV7(now);const lineageId = input.lineageId ?? uuidV7(now);const candidateId = policyCandidateId(input.candidatePolicy);+ // Verifiers recompute the statistics from the payload's scale-12 decimal+ // strings — the only values they ever have. The encoded values are therefore+ // the statistical inputs of record: compute the decision from them, not from+ // full-precision intermediates, or any input that does not terminate within+ // twelve decimals produces an honest receipt that fails its own verification.+ const encodedBaselineScore = decimal(input.baselineScore);+ const encodedCandidateScore = decimal(input.candidateScore);+ const encodedHeldOutDeltas = input.heldOutDeltas.map((v) => decimal(v));const statistics = computePromotionStatistics({- baselineScore: input.baselineScore,- candidateScore: input.candidateScore,- heldOutDeltas: input.heldOutDeltas,- frozenAnchorRegression: input.frozenAnchorRegression,+ baselineScore: Number(encodedBaselineScore),+ candidateScore: Number(encodedCandidateScore),+ heldOutDeltas: encodedHeldOutDeltas.map(Number),+ frozenAnchorRegression: Number(decimal(input.frozenAnchorRegression)),corpusHash: input.corpusHash,candidateId,baselineRef: input.baselineRef,@@ -352,9 +360,9 @@ export function createFlywheelReceipt(input: CreateReceiptInput): FlywheelEvalua...(input.proposerSubstitution ? { proposerSubstitution: input.proposerSubstitution } : {}),corpusVersion: input.corpusVersion,corpusHash: input.corpusHash,- baselineScore: decimal(input.baselineScore),- candidateScore: decimal(input.candidateScore),- heldOutDeltas: input.heldOutDeltas.map((v) => decimal(v)),+ baselineScore: encodedBaselineScore,+ candidateScore: encodedCandidateScore,+ heldOutDeltas: encodedHeldOutDeltas,...(input.pairedOutcomes? {pairedOutcomes: input.pairedOutcomes.map((o) => ({