Repository navigation
Conversation
CLI interface change detectedThis PR changes dokimi's user-facing CLI surface (commands and/or options): ~ `dokimi eval triggers generate` parameters changed:
+ added option `--dry-run`
+ added option `--max-usd`Updated on every push; the |
There was a problem hiding this comment.
🟡 Changes recommended
Analyze/review can stop even when estimates exactly fit the budget because floating-point reservation sums exceed the cap by roundoff; separately, releasing a child reservation leaves the parent’s reservation held, so a retry can be incorrectly refused even though nothing was spent.
2 open issues
What changed in this PR
2 new findings. This PR extends dokimi’s paid-command spend controls for #94, adding guarded trigger rewrites and concurrent-call reservations.
Changes:
- Adds
--dry-runand--max-usdto trigger generation. - Reserves estimated spend for question analysis/review calls in flight.
- Makes cap-refusal hints specific to each command.
| File | Description |
|---|---|
dokimi/tests/test_triggers_dry_run_and_cap.py |
Tests rewrite previews and spending limits. |
dokimi/tests/test_spend_inflight_reserve.py |
Tests reservations, releases, and hints. |
dokimi/tests/test_cli_spend_controls.py |
Updates guarded-command coverage. |
dokimi/dokimi/spend.py |
Adds spend reservations and configurable hints. |
dokimi/dokimi/questions/quality_analyzer.py |
Supplies classification token estimates. |
dokimi/dokimi/questions/panel_reviewer.py |
Supplies review token estimates. |
dokimi/dokimi/questions/metered.py |
Reserves and releases estimated call costs. |
dokimi/dokimi/novelty/cost.py |
Builds command-specific refusal hints. |
dokimi/dokimi/novelty/client.py |
Propagates reservations through nested caps. |
dokimi/dokimi/commands/questions.py |
Reuses shared token assumptions. |
dokimi/dokimi/commands/catalog.py |
Registers flags and delegates rewrite handling. |
dokimi/dokimi/commands/catalog_rewrite.py |
Implements rewrite pricing and spending guards. |
dokimi/dokimi/commands/catalog_novelty.py |
Passes hints to shared and nested caps. |
dokimi/docs/reference/cli-interface.json |
Records the two new flags. |
dokimi/changelog.d/20261205_120000_cli-paid-guards-4.md |
Documents spend-control changes. |
Review effort: Balanced
| self.parent.record(usage, model, reserved=reserved) | ||
| super().record(usage, model, reserved=reserved) | ||
| self.parent.record(usage, model, reserved=reserved, reserve_usd=reserve_usd) | ||
| super().record(usage, model, reserved=reserved, reserve_usd=reserve_usd) |
| if self.limit_usd is not None and reserve_usd > 0 and ( | ||
| self.spent_usd + self.reserved_usd + reserve_usd > self.limit_usd): |
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 16 selected item(s). CI at Test notes (2)
Review details
|
| if self.limit_usd is not None and reserve_usd > 0 and ( | ||
| self.spent_usd + self.reserved_usd + reserve_usd > self.limit_usd): |
There was a problem hiding this comment.
Impact: a call whose estimate fits the remaining budget exactly can be refused, prematurely stopping analyze/review.
Trigger: cap = SpendCap(0.3); cap.before_call("m", reserve_usd=0.1); cap.before_call("m", reserve_usd=0.2).
Evidence: the new sum evaluates to 0.30000000000000004 > 0.3, so the second reservation raises SpendCapReached; production MeteredCalls passes float list-price estimates into this comparison. The preview sums prices using Decimal and accepts the corresponding $0.30 budget, making admission inconsistent with that gate.
Fix: Use decimal accounting or a tightly bounded rounding tolerance for reservation admission, and add an exact-budget regression test (including release/re-reserve).
Workaround: increase --max-usd slightly.
Should fix: A run shows it; it was not judged to be met in ordinary use.
Shown by running: exit 1 (at the head) · exit 1 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)
python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_proof_reserve_exact.py
What the proof does: Reserves 0.1 then 0.2 against a 0.3 cap and asserts the second reservation is admitted.
The problem shows as the output EXACT_FIT_REFUSED.
dokimi/tests/test_proof_reserve_exact.py
from dokimi.spend import SpendCap, SpendCapReached
def test_exact_fit_reservation_admitted():
cap = SpendCap(0.3)
cap.before_call('m', reserve_usd=0.1)
try:
cap.before_call('m', reserve_usd=0.2)
except SpendCapReached:
raise AssertionError('EXACT_FIT_REFUSED: reservation that equals the limit was refused') try:
cap.before_call('m', reserve_usd=0.2)
except SpendCapReached:
> raise AssertionError('EXACT_FIT_REFUSED: reservation that equals the limit was refused')
E AssertionError: EXACT_FIT_REFUSED: reservation that equals the limit was refused
tests/test_proof_reserve_exact.py:10: AssertionError
=========================== short test summary info ============================
FAILED tests/test_proof_reserve_exact.py::test_exact_fit_reservation_admitted
1 failed in 0.50s
…ed and capped - eval triggers generate --rewrite: --dry-run prints the estimate (200 reply tokens per rewrite) and makes no client; --max-usd refuses before the first call or stops mid-run with exit 1 and writes no file. - --concurrency with --max-usd: a call in flight reserves its list-price estimate before dispatch and releases it on return, so calls in flight cannot pass the cap together (questions analyze/review). - The cap refusal names only the flags the leaf has: SpendCap.measure_less is set per leaf (novelty names --tier/--max-atoms only where they exist). Part of intel#94 (F1b, spend: paid-guards slice 4). Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
e82eadc to
2ded3ab
Compare
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1670 +/- ##
==========================================
- Coverage 96.44% 96.44% -0.01%
==========================================
Files 585 586 +1
Lines 76600 76680 +80
Branches 13175 13185 +10
==========================================
+ Hits 73876 73951 +75
- Misses 1671 1672 +1
- Partials 1053 1057 +4
🚀 New features to boost your workflow:
|
Mutation of changed linesAt 2ded3ab: 42 caught · 14 missed · 24 not tried in time 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 the whole picture:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |

Part of #94 (F1b, spend: paid-guards slice 4, the leftovers of #1576). #94 stays open.
What
eval triggers generate --rewritegets--dry-runand--max-usd(the feat(questions): --dry-run and --max-usd on eval questions analyze and review (Part of #94) #1576 pattern).--max-usd: refused before the first call (exit 3, no call made), or stopped mid-run (exit 1, no file written).--max-usdby its own cost.SpendCap.before_call(reserve_usd=...)reserves a call's list-price estimate before dispatch, released when the call returns or raises.MeteredCalls(questions analyze/review) uses it, so calls in flight under--concurrencycannot pass the cap together. Trigger generate is serial and keeps the plain check-then-record.questions analyze/reviewat any--concurrency: a call is refused when its list-price estimate (400 or 800 assumed reply tokens) plus the calls in flight would pass--max-usd. A run can therefore stop a little earlier than before. The reservation is a guard at list price, not the accounting figure.SpendCap.measure_lessis set per leaf. Novelty names--tier/--max-atomsonly where those flags exist; other leaves say "measure less".dokimi/commands/catalog_rewrite.py(catalog.pywas over the 800-line cap). The reply-token constants moved todokimi/spend_preview.py, so the command no longer imports the questions package (which needs optional deps such as httpx).Leaves
eval triggers generate --rewrite--dry-run,--max-usdKept rows: none.
cli-interface.jsongains the two flags (+2 lines).Not guarded, with reasons
eval score pointwise: the judge plan (retries, redraws, placeholder skips, ask-rubric) decides the call count. feat(questions): --dry-run and --max-usd on eval questions analyze and review (Part of #94) #1576 rejected a client-free estimate for the same reason.eval judge wording|validate|agreement: the call count depends on pair building, intact-answer reuse, sequential mode, grounding and stored context. A client-free count would copy that logic.Remaining paid leaves with no
--max-usd(fromscripts/cli_spend_controls.py, after this PR): agent run; answers generate; arms matrix-run; arms run; benchmark batch; benchmark run; catalog trigger-probe; delivery scan; eval judge agreement/validate/wording; eval questions generate/refine; eval redteam; eval score checklist/pairwise/panel/pointwise/ragas/reference; evaluate; explore run; repo reach; repo skill-reach; subjects run; tasks run.Evidence
tests/test_triggers_dry_run_and_cap.py(8),tests/test_spend_inflight_reserve.py(9). The reservation, hint and dry-run/cap tests failed on the old code;test_plain_rewrite_still_writes_the_setandtest_metered_calls_without_a_cap_price_nothingguard existing paths.make ci-local CI_LOCAL_ARGS="--offline": exit 0.🤖 Generated with Claude Code