Repository navigation
feat(spend): sign-in preflight before paid runs, and --max-calls for providers with no price - #1565
Conversation
…providers with no price repo reach, repo skill-reach and repo run make one zero-tool call under the run's own environment (repo run: in the agent's container) and stop with exit 2 on a sign-in error instead of erroring in every cell; arms run asks a CLI provider's auth status. --no-preflight or DOKIMI_NO_PREFLIGHT=1 skips it. --max-calls caps model calls without a price (novelty commands, catalog novelty, eval skill-coverage); --max-usd on a CLI provider is refused before the first call and points to --max-calls. Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
CLI interface change detectedThis PR changes dokimi's user-facing CLI surface (commands and/or options): ~ `dokimi arms matrix-run` parameters changed:
+ added option `--no-preflight`
~ `dokimi arms run` parameters changed:
+ added option `--no-preflight`
~ `dokimi catalog novelty` parameters changed:
+ added option `--max-calls`
~ `dokimi catalog routing` parameters changed:
+ added option `--max-calls`
~ `dokimi eval graph` parameters changed:
+ added option `--max-calls`
~ `dokimi eval skill-coverage` parameters changed:
+ added option `--max-calls`
~ `dokimi repo reach` parameters changed:
+ added option `--no-preflight`
~ `dokimi repo run` parameters changed:
+ added option `--no-preflight`
~ `dokimi repo skill-reach` parameters changed:
+ added option `--no-preflight`
~ `dokimi skill novelty analyze` parameters changed:
+ added option `--max-calls`
~ `dokimi skill novelty atoms` parameters changed:
+ added option `--max-calls`
~ `dokimi skill novelty probe` parameters changed:
+ added option `--max-calls`
~ `dokimi skill routing` parameters changed:
+ added option `--max-calls`
~ `dokimi skill sensitivity` parameters changed:
+ added option `--max-calls`
~ `dokimi skill shorten` parameters changed:
+ added option `--max-calls`Updated on every push; the |
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved spend-cap defects permit unvalidated providers and uncounted retries, while cache handling, authentication preflight, and cost reporting can reject valid runs or misstate spending.
6 open issues
Validate each provider before reusing the shared cap · New Write profile configuration before host preflight · New Reserve a call slot for every provider retry · New Preserve unknown costs in sweep totals · New Treat inconclusive Codex auth probes as unknown · New Resolve cache hits before checking the call cap · New
What changed in this PR
7 findings.
This PR adds sign-in checks before paid evaluations and call-count budgets for providers that do not report prices.
Changes:
- Adds sign-in preflights and opt-out controls to repository and arms runs.
- Introduces
--max-callsand rejects unsupported CLI-provider dollar caps. - Updates stop reasons, recovery guidance, tests, and CLI documentation.
| File | Description |
|---|---|
dokimi/tests/test_spend_call_cap.py |
Tests call limits and provider refusals. |
dokimi/tests/test_sign_in_preflight.py |
Tests authentication checks and opt-outs. |
dokimi/tests/test_catalog_novelty_call_cap.py |
Tests call-limited catalog sweeps. |
dokimi/tests/test_atoms_partial_status.py |
Covers call-cap recovery messages. |
dokimi/tests/data/cli_flags_allowlist.txt |
Allows the preflight opt-out flag. |
dokimi/tests/conftest.py |
Disables preflights by default in tests. |
dokimi/dokimi/spend.py |
Adds shared call-count accounting. |
dokimi/dokimi/schemas/run.v1.json |
Accepts call-cap stop reasons. |
dokimi/dokimi/schemas/novelty.v1.json |
Accepts call-limited partial results. |
dokimi/dokimi/runs/rundir.py |
Records call-cap termination. |
dokimi/dokimi/repos/skill_reach.py |
Checks sign-in before skill probes. |
dokimi/dokimi/repos/sign_in.py |
Implements host and container preflights. |
dokimi/dokimi/repos/runner.py |
Reuses shared environment assembly. |
dokimi/dokimi/repos/reach.py |
Checks sign-in before reach probes. |
dokimi/dokimi/repos/agent_env.py |
Shares container credential handling. |
dokimi/dokimi/novelty/items.py |
Identifies call-limited probe results. |
dokimi/dokimi/novelty/cost.py |
Builds caps and validates providers. |
dokimi/dokimi/novelty/client.py |
Releases refused nested reservations. |
dokimi/dokimi/novelty/atoms_refusal.py |
Adds call-cap rerun advice. |
dokimi/dokimi/llm_cli.py |
Adds CLI authentication preflight. |
dokimi/dokimi/eval/arms_run.py |
Checks answerer and judge sign-in. |
dokimi/dokimi/commands/skill_coverage.py |
Adds call limits and early refusals. |
dokimi/dokimi/commands/repo_skill_reach.py |
Exposes preflight controls and errors. |
dokimi/dokimi/commands/repo_run.py |
Runs container sign-in checks. |
dokimi/dokimi/commands/repo_reach.py |
Handles authentication refusals. |
dokimi/dokimi/commands/novelty_run.py |
Registers shared call-cap options. |
dokimi/dokimi/commands/novelty_routing_report.py |
Classifies call caps as budget stops. |
dokimi/dokimi/commands/novelty_budget.py |
Updates replay guidance. |
dokimi/dokimi/commands/novelty_atoms_file.py |
Updates verdict-cache rerun advice. |
dokimi/dokimi/commands/eval_graph.py |
Passes provider into cap validation. |
dokimi/dokimi/commands/catalog_novelty.py |
Supports call-budgeted sweeps. |
dokimi/dokimi/commands/arms.py |
Exposes preflight opt-out. |
dokimi/dokimi/cli_flags.py |
Registers the call-cap concept. |
dokimi/dokimi/artifacts.py |
Explains call-limited artifact refusals. |
dokimi/docs/reference/cli-interface.json |
Refreshes the CLI interface snapshot. |
dokimi/changelog.d/20261202_140000_sign-in-preflight-and-max-calls.md |
Documents preflights and call budgets. |
Review effort: Balanced
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1565 +/- ##
========================================
Coverage 96.46% 96.46%
========================================
Files 558 563 +5
Lines 73926 74546 +620
Branches 12769 12866 +97
========================================
+ Hits 71313 71912 +599
- Misses 1596 1611 +15
- Partials 1017 1023 +6
🚀 New features to boost your workflow:
|
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). CI at Test notes (1)
Review details
|
napetrov
left a comment
There was a problem hiding this comment.
Change class: CONTRACT (head 0d236b7)
- Contract: changed. errors dokimi/dokimi/commands/catalog_novelty.py:552; errors dokimi/dokimi/commands/catalog_novelty.py:553
- Responsibility: candidate (count signal only, no file:line)
- Dependency: none
- Review depth: check the changed surface: callers, docs, tests pin new behaviour
- Coverage gaps: none
1 new must-fix finding. The fake harness shows that duplicate or fully completed batches start a sign-in call before plan validation and skip handling.
| # | Finding | Severity | Provenance | Evidence |
|---|---|---|---|---|
| 1 | Sign-in spends a call before the batch knows any cell can run | must-fix | introduced | Reproduced in an offline probe. |
Checked the diff, input edges, and focused offline Linux tests (cache-recheck: 232 passed in 41.67s). Providers and the container harness were stubbed.
- Still open. The call limit does not reserve retry attempts. Earlier thread
- Still open. A full budget also blocks cache hits. Earlier thread
Mutation of changed linesAt fae47ae: 29 caught · 0 missed · 11 inconclusive · 40 not tried in time This is not a clean result:
Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary. |
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟡 Changes needed · reviewed 0d236b7
To fix: the new caps and the sign-in check can still spend money they do not count, or refuse a run that would work (the existing threads). The two small points in my line comments are optional. Also answer the @napetrov, @Copilot and @exai-bot threads below.
✅ make ci-local --offline: 34,168 passed · eval score ragas fault-contract test fails on the base too (a local langchain_openai import), not from this PR · ✅ the 4 new test files pass under random order
--max-calls and the sign-in refusal are the right tools for CLI logins, and the tests cover the main paths.
Agreed with @napetrov: the repo run preflight runs before plan validation and on a finished batch.
Agreed with @Copilot: --max-usd is not refused for the second role, retries are not counted, a full cap blocks cache hits, and 3 more.
Agreed with @exai-bot: the preflight has no profile config and uses the caller's cwd, cached sweeps can lose a skill, and 2 more.
Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
Fixes the review findings on the call cap and the sign-in preflight: - a provider retry takes its own --max-calls slot, and a response-cache hit takes none, so it is answered at a full cap - every role's provider is checked against --max-usd, not only the first - catalog novelty rows and summary keep unpriced calls instead of $0.00 - repo run signs in only once the plan is valid and a cell is left to run, and the call is charged to the batch cap - repo reach and skill-reach write the profile's config files and run the check in the run's workspace - a timed-out auth status is unknown, not signed out - arms run prints the sign-in refusal alone; arms matrix-run gets --no-preflight - skill routing reports a call_cap stop as budget_stopped - eval skill-coverage refuses a --max-calls below its two calls Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
|
This is ready for another look: I've pushed 2 commits on
Changes:
PR description updated:
Vlad-perevezentsev's comment:
Napetrov's comment:
Threads:
Not caused by this PR:
What I checked on the new commit:
What each test shows
|
| if result.timed_out: | ||
| return 0.0 |
There was a problem hiding this comment.
Impact: a paid preflight's reported charge can be omitted from _eval/spend.json, allowing later cells to start against understated batch spending.
Trigger: the harness writes a result with total_cost_usd: 0.04 and then hangs during shutdown until the container timeout.
Evidence: DockerRunner retains captured output on timeout, but this early return skips reading and converting it; run_batch therefore settles $0 even though the trace contains a price.
Workaround: use --no-preflight for affected harnesses. Parse the captured transcript before handling the timeout and return any reported cost while still treating authentication status as unknown; add a timed-out container regression test with a priced result.
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)
python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_verify_preflight_timeout_charge.py
What the proof does: Calls the real container sign-in preflight with a stand-in container runner that writes a priced result before returning a timeout, and checks that the reported charge is retained.
The problem shows as the output timed-out preflight lost its reported charge.
Script: dokimi/tests/test_verify_preflight_timeout_charge.py (40 lines).
E assert 0.0 == 0.04 ± 4.0e-08
E
E comparison failed
E Obtained: 0.0
E Expected: 0.04 ± 4.0e-08
tests/test_verify_preflight_timeout_charge.py:40: AssertionError
=========================== short test summary info ============================
FAILED tests/test_verify_preflight_timeout_charge.py::test_timeout_preserves_reported_preflight_charge
1 failed in 0.72s
There was a problem hiding this comment.
Fixed in fae47ae: the repo run preflight now reads its trace even after a timeout and counts the reported price, or its 0.05 budget when there is none, as a cell does; a test covers both cases with and without a timeout.
There was a problem hiding this comment.
This was already fixed in fae47ae: the repo run preflight now reads the transcript before the timeout check at dokimi/dokimi/repos/sign_in.py:137-140 and counts the reported price, or the 0.05 budget when there is none. test_repo_run_counts_the_preflight_charge_or_its_budget in tests/test_sign_in_preflight.py covers a priced result with and without a timeout.
A preflight that timed out or reported no price was counted as $0 against --max-usd; it is now counted like a cell: its reported price, read even after a timeout, else its budget. Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
vlad-perevezentsev
left a comment
There was a problem hiding this comment.
🟢 LGTM · re-checked fae47ae · nothing required from @vchamarthi
🔀 Merge: safe now · merges cleanly into current main, 5 commits behind; its tests pass on the merge · after it, #1582 (repo_reach.py, repo_run.py, repo_skill_reach.py, runner.py), #1581 and #1576 (skill_coverage.py), #1600 (novelty_routing.py) and #1559 (cli_flags_allowlist.txt) need a rebase
✅ make ci-local --offline: 35,124 passed · eval score ragas fault-contract test fails on the base too (a local langchain_openai import), not from this PR · ✅ the new preflight-charge test fails at 02abac9 · ✅ on the merge with main: 301 tests pass, CLI snapshot is current
The earlier points are fixed, each with a test that fails without its fix.
Fixed in this branch, up to fae47ae:
- A
repo runpreflight with no reported price, or one that timed out, counted $0 in the batch spend: fae47ae reads the price even after a timeout, else counts its 0.05 budget, as a cell does.


Why
repo reachwith Claude Code and no credential in the isolated run: every scenario errored ("Not logged in · Please run /login") and the run reported a full matrix ofE; a Codex run took 181 s to fail 11 times with retries.eval skill-coverage --model claude-cli/sonnet --max-usd 1: the run stopped after its first, paid call ("no price is known for sonnet"). A CLI login reports no charged price, so a user on an OAuth token had no working cap at all.What changes
dokimi/repos/sign_in.py: before the first scenario,repo reachandrepo skill-reachrun one zero-tool "reply ok" call under the exact child environment the scenarios get;repo runmakes the same call in the agent's own container, with the cells' mounts, credentials and network (check_container_signed_in; the env assembly moved torepos/agent_env.py, shared withrun_cell).arms runon a CLI provider:llm_cli.check_signed_inasks the CLI'sauth status(no model call) for the answerer and judge providers and refuses with exit 2 when it says not signed in. A sign-in failure (Not logged in,authentication_failed, invalid key,401 Unauthorized, missing bearer) raisesNotSignedIn(aProfileError) and the command exits 2 naming the profile's credential variables. Any other failure (timeout, usage limit, overloaded API) lets the run continue as before.--no-preflight(on the four commands) orDOKIMI_NO_PREFLIGHT=1skips it; the preflight waits no longer than one scenario's--timeout.SpendCaptakesmax_calls; new--max-calls N(spend concept incli_flags) on every command using the novelty--max-usd, oncatalog novelty(which now accepts--max-callsin place of its required--max-usd) and oneval skill-coverage. Each provider request, a retry included, reserves its slot under the lock before it is sent, after the cache lookup, so calls in flight cannot overshoot; a cache hit sends no request and takes no slot; a nested cap frees its slot when the parent refuses.--max-usdon a CLI provider (claude-cli,codex-cli) is refused before any call, pointing to--max-calls.call_capinrun.v1/novelty.v1, exit 3 like other budget stops, with "a higher --max-calls" rerun advice.docs/reference/cli-interface.jsonregenerated; changelog fragment added.Evidence
repo reach, harness not signed inEeval skill-coverage --model claude-cli/sonnet --max-usd 1--max-callsrepo run/arms run, not signed inauth status(arms run), exit 2--max-calls 1on a CLI providerHow to test
Result:
1 failed, 34260 passed, 33 skipped. The failure also fails on unchanged main:test_repo_compare_interval::test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apart. mypy is clean.Mutation
Local mutation run: 0 survived (36 caught, 33 not tried in time). Tests added for the 3 survivors (the
call_capadvice in a partial atoms refusal,PATHin the host-only names, and the host-only filter on names passed into the agent container).Conflicts with #1559
This PR and #1559 both edit
dokimi/repos/reach.pyanddokimi/commands/repo_reach.py. Whichever lands second:reach.pyimports: keep both (from .sign_in import checked_versionhere,from .reach_held ...there).run_reach: keep this PR'sversion = checked_version(...)line in place ofversion_env/profile.version; keep feat(reach): held class for external imports, --reps majority vote and --confirm-surprises #1559's new keyword arguments (reps,approve_external_imports,confirm_surprises).repo_reach.py: keep this PR'sapply_preflight_flag,except NotSignedInandadd_preflight_flagnext to feat(reach): held class for external imports, --reps majority vote and --confirm-surprises #1559'sreps=...arguments and new checks.Not in this PR
--max-tokenscap:--max-tokensalready means the output ceiling on these commands.--max-usdstill does not use the CLI's owntotal_cost_usd: that figure is a list-price estimate, not what an OAuth token login is charged.References