Skip to content

feat(tools): tools preference --out-dir writes a run directory - #1543

Merged
vlad-perevezentsev merged 13 commits into
intel:mainfrom
vlad-perevezentsev:feat/tools-preference-run-directory
Dec 4, 2026
Merged

vlad-perevezentsev merged 13 commits into
intel:mainfrom
vlad-perevezentsev:feat/tools-preference-run-directory

Conversation

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor

Summary

Step R-7 of #94 R2, the first catalog diagnostic: tools preference --out-dir DIR runs in a run directory written through runs/rundir.py, in the shape subjects run took in #1494.

  • Opt-in. Without --out-dir nothing changes: the artifact goes to tool_preference.json, or --out FILE, and no directory is made. --dry-run makes none either.
  • What the directory holds. run.json, plan.v1.json, result.v1.json and the artifact as tool_preference.v1.json, all listed in run.json. An --out-dir that exists and is not empty is refused (exit 2) before anything is written.
  • The plan. One cell per item and rep, in the order the calls are taken: arm <factor>/<treated twin>-<first|last> (baseline/<first twin>-first), task the group. The suite hash is taken over the items as sent (messages and tools), so another system prompt or other cues give another plan_digest.
  • Statuses. A call has no verdict of its own (the summary compares the items): a scored first turn is inconclusive, with the outcome in its detail (first turn: A); a failed call is infra_error with its error. Each call is recorded as it ends.
  • The --max-usd stop. The command still exits 3 and keeps the partial artifact. run.json is now incomplete with stop.reason spend_cap, or no_price for a call that came back without a price, as the table in docs/run-directories.md says. The calls left are not_run.
  • Ctrl-C or SIGTERM. run.json ends incomplete (interrupted / terminated). result.v1.json and tool_preference.v1.json keep the calls that ended before the stop, with their usage and cost; the others are skipped there. run_probe no longer waits in the pool's exit for the calls in flight. A call in flight at the stop is left out of both files, and out of on_result and the progress line.
  • A schema-rejected artifact ends the run failed (exit 1, as before), not complete without its file.
  • --out with --out-dir. It is a copy, written after the run has ended, and only when given. A --out or --items-out file in this run's directory or in another's (one holding a run.json) is refused (exit 2) before any call. The check is the new runs.rundir.in_a_run; subjects run uses it too, in place of its own copy of the same lines. runs.rundir.refuse_taken gives open_run's refusal before anything is written.

Changed modules: dokimi/tool_preference.py (plan, record_result, run_probe's on_result / on_stop) and dokimi/commands/tools.py. cmd_tools_preference is split into helpers: complexity 11 -> 7, and its baseline entry is removed. Layout and rules: docs/run-directories.md, new section tools preference.

Refs #94 R2

Changed output

$ dokimi tools preference --groups groups.json --model m --out-dir out --out copy.json
...
-> out/tool_preference.v1.json (copy: copy.json)

out/
  run.json  plan.v1.json  result.v1.json  tool_preference.v1.json

On a Ctrl-C (stderr, new):

The run was stopped: 14 of 16 call(s) not run; the calls that ended -> out/tool_preference.v1.json
  • --out's default in --help and cli-interface.json is now None. The command still writes tool_preference.json when neither --out nor --out-dir is given.
  • The skipped description in tool_preference.v1.json (the schema) now also names a stop. It is a wording change only: the schema accepts and rejects the same files (schema_compat passes).

Evidence

  • Main: tests/test_tools_preference_run_directory.py fails 11 of its first 12 tests: --out-dir is an unknown argument. The one that passes pins today's behaviour without --out-dir.
  • Branch: 17 tests pass. They cover:
    • a complete run, its plan cells against the items and their reps, the budget, and run.json's artifacts;
    • the --out copy, no directory without --out-dir, none for --dry-run;
    • spend_cap and no_price stops (exit 3, incomplete, the calls left not_run, the partial artifact);
    • every call failing (exit 1, infra_error), a rejected artifact (failed);
    • Ctrl-C (the ended calls kept in both files, a call in flight not waited for and left out);
    • a call that ends after the stop not reported, a job taken after the stop not called;
    • --out / --items-out in this run's or another run's directory, and a taken --out-dir, refused before anything is written;
    • the suite hash following the cues and the system prompt.
  • Mutations, each failing a test and then reverted:
    • first/last swapped in the arm; infra_error -> inconclusive;
    • the suite hash without the tools, and without the messages; no cost_usd in the budget;
    • no SpendCapReached raise; spend_cap <-> no_price;
    • --items-out dropped from the refusal; the default --out kept with --out-dir; in_a_run without the run's own directory;
    • the pool waiting for the calls in flight on a stop; no stopped flag, or no check of it; no on_stop call; the stop's unrun calls not skipped; no partial save in the run;
    • a rejected artifact saved through the exit-1 path; no refuse_taken; skip = capped() without the stop.
  • Bad inputs: --out-dir that is a file, a non-empty directory or "". Each exits 2 (run directory ... already exists) before any call and leaves nothing behind.
  • slot ci --quick (lint, mypy, the whole suite): 0 failed, 33624 passed, 132 skipped. Two runs before it failed tests/test_blank_inline.py::test_the_opener_of_each_link_of_one_row_is_found_without_reading_the_brackets_before_it (a growth-ratio timing: 64.0 and 64.9 against < 64, at load average 54). That test passes on its own, and this PR does not touch its module. The full make ci-local --offline runs on the last commit before publishing.
  • Not run: a real model (the tests are offline), SIGTERM by hand (rundir.py's own tests cover the signal path, and the probe's code for a stop is the same for both), Windows.

Not in this PR

  • No run directory by default (<runs root>/<run_id> without --out-dir, as subjects run has), and no --name: the card asks for --out-dir, and --out FILE keeps its default.
  • On Ctrl-C the process still lets the calls in flight finish before it exits (concurrent.futures joins its workers at exit). They may be billed, but they are not in the artifact.
  • --items-out is not part of the run directory (it is no registered artifact kind).
  • The other R-7 diagnostics, skill novelty analyze and repo scan, wait for the open PRs on their files.

Open questions

  • Should tools preference run in <runs root>/<run_id> without --out-dir too, as subjects run does? That changes where the default output goes.

Checklist

  • Tests added/updated and pytest passes: tests/test_tools_preference_run_directory.py (new, 17 tests); slot ci --quick 0 failed
  • ruff, mypy, and schema checks pass: ci-local --jobs static,typecheck 0 failed, schema_compat passes
  • Docs updated: docs/run-directories.md (section tools preference), docs/tool-preference.md, docs/runs.md, docs/reference/cli-interface.json
  • Self-reviewed per "Before opening a PR" in AGENTS.md: the mutations and bad inputs above, list_new_error_paths.py, check_growth.py (cmd_tools_preference baseline removed)
  • Each new raise/exit and test names the doc, contract or issue it traces to: the refusals cite docs/run-directories.md; each test cites a line of it or of run_probe's docstring
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header: the test file, the fragment

`tools preference --out-dir DIR` now runs in a run directory of its
own (intel#94 R2, R-7), opened with runs/rundir.py: run.json, a plan.v1
with one cell per item and rep (arm <factor>/<treated twin>-<first|last>,
task the group), a result.v1 status for each call as it ends
(a scored first turn is inconclusive, a failed call infra_error) and
the artifact as tool_preference.v1.json, all listed in run.json.

When --max-usd leaves calls unrun the command still exits 3 with the
partial artifact; run.json is incomplete with stop.reason spend_cap or
no_price, and the calls left are not_run. A Ctrl-C or SIGTERM leaves
run.json incomplete with the calls that ended recorded: run_probe no
longer waits in the pool's exit for the calls in flight, so the
record is written at once.

With --out-dir, --out is a copy only when given, and a --out or
--items-out file in a run directory is refused (exit 2) before any
call; the check is runs.rundir.in_a_run, which subjects run now uses
too. Without --out-dir the command writes tool_preference.json (or
--out FILE) as before; --dry-run makes no directory.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The test varied only the cues, which land in the tools: hashing only
the items' ids and tools passed it, though tp.plan says the hash covers
the system prompt too. A document with another system prompt now gets
another hash.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Inside --out-dir, a tool_preference.v1 the schema rejected exited 1
from within the run's block, and exit 1 ends a run by its cells: run.json
said complete with no tool_preference.v1.json in the directory. The
rejection now leaves the block as ArtifactValidationError, so the run is
failed (stop.reason error), and the command still exits 1 after it.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The new-or-empty rule of --out-dir was checked only in open_run, after
--items-out was written and --out's parent directories were made: a
refused run left them behind. tools preference now checks the directory
first with runs.rundir.refuse_taken, which gives open_run's message;
open_run's exclusive claim still decides a race.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A Ctrl-C or SIGTERM inside --out-dir left run.json and result.v1 but
no tool_preference.v1: the choices, usage and cost of the calls already
paid for were lost. run_probe now hands the results of the calls that
ended before the stop, the others skipped, to an on_stop callback, and
tools preference saves them as tool_preference.v1.json before the stop
goes on. A call that ends after the stop no longer reaches on_result or
on_progress, so it is not recorded into an ended run or printed after
the interrupt, and a job taken after the stop is not called.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
run_probe skips a job a worker takes after the stop is recorded, before
the pool's cancel reaches it, but no test held it: 'skip = capped()'
passed the suite. A pool whose shutdown runs the job a worker had
already taken now shows that the job makes no call.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
@vlad-perevezentsev
vlad-perevezentsev requested a review from a team as a code owner December 2, 2026 17:08
@vlad-perevezentsev vlad-perevezentsev self-assigned this Dec 2, 2026
@exai-bot

exai-bot commented Dec 2, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s).

CI at `97bbc8c`: 3 failing, 18 passing, 4 skipped

Not fully read: log of Test Linux Python 3.14: longer than 8000000 bytes, only the start was read; log of Test Linux Wheels Python 3.14: longer than 8000000 bytes, only the start was read

Three checks failed. The main test job reports growth-ratchet violations in files untouched by this change; the two Linux test logs are truncated before any failure diagnostic, so their causes cannot be determined. Local lint and type checking passed.

Check Status Assessment
Test Linux Python 3.14 failing at step Install the package and run ci/test.py Cause unclear. The available log exceeds the tool's 8 MB read limit and ends around 78% with passing tests. Searches found no failure summary or termination diagnostic, so there is insufficient evidence to attribute this failure.
Test Linux Wheels Python 3.14 failing Cause unclear. The available log exceeds the tool's 8 MB read limit and ends around 78% with passing tests. No actual failing test or termination diagnostic is available, so this cannot be classified as a regression or infrastructure failure.
Tests (py3.14) failing at step Run tests Also fails without this PR. The growth ratchet reports manifest.py at 807 lines and workspace.py at 803, without file baseline entries. Neither file, the ratchet implementation, nor its test changes here; the baseline diff only removes an unrelated tools-command complexity entry, so reverting this change would not resolve...
Review details
  • Commit reviewed: 97bbc8c against merge base cb2d4de
  • Coverage: 1 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 87k tokens (65k from cache), 24s
  • Tool calls: 7 (4 file_read, 3 code_search)
  • dokimi/dokimi/commands/tools.py: 1 file

Comment thread dokimi/docs/run-directories.md Resolved
Comment thread dokimi/dokimi/commands/tools.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
After a Ctrl-C or a signal, the calls that did not end are not_run
cells in result.v1.json and skipped results in tool_preference.v1.json;
the docs and the fragment said only skipped.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
tools preference --out output --out-dir output/run passed the checks,
the run then made output a directory, and after every paid call the
copy failed with exit 2. A --out or --items-out that is the run
directory or one of its parents is now refused before any call.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/tool_preference.py Resolved
@codecov-commenter

codecov-commenter commented Dec 2, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 95.53073% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.51%. Comparing base (599fcad) to head (97bbc8c).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
dokimi/dokimi/commands/tools.py 95.09% 5 Missing ⚠️
dokimi/dokimi/runs/rundir.py 84.61% 2 Missing ⚠️
dokimi/dokimi/tool_preference.py 98.38% 0 Missing and 1 partial ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@           Coverage Diff            @@
##             main    #1543    +/-   ##
========================================
  Coverage   96.51%   96.51%            
========================================
  Files         540      549     +9     
  Lines       72237    73196   +959     
  Branches    12451    12618   +167     
========================================
+ Hits        69717    70645   +928     
- Misses       1544     1563    +19     
- Partials      976      988    +12     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/subjects.py 96.43% <100.00%> (-0.01%) ⬇️
dokimi/dokimi/tool_preference.py 98.80% <98.38%> (-0.23%) ⬇️
dokimi/dokimi/runs/rundir.py 99.06% <84.61%> (-0.94%) ⬇️
dokimi/dokimi/commands/tools.py 96.18% <95.09%> (-1.20%) ⬇️

... and 48 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added the cli-interface-change Changes dokimi's user-facing CLI surface label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

CLI interface change detected

This PR changes dokimi's user-facing CLI surface (commands and/or options):

~ `dokimi tools preference` parameters changed:
    + added option `--out-dir`
    ~ changed option `--out`: default: 'tool_preference.json' -> None

Updated on every push; the cli-interface-change label is on while the diff is non-empty.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head 8d7ccbd)

  • Contract: changed. errors dokimi/dokimi/commands/tools.py:251; errors dokimi/dokimi/commands/tools.py:266
  • Responsibility: candidate. delegate cmd_tools_preference in dokimi/dokimi/commands/tools.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

0 new must-fix findings. The earlier items below remain open. The new run-directory tests cover the plan, result, tool preference artifact, budget stop, and interruption. The existing worker-stop issue reproduced with three stub calls and two workers.

Checked the diff, input edges, and focused offline Linux tests (merged: 175 passed in 5.88s). Checked run publication with stubbed providers.

  • Still open. An interrupted worker can leave the main thread waiting on a slower earlier result while another queued call starts. The isolated probe shows this on both trees. Earlier thread

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 6 of 80 small breaks of the lines this PR changes, and not every break was tried

At 97bbc8c: 74 caught · 6 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 # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Where Operator Change no test notices Tests reaching the line
dokimi/dokimi/runs/rundir.py:117 drop-clause not path.exists() or (path.is_dir() and not any(path.iterdir())) → (not path.exists()) 14
dokimi/dokimi/tool_preference.py:43 negate-condition TYPE_CHECKING → not (TYPE_CHECKING) 6
dokimi/dokimi/tool_preference.py:352 bump-int 1 → 2 57
dokimi/dokimi/tool_preference.py:358 delete-statement stopped[0] = True → pass 5
dokimi/dokimi/tool_preference.py:364 delete-statement pool.shutdown() → pass 52
dokimi/dokimi/tool_preference.py:386 bump-int 200 → 201 45

Not checked:

  • 95 more breaks of covered changed lines were over the limit and not tried
  • 29 changed lines were not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
run_probe read the pool's results in submission order, so a stop raised
in a later call waited behind an earlier call still running, and the
other workers went on starting queued calls meanwhile. The results are
now read in the order the calls end: the stop is seen at once, no queued
call starts, and on_stop gets the results kept so far.

The test pool of 'a job taken after the stop' now takes submit() instead
of map().

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Only the main thread set the stop flag, after as_completed woke it. The
worker whose call raised went straight back to the queue, saw no stop
and started the next job: with a 1 us switch interval 35 of 200 runs
made a call after the stop. The worker now marks the stop under the
lock before the exception goes on (in _call_or_stop, which keeps
run_probe under the complexity cap), and 0 of 200 runs do.

A test pool whose worker takes the next jobs right after the raise
pins it.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
@vlad-perevezentsev

Copy link
Copy Markdown
Contributor Author

Change class: CONTRACT (head 8d7ccbd) - Contract: changed. errors dokimi/dokimi/commands/tools.py:251; errors dokimi/dokimi/commands/tools.py:266 - Responsibility: candidate. delegate cmd_tools_…

@napetrov Thanks. The open item (a worker's stop waiting behind a slower earlier call) is fixed in 1140a4e and cb2d4de: the results are read in completion order, and the worker that raised marks the stop itself, so no queued call starts after it; regression tests cover both.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head cb2d4de)

  • Contract: changed. errors dokimi/dokimi/commands/tools.py:251; errors dokimi/dokimi/commands/tools.py:266
  • Responsibility: candidate. delegate cmd_tools_preference in dokimi/dokimi/commands/tools.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

No merge-blocking findings.

Checked the worker-stop fixes and the persisted run artifacts. Ran 96 focused tests with current main. Required checks passed. The only failures in the three Linux jobs are the same two file length violations reproduced on main after #1514.

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The run directory follows the shape subjects run took: plan, per-call statuses, partial artifact on a stop, and the refusals come before any write. The worker-stop fixes hold. One nit inline.

What I ran, on a Linux review host at cb2d4de:

  • make ci-local: 38 passed, 0 failed, 16 skipped (the other Python legs and the org-level scan are not run locally).
  • The --dry-run case below, with an existing non-empty --out-dir.

Checked, no issues

  • Docs: run-directories.md, tool-preference.md, runs.md, cli-interface.json and the schema description match the flags and statuses in tools.py and tool_preference.py.
  • Commits: all 10 non-merge commits carry Signed-off-by.
  • Growth baseline: the cmd_tools_preference entry is removed and ci-local passes.

Comment thread dokimi/dokimi/commands/tools.py Resolved
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I pushed a commit per nit, up to 97bbc8c, which fix the nit from my review:

  • 97bbc8c: dokimi/dokimi/commands/tools.py:313: a dry run no longer refuses a taken --out-dir, and the --out and --items-out checks still run.

make ci-local at 97bbc8c: 38 passed, 0 failed, 16 skipped.

@napetrov napetrov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change class: CONTRACT (head 97bbc8c)

  • Contract: changed. errors dokimi/dokimi/commands/tools.py:251; errors dokimi/dokimi/commands/tools.py:266
  • Responsibility: candidate. delegate cmd_tools_preference in dokimi/dokimi/commands/tools.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

Ready to merge.

Rechecked dry-run behavior with an occupied directory, an external items file and a protected run file. 97 focused tests and required CI passed. The optional Linux jobs reproduce the file-length failure on main (#1605).

@vlad-perevezentsev
vlad-perevezentsev merged commit 85a4fb8 into intel:main Dec 4, 2026
22 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli-interface-change Changes dokimi's user-facing CLI surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants