Skip to content

feat(catalog): acceptable alternative skills per query, and catalog routing-compare for two saved runs - #915

Merged
antonwolfy merged 6 commits into
intel:mainfrom
antonwolfy:fix/routing-acceptable-compare
Nov 19, 2026
Merged

antonwolfy merged 6 commits into
intel:mainfrom
antonwolfy:fix/routing-acceptable-compare

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#710 asks for two optional parts of the all-vs-all routing measurement, left out of the #678 fix because they are features. On main (the command is catalog routing now; #595 is merged and novelty routing --all-vs-all is retired):

main today
A request that two skills both answer --queries-by-skill takes a list of strings per skill, so the second skill's pick counts as a miss and an attractor: {"a": [{"query": "tune b things", "acceptable": ["b"]}]} is refused with the queries for 'a' must be a list of strings
Two saved runs (before and after a description edit) nothing reads both; lexical.per_query and model.noise.per_query hold the rows (#711), but comparing them query by query is left to a script

Option taken for the queries file: extend it backward-compatibly, since a request may be a plain string or an object {"query": "...", "acceptable": ["<other skill>", ...]}; a file of strings reads and saves as before (no new key is written). The comparison is a new leaf, catalog routing-compare BASE.json OTHER.json, beside catalog routing, because the two parts share one saved shape.

Closes #710

Changes

  • dokimi/novelty/all_vs_all.py: load_queries_with_acceptable returns the dict[str, list[str]] of queries together with an acceptable map; load_queries_by_skill keeps its dict[str, list[str]] return. An object without a string query, an acceptable that is not a list of strings or an unknown key is refused naming the file, the skill and the query; the gold named as its own alternative is dropped by the loader when it reads the file, and kept_alternatives, which all_vs_all and check_acceptable call, leaves the gold out of the names it keeps, so a direct all_vs_all(..., acceptable=) call never counts a gold pick as an acceptable hit as well; a blank query is dropped with its object. check_acceptable refuses an acceptable name that is not in the field (skill, query and name named); the alternatives of a skill the field leaves out are moot, since its queries are dropped.
  • all_vs_all(..., acceptable=) adds acceptable_rate per gold skill beside own_rate in both arms, only when the file names an alternative (same scored denominator; (none), (tie) and a failed call never count; the model arm counts per call). confusion and attractors still follow the gold alone. Rows of a query with alternatives keep acceptable (lexical.per_query, model.noise.per_query); other rows do not get the key.
  • commands/novelty.py, commands/novelty_routing_report.py: the command loads the map, checks it before --estimate-only too, and the summary prints the pooled gold and gold-or-acceptable counts per arm, from confusion and a new exact per-gold acceptable_picks, not from the rounded rates (1 hit in 30000 scored queries prints as 1, not 0).
  • dokimi/novelty/routing_compare.py, dokimi/commands/routing_compare.py: catalog routing-compare BASE OTHER [--arm lexical|model] [--out FILE] pairs rows by (gold, query), makes no model call, and reports each run's number right, the discordant counts, the exact two-sided sign test (exact_binomial_two_sided, 1.0 with no discordant pair) and the queries whose pick changed. The sign test counts distinct (gold, query) queries, not pairs: a request listed twice is one query (discordant_queries in the JSON; discordant keeps the pair counts), so six copies of one request, right in BASE and wrong in OTHER, give p = 1.0, not 0.03125. Every row is checked on load: query and gold strings, acceptable a list of strings, for the lexical arm rank present and null or a positive integer and picked a string when rank is set (a null rank and the picks (none) and (tie) are kept), and for --arm model picks a list of strings; a row of another type is refused naming the file and the row number, and a model section of the wrong type no longer stops a lexical comparison. A query in one run only is counted and shown by example; a row with no content word, a model query with no answered call or with no unique modal pick (--reps) is left out and counted. When both runs name the same acceptable for a pair, right means gold or acceptable; otherwise that pair is scored on the gold alone and a note says so. A file that is not JSON, not mode: all_vs_all, or without per-query rows (saved before feat(novelty): all-vs-all routing keeps a row per query for the lexical arm #711) is refused naming the file and the cause, as is --arm model for a run without a model arm and two runs with no pair in common (exit 2).
  • Registered in commands/catalog.py and cli_routes.py (a free leaf); docs/reference/cli-interface.json regenerated with make cli-snapshot; docs/skill-novelty.md documents the file shape, acceptable_rate and the compare command.
  • Changelog fragment (Added).

Risk

None for existing files: a queries file of strings gives the same loader result and the same saved result (pinned by a test comparing the two). A queries file that was refused before (an object in a list) is read now. The comparison --out is plain JSON with no schema, like catalog routing --out. --arm is the existing canonical spelling of the flag registry; here it names a routing arm, not a subject variant. Open PRs that add catalog leaves or flags (#838, #840, #841, #846, #849) also edit cli_routes.py, commands/catalog.py and docs/reference/cli-interface.json, so a merge meets textual conflicts in those one-line additions; the snapshot is regenerated with make cli-snapshot after either merges. No open PR changes novelty/all_vs_all.py.

Testing

On a Linux review host, at 0fc5618 (on main d4023b9):

  • make ci-local: 36 passed, 0 failed, 14 skipped (docker and network smoke, other Python legs, conda-forge, fuzz, semgrep, jobs that do not run on a PR). 23610 tests passed, 19 skipped.
  • New tests: tests/test_novelty_routing_acceptable.py (21) and tests/test_catalog_routing_compare.py (45), including the sign-test counterexamples (5 against 0 of 10 pairs gives p = 0.0625, 6 against 0 gives 0.03125) and an end-to-end run from two files the real all_vs_all wrote with a stub selector. On main's code (with the new loader names stubbed as the old loader and a no-op check) the first file gives 17 failed, 1 passed (the one that passes pins that a file of strings gives no acceptable key). For the second, main's copy gets stub routing_compare modules with the real names and signatures that answer wrongly (a comparison of 0 paired queries, no discordant pairs, p 1.0, no changed picks; a command that exits 0 and prints nothing): 24 failed, each on a value or a refusal that did not happen, the first being assert 0 == 10 on n_paired of the 5-against-0 case.
  • 28 mutants, one break each (the gold kept as its own alternative, each loader refusal, the hit counts of both arms, the rate formula, the dropped-skill moot rule, the outside-the-field check, the unknown-key and the no-alternative cases, the modal tie, the p value, the key mismatch rule, the pairing of a query listed twice, each refusal of the compare command): every one fails a test.
  • Review fixes, 11 more mutants, each failing its test: the pooled own and either counts (30000 scored queries, one gold hit, one acceptable hit), the sign test over pairs instead of distinct queries, the net sign of a repeated request, the acceptable and picks row checks, the model-section guard, the cap on listed changes, the unwritable --out, the too-deeply-nested file and the no-scored-query line.
  • Second review round, 4 more mutants, each failing its test: the gold kept in kept_alternatives (both arms double-count it), the picked check and the missing-rank check of a lexical row, and the RecursionError handler of load_run. The too-deeply-nested test makes json.loads raise RecursionError, because an unterminated run of [ raises a JSON error on Python 3.14 instead.
  • Third review round, 2 more mutants, each failing its test: a saved run whose result is null or missing is refused with "the result object is missing" rather than as a wrong mode ({"mode": "all_vs_all", "result": null} and a file with no result), and the gold only: BASE n, OTHER m line of the summary is printed for a comparison with alternatives and absent for one without. docs/skill-novelty.md now says a request object has no key besides query and acceptable, and that routing-compare --out creates a missing parent directory, as catalog routing --out does (the end-to-end test writes --out into a directory that does not exist).
  • Fourth review round, 1 more mutant, failing its test: a saved run whose result is present but not an object ({"mode": "all_vs_all", "result": []}) is refused with "the result object is missing or not an object"; restoring the old "is missing" wording fails the three result refusal cases.
  • Fifth review round, 2 more mutants, each failing its test: a saved run holding an integer of 5000 digits (past Python's integer digit limit, which makes json.loads raise a plain ValueError) is refused with "not JSON this reader accepts" naming the file instead of a traceback, and a model row whose picks is null or missing is refused as "picks is not a list of strings" while an empty list stays an unanswered call. Dropping the ValueError handler fails the first, and accepting a null picks fails the two model cases.
  • Not run: the other Python versions (3.11, 3.12, 3.14), the docker smoke and semgrep.

Open questions

None.

Revert

A plain revert restores the old loader and removes catalog routing-compare. Nothing is stored: a saved run that has acceptable_rate or acceptable keys keeps them, and is still read by every reader that ignores unknown keys.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…compare for two saved runs (intel#710)

catalog routing scored a query against its one gold skill only, and two saved all-vs-all runs could not be compared without rescoring by hand.

A request in the --queries-by-skill file may now be an object {"query", "acceptable"} beside plain strings. A file of strings reads and saves exactly as before. When the file names an alternative, each arm adds acceptable_rate per gold skill next to own_rate (same scored denominator; (none), (tie) and a failed call never count), the summary prints it, and the rows of such a query keep acceptable. confusion and attractors still follow the gold alone. A malformed object, an unknown key or an acceptable name outside the field is refused naming the file, the skill and the query.

catalog routing-compare BASE.json OTHER.json [--arm lexical|model] [--out FILE] pairs the per-query rows of two saved runs by (gold, query), makes no model call, and reports each run's number right, the discordant counts, the exact two-sided sign test over them and the queries whose pick changed. Queries in one run only and unscored rows are counted and left out; alternatives are used only when both runs name the same ones.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 18, 2026 13:40
@antonwolfy antonwolfy self-assigned this Nov 18, 2026
@github-actions github-actions Bot added the cli-interface-change Changes dokimi's user-facing CLI surface label Nov 18, 2026
@github-actions

Copy link
Copy Markdown

CLI interface change detected

This PR changes dokimi's user-facing CLI surface (commands and/or options):

+ added command `dokimi catalog routing-compare`
    + argument `base`
    + argument `other`
    + option `--arm`
    + option `--help/-h`
    + option `--out`

Updated on every push; the cli-interface-change label is on while the diff is non-empty.

@exai-bot

exai-bot commented Nov 18, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Found no critical or high issues in this commit.

CI at 0fc5618: 26 passing, 3 skipped.

Review limit reached. This PR has had 6 reviews, so it will only be reviewed again when you ask.
To ask: re-request review from exai-bot in the Reviewers list.

Lower-severity findings not shown (1)

1 medium

Review details
  • Commit reviewed: 0fc5618 against merge base d4023b9
  • Coverage: 12 files in 2 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 663k tokens (410k from cache), 1m25s
  • Tool calls: 45 (23 file_read, 10 pr_threads, 5 code_search, 3 local_check_results, 1 ci_log_search, 1 ci_status, 1 code_comment, 1 file_read_diff)
  • Routing comparison command, integration, and tests: 7 files
  • Acceptable novelty routing, reporting, and documentation: 5 files

@codecov-commenter

codecov-commenter commented Nov 18, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.86%. Comparing base (d4023b9) to head (0fc5618).
⚠️ Report is 10 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #915      +/-   ##
==========================================
+ Coverage   95.83%   95.86%   +0.02%     
==========================================
  Files         442      444       +2     
  Lines       58788    59101     +313     
  Branches    10146    10198      +52     
==========================================
+ Hits        56342    56655     +313     
  Misses       1521     1521              
  Partials      925      925              
Files with missing lines Coverage Δ
dokimi/dokimi/cli_routes.py 97.47% <ø> (ø)
dokimi/dokimi/commands/catalog.py 98.12% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/commands/novelty.py 99.07% <100.00%> (+<0.01%) ⬆️
dokimi/dokimi/commands/novelty_routing_report.py 99.41% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/commands/routing_compare.py 100.00% <100.00%> (ø)
dokimi/dokimi/novelty/all_vs_all.py 99.53% <100.00%> (+0.14%) ⬆️
dokimi/dokimi/novelty/routing_compare.py 100.00% <100.00%> (ø)

... and 14 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…t and refuses a malformed row, exact acceptable counts in the summary

Settles the three open review threads of intel#915.

The summary line of `catalog routing` took its pooled gold and gold-or-acceptable counts from the four-decimal rates, so 1 hit in 30000 scored queries printed as 0. It now sums `confusion` for the gold picks and a new exact per-gold `acceptable_picks` for the acceptable ones.

`routing-compare` ran its sign test over every pair, so a request listed six times, right in BASE and wrong in OTHER, gave p = 0.03125. The test now counts each distinct `(gold, query)` once (right in BASE only when more of its pairs are right there); `discordant` keeps the pair counts and `discordant_queries` holds the counts the test uses.

`load_run` now checks every row: `query` and `gold` strings, `acceptable` a list of strings, and for the model arm `picks` a list of strings, and refuses with the file and row number. A model section of the wrong type no longer raises for the lexical arm, it only leaves the model name out.

Tests also cover the unreachable-before lines codecov named: a too deeply nested file, an unwritable `--out`, the left-out and changed-pick lines of the summary, and a field with no scored query.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
Comment thread dokimi/dokimi/novelty/all_vs_all.py Resolved
…ting-compare checks the lexical rank and pick

Settles the two open review threads and the Python 3.14 wheel failure of intel#915.

all_vs_all now drops the gold from a query's acceptable names in kept_alternatives, not only in the file loader, and omits a query left with none, so a direct call no longer counts a gold pick as both the gold and an acceptable hit in either arm.

load_run refuses a lexical row whose rank is missing or is neither null nor a positive integer, and a row with a rank whose picked is not a string, naming the file and row; null ranks and the picks (none) and (tie) are kept.

The deep-nesting test no longer relies on an unterminated run of brackets, which Python 3.14 reports as a JSON error rather than a RecursionError: it makes json.loads hit the depth limit, as the sibling tests of the queries file do.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

Review points answered at 6362b4c; failed: Tests (py3.14).

Declined, with the evidence in the replies:

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Not approved yet · reviewed 6362b4c

Next: @antonwolfy: settle 1 open question (below). 3 nits optional.

Blocking

  • Open question for @antonwolfy: catalog routing-compare --out FILE creates a missing parent directory (dokimi/dokimi/commands/routing_compare.py:52), so a mistyped directory is created rather than refused, the way catalog routing --out does. State in docs/skill-novelty.md that --out creates its parent directory, or drop the mkdir and refuse a missing directory.

Verified on 6362b4c: ✅ changed tests: 63 passed, fail on main · ✅ full suite with main merged in: 23613 passed · ✅ merges onto main · ⚠️ 12 broken variants of the changed code: 11 caught by the tests, 1 not · 3 mutations tried · 9 edge inputs tried

16 checks behind it, each with its evidence
Area What holds How
Queries file objects A request given as {query, acceptable} loads with its alternatives, and a file of strings gives an empty alternatives map and no acceptable key in the result tests on the head
Gold as own alternative The gold named in its own acceptable is dropped in both arms of a direct all_vs_all call, so a gold pick is counted once tests on the head
Acceptable rate acceptable_rate shares the scored denominator with own_rate, and the pooled gold and gold-or-acceptable counts are exact at 30000 scored queries tests on the head
Sign test The exact two-sided sign test gives the known p over the discordant pairs, and a request listed twice counts once tests on the head
Compare refusals --arm model is refused for a run made without --model, and two runs with no pair in common are refused as an input error tests on the head
File shapes {}, [], truncated JSON and an empty file are refused naming the file, and the refusal does not reach a traceback ran it, edge input (structured)
Text input Bytes that are not UTF-8 are refused naming the file, and a byte order mark with CRLF line endings loads ran it, edge input (text)
Command exit catalog routing-compare with a missing file exits 2 and prints an Error: line on stderr ran it, edge input (cli)
Paths A directory and a missing file given as BASE are refused naming the path and the cause ran it, edge input (paths)
Numbers A lexical rank of 0, -1, true, 1.0 or NaN is refused naming the row ran it, edge input (numbers)
Collections Six copies of one request that is right in BASE and wrong in OTHER count as one discordant query with p 1.0, and two empty runs give p 1.0 with no pair ran it, edge input (collections)
Nulls A null acceptable and a null unscored rank and picked are read as no alternative, and a null gold is refused naming the row ran it, edge input (none)
Gold filter mutant Negating the check that drops a query's alternatives when the query is outside the field makes the changed tests fail broke the code, tests caught it
Load mode check mutant Negating the mode and result check in load_run makes the changed tests fail broke the code, tests caught it, edge input (structured)
Merge The PR merges onto current main with no conflict merge onto main
Local ci The whole local CI passes with main merged in, including the CLI snapshot, mypy and the coverage of changed lines full suite, main merged in

Comment thread dokimi/docs/skill-novelty.md Resolved
…docs name the acceptable key and the --out parent directory

A run whose `result` is null or absent was refused as "not an all-vs-all routing result (mode 'all_vs_all')", naming a mode the file has: it now says the `result` object is missing.

docs/skill-novelty.md says a request object has no key besides `query` and `acceptable`, and that `catalog routing-compare --out` creates a missing parent directory, as `catalog routing --out` does.

A test reads the `gold only` line of the summary: printed for a comparison with alternatives, absent for one without.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(commented) 🟡 Not approved yet · reviewed 6362b4c

@vchamarthi (#915 (review)): On the open question: kept the mkdir, so --out creates a missing parent directory like catalog routing --out, and stated it in docs/skill-novelty.md ("--out writes the comparison as JSON and creates a missing parent directory, as catalog routing --out does"). The end-to-end test already writes --out into a directory that does not exist. The three nits are settled in the threads above. Commit 7995f58.

@antonwolfy

Copy link
Copy Markdown
Contributor Author

Ready for another look at 7995f58; CI is green.

Declined, with the evidence in the reply:

  • R5964640571 (@vchamarthi) (fixed in part): Kept the mkdir rather than refusing a missing directory, matching catalog routing --out; the docs now state it.

@vchamarthi vchamarthi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approved · re-reviewed 7995f58

Next: nothing required from @antonwolfy. 1 nit optional.

Verified on 7995f58: ✅ changed tests: 66 passed, fail on main · ✅ full suite with main merged in: 23677 passed · ✅ merges onto main · ✅ 12 broken variants of the changed code: 12 caught by the tests · 1 mutation tried · 8 edge inputs tried

10 checks behind it, each with its evidence
Area What holds How
Changed tests The changed test files pass on the head: 66 tests in tests/test_catalog_routing_compare.py and tests/test_novelty_routing_acceptable.py tests on the head
Changed tests on main The same two test files fail on main at collection, since dokimi.novelty.routing_compare and check_acceptable do not exist there same tests on main
Null result "result": null as BASE is refused naming the file and the result object is missing, as the check at dokimi/dokimi/novelty/routing_compare.py:49-50 does ran it, edge input (none)
Malformed run files {}, [], a truncated object, an empty file and a result of {} are each refused naming the file and the cause ran it, edge input (structured)
Encoding A run file with bytes that are not UTF-8 is refused naming the file, and a file with a byte order mark and CRLF line endings loads ran it, edge input (text)
Empty collection A result holding an empty lexical object is refused naming the missing lexical.per_query rows ran it, edge input (collections)
--out and missing paths --out into a directory that does not exist writes the comparison, and a missing BASE is refused naming the path ran it, edge input (paths)
Exit code catalog routing-compare with a missing BASE exits 2 and prints missing.json: cannot read on stderr ran it, edge input (cli)
Query object keys A query object with query and acceptable loads with its alternatives, and an extra key is refused naming the key, as docs/skill-novelty.md now says ran it, edge input (structured)
Gold only line Negating if scoring == "gold_or_acceptable": at dokimi/dokimi/commands/routing_compare.py:80 fails the changed tests, so the new test pins the line broke the code, tests caught it

…t an object

Settles the review nit on routing_compare.py:50: `"result": []` was reported as a missing `result` object although the key is present. The message now reads "the `result` object is missing or not an object", and the refusal test gains the `[]` case.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author

(approved) 🟢 Approved · re-reviewed 7995f58

@vchamarthi (#915 (review)): Approval with one optional nit; it is the thread above (4621804247), settled in 5ccbed7.

… limit and a model row with no picks list

A saved run holding an integer past Python's digit limit made json.loads raise a plain ValueError that neither handler caught, so the command ended in a traceback. The reader now turns it into a RoutingInputError naming the file, and the JSON read moves into its own helper to keep load_run under the complexity cap.

A model row whose `picks` is missing or null was read as an unanswered call and silently dropped from the counts. Only a list of strings is accepted now; an empty list stays an unanswered call.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy merged commit d2790e1 into intel:main Nov 19, 2026
29 checks passed
@antonwolfy
antonwolfy deleted the fix/routing-acceptable-compare branch November 19, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-interface-change Changes dokimi's user-facing CLI surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

novelty routing --all-vs-all: acceptable alternatives per query and a command that compares two saved runs

4 participants