Files
ruflo/v3/@claude-flow/cli/benchmarks/router
rUv 82dac70fd7 feat(router): ADR-389–391 — refresh router helper, opt-in MiniLM embedder, benchmark gate (no default change) (#3410)
* docs(adr): ADR-389..391 — router: refresh the helper, use the real embedder, change defaults only on a measured win

ADR-389: add router.js to CRITICAL_HELPERS + re-sign, so installed copies get
the word-boundary fix (#3401); today they are frozen at first write.
ADR-390: hooks_route embeds patterns and tasks with the local MiniLM chain
(generateLocalEmbedding), hash embedder as the reported fallback.
ADR-391: frozen, labelled 150-200 prompt corpus; A/B/C/D (current, MiniLM,
typesafe-hash, typesafe-onnx); ADR-150-style AND-gate for promotion.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(init): refresh router.js as a critical helper on upgrade (ADR-389, #3401)

Installed copies of .claude/helpers/router.js never received the #2257
word-boundary fix: helper-refresh only re-copies CRITICAL_HELPERS and
router.js was not on the list, so an April substring router kept routing
"sync and review latest issues" to tester.

- helper-refresh.ts: add router.js to CRITICAL_HELPERS; generator
  fallback also emits it (generateAgentRouter).
- sign-helpers.mjs / verify-helpers.mjs / executor.ts executeUpgrade /
  smoke-helper-signing-security.mjs: keep their copies of the list in sync.
- New test: stale April router.js is replaced by the package copy via the
  signed refresh path (throwaway key), after which the prompt no longer
  routes to tester.

helpers.manifest.json is NOT re-signed here. Until it is, verify-helpers
fails ("manifest has no entry for router.js") and the production refresh
is fail-closed blocked for all helpers.

Co-Authored-By: RuFlo <ruv@ruv.net>

* bench(router): ADR-391 labelled evaluation corpus (197 prompts, frozen)

Blind-labelled corpus for comparing routing candidates: 11 labels incl. none,
64 adversarial trap cases, deterministic stratified dev/test split (i%5 in
{0,2} -> dev), dependency-free validator that recomputes the split and prints
the sha256. Frozen at sha256 b0c1923b2813b61907304dff56c53d199b709797bfb9600a7c1f496cf0c0bf04.

Co-Authored-By: RuFlo <ruv@ruv.net>

* feat(hooks): ADR-390 — semantic router can use the real MiniLM embedder

hooks_route compared tasks with pattern keywords using a character hash
(generateSimpleEmbedding), which measures spelling, not meaning. This adds a
router-embedder abstraction (src/ruvector/router-embedder.ts):

- embedForRouter(texts, kind) -> { vectors, embedder: 'minilm'|'hash', reason? }
- MiniLM path uses generateLocalEmbedding ONLY (never the bridge-first
  generateEmbedding, #2312). backend !== 'onnx', a throw, or a non-384-d
  vector degrades EVERY text in the call to the hash, with a reason.
- Selection: CLAUDE_FLOW_ROUTER_EMBEDDER=minilm|hash; DEFAULT_ROUTER_EMBEDDER
  stays 'hash' until ADR-391's benchmark decides.

getSemanticRouter builds both the native VectorDb and pure-JS indexes from one
embedder, records which one actually built the index, embeds the query with
that same embedder, rebuilds when the requested embedder changes, and shares
one in-flight build between concurrent callers. If the query fails on MiniLM
after a MiniLM index was built, the index is rebuilt with the hash so the two
spaces never mix. hooks_route results gain `embedder` (+ `embedderReason` when
degraded); existing fields are unchanged.

routeTaskForBench(task, { embedder }) is an internal, bench-only entry that
runs the same local path as hooks_route (skipping the AgentDB pre-route and
the opt-in typesafe wrapper) for ADR-391.

Co-Authored-By: RuFlo <ruv@ruv.net>

* chore(audit): register CLAUDE_FLOW_ROUTER_EMBEDDER as a known env escape hatch

ADR-390's router embedder selector is process-lifetime MCP router state, like
CLAUDE_FLOW_DISABLE_NATIVE_ROUTER; the ADR-391 bench passes the embedder
explicitly rather than through a CLI flag.

Co-Authored-By: RuFlo <ruv@ruv.net>

* bench(router): ADR-391 first run — no candidate promoted; fix typesafe-router test (e)

Benchmark (run-bench.mjs) on the frozen 197-prompt corpus
(sha256 b0c1923b…), test split n=113:
  A current (hash)   25.7% acc, p95 1.06 ms
  B MiniLM (ADR-390) 36.3% acc, p95 6.21 ms   (+10.6 pts, +485% p95)
  C typesafe hash    26.5% acc, p95 1.20 ms
  D typesafe onnx    29.2% acc, p95 8.35 ms   (raw pick 44.3%, gated to 5.6%)
No candidate passes the ADR-391 AND-gate (B fails the relative latency
bound), so DEFAULT_ROUTER_EMBEDDER stays 'hash' and typesafe stays opt-in.
Receipt committed under benchmarks/router/results/. ADR-391 gains a Results
section with the findings (structural ceiling: no pattern returns
researcher/reviewer/none; latency criterion mis-specified for a ~1 ms base;
typesafe gate too tight) as owner decisions, not applied.

ADR-389 -> Implemented; ADR-390 -> Implemented as opt-in; ADR-391 -> Implemented.

typesafe-router test (e) was red on main since #3402 made the keyword
fallback word-bounded: it still asserted the old "latest"->tester fallback.
It now asserts the typesafe override and that a legacy fallback is kept.

Co-Authored-By: RuFlo <ruv@ruv.net>
2026-09-23 18:39:18 +00:00
..

Router evaluation corpus (ADR-391)

corpus.jsonl is the labelled, frozen evaluation set that ADR-391 uses to compare agent-routing candidates (A current, B MiniLM, C typesafe-hash, D typesafe-onnx). It contains 197 prompts, each labelled with the one agent a competent engineering lead would assign.

Frozen at sha256 b0c1923b2813b61907304dff56c53d199b709797bfb9600a7c1f496cf0c0bf04. Any edit to corpus.jsonl changes this hash. A changed corpus is a new corpus: earlier receipts don't carry over to it.

Line format

{"id":"r001","prompt":"...","label":"researcher","split":"dev","trap":false,"source":"issue","note":"why this label"}
  • source: issue or pr means the prompt paraphrases a real ruflo issue or PR title into how a developer would ask for it. synthetic means the labeller wrote it.
  • trap: true marks an adversarial case, where a naive keyword match points to the wrong agent. Examples: "review the latest issues" is researcher, "update the test fixtures for the auth API" is tester, and "run the benchmark" is performance-engineer.

Labels

label primary work
coder implement a feature or change, fix a bug, write code
tester write, extend or fix tests; coverage; test strategy
reviewer review a PR, diff or code for quality or correctness
researcher investigate, look up, compare, summarise, triage; explain how existing code or issues work
architect design, ADRs, API or schema design, module boundaries, refactor planning
security-architect security review, vulnerabilities, auth hardening, threat modelling, CVEs
performance-engineer profiling, latency and throughput, benchmarks, optimisation
devops CI/CD, deploy, Docker, release pipelines, infrastructure
swarm-specialist multi-agent, swarm or hive-mind orchestration and coordination
memory-specialist memory store, vector index, embeddings, AgentDB, HNSW
none not an engineering task: chit-chat, thanks, vague one-word asks, non-software requests

Tie-break rules, applied the same way to every prompt:

  • Specialist vs coder. A specialist label wins only when the work sits squarely in that domain and needs its expertise, such as memory-store persistence, HNSW or embeddings internals, auth exposure, or agent coordination. When the domain is incidental, the label is coder. A wrong exit code in the memory command, or a hiveId that is never saved, are both coder.
  • reviewer vs researcher. Reviewing a PR, diff or code is reviewer. Reading issues, changelogs or docs to report back is researcher, even when the prompt says "review".
  • Mixed intent. The label is the primary ask. For example, "profile X" is performance work even when X is the memory store. The note field says why.

Prompts that two reasonable leads could label differently were rewritten or dropped.

Split rule

The split is deterministic and stratified by label. Within each label, sort rows by id. The row at 0-indexed position i goes to dev if i % 5 is 0 or 2, and to test otherwise. validate-corpus.mjs recomputes this rule and fails if any row disagrees.

  • dev is for tuning thresholds.
  • test decides promotion. Each candidate runs on it once.

Ids were assigned after a seeded shuffle, so they don't encode the label.

Counts

label dev test total traps
coder 12 16 28 12
tester 8 10 18 10
reviewer 6 9 15 4
researcher 10 15 25 11
architect 7 9 16 3
security-architect 7 9 16 5
performance-engineer 7 9 16 5
devops 7 9 16 3
swarm-specialist 6 7 13 6
memory-specialist 6 9 15 3
none 8 11 19 2
total 84 113 197 64

Blindness rule

The labeller never saw any router's output. No router was run while the corpus was built: not hooks route, hooks_route, router.js/router.cjs, or typesafe. The labeller also didn't read the router keyword/pattern tables (TASK_PATTERNS in hooks-tools.ts, typesafe-router.ts) or any routing test tables. Labels reflect only what the prompt asks for. That independence is what makes the corpus a fair benchmark, so keep it when extending or relabelling: whoever labels must not look at router output first.

Validate

node validate-corpus.mjs            # defaults to ./corpus.jsonl

The validator uses no dependencies. It checks:

  • every line is valid JSON
  • ids are unique and match r\d{3}
  • no prompt appears twice
  • each label is in the set above
  • each split is dev or test, and matches the split rule
  • trap is a boolean
  • source is issue, pr or synthetic
  • the total is 180–200
  • every label except none has at least 8 rows, and none has 15–20
  • there are at least 30 traps

It prints the counts table above and the file's sha256.