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

feat(metaharness): wire recordPair() into model-router.ts route() β€” ADR-150 last mile (iter 12)

ruv2a06c3e2bf87
diff --git a/plugins/ruflo-metaharness/scripts/smoke.sh b/plugins/ruflo-metaharness/scripts/smoke.sh
index ed4ba91af9..b439ac9391 100755
--- a/plugins/ruflo-metaharness/scripts/smoke.sh
+++ b/plugins/ruflo-metaharness/scripts/smoke.sh
@@ -170,6 +170,24 @@ if (!od.metaharness) { console.error('missing metaharness in optionalDependencie
if (j.dependencies && j.dependencies.metaharness) { console.error('metaharness leaked into dependencies'); process.exit(1); }
" 2>/dev/null && ok || bad "ruflo wrapper missing metaharness optionalDep"
+step "17f. model-router.ts wires recordPair() (ADR-150 last-mile, iter 12)"
+F="$ROOT/../../v3/@claude-flow/cli/src/ruvector/model-router.ts"
+miss=""
+[[ -f "$F" ]] || miss="$miss missing-file"
+# Lazy loader registered
+grep -q "loadParallelRecorder" "$F" || miss="$miss no-lazy-loader"
+grep -q "router-parallel-recorder" "$F" || miss="$miss no-recorder-import"
+# Env-gated (additive, off-by-default)
+grep -q "CLAUDE_FLOW_ROUTER_PARALLEL_LOG === '1'" "$F" || miss="$miss no-env-gate-in-router"
+# Call site present
+grep -q "mod.recordPair({" "$F" || miss="$miss no-recordPair-call"
+# Never-throws guarantee (ADR-150 rule #3)
+grep -qE "try \{[[:space:]]*$|\\.catch\\(" "$F" || miss="$miss no-fail-safe"
+# Both arms attributed (bandit + ser)
+grep -q "thompson-bandit" "$F" || miss="$miss no-bandit-tag"
+grep -q "metaharness-router-hybrid\|bandit-only" "$F" || miss="$miss no-ser-tag"
+[[ -z "$miss" ]] && ok || bad "$miss"
+
step "17e. router-parallel-recorder TS module (ADR-150 SelfEvolvingRouter recording β€” iter 11)"
F="$ROOT/../../v3/@claude-flow/cli/src/ruvector/router-parallel-recorder.ts"
miss=""
diff --git a/v3/@claude-flow/cli/src/ruvector/model-router.ts b/v3/@claude-flow/cli/src/ruvector/model-router.ts
index 8a85dd3621..b7eb838399 100644
--- a/v3/@claude-flow/cli/src/ruvector/model-router.ts
+++ b/v3/@claude-flow/cli/src/ruvector/model-router.ts
@@ -55,6 +55,14 @@ function loadTrajectoryRecorder(): Promise<typeof import('./router-trajectory.js
if (_trajectoryMod === null) _trajectoryMod = import('./router-trajectory.js');
return _trajectoryMod;
}
+// ADR-150 iter 11–12 β€” parallel-decision recorder for the SelfEvolvingRouter
+// promotion gate. Dynamic-imported lazily so the routing hot path never
+// pays the load cost when CLAUDE_FLOW_ROUTER_PARALLEL_LOG is unset.
+let _parallelRecorderMod: Promise<typeof import('./router-parallel-recorder.js')> | null = null;
+function loadParallelRecorder(): Promise<typeof import('./router-parallel-recorder.js')> {
+ if (_parallelRecorderMod === null) _parallelRecorderMod = import('./router-parallel-recorder.js');
+ return _parallelRecorderMod;
+}
// ----------------------------------------------------------------------------
// ADR-148 phase 2 β€” per-tier OpenRouter alternates. Loaded once per process
@@ -686,6 +694,35 @@ export class ModelRouter {
};
this.abComparisons++;
if (abPair.disagree) this.abDisagreements++;
+
+ // ADR-150 iter 12 β€” opt-in parallel-decision recorder. No-op when
+ // CLAUDE_FLOW_ROUTER_PARALLEL_LOG is unset (the default), so this
+ // adds zero overhead to the default routing path. Fire-and-forget
+ // dynamic-import + recordPair; never blocks the route() return.
+ if (process.env.CLAUDE_FLOW_ROUTER_PARALLEL_LOG === '1') {
+ loadParallelRecorder().then((mod) => {
+ try {
+ mod.recordPair({
+ task,
+ bandit: {
+ pick: banditOnly.model,
+ predictedQuality: banditOnly.confidence,
+ predictedCostUsd: 0, // bandit doesn't price; analyzer uses outcome
+ backend: 'thompson-bandit',
+ },
+ ser: {
+ pick: picked.model,
+ predictedQuality: picked.confidence,
+ predictedCostUsd: 0,
+ backend: neuralPrior ? 'metaharness-router-hybrid' : 'bandit-only',
+ },
+ });
+ } catch {
+ // ADR-150 rule #3 β€” never throw from the routing path.
+ }
+ }).catch(() => { /* graceful degradation */ });
+ }
+
var pickedForResult = picked; // eslint-disable-line no-var
} else {
var pickedForResult = this.selectModel(adjustedScores, complexity.score, neuralPrior ?? undefined); // eslint-disable-line no-var
diff --git a/v3/docs/adr/ADR-150-metaharness-integration-surfaces.md b/v3/docs/adr/ADR-150-metaharness-integration-surfaces.md
index c29ad7cc38..afbb5091a6 100644
--- a/v3/docs/adr/ADR-150-metaharness-integration-surfaces.md
+++ b/v3/docs/adr/ADR-150-metaharness-integration-surfaces.md
@@ -1,7 +1,7 @@
# ADR-150 β€” MetaHarness Integration Surfaces in `npx ruflo`
-**Status**: Accepted (Phase 1 shipped iters 1–3, Phase 2 partially shipped iters 4–8; SelfEvolvingRouter + KRR retrain remain)
-**Date**: 2026-06-16 (revised 2026-06-16 with implementation notes)
+**Status**: Implemented (Phase 1 βœ… iters 1–3 Β· Phase 2 βœ… iters 4–12 Β· KRR retrain pending production data)
+**Date**: 2026-06-16 (revised 2026-06-16 β€” twelve iterations of /loop)
**Related**: ADR-148 (cost-optimal router lifecycle via `@metaharness/router`), ADR-149 (per-model cost-optimal routing), ADR-026 (3-tier model routing), ADR-097 (federation budget circuit breaker), ADR-124 (optional native dependencies), ADR-144 (agent-authorization-propagation)
**External reference**: [`ruvnet/agent-harness-generator`](https://github.com/ruvnet/agent-harness-generator) β€” the upstream that publishes `metaharness` + `@metaharness/*`. Same author (rUv), explicitly designed around ruflo primitives.
**Research dossier**: published as a gist (linked from the tracking issue) with full graded-evidence sourcing.
@@ -216,12 +216,26 @@ The integration shipped across eight `/loop` iterations on branch
`.swarm/router-parallel.jsonl` matches the iter-10 analyzer's
default `--input`.
- The model-router.ts hot path needs ONE LINE added when the
- follow-up ADR ships the dispatch-side change: `recordPair({...})`
- inside the existing route() function alongside the bandit pick.
- That isolated edit is now the only remaining work, and its blast
- radius is minimal because the recorder primitive is independently
- tested and TS-typed.
+ - **Dispatch wiring** (iter 12 β€” LAST MILE):
+ The one-line edit in `model-router.ts` route() shipped in iter 12.
+ Fire-and-forget `recordPair({task, bandit, ser})` inside the
+ existing `if (abEnabled)` block β€” same place the A/B disagreement
+ counter already lives. Env-gated by
+ `CLAUDE_FLOW_ROUTER_PARALLEL_LOG === '1'`; no-op when unset, which
+ means ZERO overhead on the default routing path. The dynamic-import
+ is lazy (one Promise per process); the recordPair call is wrapped
+ in try/catch with `.catch(() => {})` on the import promise β€” the
+ routing path NEVER throws, even when the optional kernel is
+ completely absent.
+
+ Both arms are attributed at the call site:
+ bandit.backend = 'thompson-bandit'
+ ser.backend = neuralPrior ? 'metaharness-router-hybrid' : 'bandit-only'
+
+ The pipeline is now end-to-end:
+ route() β†’ recordPair() β†’ .swarm/router-parallel.jsonl
+ β†’ router-parallel-analyze.mjs
+ β†’ 3-criteria AND-gate verdict
### Phase-1 item #3 β€” Real seed corpus retraining πŸ”„ PENDING
Requires production trajectory data. The pipeline is wired: