Repository navigation
feat(questions): --dry-run and --max-usd on eval questions analyze and review (Part of #94) - #1576
Conversation
…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>
CLI interface change detectedThis 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 |
There was a problem hiding this comment.
🟡 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-runestimates and--max-usdguards 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
| with self._lock: | ||
| self.spend.add_call(usage) | ||
| if self.cap is not None: | ||
| self.cap.record(usage, self.model) |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 19 selected item(s). CI at Test notes (1)
Review details
|
| 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Mutation of changed linesAt 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
Not checked:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
|
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 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.
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>
|
Re: review by vlad-perevezentsev
|
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
left a comment
There was a problem hiding this comment.
🟢 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
left a comment
There was a problem hiding this comment.
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:
SpendCapReachedderives fromBaseException(spend.py:124), so theexcept Exceptioninclassify_questionand_call_reviewerdoes not swallow it. A mid-run stop reaches the command handlers. - Schema:
plannedis an optional field added toquestion_panel.v1in place, and the writer emits it. - Docs: the quickstart exit-code lines, the
experiments.mdcap list andcli-interface.jsonmatch 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:
SpendCapis checked before each call, so a run can overshoot by the calls in flight (spend.py:148-153), and the other--max-usdcommands 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>

Part of #94 (F1b, spend: paid-guards slice 3, the two question-quality leaves). #94 stays open.
Summary
eval questions analyzeandeval questions reviewnow price their model calls before any spend, following theeval skill-coveragepattern from #1419:--dry-runprints 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 Xrefuses 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.analyzeexits 1 and writes no report.reviewexits 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.llm_call_with_usageand their usage is summed into aSpend(the fix(cost): judge_metrics skips cache replays; one Spend accumulator for totals #1183 accumulator), which is what the cap reads.Leaf table
eval questions analyze--dry-run(estimate, exit 0, no client);--max-usd(pre-call refusal exit 3, mid-run stop exit 1)eval questions review--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.
--jsonis not added (F2).Reply-token assumptions, stated in the
--dry-runoutput: 400 per classification, 800 per review vote.Evidence
tests/test_questions_dry_run_and_cap.pypass with the review fixes, including the stale output, saved checkpoint and matching-model warning cases.llm_call_with_usagein both modules, andLLM.__init__, with functions that fail the test, so any client construction or model call is caught.llm_call_with_usageand return(text, None). Their assertions are unchanged.tests/test_cli_spend_controls.py: the two leaves leave the uncapped list.docs/reference/cli-interface.jsonregenerated withmake cli-snapshot(four new option entries).spend_previewends no process (import-architecture test); prompts are built only for a priced run; both analyzers sharequestions/metered.MeteredCalls;skill_coveragereuses the estimate and cap-refusal helpers (duplicate-code ratchet); panel-review input parsing moves to a helper (complexity ratchet).pytest testson the rebased head: see the CI checks. Local:make ci-local CI_LOCAL_ARGS="--offline --jobs static,typecheck"0 failed;pytest -n 16 tests34330 passed, 29 skipped.Not in this PR
Paid leaves still unguarded on intel/main
26cb1543dplus this change (the check inscripts/cli_spend_controls.pyis the source of truth):--jsonmissing (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(--jsononly).--dry-runpresent, no--max-usd:repo reach,repo skill-reach,tasks run,eval questions refine.--max-usdpresent, no--dry-run:catalog novelty,skill novelty atoms,skill novelty probe,skill shorten,eval graph,repo run.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 pointwisewas 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 --rewritewas left out: the number of rewrite calls is known only after the trigger set is built.Label:
cli-interface-change.🤖 Generated with Claude Code