Skip to content

feat(questions): --dry-run and --max-usd on eval questions analyze and review (Part of #94) - #1576

Merged
napetrov merged 16 commits into
intel:mainfrom
napetrov:feat/cli-paid-guards-3
Dec 6, 2026
Merged

napetrov merged 16 commits into
intel:mainfrom
napetrov:feat/cli-paid-guards-3

Conversation

@napetrov

@napetrov napetrov commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Part of #94 (F1b, spend: paid-guards slice 3, the two question-quality leaves). #94 stays open.

Summary

eval questions analyze and eval questions review now price their model calls before any spend, following the eval skill-coverage pattern from #1419:

  • --dry-run prints the list-price estimate and exits 0. It builds no client, calls no model and writes no report. The prompts are built without a client, so the estimate is built from the exact prompts (the token count is a four-characters-per-token estimate).
  • --max-usd X refuses a real run before its first call (exit 3, no client built) when the estimate is over X, or when the model has no list price.
  • The cap is checked before each call, and in-flight calls can overshoot it. On a mid-run stop, analyze exits 1 and writes no report. review exits 3 if this invocation saved a checkpoint, or 1 if it saved none. The checkpoint records the planned question count. Both previews show the matching-model warning.
  • Spend: both commands' calls now go through llm_call_with_usage and their usage is summed into a Spend (the fix(cost): judge_metrics skips cache replays; one Spend accumulator for totals #1183 accumulator), which is what the cap reads.

Leaf table

Leaf Flags before Flags after
eval questions analyze none (uncapped, no preview) --dry-run (estimate, exit 0, no client); --max-usd (pre-call refusal exit 3, mid-run stop exit 1)
eval questions review none (uncapped, no preview) --dry-run (estimate over questions x reviewers, honours --limit); --max-usd (pre-call refusal exit 3, mid-run stop exit 3 with a checkpoint or 1 without one)

Kept rows: none. --json is not added (F2).

Reply-token assumptions, stated in the --dry-run output: 400 per classification, 800 per review vote.

Evidence

  • The new checkpoint and preview tests failed on the previous head. All 17 tests in tests/test_questions_dry_run_and_cap.py pass with the review fixes, including the stale output, saved checkpoint and matching-model warning cases.
  • The dry-run and refusal tests replace llm_call_with_usage in both modules, and LLM.__init__, with functions that fail the test, so any client construction or model call is caught.
  • Existing analyzer and reviewer tests now patch llm_call_with_usage and return (text, None). Their assertions are unchanged.
  • tests/test_cli_spend_controls.py: the two leaves leave the uncapped list.
  • docs/reference/cli-interface.json regenerated with make cli-snapshot (four new option entries).
  • Second commit (review fixes): the gate returns a verdict and the command exits, since spend_preview ends no process (import-architecture test); prompts are built only for a priced run; both analyzers share questions/metered.MeteredCalls; skill_coverage reuses the estimate and cap-refusal helpers (duplicate-code ratchet); panel-review input parsing moves to a helper (complexity ratchet).
  • Full suite pytest tests on the rebased head: see the CI checks. Local: make ci-local CI_LOCAL_ARGS="--offline --jobs static,typecheck" 0 failed; pytest -n 16 tests 34330 passed, 29 skipped.

Not in this PR

Paid leaves still unguarded on intel/main 26cb1543d plus this change (the check in scripts/cli_spend_controls.py is the source of truth):

  1. Fully guarded, or only --json missing (F2): skill routing, repo hits judge (guarded); catalog routing, skill novelty analyze, eval personas discover, tools preference, eval skill-coverage, eval questions analyze, eval questions review (--json only).
  2. --dry-run present, no --max-usd: repo reach, repo skill-reach, tasks run, eval questions refine.
  3. --max-usd present, no --dry-run: catalog novelty, skill novelty atoms, skill novelty probe, skill shorten, eval graph, repo run.
  4. Neither flag: answers generate, arms run, arms matrix-run, benchmark run, benchmark batch, catalog trigger-probe, delivery scan, eval judge agreement|validate|wording, eval questions generate, eval redteam, eval score checklist|pairwise|panel|pointwise|ragas|reference, eval triggers generate, evaluate, explore run, subjects run.

Brief W3 named up to three leaves. Two were done. eval score pointwise was left out: the judge's call plan (retries, redraws, placeholder skips, the ask rubric) would need a client-free mirror, which is a larger change. eval triggers generate --rewrite was left out: the number of rewrite calls is known only after the trigger set is built.

Label: cli-interface-change.

🤖 Generated with Claude Code

…iew (Part of intel#94)

Both leaves price their model calls before any spend: --dry-run prints the
list-price estimate and calls no model; --max-usd refuses a real run before
its first call when the estimate is over the cap or the model is unpriced
(exit 3). Their calls now report usage and are summed into a Spend, which the
cap reads, so a run that goes over the cap mid-run stops with exit 1.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
… of intel#94)

Review of the --dry-run and --max-usd leaves found the gate and the analyzers
breaking repo rules, so this commit fixes them without changing the flags,
output or exit codes:

- spend_preview.gate returns DRY or REFUSED and the command exits. The module
  ends no process (test_only_the_frontend_ends_the_process), and is a
  foundation layer. The prompts are built only when the run is priced, so a
  plain run builds nothing.
- The metering (cap check before a call, usage recorded after it) lives in
  questions/metered.MeteredCalls, shared by both analyzers. The call function
  is passed in, so the llm_call_with_usage patch points stay where they were.
- skill_coverage reuses spend_preview's estimate and cap-refusal helpers instead
  of copies (duplicate-code ratchet).
- Panel-review input parsing moves to _panel_questions (complexity ratchet).
- Test fixtures move to llm_call_with_usage, gain review_prompts, and carry the
  max_usd and dry_run flags the parser always sets.

Full suite: 34229 passed, 29 skipped. Static and typecheck jobs: 0 failed.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov
napetrov requested a review from a team as a code owner December 3, 2026 07:55
Copilot AI balanced review requested due to automatic review settings December 3, 2026 07:55
@napetrov napetrov added the cli-interface-change Changes dokimi's user-facing CLI surface label Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

CLI interface change detected

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

~ `dokimi eval questions analyze` parameters changed:
    + added option `--dry-run`
    + added option `--max-usd`
~ `dokimi eval questions review` parameters changed:
    + added option `--dry-run`
    + added option `--max-usd`

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The spend cap can be exceeded on a final call without failure, and an early cap stop can misrepresent a stale report as the current run’s partial results.

2 open issues
What changed in this PR

2 findings. This PR extends #94’s spend controls to question analysis and panel review, following the skill-coverage pattern.

Changes:

  • Adds --dry-run estimates and --max-usd guards to both commands.
  • Shares pricing helpers and meters model usage through Spend.
  • Updates CLI metadata, regression tests, and the changelog.
File Description
dokimi/​tests/​test_writers_save_artifact.py Adapts writer mocks to metered calls.
dokimi/​tests/​test_record_readers.py Supplies new command arguments.
dokimi/​tests/​test_questions_output_unwritable.py Adds prompt-building test support.
dokimi/​tests/​test_questions_dry_run_and_cap.py Tests previews, refusals, and spend tracking.
dokimi/​tests/​test_question_quality_analyzer.py Updates analyzer mocks.
dokimi/​tests/​test_question_panel_reviewer.py Updates reviewer mocks.
dokimi/​tests/​test_import_architecture.py Registers the pricing foundation module.
dokimi/​tests/​test_cli_spend_controls.py Removes both leaves from the uncapped list.
dokimi/​dokimi/​spend_preview.py Adds shared pricing and refusal helpers.
dokimi/​dokimi/​questions/​quality_analyzer.py Adds metering and client-free prompts.
dokimi/​dokimi/​questions/​panel_reviewer.py Adds metering and review prompt previews.
dokimi/​dokimi/​questions/​metered.py Shares usage accounting and cap checks.
dokimi/​dokimi/​commands/​skill_coverage.py Reuses pricing helpers.
dokimi/​dokimi/​commands/​questions.py Wires flags, previews, and budget stops.
dokimi/​docs/​reference/​cli-interface.json Records four new CLI options.
dokimi/​changelog.d/​20261202_120000_cli-paid-guards-3.md Documents spend controls and metering.

Review effort: Balanced

Comment thread dokimi/dokimi/commands/questions.py Resolved
with self._lock:
self.spend.add_call(usage)
if self.cap is not None:
self.cap.record(usage, self.model)

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.

This matches the shared cap contract: SpendCap is checked before each call, and its docstring says a run "can overshoot by the calls already in flight". The other --max-usd commands (through LLMClient) also exit 0 when their last call crosses the cap, so a final check only here would make these two the odd ones. At most the changelog could say "reaches the cap before a call" instead of "goes over the cap".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

With two $0.02 calls and a $0.03 cap, the next call is refused. The last in-flight call can overshoot the cap, per SpendCap. The changelog now describes that boundary.

@exai-bot

exai-bot commented Dec 3, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 19 selected item(s).

CI at 8507a38: 21 passing, 4 skipped.

Test notes (1)
  • dokimi/dokimi/spend_preview.py:54: With if est["usd"] is not None and est["usd"] <= max_usd: changed to if est["usd"] is not None and est["usd"] < max_usd:, the tests still pass: dokimi/tests/test_cli_spend_controls.py, dokimi/tests/test_import_architecture.py, dokimi/tests/test_question_panel_reviewer.py, dokimi/tests/test_question_quality_analyzer.py, dokimi/tests/test_questions_dry_run_and_cap.py, dokimi/tests/test_questions_output_unwritable.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
Review details
  • Commit reviewed: 8507a38 against merge base 60948d0
  • Coverage: 19 files in 3 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 511k tokens (326k from cache), 54s
  • Tool calls: 48 (36 file_read, 4 code_search, 4 file_read_diff, 2 ci_status, 2 local_check_results)
  • CLI spend previews, paid-operation guards, and regression tests: 7 files
  • Metered question analysis, panel schema, and artifact compatibility: 8 files
  • Paid CLI controls documentation and changelog: 4 files

Comment thread dokimi/dokimi/commands/questions.py Resolved
Comment on lines +260 to +262
try:
report = analyzer.analyze(questions, library_name=args.product)
except SpendCapReached as exc: # nothing is written before the report, so a stop here leaves no file

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · should fix
Impact: a run exceeding --max-usd on its final call/batch exits 0 and analyze writes a report, contrary to the documented exit-1/no-report contract.

Trigger: one question, an estimate of $0.001, --max-usd 0.03, and actual usage of $0.04 (also affects review with its final reviewer batch).

Evidence: MeteredCalls only checks before calls; SpendCap.record raises for unknown prices, not for exceeding the limit. With no next call, this handler is never reached.

Fix: Check final accumulated spend inside the guarded path before publishing analyze's report, and apply the corresponding final check to review while retaining its checkpoint. Add single-call/final-batch regression tests.

Workaround: independently inspect actual spend rather than trusting exit status.

Should fix: A run shows it; it was not judged to be met in ordinary use.

This proof replaces part of the code with stand-ins (monkeypatch): it shows the code path, not the real dependency or platform.

Shown by running: exit 1 (at the head) · exit 2 (at the merge base, which cannot run it) · exit 0 (at the head with the fix) · exit 1 (proof 2, at the head) · exit 2 (proof 2, at the merge base, which cannot run it) · exit 0 (proof 2, at the head with the fix)

python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_verify_c1_analyze_final.py

What the proof does: Calls the real analysis command with real list pricing and a stand-in model response costing $0.04, then checks exit 1 and absence of its report.

The problem shows as the output FINAL_ANALYZE_CAP: expected exit 1 and no report after final-call overspend.

Script: dokimi/tests/test_verify_c1_analyze_final.py (33 lines).

Diversity score : 0.000  (1.0 = perfectly balanced)

Recommendations:
  • Question set is heavily skewed toward beginner difficulty. Add intermediate/advanced personas to improve coverage.
  • Very few advanced questions (<10%). Consider adding expert-level personas.

✅ Full report saved to /tmp/pytest-of-root/pytest-0/test_final_classification_exce0/quality.json
=========================== short test summary info ============================
FAILED tests/test_verify_c1_analyze_final.py::test_final_classification_exceeding_cap
1 failed in 0.62s

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.

The exit-1 promise is for a stop before a call. SpendCap is checked before each call, and its docstring says the run can overshoot by the calls in flight; every other capped command (through LLMClient) also exits 0 when its last call crosses the cap. So this is the shared contract, not a gap of this PR; rewording the changelog line would avoid the misreading.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A final in-flight batch can finish above the cap under the shared pre-call check. The revised changelog spells this out and describes the different exit codes when a subsequent call is stopped.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 8 of 80 small breaks of the lines this PR changes, and not every break was tried

At 8507a38: 72 caught · 8 missed

Each row is a small deliberate break (a mutant) of a line this PR changes that every test reaching that line still passes. Add a test that fails on it or, if it cannot change behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/commands/questions.py:28 bump-int 400 → 401 18
dokimi/dokimi/commands/questions.py:29 bump-int 800 → 801 18
dokimi/dokimi/questions/panel_reviewer.py:176 delete-statement self.reviews_saved = 0 → pass 29
dokimi/dokimi/questions/panel_reviewer.py:181 delete-statement self.cap = cap → pass 29
dokimi/dokimi/questions/panel_reviewer.py:288 delete-statement self.reviews_saved = 0 → pass 10
dokimi/dokimi/questions/quality_analyzer.py:94 delete-statement self.cap = cap → pass 23
dokimi/dokimi/commands/questions.py:93 drop-filter q → True 19
dokimi/dokimi/commands/questions.py:108 take-branch SpendCap(args.max_usd) if args.max_usd is not None else None → (SpendCap(args.max_usd)) 19

Not checked:

  • 48 more breaks of covered changed lines were over the limit and not tried
  • 30 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

@codecov-commenter

codecov-commenter commented Dec 3, 2026 •

Copy link
Copy Markdown

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

Codecov Report

❌ Patch coverage is 98.65772% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.45%. Comparing base (60948d0) to head (8507a38).

Files with missing lines Patch % Lines
dokimi/dokimi/commands/questions.py 95.91% 1 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1576    +/-   ##
========================================
  Coverage   96.45%   96.45%            
========================================
  Files         575      577     +2     
  Lines       75872    75984   +112     
  Branches    13076    13089    +13     
========================================
+ Hits        73179    73289   +110     
- Misses       1644     1645     +1     
- Partials     1049     1050     +1     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/skill_coverage.py 98.90% <100.00%> (-0.06%) ⬇️
dokimi/dokimi/questions/metered.py 100.00% <100.00%> (ø)
dokimi/dokimi/questions/panel_reviewer.py 95.80% <100.00%> (+2.78%) ⬆️
dokimi/dokimi/questions/quality_analyzer.py 100.00% <100.00%> (ø)
dokimi/dokimi/spend_preview.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/questions.py 92.40% <95.91%> (+0.79%) ⬆️

... and 6 files with indirect coverage changes

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

@vlad-perevezentsev vlad-perevezentsev 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.

🟡 Changes needed · reviewed 5c39076

To fix: a review stop under --max-usd exits 1 although it keeps a partial report, where the docs promise 3 (line comments); the smaller gaps there are optional. Also answer the stale-report threads of @Copilot and @exai-bot below.

✅ make ci-local --offline: 34,233 passed, changed-line coverage 98%, mutation step passes · ⚠️ test_cli_fault_contract[eval score ragas] fails at the base 26cb154 too, not from this PR

The dry run and the over-cap refusal price every call before any client is built, as in skill coverage.

Agreed with @Copilot that a stale --out file is named as this run's output; on the final call crossing the cap I disagree and replied in its thread.

Agreed with @exai-bot on the stale report; on the final-call overspend I disagree and replied in its thread.

Comment thread dokimi/dokimi/commands/questions.py Resolved
Comment thread dokimi/dokimi/commands/questions.py Resolved
Comment thread dokimi/dokimi/commands/questions.py Resolved
Comment thread dokimi/dokimi/commands/questions.py Resolved
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/tests/test_import_architecture.py
Thread: PRRT_kwDOVBg7g86_CT7s
Thread: PRRT_kwDOVBg7g86_CZfW
Thread: PRRT_kwDOVBg7g86_IjLu
Thread: PRRT_kwDOVBg7g86_IjL4
Thread: PRRT_kwDOVBg7g86_IjL8
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Thread: PRRT_kwDOVBg7g86_IjL2
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Review: PRR_kwDOVBg7g88AAAABb7dQgQ
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov

napetrov commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

Re: review by vlad-perevezentsev

a review stop under --max-usd exits 1 although it keeps a partial report, where the docs promise 3
3e300bc uses exit 3 only when this invocation checkpointed a review and records the planned count. The stale-file case now reports zero saved reviews.

Comment thread dokimi/dokimi/spend_preview.py Resolved
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
…paid-guards-3

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/dokimi/commands/questions.py
#	dokimi/dokimi/commands/skill_coverage.py
Thread: PRRT_kwDOVBg7g86_bMPD
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

@vlad-perevezentsev vlad-perevezentsev 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.

🟢 LGTM · re-checked f855e03 · nothing required from @napetrov

🔀 Merge: safe now · merges cleanly into current main, 5 commits behind; its tests pass on the merge · after it, #1581 and #1565 need a rebase (commands/skill_coverage.py)

✅ GitHub CI on f855e03: 22 jobs pass · ✅ on the merge with main: 829 passed in the 9 touched test files · ✅ a stop after 1 of 3 questions exits 3 with total: 1, planned: 3; a stale --out file gives exit 1

The earlier points are fixed; the review checkpoint now tells this run's work from an old file and says how much is left.

@antonwolfy antonwolfy 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.

LGTM. The gate returns a verdict and the commands exit, so a dry run and an over-cap refusal build no client and make no call. The earlier stale-report, exit-code and preview-text points are fixed at this head. No findings. The PR conflicts with main, so GitHub CI does not run on it until main is merged in.

What I ran, on a Linux review host at f855e03:

  • make ci-local: 38 passed, 0 failed, 16 skipped (matrix legs on other Pythons and org-level scans that run on the PR).
  • tests/test_questions_dry_run_and_cap.py: 18 passed.
  • All 7 non-merge commits carry Signed-off-by.

Checked, no issues

  • Cap exception: SpendCapReached derives from BaseException (spend.py:124), so the except Exception in classify_question and _call_reviewer does not swallow it. A mid-run stop reaches the command handlers.
  • Schema: planned is an optional field added to question_panel.v1 in place, and the writer emits it.
  • Docs: the quickstart exit-code lines, the experiments.md cap list and cli-interface.json match the new flags.
Bot points I checked that no longer apply at this head (1)
  • Copilot's point on the final call crossing the cap does not apply: SpendCap is checked before each call, so a run can overshoot by the calls in flight (spend.py:148-153), and the other --max-usd commands behave the same. The changelog now states this boundary.

Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>

# Conflicts:
#	dokimi/dokimi/commands/skill_coverage.py
#	dokimi/tests/test_import_architecture.py
Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
@napetrov
napetrov merged commit 9b04c55 into intel:main Dec 6, 2026
25 checks passed
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.

6 participants