Repository navigation
feat(tools): tools preference --out-dir writes a run directory - #1543
vlad-perevezentsev merged 13 commits into
Conversation
`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>
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 1 selected item(s). CI at `97bbc8c`: 3 failing, 18 passing, 4 skippedNot 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
Review details
|
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>
|
Codecov Report❌ Patch coverage is
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
🚀 New features to boost your workflow:
|
CLI interface change detectedThis 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' -> NoneUpdated on every push; the |
napetrov
left a comment
There was a problem hiding this comment.
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
Mutation of changed linesAt 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
Not checked:
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>
@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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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-runcase below, with an existing non-empty--out-dir.
Checked, no issues
- Docs:
run-directories.md,tool-preference.md,runs.md,cli-interface.jsonand the schema description match the flags and statuses intools.pyandtool_preference.py. - Commits: all 10 non-merge commits carry
Signed-off-by. - Growth baseline: the
cmd_tools_preferenceentry is removed andci-localpasses.
Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
antonwolfy
left a comment
There was a problem hiding this comment.
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--outand--items-outchecks still run.
make ci-local at 97bbc8c: 38 passed, 0 failed, 16 skipped.
napetrov
left a comment
There was a problem hiding this comment.
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).
Summary
Step R-7 of #94 R2, the first catalog diagnostic:
tools preference --out-dir DIRruns in a run directory written throughruns/rundir.py, in the shapesubjects runtook in #1494.--out-dirnothing changes: the artifact goes totool_preference.json, or--out FILE, and no directory is made.--dry-runmakes none either.run.json,plan.v1.json,result.v1.jsonand the artifact astool_preference.v1.json, all listed inrun.json. An--out-dirthat exists and is not empty is refused (exit 2) before anything is written.<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 anotherplan_digest.inconclusive, with the outcome in its detail (first turn: A); a failed call isinfra_errorwith its error. Each call is recorded as it ends.--max-usdstop. The command still exits 3 and keeps the partial artifact.run.jsonis nowincompletewithstop.reasonspend_cap, orno_pricefor a call that came back without a price, as the table indocs/run-directories.mdsays. The calls left arenot_run.run.jsonendsincomplete(interrupted/terminated).result.v1.jsonandtool_preference.v1.jsonkeep the calls that ended before the stop, with their usage and cost; the others areskippedthere.run_probeno 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 ofon_resultand the progress line.failed(exit 1, as before), notcompletewithout its file.--outwith--out-dir. It is a copy, written after the run has ended, and only when given. A--outor--items-outfile in this run's directory or in another's (one holding arun.json) is refused (exit 2) before any call. The check is the newruns.rundir.in_a_run;subjects runuses it too, in place of its own copy of the same lines.runs.rundir.refuse_takengivesopen_run's refusal before anything is written.Changed modules:
dokimi/tool_preference.py(plan,record_result,run_probe'son_result/on_stop) anddokimi/commands/tools.py.cmd_tools_preferenceis split into helpers: complexity 11 -> 7, and its baseline entry is removed. Layout and rules:docs/run-directories.md, new sectiontools preference.Refs #94 R2
Changed output
On a Ctrl-C (stderr, new):
--out's default in--helpandcli-interface.jsonis nowNone. The command still writestool_preference.jsonwhen neither--outnor--out-diris given.skippeddescription intool_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_compatpasses).Evidence
tests/test_tools_preference_run_directory.pyfails 11 of its first 12 tests:--out-diris an unknown argument. The one that passes pins today's behaviour without--out-dir.run.json's artifacts;--outcopy, no directory without--out-dir, none for--dry-run;spend_capandno_pricestops (exit 3,incomplete, the calls leftnot_run, the partial artifact);infra_error), a rejected artifact (failed);--out/--items-outin this run's or another run's directory, and a taken--out-dir, refused before anything is written;infra_error->inconclusive;cost_usdin the budget;SpendCapReachedraise;spend_cap<->no_price;--items-outdropped from the refusal; the default--outkept with--out-dir;in_a_runwithout the run's own directory;stoppedflag, or no check of it; noon_stopcall; the stop's unrun calls notskipped; no partial save in the run;refuse_taken;skip = capped()without the stop.--out-dirthat 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 failedtests/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 fullmake ci-local --offlineruns on the last commit before publishing.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
<runs root>/<run_id>without--out-dir, assubjects runhas), and no--name: the card asks for--out-dir, and--out FILEkeeps its default.concurrent.futuresjoins its workers at exit). They may be billed, but they are not in the artifact.--items-outis not part of the run directory (it is no registered artifact kind).skill novelty analyzeandrepo scan, wait for the open PRs on their files.Open questions
tools preferencerun in<runs root>/<run_id>without--out-dirtoo, assubjects rundoes? That changes where the default output goes.Checklist
pytestpasses:tests/test_tools_preference_run_directory.py(new, 17 tests);slot ci --quick0 failedruff,mypy, and schema checks pass:ci-local --jobs static,typecheck0 failed,schema_compatpassesdocs/run-directories.md(sectiontools preference),docs/tool-preference.md,docs/runs.md,docs/reference/cli-interface.jsonAGENTS.md: the mutations and bad inputs above,list_new_error_paths.py,check_growth.py(cmd_tools_preferencebaseline removed)raise/exit and test names the doc, contract or issue it traces to: the refusals citedocs/run-directories.md; each test cites a line of it or ofrun_probe's docstring