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
3 changes: 3 additions & 0 deletions dokimi/changelog.d/20261128_140000_partial-stop-exit-3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Changed

- **`skill novelty atoms`, `probe`, `analyze`, `skill routing` and `catalog routing` exit 3, not 1, when `--max-usd` or a call with no price stops them and they keep the partial file** — the exit-code table in `docs/quickstart.md` gives 3 to a run that stopped short on a budget and kept its partial output, as `tools preference` does, but these commands exited 1. The message on stderr is the same. A stop on a permanent provider error (`"reason": "permanent_error"`) is a runtime failure and still exits 1, as does a run that kept nothing (`skill shorten`) or an all-vs-all run where model calls failed. A script that read exit 1 as "stopped by the budget" now sees 3.
9 changes: 6 additions & 3 deletions dokimi/docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,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 --custom-questions` on an empty or non-JSON file (`--custom-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` today; `eval personas discover` refuses its one call before it runs, so nothing is written; other spend-capped commands such as `repo run`, `repo hits judge` and `skill routing` 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`; 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 |
| 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 @@ -272,8 +272,11 @@ 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` and the novelty commands' `--max-usd` still exit 1
when the budget or an unpriced call stops them (`catalog novelty` too, once it has written
`repo hits judge --max-usd` still exit 1 when the budget or an unpriced call stops them.
`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
stopped them (`catalog novelty` exits 1 too, once it has written
its rows, when any skill it took on is `partial`, `error` or not run).
`eval judge agreement --judges` and `eval score pairwise` exit 1, not 2, when
every judge call fails, a missing provider credential included.
Expand Down
2 changes: 1 addition & 1 deletion dokimi/docs/skill-novelty-walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ What a stopped run leaves behind depends on the step:
refused after it came back keeps the verdict it names; one that names none is kept as
`error` too. If the cap stops it while the
paraphrase or reversal wordings are built, nothing is written.
- Each exits with a message that names the partial file. A partial file is never read as a
- Each exits 3 (1 when a permanent provider error stopped it) with a message that names the partial file. A partial file is never read as a
finished one: the atom readers and `novelty items` refuse it. A later stopped run replaces
an earlier partial file, but never a finished one: if `<stem>.partial.json` holds anything
other than a partial result, the new one goes to `<stem>.partial2.json` (and so on).
Expand Down
8 changes: 4 additions & 4 deletions dokimi/docs/skill-novelty.md
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,8 @@ research runs and for any run you may repeat. `--cache-dir` keeps only the reten

**A routing run stopped by `--max-usd` keeps what it paid for.** `skill routing --model`, single
artifact or `catalog routing`, writes the result of the calls made before the cap (or a call with no
known price) stopped it, prints the summary and `cost` lines, and still exits non-zero with the
cap message and the path of the file. The file carries
known price) stopped it, prints the summary and `cost` lines, and exits 3 with the
cap message and the path of the file (1 for a `permanent_error` stop). The file carries
`"partial": {"reason": "spend_cap", "calls_done": N, "calls_planned": M, "message": ...}` (`"permanent_error"` for the stop above, `"no_price"` for an unpriced call) at the
top level (and under the model arm), and no `partial` key when the run finished. The record's
`status` is then `"partial"` instead of `"ok"` (a single run; an all-vs-all file carries `status`
Expand Down Expand Up @@ -1429,7 +1429,7 @@ with no network that is a pause of a few seconds and a warning. Setting
**Spend cap on `atoms`, `probe` and `analyze`.** `--max-usd` stops these at the limit and keeps the work it
paid for. `atoms` writes `<stem>.partial.json` beside the `--out` file (`atoms.json` by default;
the spans read so far, the rest marked unread), and `probe` does the same beside its `--out`
file (`probes.json` by default; the answers so far). Both exit with a message naming the file. A partial file is never read as a
file (`probes.json` by default; the answers so far). Both exit 3 (1 for a `permanent_error` stop) with a message naming the file. A partial file is never read as a
finished one: `probe` and the other atom readers refuse `atoms.partial.json`, and `novelty items`
refuses a partial probe file. A partial probe file keeps its `runs` and `probes` and holds null for
the summaries computed over the answers the cap left (`paired`, `arms`, `abstentions`, the reversal and
Expand All @@ -1446,7 +1446,7 @@ spent), and `spans_read` / `spans_total` for an extraction stop or `calls_done`
(the unread spans are in `extraction.unread_span_ids`), the `probes` once built (with the
wordings and answer keys in `probes.items`, so a stop before the first answer still keeps them) and
the `runs` (probe answers and judgments) so far; it has no `paired`, `arms`, `k0` or view summaries, and no
`novelty.md` or annotated view is written. The exit is non-zero (1), the message names the file and
`novelty.md` or annotated view is written. The exit is 3 (1 for a `permanent_error` stop), the message names the file and
how to get the paid calls back: with `DOKIMI_RESPONSE_CACHE` set to a writable directory on the capped run, a rerun with a
higher `--max-usd` and the same cache replays them at $0 (a reply that was cut off or unusable is
asked again; after a `no_price` stop the message says to price the model or drop `--max-usd`
Expand Down
15 changes: 8 additions & 7 deletions dokimi/dokimi/commands/novelty_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from pathlib import Path
from typing import NoReturn

from dokimi.commands.novelty_routing_report import _partial_destinations
from dokimi.commands.novelty_routing_report import _partial_destinations, stop_partial


def partial_destination(out: Path) -> Path:
Expand Down Expand Up @@ -63,9 +63,10 @@ def partial_write(out: Path, write: Callable[[Path], object]) -> Path:
raise RuntimeError("unreachable: the sidecar names never run out")


def exit_partial(summary: str, path: Path, note: str = "") -> NoReturn:
"""Stop with a message that names the partial file, as a run the cap stopped must."""
raise SystemExit(f"{summary}; the partial result is in {path}{note}")
def exit_partial(summary: str, path: Path, note: str = "", *, reason: str) -> NoReturn:
"""Stop with a message that names the partial file, as a run the cap stopped must; ``reason`` is the
stop's (``partial["reason"]``) and picks the exit code (:func:`partial_exit_code`)."""
stop_partial(f"{summary}; the partial result is in {path}{note}", reason)


def response_cache_active() -> bool:
Expand Down Expand Up @@ -110,7 +111,7 @@ def save_analyze_partial(result, out: Path) -> NoReturn:
cause = partial.get("cause")
summary = f"{partial['message']} ({cause})" if cause else partial["message"]
exit_partial(summary, write_run(result.artifact, out, partial),
replay_hint(partial["reason"]))
replay_hint(partial["reason"]), reason=partial["reason"])


def write_run(payload: dict, out: Path, partial: dict | None = None) -> Path:
Expand Down Expand Up @@ -157,7 +158,7 @@ def save_probe_run(payload: dict, out: Path, *, done: int, not_run: int,
payload[block] = None
if panel:
payload["judge_panel"] = {k: panel[k] for k in ("judges", "rule") if k in panel}
exit_partial(message, write_run(payload, out, partial))
exit_partial(message, write_run(payload, out, partial), reason=reason)


def save_probe_measure(payload: dict, out: Path, result) -> Path:
Expand All @@ -176,7 +177,7 @@ def save_atoms_run(atoms, spans, out: Path, partial: dict | None, **record) -> P
return out
dest = partial_write(out, lambda side: save_atoms(atoms, spans, side, partial=partial,
**record))
exit_partial(partial["message"], dest)
exit_partial(partial["message"], dest, reason=partial["reason"])


def verify_or_partial(sample, spans, client) -> dict | None:
Expand Down
7 changes: 4 additions & 3 deletions dokimi/dokimi/commands/novelty_routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def cmd_routing(args: argparse.Namespace) -> tuple[dict, Path, str] | None:
stop_if_partial(payload, out,
lambda: print_routing_summary(payload, len(competitors), self_derived))
except SystemExit as stop:
raise RoutingStopped(stop.code, payload, out, gold.name) from None
raise RoutingStopped(stop, payload, out, gold.name) from None
print(f"OK Saved routing measurement: {out}")

print_routing_summary(payload, len(competitors), self_derived)
Expand All @@ -172,8 +172,9 @@ def cmd_routing(args: argparse.Namespace) -> tuple[dict, Path, str] | None:
class RoutingStopped(SystemExit):
"""A routing run the cap or a model error cut short: it exits as before, and carries the saved result for --json."""

def __init__(self, message: object, payload: dict, out: Path, skill: str) -> None:
super().__init__(message)
def __init__(self, stop: SystemExit, payload: dict, out: Path, skill: str) -> None:
super().__init__(*stop.args) # the message, already printed by stop_if_partial
self.code = stop.code
self.result = (payload, out, skill)


Expand Down
37 changes: 30 additions & 7 deletions dokimi/dokimi/commands/novelty_routing_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, NoReturn

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

if TYPE_CHECKING:
Expand Down Expand Up @@ -523,10 +524,10 @@ def exit_partial_all_vs_all(model_arm: dict, cost: dict | None, failed: int, sen
noise and cost lines print before the exit; the partial result is already saved in ``out``.
"""
print_all_vs_all_model(model_arm, cost)
raise SystemExit(f"{failed} of {sent} model call(s) failed "
f"({model_arm['first_error']}); the partial result leaves the failed calls "
"out of model-arm scoring, and a query with a failed repeat out of the "
f"repeat-noise rates, is in {out}")
stop_partial(f"{failed} of {sent} model call(s) failed "
f"({model_arm['first_error']}); the partial result leaves the failed calls "
"out of model-arm scoring, and a query with a failed repeat out of the "
f"repeat-noise rates, is in {out}", "failed_calls")


def partial_block(model_arm: dict) -> dict:
Expand Down Expand Up @@ -657,7 +658,8 @@ def save_result(payload: dict, out: Path, model_arm: dict) -> Path:


def stop_if_partial(payload: dict, out: Path, show: Callable[[], None]) -> None:
"""Exit non-zero when ``--max-usd`` stopped the run; the result is already saved in ``out``.
"""Exit when ``--max-usd`` (or a model error) stopped the run, with :func:`partial_exit_code`; the result
is already saved in ``out``.

``show`` prints the summary and cost lines first, so the calls paid for are on the console.
The partial block says how many of the planned model calls were made.
Expand All @@ -666,8 +668,29 @@ def stop_if_partial(payload: dict, out: Path, show: Callable[[], None]) -> None:
if partial is None:
return
show()
raise SystemExit(f"{partial['message']}. The partial result, {partial['calls_done']} of "
f"{partial['calls_planned']} model calls, is in {out}")
stop_partial(f"{partial['message']}. The partial result, {partial['calls_done']} of "
f"{partial['calls_planned']} model calls, is in {out}", partial["reason"])


class PartialStop(SystemExit):
"""A stop that kept its partial result: ``code`` is the exit code (:func:`partial_exit_code`), ``str()`` the
message, which :func:`stop_partial` has already printed (an int ``code`` is not printed by the interpreter)."""

def __init__(self, message: str, code: int) -> None:
super().__init__(message)
self.code = code


def partial_exit_code(reason: str) -> int:
"""The exit code of a stop that kept its partial result (docs/quickstart.md, exit codes): 3 for a budget
stop (``spend_cap``, ``no_price``), 1 for a runtime failure (``permanent_error``) or any other reason."""
return EXIT_INCONCLUSIVE if reason in ("spend_cap", "no_price") else EXIT_FAILURE


def stop_partial(message: str, reason: str) -> NoReturn:
"""Print ``message`` on stderr and exit with the code of ``reason``."""
print(message, file=sys.stderr)
raise PartialStop(message, partial_exit_code(reason))


def warn_blind_skills(result: dict, queries_by_skill: dict[str, list[str]]) -> None:
Expand Down
15 changes: 11 additions & 4 deletions dokimi/tests/test_novelty_analyze_cap_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ def test_the_command_writes_the_partial_file_beside_novelty_json_and_names_it(tm
args, out_dir = _command(tmp_path, monkeypatch, _answers_cost)
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
message = str(stop.value)
partial = out_dir / "novelty.partial.json"
assert f"the partial result is in {partial}" in message
Expand All @@ -295,8 +296,9 @@ def test_the_message_says_a_rerun_replays_the_paid_calls_when_the_cache_was_set(
monkeypatch.setenv("DOKIMI_RESPONSE_CACHE", str(tmp_path / "cache"))
args, _out_dir = _command(tmp_path, monkeypatch, _answers_cost)
with pytest.raises(SystemExit, match="same DOKIMI_RESPONSE_CACHE: the calls already paid for "
"replay at \\$0"):
"replay at \\$0") as stop:
args.func(args)
assert stop.value.code == 3


def test_a_no_price_stop_does_not_advise_a_higher_cap(tmp_path, monkeypatch):
Expand All @@ -305,6 +307,7 @@ def test_a_no_price_stop_does_not_advise_a_higher_cap(tmp_path, monkeypatch):
args, _out_dir = _command(tmp_path, monkeypatch, lambda prompt: None)
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
message = str(stop.value)
assert "Rerun with the model priced, or without --max-usd, and the same DOKIMI_RESPONSE_CACHE" \
in message
Expand All @@ -319,6 +322,7 @@ def test_the_message_does_not_claim_a_replay_when_the_cache_variable_names_a_fil
args, _out_dir = _command(tmp_path, monkeypatch, _answers_cost)
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
message = str(stop.value)
assert "DOKIMI_RESPONSE_CACHE was not set on this run" in message
assert "a rerun pays for these calls again" in message
Expand Down Expand Up @@ -425,8 +429,9 @@ def test_a_partial_result_never_replaces_a_finished_novelty_json(tmp_path, monke
out_dir.mkdir()
finished = out_dir / "novelty.json"
finished.write_text('{"schema_version": "novelty.v1", "finished": true}', encoding="utf-8")
with pytest.raises(SystemExit):
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
assert json.loads(finished.read_text(encoding="utf-8"))["finished"] is True
assert json.loads((out_dir / "novelty.partial.json").read_text(encoding="utf-8"))["status"] \
== "partial"
Expand All @@ -439,8 +444,9 @@ def test_a_partial_analyze_file_is_refused_by_the_readers_of_a_finished_one(tmp_
from dokimi.subjects.novelty_track import load_novelty_artifacts

args, out_dir = _command(tmp_path, monkeypatch, _answers_cost)
with pytest.raises(SystemExit):
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
partial = out_dir / "novelty.partial.json"
record = json.loads(partial.read_text(encoding="utf-8"))
del record["partial"] # the schema lets `status` stand alone
Expand Down Expand Up @@ -487,7 +493,8 @@ def test_a_partial_analyze_file_is_not_listed_as_a_finished_run(tmp_path, monkey
from dokimi.runs.scan import scan

args, out_dir = _command(tmp_path, monkeypatch, _answers_cost)
with pytest.raises(SystemExit):
with pytest.raises(SystemExit) as stop:
args.func(args)
assert stop.value.code == 3
result = scan(out_dir)
assert result.artifacts == [] and result.skipped["no_leading_schema_version"] == 1
Loading
Loading