Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### Fixed

- **`repo run --max-usd` exits 3 (inconclusive) when the batch budget is the only reason a cell was not started** — the finished cells keep their `result.json`, as the other spend-capped commands keep a partial output; it exited 1. A batch with a budget stop and also an error or a failed probe still exits 1, and a cell that crashed of the machinery still exits 5. A batch whose budget starts no cell keeps nothing and still exits 1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
Copyright (C) 2026 Intel Corporation
SPDX-License-Identifier: Apache-2.0
-->

### Fixed

- **`repo hits judge --max-usd` exits 3 (inconclusive) when the cap or a call with no price stops it** — the cells judged before the stop keep their `hits_judged.json` and `--json` prints status `budget_stopped`, as before; the exit was 1. A run stopped by 3 judge calls in a row failing with one error still exits 1.
7 changes: 4 additions & 3 deletions dokimi/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ failed check.
| 0 | The command ran and, if it checks something, the check passed. | |
| 1 | A verdict or a gate that ran and failed, or a runtime failure the command reports (a model call, a run, a clone or fetch); a crash that escapes is 5. `eval judge validate --strict` and `eval leak`/`eval redteam` that fail as blocked. | `baseline compare --max-context-drop 0` over a regression, `repo reach` with a harness binary that cannot run, `eval triggers generate --fail-on warn` over a lint finding |
| 2 | A bad invocation: a missing, unreadable or malformed input file, a configuration the agent's CLI rejects (`repo run --tools all` with a `.mcp.json` the CLI does not accept: refused before any cell runs), a device given as one (`<flag> <path>: not a file`), a flag combination the command refuses, an output file that cannot be written, a missing provider credential, a source string that is malformed, unpinned or not a repository root. | `baseline save` on a bad eval file, `evaluate --questions` on an empty or non-JSON file (`--questions <path>: <reason>`), `benchmark preflight` with no golden set, `repo scan --manifest ../x.yaml` |
| 3 | Inconclusive: the run stopped short because a budget ran out (`--max-usd`, or a call with no price) and kept the partial output (`tools preference`, `skill novelty atoms`, `probe` and `analyze`, `skill routing` and `catalog routing`; a stop on a permanent provider error exits 1; `eval personas discover` refuses its one call before it runs, so nothing is written; other spend-capped commands such as `repo run` and `repo hits judge` still exit 1 on a budget stop), or the result is undecided (`eval judge validate`: a pass whose interval straddles the gate, or a variant no pair was built for, with `--strict` making it 1; `eval leak`: an item that could not be checked, or none could; `eval redteam`: a graded question not measured, or nothing graded; `eval judge agreement --strict`: an arm NOT MEASURED, or no arm to compare; `repo security --fail-on`: an unfinished cell or an arm with no measured cell, when no arm failed and every model has a baseline cell). | `tools preference --max-usd 5` with calls not run; `eval judge validate` with too few bases |
| 3 | Inconclusive: the run stopped short because a budget ran out (`--max-usd`, or a call with no price) and kept the partial output (`tools preference`, `skill novelty atoms`, `probe` and `analyze`, `skill routing` and `catalog routing`, `repo run` when the batch budget is the only reason a cell was not started (with a cell error or a failed probe too it exits 1, 5 for a cell that crashed of the machinery; a batch that started no cell exits 1), and `repo hits judge`; a stop on a permanent provider error, or on 3 judge calls in a row failing with one error, exits 1; `eval personas discover` refuses its one call before it runs, so nothing is written), or the result is undecided (`eval judge validate`: a pass whose interval straddles the gate, or a variant no pair was built for, with `--strict` making it 1; `eval leak`: an item that could not be checked, or none could; `eval redteam`: a graded question not measured, or nothing graded; `eval judge agreement --strict`: an arm NOT MEASURED, or no arm to compare; `repo security --fail-on`: an unfinished cell or an arm with no measured cell, when no arm failed and every model has a baseline cell). | `tools preference --max-usd 5` with calls not run; `eval judge validate` with too few bases |
| 4 | Invalid: the result is not comparable or not trustworthy: a model that differs from the baseline's, or one that cannot be verified, under `baseline compare --strict` or the regression gate (`--max-context-drop` or `--max-lift-drop`); under `repo security --fail-on`, a model with no baseline cell when no arm failed; under `eval judge agreement --strict`, an arm JUDGE-DEPENDENT. | `baseline compare --strict` over a baseline scored with another judge |
| 5 | Infrastructure failure: a crash (an uncaught exception) in any command, with its traceback on stderr. For a command that emits the cli_output document, `--json` prints its `infra` document on stdout first. Also a `repo run` cell that crashes (a harness that exits nonzero before its first trace line, unless the cap killed it, a docker daemon or CLI failure that stops the agent, a scratch directory that vanished): the batch keeps the other cells and exits 5. | `backends --json` when `detect` raises; `repo run` with the docker daemon down |

Expand All @@ -273,8 +273,9 @@ but still exit 1 for other input refusals (a missing or malformed manifest, a ba
a `.mcp.json` the CLI rejects under `--tools all` is exit 2 before any cell;
a `--manifest` path that leaves the source tree as typed is exit 2, pinned or not, as a source refusal; a link in the tree that leads out of it is exit 1), and
`tools preference` exits 1 when every call failed and 3 when `--max-usd`
or an unpriced model stopped it short, and `eval personas discover` exits 3 when its `--max-usd` refuses the one call. `repo run --max-usd`,
`repo hits judge --max-usd` still exit 1 when the budget or an unpriced call stops them.
or an unpriced model stopped it short, and `eval personas discover` exits 3 when its `--max-usd` refuses the one call. `repo run --max-usd` exits 3 when the batch budget stops cells and nothing else went wrong
(with a cell error or a failed probe too it exits 1, and 5 for a cell that crashed of the machinery), and
`repo hits judge --max-usd` exits 3 when the budget or an unpriced call stops it, and 1 when 3 judge calls in a row failed with one error.
`skill novelty atoms`, `probe` and `analyze` and `skill routing` and `catalog routing` exit 3 when
the budget or an unpriced call stops them and they keep a partial file, and 1 when they keep
nothing (`skill shorten`, and a stop that leaves no partial file: "nothing was written") or a permanent provider error
Expand Down
9 changes: 6 additions & 3 deletions dokimi/docs/repo-evaluation-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -2617,7 +2617,10 @@ python cli.py repo compare repo-runs/authoring --baseline guidance:none --metric
then the CLI's process group is killed, the container is killed by name,
and the cell is still graded. `--max-usd` starts no new cell
once the batch has spent that much, earlier invocations included (kept in
`_eval/spend.json`), counting the budget of each cell in flight.
`_eval/spend.json`), counting the budget of each cell in flight. When the
batch budget is the only reason a cell was not started, the finished cells
keep their `result.json` and the command exits 3 (inconclusive); with a cell
error or a failed probe too it exits 1 (5 for a cell that crashed of the machinery).
- Every container runs with `--security-opt no-new-privileges`, `--cap-drop
ALL` and a `--pids-limit`, as the caller's uid and gid.
- `--agent-network` is required while the egress proxy is missing: it gives the
Expand Down Expand Up @@ -2712,14 +2715,14 @@ python cli.py repo compare repo-runs/authoring --baseline guidance:none --metric
call. `--dry-run` writes nothing and takes no lock.
`--max-usd X` starts no new call once X is spent: a cell not fully judged
gets no `hits_judged.json` (one an earlier run wrote is removed), and the
command exits 1. After a live judge reply with no known price, such a run
command exits 3 (inconclusive; the cells judged keep their files). After a live judge reply with no known price, such a run
starts no further live call, as `novelty`'s spend cap does: the cap cannot
be enforced on spend it cannot see. That reply still labels its pair when
it parses (a redraw would be a further call), and pairs replayed from the
response cache still finish; when
pairs are left, the cells they are in get no file, the line naming those
cells says why (`--json`, under `data`: `budget_stop`; drop `--max-usd` to run
unmetered), and the command exits 1. When none is left, the run ends as
unmetered), and the command exits 3. When none is left, the run ends as
one with no cap does (exit 0, `budget_stop` null). Without
`--max-usd` an unpriced call counts as 0, and the spend line says how many
calls had no price and that the spend is not known (`--json`, under `data`:
Expand Down
8 changes: 4 additions & 4 deletions dokimi/dokimi/commands/repo_hits.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pathlib import Path
from typing import Any, Callable, NoReturn

from dokimi.exit_codes import EXIT_FAILURE, EXIT_USAGE
from dokimi.exit_codes import EXIT_FAILURE, EXIT_INCONCLUSIVE, EXIT_USAGE
from dokimi.utils import InputError

from ._output import exit_on_unwritable
Expand Down Expand Up @@ -160,8 +160,8 @@ def _judge(batch_dir: Path, args: argparse.Namespace) -> None:
cost=_cost(done.meter, args.max_usd))
else:
print(format_summary(result))
if done.stopped: # as repo run: a cap that left work undone is not a finished run
sys.exit(EXIT_FAILURE)
if done.stopped: # a cap that left work undone: inconclusive, the judged cells keep their files
sys.exit(EXIT_INCONCLUSIVE)


def cmd_repo_hits_sheet(args: argparse.Namespace) -> None:
Expand Down Expand Up @@ -209,7 +209,7 @@ def register(repo_sub, positive_int, usd: Callable[[str], float]) -> None:
help="A `repo hits sheet` file with `label` filled in: report agreement and Cohen's kappa "
"per arm and answer model between the person and the judge")
judge_p.add_argument("--max-usd", type=usd, default=None, dest="max_usd", metavar="X",
help="Start no new judge call once this much has been spent (exit 1 if a cell was left); "
help="Start no new judge call once this much has been spent (exit 3 if a cell was left); "
"after a judge reply with no known price no further call starts, since the cap cannot "
"be enforced (drop --max-usd to run unmetered)")
judge_p.add_argument("--dry-run", action="store_true", dest="dry_run",
Expand Down
15 changes: 9 additions & 6 deletions dokimi/dokimi/commands/repo_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from dokimi.atomic_write import write_text_atomic
from dokimi import cli_flags
from dokimi import docker_cmd
from dokimi.exit_codes import EXIT_INFRA
from dokimi.exit_codes import EXIT_INCONCLUSIVE, EXIT_INFRA
from dokimi.repos.harness_profile import DELEGATION_MODES
from dokimi.repos.source import SourceArgumentError, tree_path
from dokimi.utils import tree_digest
Expand Down Expand Up @@ -500,13 +500,16 @@


def _exit_of_batch(summary: dict) -> None:
"""A cell that crashed of the machinery is infrastructure (exit 5, §2.6), never a verdict; a refused cell, a budget
stop, a failed probe or a batch with no result is exit 1."""
"""A cell that crashed of the machinery is infrastructure (exit 5, §2.6), never a verdict; a refused cell, a failed
probe or a batch with no result is exit 1. A budget stop alone is inconclusive (exit 3: the finished cells keep
their results); with an error or a failed probe too it is exit 1, a defect outranks an inconclusive result."""
if any(err.get("infra") for err in summary["errors"]):
sys.exit(EXIT_INFRA)
if summary["errors"] or summary["budget_stopped"] or summary["probe_failed"]:
if summary["errors"] or summary["probe_failed"]:
sys.exit(1)
if not summary["ran"] and not summary["skipped"]: # every cell unsupported: the batch holds no result
if summary["budget_stopped"] and (summary["ran"] or summary["skipped"]):
sys.exit(EXIT_INCONCLUSIVE)
if not summary["ran"] and not summary["skipped"]: # every cell unsupported or not started: the batch holds no result

Check warning on line 512 in dokimi/dokimi/commands/repo_run.py

View workflow job for this annotation

GitHub Actions / Mutation of changed lines

mutant survived: drop-clause `not summary["ran"] and not summary["skipped"]` -> `(not summary["ran"])`
print(f"✗ incomplete: no cell has a result ({summary['cells']} cells, {summary['unsupported']} unsupported)",
file=sys.stderr)
sys.exit(1)
Expand Down Expand Up @@ -666,7 +669,7 @@
"(clone, fetch, revision) and "
)
CHECK_EXIT = _SOURCE_EXIT + "for a task that fails the check, or when no task was checked (every one a suite gap)."
RUN_EXIT = _SOURCE_EXIT + "for a cell that crashed, a batch budget stop or an incomplete batch."
RUN_EXIT = _SOURCE_EXIT + "for a cell that crashed or an incomplete batch; exit 3 when the batch budget alone left cells not started."


def register(repo_sub, eval_sub, positive_int, source_help: str, cache_help: str) -> None:
Expand Down
6 changes: 3 additions & 3 deletions dokimi/tests/test_repo_hits_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def test_max_usd_starts_no_call_once_spent_and_a_cell_left_gets_no_file(tmp_path
stale = _judged(batch, "guidance:raw", 1)
stale.write_text("{}") # an earlier run's file is not left to read as this run's
code, out, _ = _run(capsys, "judge", str(batch), "--judge", JUDGE, "--max-usd", "1")
assert code == 1
assert code == 3
assert len(judge_llm.requests) == 3 # $0.40 each: the third starts at $0.80, the fourth would at $1.20
assert _judged(batch, "guidance:none", 1).is_file() and not stale.exists()
assert (f"1 cell(s) not fully judged (--max-usd spent), no {HITS_JUDGED}: "
Expand Down Expand Up @@ -429,7 +429,7 @@ def test_an_unpriced_judge_under_max_usd_stops_the_run_and_says_why(tmp_path, ca
batch = _batch(tmp_path)
with llm.use_adapter(llm.FakeAdapter(respond=_reply)) as fake: # no cost_usd: the judge has no known price
code, out, _ = _run(capsys, "judge", str(batch), "--judge", JUDGE, "--max-usd", "0.5")
assert (code, len(fake.requests)) == (1, 1)
assert (code, len(fake.requests)) == (3, 1)
lines = out.splitlines()
assert (f"2 cell(s) not fully judged ({UNPRICED_STOP}), no {HITS_JUDGED}: {TASK}__guidance-none__{MODEL}__r1, "
f"{TASK}__guidance-raw__{MODEL}__r1") in lines
Expand All @@ -453,7 +453,7 @@ def test_pairs_in_the_response_cache_still_finish_after_an_unpriced_stop(tmp_pat
with llm.use_adapter(llm.FakeAdapter(respond=_reply)) as fake: # no cost_usd: the judge has no known price
code, out, _ = _run(capsys, "judge", str(batch), "--judge", JUDGE, "--max-usd", "5", "--json")
result = json.loads(out)["data"]
assert (code, len(fake.requests), result["calls"]) == (1, 1, 1) # none's first pair live, then the stop
assert (code, len(fake.requests), result["calls"]) == (3, 1, 1) # none's first pair live, then the stop
assert result["budget_stopped"] == [f"{TASK}__guidance-none__{MODEL}__r1"] and result["budget_stop"] == UNPRICED_STOP
document = json.loads(out)
assert (document["status"], document["cost"]["calls"], document["cost"]["cap_usd"]) == ("budget_stopped", 1, 5.0)
Expand Down
2 changes: 1 addition & 1 deletion dokimi/tests/test_repo_hits_judge_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ def test_an_unpriced_judge_under_max_usd_json_has_no_remaining_budget_and_gives_
with llm.use_adapter(llm.FakeAdapter(respond=_reply)): # no cost_usd: the judge has no known price
code, out, _ = _run(capsys, "judge", str(batch), "--judge", JUDGE, "--max-usd", "0.5", "--json")
doc = json.loads(out)
assert code == 1 and (doc["status"], doc["reason"]) == ("budget_stopped", UNPRICED_STOP)
assert code == 3 and (doc["status"], doc["reason"]) == ("budget_stopped", UNPRICED_STOP)
assert (doc["cost"]["remaining_usd"], doc["cost"]["priced"]) == (None, False) # not "the full budget left"
assert schema_errors("cli_output.v1", doc) == []
2 changes: 1 addition & 1 deletion dokimi/tests/test_repo_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def test_timed_out_cell_counts_toward_batch_budget(setup, monkeypatch, capsys):
with pytest.raises(SystemExit) as exc:
_run(setup, "--arm", "guidance:raw", "--task", "fix_add", "--reps", "2", "--timeout", "2",
"--max-usd-per-cell", "0.5", "--max-usd", "0.01")
assert exc.value.code == 1
assert exc.value.code == 3
assert "1 ran" in (out := capsys.readouterr().out) and "1 not started (batch budget), 0 unsupported; $0.5000" in out
rec = json.loads((setup["out"] / "b1/fix_add__guidance-raw__m-1__r1/result.json").read_text())
assert rec["agent"]["cost_usd"] is None and rec["agent"]["charged_usd"] == 0.5
Expand Down
70 changes: 70 additions & 0 deletions dokimi/tests/test_repo_run_batch_exit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Copyright (C) 2026 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

"""The exit code of a `repo run` batch, from its summary (docs/quickstart.md, exit-code table rows 1, 3 and 5)."""

from __future__ import annotations

import pytest

from dokimi.cli import build_parser
from dokimi.commands.repo_run import _exit_of_batch
from repo_eval_fixture import FakeRunner, fake_harness, make_repo


def _summary(**over):
base = {"ran": 1, "skipped": 0, "errors": [], "budget_stopped": 0, "probe_failed": [], "unsupported": 0, "cells": 2}
return {**base, **over}


def _code(summary) -> int | None:
try:
_exit_of_batch(summary)
except SystemExit as exc:
return exc.code
return None


@pytest.mark.parametrize(("over", "code"), [
({}, None),
({"budget_stopped": 1}, 3), # the finished cells keep their results: inconclusive
({"budget_stopped": 1, "errors": [{"infra": False}]}, 1), # a defect outranks an inconclusive result
({"budget_stopped": 1, "probe_failed": ["t1"]}, 1),
({"budget_stopped": 1, "errors": [{"infra": True}]}, 5), # an infrastructure crash outranks both
({"budget_stopped": 1, "errors": [{"infra": False}, {"infra": True}]}, 5),
({"errors": [{"infra": False}]}, 1),
({"probe_failed": ["t1"]}, 1),
({"ran": 0, "unsupported": 2}, 1), # no cell has a result
({"ran": 0, "budget_stopped": 2}, 1), # every cell not started: nothing kept, not inconclusive
({"ran": 0, "skipped": 1, "budget_stopped": 1}, 3), # a rerun: the cells done before keep their results
])
def test_exit_of_a_batch(over, code):
assert _code(_summary(**over)) == code


def test_a_rerun_whose_spent_budget_starts_no_cell_exits_1(tmp_path, monkeypatch, capsys):
root, _ = make_repo(tmp_path)
exe, profile = fake_harness(tmp_path)
monkeypatch.setattr("dokimi.repos.container.DockerRunner", lambda *a, **k: FakeRunner())
monkeypatch.setenv("FAKE_ACTION", "sleep")
out = tmp_path / "runs"

def run(arm):
argv = ["repo", "run", f"{root}@HEAD", "--manifest", ".agent-eval/repo-eval.yaml", "--harness", str(profile),
"--bin", str(exe), "--model", "m-1", "--name", "b1", "--out", str(out), "--cache-root",
str(out / "caches"), "--agent-network", "host", "--arm", arm, "--task", "fix_add", "--timeout", "2",
"--max-usd-per-cell", "0.5", "--max-usd", "0.01"]
args = build_parser().parse_args(argv)
return _exit(args)

assert run("guidance:raw") is None # the one cell runs and spends the cap
assert run("guidance:none") == 1
assert "0 ran, 0 already done, 0 crashed, 1 not started (batch budget)" in capsys.readouterr().out


def _exit(args) -> int | None:
try:
args.func(args)
except SystemExit as exc:
return exc.code
return None
Loading