Skip to content

feat(ai): model-in-the-loop prompt benchmarking #413

Closed

Description

@dan-petty

Context & Rationale

No tool runs the review prompts through a model and measures the result. Every prompt edit ships on argument alone.

What exists, checked at ef21785:

  • devops ai prompt-eval replays only the deterministic suppression layer against recorded verdicts. It never calls a model (src/devops_cli/ai/prompt_eval.py:1-16, 145-195).
  • devops benchmark --suite calls models, but not with the review prompts (src/devops_cli/ai/benchmark/suite.py:38-39, 581-600). It also treats VERIFIED as ground truth (suite.py:80-84).
  • devops review corpus score measures recall against injected defects. That ground truth does not come from the review loop. But it scores one session at a time:
    • CorpusScore holds one session_id (src/devops_cli/ai/review/defects.py:1384-1410).
    • score_corpus takes one session's findings (defects.py:1456-1494).
    • --session takes one value (src/devops_cli/commands/review.py:1568-1605).
  • devops review benchmark reviews the same files k times with the response cache off (DEFAULT_REVIEW_BENCHMARK_RUNS = 3, src/devops_cli/config/defaults.py:391; commands/review.py:1365-1377). It keeps only medians of time, calls and tokens, not which defects each run found (src/devops_cli/ai/review/profile.py:335-421).
  • The run store compares one number per metric from each run: compare_runs (src/devops_cli/ai/run_store.py:634-655) and check_regression (run_store.py:731-769). Nothing shows a difference against run-to-run variation.
  • A run's setup records models, page size and gateway pools (run_store.py:140-154). It records neither the prompts nor the temperature, so two runs with different prompts look like one setup.
  • The setup can also name the wrong verification model.
    • Reviews layer verification on the analysis task (src/devops_cli/ai/review/runner.py:1539-1556).
    • review_setup layers it on the base ai settings instead (run_store.py:146).
    • So when ai.tasks.verification is unset, which is the shipped default (docs/ROADMAP.md:354), the setup records ai.model and that group's pool for verification, not the analysis model that actually verified.

Prompt edits that shipped without measurement:

Ground truth:

  • VERIFIED labels come from the verifier under test. Two calibration sessions measured false-positive rates near 40% and 85% among high-severity findings (prompt_eval.py:7-12). So a VERIFIED count is a prior, not a label.

  • The "122 human-verified records" this item first named are not a usable seed. Before v0.2.23, the exporter filed every finding that had no adjudicator as human (fixed in ea49d6e; src/devops_cli/ai/review/exporter.py:60-63).

  • On 2026-10-01 the local data hold no human verdicts:

    • 0 of 2,237 findings in the 26 sessions under .data/reviews;
    • 0 of 1,744 records in .data/reviews/feedback_dataset.jsonl.

    The "1066 VERIFIED records" figure is also out of date: 633 records are VERIFIED today.

  • This item therefore uses the injected defects of a synthetic corpus as its ground truth. They measure regression on defect shapes the generator knows, not general review capability. The report keeps saying so (SYNTHETIC_CAVEAT, defects.py:41-44).

  • Agreement with human verdicts is split off (see Strategic Alignment), because the labels it needs do not exist yet.

Why repeated runs:

  • Identical reviews produce different findings (commands/review.py:1365-1367).
  • A judge can be consistent and still wrong. arXiv 2606.19544 reports test-retest reliability above 0.95 alongside position bias above 0.10 in two production judges.
  • So one run per prompt says little. Each arm runs k times, and the difference between arms is shown next to the spread within each arm. One run has no spread, so it is never shown as one.

Scope & Deliverables

  • Deliverable: Score k sessions of one corpus together (src/devops_cli/ai/review/defects.py).
    • CorpusScore gains three counts, all set in score_corpus. Existing fields keep their values.
      • candidate_findings: every finding the review raised before verification (the candidates argument).
      • invalidated_findings: those findings with status INVALIDATED.
      • reported_findings: the findings verification kept (the reported argument).
    • A new score_corpus_runs combines k per-session CorpusScores and each session's ReviewProfile (or None) into a CorpusRunsScore with these fields:
      • Per injection, keyed by its existing id (file, line, template): found_in and reported_in, the number of sessions that found or reported it.
      • Found and reported totals, each with:
        • pass_at_k: the share of injections found in at least one session;
        • pass_hat_k: the share found in every session;
        • in_none: the number found in no session.
      • One row per session:
        • its session_id;
        • recall found and recall reported;
        • candidate, invalidated and reported findings;
        • prompt tokens, completion tokens and unparsed persona replies (the profile's persona_outcomes count for CONST_PERSONA_REPLY_UNPARSED), read from profile.json (0 when it is missing).
      • Top-level means of the per-session figures. They use the names the run store already extracts (recall_found, recall_reported, prompt_tokens, completion_tokens), plus candidate_findings, invalidated_findings and reported_findings. Ratios round to 3 decimals and counts to 1.
      • spread: [min, max] of each of those figures across the sessions. It is None when k is 1, because one run measures no spread.
      • scores: the full per-session CorpusScores.
      • Run details: the caveat, runs (k) and the sessions' shared prompt_digest.
    • It uses only the standard library.
  • Deliverable: Each review session records which prompts it ran.
    • review_prompt_digest() goes in src/devops_cli/ai/personas/__init__.py.
      • It applies run_store.digest to the relative path and text of every .md file under ai/tasks/ and ai/personas/.
      • It takes the two directories as parameters, defaulting to the package's own.
    • ReviewProfile gains prompt_digest: str = "", set by ReviewProfiler.build (profile.py:231-264).
  • Deliverable: devops review corpus score scores one arm of k runs (commands/review.py:1494-1605).
    • Session selection.
      • --session/-s becomes repeatable.
      • A new --runs/-n N (minimum 1) takes the latest N sessions whose profile target is the corpus. This generalizes _corpus_session_dir (commands/review.py:1494-1509). With neither option, the command still scores the latest session, as it does today. The option defaults to unset rather than 1, so an explicit --runs can be refused next to --session.
    • Refusals. Each of these exits 1:
      • --session given together with --runs;
      • fewer matching sessions than N. The message says how many exist.
      • sessions whose prompt_digest values differ. The message lists each session's digest, and no run is recorded. One score is one arm.
    • Run record.
      • The subject stays as it is today: the corpus digest.
      • The setup is review_setup(prompt_digest=..., runs=k, personas=...). personas is the sorted set of personas that replied in the scored sessions, read from each profile's persona_replies.
      • The results are the CorpusRunsScore. --json prints the same object.
    • Text report.
      • The totals.
      • One row per session.
      • One row per injection, with found in x/k, reported in y/k and the finding titles that matched it in any session.
      • Per template: injections, found in any session, found in every session.
      • The caveat line stays.
    • Model pinning. When a gateway group in the setup's pools serves more than one distinct model, the report prints not model-pinned: <group> serves <n> models. The run is still recorded.
    • Unchanged. _scored_session and sample validation (commands/review.py:1703-1736) still score one session with score_corpus.
  • Deliverable: The setup describes the review that ran, and arms are compared next to their spread (src/devops_cli/ai/run_store.py, src/devops_cli/commands/ai_runs.py).
    • review_setup (run_store.py:140-154) resolves verification the way reviews do: ai.for_task("analysis").for_task("verification") (runner.py:1539-1556). With ai.tasks.verification unset, the setup then records the analysis model and pool for verification. This also changes the setups that review benchmark and sample validation record (commands/review.py:1386, 1830).
    • review_setup also records each task's temperature and top_p.
    • _extract_core_metrics (run_store.py:581-593) also extracts candidate_findings, invalidated_findings and reported_findings.
    • MetricDiff (run_store.py:601-608) gains base_range and current_range, both tuple[float, float] | None. compare_runs fills each from that record's results["spread"] when it is present.
    • When any metric has a range, the devops ai runs compare table (ai_runs.py:262-279) adds three columns: Base range, Current range and Spread.
      • Spread reads overlaps when the two ranges overlap and apart when they do not.
      • It reads — when either run has no range, such as a one-run score.
    • devops ai runs check is unchanged and still compares means.
  • Deliverable: Docs and records.
    • Help text for --runs and the repeatable --session (src/devops_cli/lang/en/help.py:884-885).
    • A regenerated docs/CLI_REFERENCE.md.
    • A CHANGELOG entry. It says that run setups now record the analysis model for verification when verification is unset.
    • The task file docs/agent/tasks/task-413-model-in-the-loop-prompt-benchmarking.md, rewritten to this scope in the delivering commit. It still says Backlog and v0.2.24.
    • The roadmap entry (docs/ROADMAP.md:186-189), updated with the corrected figures. This applies only if docs/ROADMAP.md is still hand-edited when this item lands (feat(github): github-sourced roadmap, migration and generated roadmap view (devops roadmap migrate, render) #739).
  • Acceptance criteria:
    • Scoring (unit test, tests/test_review_defects.py). The fixture has 4 injections and 3 sessions:

      • session 1 finds injections 1-3 and reports 1;
      • session 2 finds 1-2 and reports 1;
      • session 3 finds 1 and reports none.

      score_corpus_runs must give:

      • [(t.found_in, t.reported_in) for t in tallies] == [(3, 2), (2, 0), (1, 0), (0, 0)];
      • found (pass_at_k, pass_hat_k, in_none) == (0.75, 0.25, 1);
      • reported (pass_at_k, pass_hat_k, in_none) == (0.25, 0.0, 3);
      • recall_found == 0.5 with spread (0.25, 0.75);
      • recall_reported == 0.167 with spread (0.0, 0.25).
    • One session reproduces today's totals. Use the fixture of test_score_matches_by_line_or_evidence_and_separates_what_verification_kept (tests/test_review_defects.py:282-318). score_corpus_runs([score], [None]) must give:

      • scores[0] == score;
      • found pass_at_k == pass_hat_k == 1.0, which equals score.recall_found;
      • reported pass_at_k == pass_hat_k == 0.75;
      • (candidate_findings, invalidated_findings, reported_findings) == (6, 1, 5);
      • spread is None.
    • CLI (tests/test_review_defects.py). Sessions are written with the _session helper (tests/test_review_defects.py:321-327), using profiles that carry token counts, one unparsed persona reply and one shared digest. Three sessions review the corpus and one reviews another target.

      • corpus score <dir> --runs 3 --json exits 0, with runs == 3, one row per corpus session in oldest-first session_id order, per-session tokens and unparsed replies taken from the profiles, and setup["personas"] recorded.
      • --runs 4 exits 1.
      • -s A -s B scores exactly sessions A and B.
      • -s A --runs 2 exits 1.
    • Mixed arms. For two sessions with different prompt_digest values, corpus score --runs 2 exits 1, prints both digests and records no run.

    • Existing tests. The two existing CLI tests (tests/test_review_defects.py:330-383) change only their JSON and results paths, to scores[0].... No other existing test changes.

    • Prompt digest (tests/test_review_profile.py):

      • review_prompt_digest() returns 16 hex characters and the same value on every call.
      • Over a temporary copy of the two directories, it returns a different value when one character of tasks/review.md changes, and a different value again when one character of personas/devsecops/prompt.md changes.
      • Adding a .py file to either directory leaves the value unchanged.
      • ReviewProfiler().build(...) carries the package's digest.
    • Setup (tests/test_run_store.py). With gateway_pool patched to return a fixed pool, and settings in which only ai.tasks.analysis names a gateway group and the base ai.model names another:

      • review_setup()["models"]["verification"] == review_setup()["models"]["analysis"];
      • pools holds only the analysis group;
      • both tasks record the analysis task's temperature and top_p.
    • Comparison (tests/test_run_comparison.py):

      • Two CORPUS_SCORE records with spread.recall_found of [0.25, 0.75] and [0.5, 1.0] give (base_range, current_range) == ((0.25, 0.75), (0.5, 1.0)), and the devops ai runs compare table marks that row overlaps.
      • With [0.8, 1.0] as the current range, the row reads apart.
      • Records without spread, including one-run scores, give None ranges. Compared with a record that has a range, the row reads —.
      • The existing tests in that file pass unmodified.
    • Pinning. With review_setup patched to return a devops-review pool serving qwen3-coder:30b and gpt-oss:20b, the text report contains not model-pinned: devops-review serves 2 models.

    • Gate.

      • The new tests touch no network, cluster or model.
      • Each new test runs in under 1 s. Check with uv run pytest tests/test_review_defects.py tests/test_review_profile.py tests/test_run_store.py tests/test_run_comparison.py --durations=0.
      • uv run devops ci passes.
    • Person-run check (needs a live model; never part of devops ci).

      • Both arms must read one configuration file. config.yaml is git-ignored (.gitignore:64), and the config lookup stops at a worktree's .git (src/devops_cli/config/settings.py:868-890). So a second worktree would otherwise run on the defaults, not the gateway.
      • Copy the main checkout's config.yaml to a file outside both checkouts. In the copy, set ai.tasks.analysis.model and ai.tasks.verification.model to devops-coder (one model: qwen3-coder:30b on ollama-48gib), both on the gateway provider.
      • Run from a checkout of the base commit:
      export DEVOPS_CLI_CONFIG=<the copied file>              # export it in arm B's worktree too
      uv run devops config get ai.tasks.analysis.model        # devops-coder
      uv run devops config get ai.tasks.verification.model    # devops-coder
      uv run devops review corpus generate src/devops_cli/core src/devops_cli/security src/devops_cli/crypto --seed 1
      CORPUS=<the directory generate printed>
      uv run devops review benchmark "$CORPUS/files" --all --runs 3
      uv run devops review corpus score "$CORPUS" --runs 3     # arm A; note its run ID
      uv run devops ai runs baseline set <A>
      uv run devops review benchmark "$CORPUS/files" --all --runs 3
      uv run devops review corpus score "$CORPUS" --runs 3     # arm A again (A/A)
      uv run devops ai runs compare <A2>                       # setups identical
      
      • Then, in a separate worktree with the same DEVOPS_CLI_CONFIG, edit one prompt and run the same benchmark and score commands to get arm B. uv run devops ai runs compare <B> lists prompt_digest as the only setup difference.
      • No not model-pinned line appears.
      • The PR description records the A/A ranges. They are the noise floor that later prompt changes are read against.
  • Key questions:
    • What is the ground truth? The synthetic corpus's injected defects (proposed).
      • The review loop did not produce them.
      • The verifier's INVALIDATED count is reported as the verifier's opinion, not as truth.
      • No human verdicts exist locally, so agreement with people is split off.
    • How is the prompt under test supplied? As a checkout (proposed).
      • Prompts are package files: personas/__init__.py:39-77, verification.py:51-52, runner.py:98-100 and classification.py:32-35.
      • So each arm runs from its own worktree, and the arm is identified by the prompt digest in each session's profile.
      • An override flag would add a second way to load prompts, used only by benchmarks.
    • What does the prompt digest cover? Every .md file under ai/tasks/ and ai/personas/ (proposed).
      • It is a closed set with no file list to maintain.
      • Including too much only makes an unrelated prompt edit look like a new arm.
      • Prompt text built in code is covered by RunRecord.commit.
    • Where is k set? No new constant (proposed).
      • review benchmark --runs already defaults to DEFAULT_REVIEW_BENCHMARK_RUNS = 3 (defaults.py:391).
      • corpus score without --runs scores one session, so a plain corpus score behaves as it does today.
    • Pinned model and temperature? Hold both fixed across the arms and record them, without forcing temperature to 0 (proposed).
      • Reviews run at the configured temperature. The default is 0.1 (defaults.py:70), but a local config.yaml can set another, so the setup records the value in use.
      • The k runs measure the spread that a nonzero temperature causes.
      • Pin the model with a single-model gateway group such as devops-coder (k8s/llm/gateway/configmap.yaml:44-47).
      • devops-review serves qwen3-coder:30b and gpt-oss:20b (configmap.yaml:89-104), and devops-chat serves two Qwen3.8 27B builds (configmap.yaml:15-42). So the report warns when a run is not pinned.
      • The person-run check holds model and temperature fixed for both arms through one shared config file.
    • How is the prompt difference read against the spread? Means and min-max ranges, marked overlaps or apart (proposed).
      • With k = 3, a significance test would claim more than the data support.
      • A one-run score has no range, so its comparison reads —, never apart.
    • New command to run both arms? No (proposed).
      • Arms are runs in the store.
      • devops ai runs baseline set names the base arm, and devops ai runs compare compares the two.
      • A wrapper that creates worktrees and runs both arms can follow if the manual sequence proves error-prone.
    • Use pydantic-evals? No; use the standard library (proposed).
      • It is locked only as a transitive dependency of pydantic-ai (uv.lock:2417, 2480).
      • Its repeat= drives Python callables, while each arm here is a whole CLI review.
    • JSON shape of corpus score --json? One shape for every k (proposed).
      • The two existing CLI tests update their paths.
      • Pre-1.0, there is no compatibility shim.
    • Does state carry from one run to the next? Yes, in one place. Not changed in this item (proposed).
      • Verification learns false-positive catalog entries from deterministic invalidations (src/devops_cli/ai/review/common_hallucinations.py:935-990) and applies learned entries to later findings (verification.py:1191-1210).
      • So an earlier run can change a later run's verdicts.
      • The A/A pair in the person-run check shows whether that moves the figures. If A2's ranges read apart from A's, file a follow-up to run benchmarks under catalog_learning_disabled() (common_hallucinations.py:183-189), the guard prompt-eval already uses (prompt_eval.py:141).
    • Agreement with human verdicts (Cohen's kappa)? Split off; see Strategic Alignment.
      • It compares recorded verdicts and needs labels that do not exist yet.
      • It measures the verifier, not prompt arms.
    • Order-swap probe? Split off; see Strategic Alignment.
      • It reuses this item's arm comparison, with reversed verification order as arm B.
    • Seeded dilution variants (the follow-on line at docs/ROADMAP.md:188)? Not in this item (proposed).
      • A diluted prompt is just another arm.
      • Counting fix_llm_response repairs needs a profile counter. File it when someone runs dilution arms.
    • Do benchmark sessions inflate devops review stats? Yes, but feat(review): subject-keyed review history with a leave-one-out baseline #607 owns session identity.
    • Priority and release? P1, in v0.2.25, as the owner retargeted it on 2026-10-01.
  • Constraint: Ground truth must not come from the loop being measured.
    • Recall comes from injections.
    • VERIFIED and INVALIDATED counts are reported as the verifier's opinion, never as labels.
    • Every report carries the synthetic caveat.
  • Constraint: Live-model runs stay on demand and never run inside devops ci.
    • The new tests use temporary sessions and patched setups only. They touch no network, cluster or model, and each costs under 1 s.
    • Tests use structural tuple assertions.
  • Constraint: No new dependency, and no prompt-override path. Prompts load only from the package.
  • Constraint: Cyclomatic complexity of 10 or less and nesting depth of 5 or less (AGENTS.md:13-17).
  • Constraint: Out of scope:

Strategic Alignment

Activity

  1. added this to the v0.2.23 milestone on Sep 22, 2026
  2. added
    type/feature
    scope/ai
    priority/p1-high
    on Sep 22, 2026
  3. modified the milestones: v0.2.23, v0.2.24 on Sep 28, 2026
  4. added a commit that references this issue on Sep 28, 2026
  5. modified the milestones: v0.2.24, v0.2.23, v0.2.25 on Sep 30, 2026
  6. dan-petty commented on Oct 1, 2026

    @dan-petty
    OwnerAuthor

    Retargeted from the shipped v0.2.23 to v0.2.25. It is still valid (checked 2026-10-01), and a P1 left open in a shipped release keeps precedence over P1 work committed later.

  7. dan-petty commented on Oct 2, 2026

    @dan-petty
    OwnerAuthor

    Closed by #939, merged into release/v0.2.25.

    GitHub only acts on closing keywords when a pull request merges into the default branch, so this was closed by devops gh issues close-merged.

  8. added a commit that references this issue on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority/p1-highscope/aitype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions