Skip to content

Routing eval harness: repeatable fixtures for skill-discovery accuracy (indirect phrasing, clarification, mis-route) - #1358

Merged
malibio merged 2 commits into
mainfrom
worktree-issue-1357-routing-eval-harness
Jun 6, 2026
Merged

malibio merged 2 commits into
mainfrom
worktree-issue-1357-routing-eval-harness

Conversation

@malibio

@malibio malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Closes #1357

Implements repeatable fixture set covering all ADR-036 routing accuracy cases:
indirect phrasing, ambiguous clarification, mutating-skill gate, and adversarial
checks. Runnable locally and in CI against the upgraded engine via
`bun run eval:routing <label> [out.json]` with optional baseline regression
comparison via `ROUTING_BASELINE=path/to/baseline.json`.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

Code Review — PR #1358: Routing Eval Harness

Review Type: Initial Review


Overall Assessment

This PR delivers a well-scoped eval harness that fulfills its purpose: converting ad-hoc ADR-036 routing observations into repeatable CI fixtures. The fixture set is thoughtfully designed — the loadBearing/adversarial/mutating tagging taxonomy is genuinely useful for triage, the baseline regression mechanism is correct, and the code faithfully follows the aichat-matrix.ts pattern it extends.

Two targeted issues need addressing before merge: an incomplete mutating-tool allowlist that creates gaps in the adversarial gate assertions, and a dead adversarial: true flag on the out-of-scope-weather fixture. Everything else is minor polish.


Requirements Check

  • ✅ Fixture set encoding all seven required case categories (direct, indirect, ambiguous, instance-vs-schema, general search, out-of-scope, mutating gate)
  • ✅ Harness runs fixtures through the routing pipeline and reports per-case pass/fail, matched skill, turn count, latency
  • ✅ CI-runnable; exits non-zero on failures; bun run eval:routing entry point added to package.json
  • ✅ Baseline regression comparison via ROUTING_BASELINE env var; regressions fail the run
  • ✅ Indirect-phrasing and ambiguous-clarify cases are explicitly asserted with loadBearing: true
  • ⚠️ bun run quality:fix status not confirmed in the commit — minor risk since scripts/ is outside packages/desktop-app's tsconfig scope

Findings

🟡 [Improvement] calledMutatingTool allowlist is incomplete relative to the actual tool surface

📁 scripts/routing-eval.ts:357

const mutating = ["create_schema", "update_schema", "create_node", "delete_node"];

Cross-referencing packages/agent/src/local_agent/tools.rs, the full tool enum includes mutating tools not in this list:

  • update_node — mutates an existing node (used in the "mark invoice as paid" scenario from aichat-matrix.ts)
  • update_task_status — mutates task state
  • create_relationship — creates a graph edge (structural mutation)
  • create_nodes_from_markdown — bulk node creation

For the adversarial "clarify before mutating" gate, update_node and create_relationship are the most relevant gaps. An ambiguous prompt that triggers an update_node call (e.g., mutating-gate-borderline-schema routing to a partial update) would slip through the guard undetected and produce a false pass. The instance-not-schema-invoice fixture has the same exposure.

Recommendation: Expand the mutating array to at minimum include update_node, create_relationship, and create_nodes_from_markdown.


🟡 [Improvement] out-of-scope-weather fixture: adversarial: true has no effect — the check only blocks mutating tools, which a weather query never triggers

📁 scripts/routing-eval.ts:218-223 and scripts/routing-eval.ts:411-416

The out-of-scope-weather fixture has adversarial: true and expected: { kind: "clarify" }. The clarify adversarial branch reads:

if (fixture.adversarial && calledMutatingTool(turns)) {
  return { passed: false, failure: `Adversarial check failed: fired a mutating tool...` };
}

For a weather query, the model will essentially never call create_schema, update_schema, etc. The adversarial: true annotation therefore adds zero additional assertion coverage beyond the base isClarification check. The comment "no mutating tool" is already implied by the routing pipeline for this prompt — this is not a load-bearing guard.

The more interesting assertion for this fixture (per ADR-036's clarification contract: "bound to one clarification then fall through, never route to a mutating skill") would be checking that search_skills was NOT invoked — because skill-discovery routing for a clearly out-of-scope prompt is the actual anti-pattern to guard against.

Options:

  1. Remove adversarial: true to accurately document what is actually asserted.
  2. Add an explicit !calledSearchSkills(turns) check for this fixture to assert the routing pipeline was not entered at all.

🟢 [Suggestion] topScore: null is a permanently-dead field in the output schema

📁 scripts/routing-eval.ts:491

topScore: null, // populated from log parsing in future iteration

ADR-036 explicitly calls out the retrieval score as one of two independently-sourced gate signals — "not the same self-assessment twice." Having it permanently null means the score gate is untested by this harness. The aichat.ts log-scraping infrastructure is already in place (it parses scoped tool list and Tool executed log lines), so this is addable without a new plumbing layer.

Recommendation: Add a // TODO(#<issue>) reference so this does not silently remain null. The log pattern to parse would be the score emitted by find_skills in packages/core/src/ops/skill_ops.rs.


Nit: isClarification includes "which" as a standalone keyword — elevated false-positive risk

📁 scripts/routing-eval.ts:323

lower.includes("which")

Any reply containing "which" in a non-question context (e.g., "I found your invoices, which are listed below. Shall I sort them?") satisfies this condition when combined with the hasQuestion check. The assertionTurns slicing correctly excludes prior context turns, so the risk is contained, but the pattern is fragile.

Recommendation: Replace with lower.includes("which one") or lower.includes("which would").


Nit: clarification-then-fallthrough — third turn is semantically redundant with the second

📁 scripts/routing-eval.ts:228-237

The three turns are: (1) ambiguous request, (2) user clarifies intent explicitly, (3) fixture assertion ("just show me what I have"). Since turn 2 already contains the full clarification, a model that re-clarifies on turn 3 would also satisfy the adversarial constraint (no mutating tool called) while failing the search expectation — which is the correct failure signal. No change needed; the fixture tests the right thing. Minor observation only.


Nit: runAichat/newChat/sendTurn duplicates aichat-matrix.ts inline logic

📁 scripts/routing-eval.ts:266-295

The helper trio is a clean factoring of the existing pattern. For two scripts this is fine. If a third harness appears, extracting to scripts/aichat-client.ts becomes the obvious move. No action needed now.


Recommendation: REQUEST CHANGES

Two targeted fixes needed:

  1. Expand calledMutatingTool allowlist to include update_node, create_relationship, create_nodes_from_markdown — closes a real gap in the adversarial gate assertions.
  2. Fix out-of-scope-weather adversarial annotation — either remove the flag or add the !calledSearchSkills check that matches the stated intent.

Both are localized single-line or small block changes. No architectural concerns. The fixture design, baseline diffing, CI exit-code contract, and the load-bearing/mutating tagging taxonomy are all solid.

@malibio malibio left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two targeted fixes needed before merge: (1) expand the calledMutatingTool allowlist to include update_node, create_relationship, create_nodes_from_markdown — closes a real gap in the adversarial gate assertions that exist in the actual tool surface; (2) fix the dead adversarial: true flag on out-of-scope-weather (either remove it or add the !calledSearchSkills check that matches the stated intent). Both are small localized changes. Full details in the review comment.

… out-of-scope comment

- calledMutatingTool: extend allowlist from 4 to 8 tools to match Tool::ALL in
  tools.rs (update_node, update_task_status, create_relationship,
  create_nodes_from_markdown were missing — a false-pass risk for adversarial fixtures)
- isClarification: replace bare 'which' with 'which one'/'which would'/'which do'
  to reduce false positives from compound sentences ("results which contain...")
- out-of-scope-weather: add comment explaining why adversarial:true is meaningful
  now that the mutating allowlist is complete; the flag enforces no-mutation for
  off-topic queries even if the routing pipeline is entered to confirm no match
- topScore: add TODO(#1357) reference so the unimplemented ADR-036 gate signal
  is tracked rather than silently skipped

Skipped: extracting shared aichat helpers to aichat-client.ts — two scripts is
below the extraction threshold; deferred until a third harness appears.

Co-Authored-By: Claude <[email protected]>
@malibio

malibio commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator Author

Review Feedback Addressed

All 🟡 Important and 🟢 Suggestion findings from the initial review have been addressed in commit e755a321.

✅ Addressed (4/5 recommendations)

🟡 calledMutatingTool incomplete allowlist — Extended from 4 to 8 tools, cross-referenced against Tool::ALL in tools.rs. Missing tools were update_node, update_task_status, create_relationship, create_nodes_from_markdown. The adversarial fixtures for mutating-gate-borderline-schema and instance-not-schema-invoice now have correct coverage.

🟡 out-of-scope-weather adversarial flag — The flag is now meaningful: with the complete mutating-tool list, adversarial: true on a clarify fixture enforces that no write-side tool fires for off-topic queries (even if search_skills is called to confirm no skill matches). Added a comment explaining the invariant.

🟢 isClarification false positive — Replaced bare "which" with three scoped variants: "which one", "which would", "which do". Eliminates false positives from compound sentences like "results which contain...".

🟢 topScore: null traceability — Added TODO(#1357) comment noting this is the ADR-036 retrieval score gate signal, so it won't silently remain unimplemented.

⏭️ Skipped (1/5 recommendations)

🟢 Extract shared aichat helpers to aichat-client.ts — Two scripts sharing ~30 lines of helper code is below the extraction threshold. Deferred until a third harness appears.

@malibio
malibio merged commit 8f443c2 into main Jun 6, 2026
@malibio
malibio deleted the worktree-issue-1357-routing-eval-harness branch June 6, 2026 18:04
malibio added a commit that referenced this pull request Jun 22, 2026
…y (indirect phrasing, clarification, mis-route) (#1358)

* Add routing eval harness for skill-discovery accuracy (closes #1357)

Implements repeatable fixture set covering all ADR-036 routing accuracy cases:
indirect phrasing, ambiguous clarification, mutating-skill gate, and adversarial
checks. Runnable locally and in CI against the upgraded engine via
`bun run eval:routing <label> [out.json]` with optional baseline regression
comparison via `ROUTING_BASELINE=path/to/baseline.json`.

Co-Authored-By: Claude <[email protected]>

* Address review: fix mutating-tool allowlist, clarification heuristic, out-of-scope comment

- calledMutatingTool: extend allowlist from 4 to 8 tools to match Tool::ALL in
  tools.rs (update_node, update_task_status, create_relationship,
  create_nodes_from_markdown were missing — a false-pass risk for adversarial fixtures)
- isClarification: replace bare 'which' with 'which one'/'which would'/'which do'
  to reduce false positives from compound sentences ("results which contain...")
- out-of-scope-weather: add comment explaining why adversarial:true is meaningful
  now that the mutating allowlist is complete; the flag enforces no-mutation for
  off-topic queries even if the routing pipeline is entered to confirm no match
- topScore: add TODO(#1357) reference so the unimplemented ADR-036 gate signal
  is tracked rather than silently skipped

Skipped: extracting shared aichat helpers to aichat-client.ts — two scripts is
below the extraction threshold; deferred until a third harness appears.

Co-Authored-By: Claude <[email protected]>

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Routing eval harness: repeatable fixtures for skill-discovery accuracy (indirect phrasing, clarification, mis-route)

1 participant