Skip to content

feat(subjects): subjects run writes a run directory with its plan and result - #1494

Merged
xaleryb merged 32 commits into
intel:mainfrom
vlad-perevezentsev:feat/subjects-run-directories
Dec 2, 2026
Merged

xaleryb merged 32 commits into
intel:mainfrom
vlad-perevezentsev:feat/subjects-run-directories

Conversation

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor

Summary

Step R-4 of #94 R2: subjects run is the first command that writes a run directory through runs/rundir.py (#1150), as R-0 (#94 comment) lays out.

  • One directory per run. --out-dir DIR, else <runs root>/<run_id> (results/, or DOKIMI_RUNS_DIR), in place of results/subjects/<subject id>/, which every run of a subject overwrote. A directory that holds anything is refused (exit 2) before any cell runs.
  • A plan and a result. The run writes plan.v1.json before the first call: one cell per product x matrix cell x awareness arm (arm <matrix cell>/<arm>, task the product), and one per work harness x task x rep (arm work/<harness>). Each matrix cell is recorded in result.v1.json as soon as its arms.v1 file is saved, so a stop in a later cell keeps it.
  • A stop (Ctrl-C, SIGTERM) leaves run.json incomplete with its reason and result.v1.json with the cells left not_run.
  • run.json lists the plan, the result, subject_scorecard.v2.json, each product's rollup, the cells' arms.v1 files (a stopped cell's partial file too), the plugin deltas and the work's task_runs (when it is inside the directory). RunDir.add_artifact is new for that: artifact_path gives one top-level file per kind, and the cells' files sit in subdirectories.
  • --out FILE / --out-md FILE still get the scorecard and its report, written after the run has ended, so a refused copy exits 2 without changing how the run is recorded.
  • Statuses. An awareness arm has no verdict of its own (the scorecard compares the arms): a cell whose arm answered a question is inconclusive, one that answered none, or whose matrix cell stopped on a run-wide failure, infra_error. A work cell is pass/fail by its verifier, infra_error without a verdict, not_run under --work-dry-run.
  • Plan ids stay unique: a harness named twice in --work-harnesses runs once; two suite.tasks with one name are refused (exit 2).
  • The subject id no longer names a directory, so its ./.. refusal is gone.

The plan module is dokimi/subjects/run_plan.py; in commands/subjects.py only the run function and its helpers change, not the parser (#1420, #1197). Layout and rules: docs/run-directories.md, new section subjects run.

Refs #94 R2

Changed output

-OK Saved subject scorecard: results/subjects/s/subject-scorecard.json
-OK Saved subject report:    results/subjects/s/subject-scorecard.md
+OK Saved subject scorecard: results/20261201T135059Z-cfcf9614/subject_scorecard.v2.json
+OK Saved subject report:    results/20261201T135059Z-cfcf9614/subject_scorecard.v2.md
+OK Run directory:           results/20261201T135059Z-cfcf9614
results/20261201T135059Z-cfcf9614/
  run.json  plan.v1.json  result.v1.json  matrix.cells.json
  subject_scorecard.v2.json  subject_scorecard.v2.md
  a/matrix-rollup.json  a/matrix-rollup.md  a/cells/c.json  a/cells/c.md
  • The default directory moves from results/subjects/<subject id>/ to results/<run_id>/, and the scorecard in it from subject-scorecard.json to subject_scorecard.v2.json.
  • An --out-dir that exists and is not empty, or a file, is refused (exit 2: run directory ... already exists); before, the run wrote into it. An --out-dir under a file says cannot make run directory ... in place of cannot write ....
  • An input refusal that comes after the run directory is made (an unknown --work-harnesses, which is checked only after the awareness matrix, as before) leaves that directory failed: the same --out-dir is refused next time.

Evidence

  • Main: two subjects run s.toml in a row (fake model) both write results/subjects/s/subject-scorecard.json; there is no run.json, plan or result.
  • Branch: the same two runs (each with its own DOKIMI_RUN_ID) give results/run-a/ and results/run-b/, each run.json complete; a third with run-a exits 2 and leaves run-a unchanged.
  • tests/test_subjects_run_directory.py, 18 tests: one directory per run; every planned cell measured (complete); Ctrl-C at a product boundary and between two matrix cells of one product (incomplete, interrupted, the saved cells kept, the rest not_run); runs list shows one run, runs show RUN_ID its artifacts, runs rm RUN_ID removes them; --out copy equal to the run's scorecard; an unwritable --out exits 2 with the run complete; a non-empty --out-dir refused before any model call; suite.tasks end to end with a passing harness (default, out/../out/w and an outside --work-output-dir); a plugin cell's delta listed; a repeated harness, two tasks with one name; the suite.tasks hash following the tasks' content; the statuses from arms.v1 and task_runs.v1 rows; add_artifact refusing a path outside the directory.
  • Mutations, each failing a test, then reverted: flipped awareness status; no dry-run branch; no recording of a product's cells; recording only after the matrix returns; no .. check in add_artifact; textual in place of resolved task_runs path; no record_work call; no --out copy; no artifact listing; no plugin-delta listing; no harness de-duplication; no repeated-task check; the copies back inside the run's block; and not a.error dropped.
  • Changed tests: test_subjects.py and test_subjects_run_input.py follow the new path, file name and messages; test_cli_refusal_parity.py removes out between its two calls, since a run directory is not reused.
  • slot ci --quick (lint, mypy, the whole suite): 0 failed, 32003 passed, 131 skipped. The full make ci-local --offline runs on the last commit before publishing.
  • Not run: a real model or Docker (the tests are offline), SIGTERM by hand (rundir.py's own tests cover it), Windows.

Not in this PR

  • A run-wide failure in an arms cell (a usage limit, no login) still exits 1 from commands/arms.py: the run ends incomplete by its cells, with stop null rather than run_stopped. That is arms' path (R-3).
  • An unknown --work-harnesses is refused only after the awareness matrix has run and been paid for (as on main); now its results stay in a failed run directory.
  • runs rm RUN_ID removes the run's artifacts, not its .md reports or matrix.cells.json, so the directory is not empty afterwards and cannot be reused (R3 core).
  • subjects run has no --max-usd, so the spend-cap stop does not apply to it yet.
  • --name for subjects run (the parser is under docs(cli): help text for every option; test the deferred list #1420/Part of #94 (F1b, model + judge) #1197).

Open questions

  • An awareness cell that answered is inconclusive (measured, no verdict). Should subjects run give it pass, or should a verdict come only from a later gate (L4)?
  • With DOKIMI_RUN_ID set for several steps of a CI job, a second subjects run without --out-dir is refused, as the R-0 open question says; should it get <root>/<run_id>/<leaf>/ instead?

Checklist

  • Tests added/updated and pytest passes: tests/test_subjects_run_directory.py (new, 18 tests); slot ci --quick 0 failed
  • ruff, mypy, and schema checks pass: ci-local --jobs static,typecheck 0 failed
  • Docs updated: docs/run-directories.md (section subjects run, RunDir.add_artifact)
  • Self-reviewed per "Before opening a PR" in AGENTS.md: mutations above, bad inputs (non-empty --out-dir, a file as DOKIMI_RUNS_DIR, a missing descriptor), list_new_error_paths.py, check_growth.py (test_subjects.py baseline lowered 1046 -> 1002)
  • Each new raise/exit and test names the doc, contract or issue it traces to: the repeated-task refusal and add_artifact's ValueError cite plan.v1 / run.v1; each test cites docs/run-directories.md
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header: run_plan.py, the test file, the fragment

`subjects run` now runs in a run directory of its own (intel#94 R2, R-4):
`--out-dir DIR`, else `<runs root>/<run_id>`, opened with
runs/rundir.py. The run writes its plan.v1 (one cell per product x
matrix cell x awareness arm, and per work harness x task x rep), gives
each cell a result.v1 status as it finishes, and saves the scorecard as
subject_scorecard.v2.json; run.json lists the plan, the result, the
scorecard, each product's rollup, the cells' arms.v1 files, the plugin
deltas and the work's task_runs. A stop (Ctrl-C, SIGTERM) leaves
run.json incomplete and a result.v1 with the cells left not_run.
`--out FILE` and `--out-md FILE` still get the scorecard and report.

RunDir.add_artifact lists an artifact a cell saved in a subdirectory.

The subject id no longer names the output directory, so its '.'/'..'
refusal goes.

Test-narrowed: the default results/subjects/<subject id> directory and the subject id '..' refusal are gone; test_subjects_run_directory.py tests the run directory that replaces them.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A stop inside a product's matrix (Ctrl-C, a run-wide failure in a later
matrix cell) left the cells saved before it not_run in result.v1 and
unlisted in run.json, though they were answered and paid for. The cells
are now recorded and listed from the files the matrix saved, in a
finally around it; a cell stopped on a run-wide failure is infra_error.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
`--work-output-dir out/../w` under `--out-dir out` passed the textual
is_relative_to check, and add_artifact refused the '..' with a
ValueError after every cell had run: the run ended failed with no
scorecard. The paths are now compared resolved, and the artifact is
listed by its path below the run directory. A test runs suite.tasks end
to end and checks the work cells' verdict and the listing.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The plugin_delta listing of a subjects run had no test: dropping it
passed the suite. An end-to-end run with a no-plugin and a plugin matrix
cell now checks that run.json lists each product's plugin delta.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…the plan

`--work-harnesses codex,codex` planned the same cell twice, so the
plan.v1 was invalid and the run ended incomplete with exit 0; two
suite.tasks with one name did the same. A harness named twice now runs
once, and two tasks with one name are refused before the run (exit 2).
The check of --work-harnesses reads the flag through the same helper as
the plan and the runner.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
An unwritable --out ended a run whose every cell was measured as
failed (stop: SystemExit 2), since the copy was saved inside the run's
block. The scorecard in the run directory is still saved there; the
--out / --out-md copies are written once the run is recorded by its
cells, and a refused one still exits 2.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The hash of the suite.tasks suite in plan.v1 hashed only the refs: a
task is a directory, so _digest_values took its text. Editing a task's
instruction or verifier left the hash unchanged, while plan.v1 says it
is the digest of the suite's content. It now hashes each task's name
and its directory's tree.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The errored answer in the infra_error test had no text, so it failed
the text check anyway and the error check went untested. It now has
partial text with its error.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…n fragment

adeb812 refuses two suite.tasks with one name (exit 2) and runs a
harness named twice in --work-harnesses once; the fragment now says so.

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 1, 2026 14:47
@vlad-perevezentsev vlad-perevezentsev self-assigned this Dec 1, 2026
@exai-bot

exai-bot commented Dec 1, 2026 •

Copy link
Copy Markdown

OpenCodeReview: Commit f40cfb3 was not reviewed. This PR has reached its review limit (6 reviews).

CI at `f40cfb3`: 9 still running, 11 passing, 3 skipped
Check Status
CodeQL (python) still running
External catalog smoke test (uxlfoundation/skills) still running
Fidelity golden (claude-code 2.1.318) still running
Linux Python 3.14 still running
Mutation of changed lines still running
Package install smoke test (py3.11) still running
Test Linux Wheels Python 3.14 still running
Tests (py3.14) still running
Windows smoke test (py3.13) still running

To review this commit: re-request review from exai-bot in the Reviewers list.

Last review (0a492bb): no findings

Open threads from the bot: 0

Comment thread dokimi/dokimi/commands/subjects.py Resolved
Comment thread dokimi/dokimi/commands/subjects.py Resolved
Comment thread dokimi/dokimi/subjects/run_plan.py Resolved
@codecov-commenter

codecov-commenter commented Dec 1, 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 97.08333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.36%. Comparing base (c597934) to head (f40cfb3).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
dokimi/dokimi/commands/subjects.py 95.30% 6 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    #1494      +/-   ##
==========================================
+ Coverage   96.32%   96.36%   +0.04%     
==========================================
  Files         521      523       +2     
  Lines       69806    70226     +420     
  Branches    12076    12137      +61     
==========================================
+ Hits        67239    67674     +435     
+ Misses       1588     1579       -9     
+ Partials      979      973       -6     
Files with missing lines Coverage Δ
dokimi/dokimi/harnesses/runner.py 99.24% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/runs/rundir.py 100.00% <100.00%> (ø)
dokimi/dokimi/subjects/run_plan.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/subjects.py 96.44% <95.30%> (+0.97%) ⬆️

... and 26 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 commented Dec 1, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

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

At f40cfb3: 76 caught · 4 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/commands/subjects.py:231 bump-int 0 → 1 39
dokimi/dokimi/commands/subjects.py:358 delete-statement out_md.parent.mkdir(parents=True, exist_ok=True) → pass 39
dokimi/dokimi/commands/subjects.py:557 flip-bool True → False 60
dokimi/dokimi/harnesses/runner.py:51 flip-bool False → True 49

Not checked:

  • 151 more breaks of covered changed lines were over the limit and not tried
  • 36 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>
A --out or --out-md file in this run's directory or in one holding a
run.json was written after the run ended and replaced its run.json,
plan.v1.json or result.v1.json. Such a file is now refused (exit 2)
before any cell runs; the path is resolved, so a '..' or a symlink
into a run directory is caught too.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The plan's subjects[].fingerprint was the digest of subject.ref only, so
a bundle with members and no ref had none, and editing a member left
plan_digest unchanged. A bundle's fingerprint now also hashes each
member's kind, ref and content digest, as the scorecard records them.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The work cells got their verdicts only after TaskSuiteRunner.run()
returned, so a Ctrl-C or SIGTERM during the work left the cells that
had finished, and been paid for, not_run in result.v1.json.
TaskSuiteRunner now hands each results[] row to an on_row callback once
its cell ends, and subjects run records the cell from it; record_work
takes one row.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A --work-output-dir in (or under) a directory holding a run.json wrote
the work's task-runs.json over the one that run lists. It is now
refused (exit 2) before any cell runs, after resolving '..' and
symlinks, as --out is.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/commands/subjects.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A --work-output-dir outside every run directory still let its
task-runs.json or task-runs.md be a symlink into an earlier run;
save_artifact follows the final symlink and would replace that run's
run.json or result. The check now resolves both files as well as the
directory, before any cell runs.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Resolving the work directory and its task-runs files left the cell
directories: <work-output-dir>/<task>/<harness>/run<N> symlinked into
an earlier run still wrote (and the docker harness rmtree'd) there.
The check now resolves every path reachable under --work-output-dir,
each directory once so a symlink loop ends, before any cell runs.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
30798fb walked everything under --work-output-dir and followed its
directory symlinks, so a reused work dir whose old cell workspace links
out (copytree keeps symlinks) to a tree holding a run, or holds an
unreadable directory, was refused, and a link to /usr walked /usr.
The check now resolves only the task-runs files and each planned
cell's <task>/<harness>/run<N> directories; runner.cell_output_dir
gives the layout both use.

Refs intel#94

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

@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 b091d6f)

  • Contract: changed. errors dokimi/dokimi/commands/subjects.py:180; errors dokimi/dokimi/commands/subjects.py:181
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The previous aggregate-file finding is fixed, and the interrupted-run test retains completed work. All 103 tests in the changed test files passed locally. One data-integrity issue remains in the new destination check.

Comment thread dokimi/dokimi/commands/subjects.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A reused --work-output-dir keeps an earlier cell's directory, and a
harness opens its files there (run.log, prompt.txt, ...) without
checking for links, so one linked into another run's directory was
overwritten. The preflight now also resolves every symlink in an
existing cell directory, outside the agent's work/ workspace, and
refuses one that leads into a directory holding a run.json.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/commands/subjects.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A product's directory sits next to run.json, plan.v1.json,
result.v1.json, matrix.cells.json, the scorecard and work/ in the run
directory. A product named result.v1.json made a directory there, so
the run could not write its result and run.json stayed running; the
others failed later or mixed the product's cells with the run's files.
Such a product is now refused with exit 2 before the run starts.

Refs intel#94

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

@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 b321b82)

  • Contract: changed. errors dokimi/dokimi/commands/subjects.py:181; errors dokimi/dokimi/commands/subjects.py:182
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The new preflight covers harness files inside an ordinary existing cell directory. Reading the new early return alongside the Docker harness shows one remaining gap. The reserved-path collision discussions are also still open.

Comment thread dokimi/dokimi/commands/subjects.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A --work-output-dir such as out/result.v1.json passed the preflight,
which runs before open_run and so saw no run.json there; the work then
made a directory where the run saves its result, and the run stayed
running with no result. A work path inside this run's directory whose
first part is one of the run's own names (run.json, plan.v1.json,
result.v1.json, the scorecard, matrix.cells.json) is now refused with
exit 2 before the run directory is opened.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
On a case-insensitive filesystem (Windows, macOS) a product named
RESULT.v1.json made the directory where the run saves result.v1.json,
and the run stayed running with no result. The product and
--work-output-dir checks now compare the run's own names case-folded,
on every platform, so a subject refused on one is refused on all.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The --work-output-dir preflight skipped the inside of a cell directory
that is a symlink, though a harness writes run.log, prompt.txt and the
rest where the symlink leads; a file there linked into an earlier run
was overwritten. The cell is now walked through the symlink, so such a
file is refused with exit 2 before any cell runs.

Refs intel#94

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

@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 0a492bb)

  • Contract: changed. errors dokimi/dokimi/commands/subjects.py:181; errors dokimi/dokimi/commands/subjects.py:182
  • Responsibility: none
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The reserved run names are now compared case-insensitively and an existing symlinked cell is visited. I reviewed the remaining preflight path and the harness writers statically, and 108 subject/CLI tests passed locally. One filesystem error can still leave a destination unchecked.

Comment thread dokimi/dokimi/commands/subjects.py Outdated
if not cell.is_dir():
return []
links = []
for root, dirs, files in os.walk(cell): # does not follow a symlinked directory: lists it in dirs

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.

question: os.walk(cell) ignores listing errors by default. If this cell can be searched and written but cannot be listed, the preflight treats it as having no links, while the harness can still open its known output files there. Can the walk raise its listing error through onerror and have the CLI refuse the unchecked cell before opening the run? This follows from the code paths; the earlier symlinked-cell fix works when the target can be listed.

@vchamarthi vchamarthi 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.

@vlad-perevezentsev, could you fix the problem I found and the small thing I've marked fix before merge (in the line comments) and fix what napetrov's thread on dokimi/dokimi/commands/subjects.py:327 still points out? Then push and I'll take another look.

Optional, non-blocking (1)
  • dokimi/dokimi/commands/subjects.py:552: _safe_name keeps the case, and the collision check compares names exactly, so products Docs and docs pass it (main has it too).

What I checked on 0a492bb:

  • When I changed the code on purpose, the tests still passed for 1 of 12 changes, and no test pins this one down yet (non-blocking): dokimi/dokimi/subjects/run_plan.py:24 (the condition is negated).
  • The 117 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (35,668 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/dokimi/commands/subjects.py Outdated
from dokimi.artifacts import run_id
from dokimi.runs.scan import runs_root

return Path(args.out_dir) if args.out_dir else runs_root().path / run_id()

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.

Must fix (blocking): --out-dir "" opens the run in the current directory, but the copy check looks at the default directory and lets --out run.json through.
Input: subjects run s.toml --out-dir "" --out run.json in an empty directory.
Got: open_run takes "" as the current directory, since it tests out_dir is not None, but _run_home tests truthiness and returns results/<run_id>.

Also at: dokimi/dokimi/commands/subjects.py:153, dokimi/dokimi/commands/subjects.py:256, dokimi/dokimi/commands/subjects.py:290.

I tested this suggestion: it fixes the problem, and the tests still pass.

Suggested change
return Path(args.out_dir) if args.out_dir else runs_root().path / run_id()
return Path(args.out_dir) if args.out_dir is not None else runs_root().path / run_id()
Details

So _refuse_copies_into_a_run checks the wrong place and does not refuse run.json, and after the run _save_scorecard writes the scorecard over the run.json that run made. I tried the calls in that order in an empty directory: the copy check returned without error, and open_run opened the current directory. The work check has the same gap: --work-output-dir result.v1.json passes there, and the work then makes a directory where the run saves its result. I expected the copy to be refused, as --out results/<run_id>/run.json is, or "" to be refused or to mean the default, with both checks agreeing. A non-empty current directory is refused by open_run, so the empty one is the case that gets through.

except (OSError, RuntimeError) as exc:
raise InputError(f"cannot resolve --work-output-dir {work_dir}: {exc}") from exc
own = _run_own_names() - {"work"} # <run directory>/work is the work's default place
taken = sorted({part for real in reals if real != home and real.is_relative_to(home)

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.

Fix before merge (blocking): A --work-output-dir equal to --out-dir passes the check only because of real != home, and no test covers that case.

Suggestion: Add a case to tests/test_subjects_run_directory.py where --work-output-dir and --out-dir are the same directory, and expect no error.

I tested this patch: it fixes the problem, and the tests still pass.

Patch
--- a/dokimi/tests/test_subjects_run_directory.py
+++ b/dokimi/tests/test_subjects_run_directory.py
@@ -602,3 +602,12 @@
             run.add_artifact("arms", run.path / path if not path.startswith("/") else path)
         with pytest.raises(ValueError, match="writes its result itself"):
             run.add_artifact("result", run.path / "x.json")
+
+
+def test_a_work_directory_equal_to_the_out_directory_is_accepted(tmp_path, monkeypatch):
+    import argparse
+
+    from dokimi.commands.subjects import _refuse_work_in_another_run
+
+    monkeypatch.chdir(tmp_path)
+    _refuse_work_in_another_run(argparse.Namespace(out_dir="out", work_output_dir="out"), [])
Details

Input: --out-dir out --work-output-dir out. The work check accepts this on 0a492bb: I called _refuse_work_in_another_run with both set to out, and it returned. If I remove real != home at this line, the same call fails with an IndexError from parts[0], and all 163 tests in the changed test files still pass. I'd add one assert to tests/test_subjects_run_directory.py: that call with both set to one directory returns without error.

… empty

open_run takes --out-dir "" as the current directory, but the copy check
looked at the default run directory, so --out run.json replaced the run's
run.json with the scorecard. The check now uses the same directory.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…ds a hard link

The check for paths into an earlier run dropped os.walk listing errors and
saw only symlinks, so an unlistable cell or a hard link to an earlier run's
run.json let a harness write over it. Both now exit 2 before any cell runs.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
…used

Only a cell's top-level work/ is the agent's workspace; a nested work/
holds harness files and must stay in the check.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
The skipped work result has no task_runs; reading it as a run crashed the
run with KeyError and left run.json failed, with no test noticing.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
The grader is part of plan_digest, so a judged run recorded as unjudged
would share the digest of an unjudged run.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
… runs

The work directory may be the run directory itself; the own-name check
skips it, and the run lists task-runs.json.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
@xaleryb

xaleryb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor
  • Ran: head 0a492bb merged with main 512e517, full suite and gates (ruff, mypy, bandit -ll, check_growth, comment blocks, docs check --strict), plus mutants of each new branch.
  • subjects run S --out-dir "" --out run.json in an empty cwd -> exit 0, run.json replaced by the scorecard -> expected exit 2 before any cell (subjects.py:274 thread).
  • Reused --work-output-dir whose cell is mode 0300 with run.log linked to an earlier run's run.json, or holds a hard link to it as prompt.txt -> exit 0, earlier run.json overwritten -> expected exit 2 (subjects.py:327 thread; the hard link is new).
  • Pushed:
    • 2b3f0d2: _run_home tests out_dir is not None, as open_run does.
    • 2ead67b: os.walk re-raises listing errors and the walk refuses hard-linked files.
    • 39fda6a, 2075970, 2b6b906, f40cfb3: tests for a nested work/ dir, --skip-work with tasks, the judge in the plan digest, and --work-output-dir equal to --out-dir.
  • Left to the author: with feat(runs): runs export | import, a verified bundle that moves a run #1521, keep one intro sentence in docs/run-directories.md that says subjects run writes a run directory.

@xaleryb xaleryb 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.

Approved on f40cfb3. subjects run writes a run directory with its plan and result under the run-directory contract of #1150; our commits refuse --out over the run's own file and a reused work cell that cannot be listed or holds a hard link (both open threads), and add four tests. Full suite and gates are green on the head merged with main. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

@xaleryb
xaleryb merged commit 8464f57 into intel:main Dec 2, 2026
38 of 40 checks passed
vlad-perevezentsev added a commit to vlad-perevezentsev/dokimi that referenced this pull request Dec 2, 2026
Main now has subjects run writing a run directory (intel#1494): the line
that no command writes one was no longer true. The fragment also says
that a run's report takes the run's answers.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
vlad-perevezentsev added a commit that referenced this pull request Dec 4, 2026
…e a run (#1523)

* feat(runs): --eval and --answers take a run as well as a file

report eval --eval and eval score pointwise --answers now also take a
run: its directory (one with a run.json), or the run_id or name of a
run directory under the runs root. dokimi/runs/resolve.py reads the
run's run.json through runs/scan and returns the one artifact of the
kind the command reads. A file at the given path still wins, so every
path reads as before.

A run that has not ended complete, lists no artifact of the kind or
more than one, a run.json that does not meet run.v1, or a run_id or
name no run (or two runs) has exits 2 and says so; the error names the
file, whose path still reads a stopped run's artifact.

baseline:NAME is not handled here: it comes once runs.baseline gets
its resolver.

Refs #94

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

* docs(runs): say that no command writes a run directory a RUN can name yet

The fragment and docs/runs.md showed --eval RUN as if a run's
run_id from runs list worked: no command writes a run directory yet,
so a RUN finds only directories the run-directory module made, and
an envelope run_id is not a RUN.

Refs #94

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

* fix(runs): refuse a run.json that is not a regular file instead of blocking on it

resolve() opened ref/run.json once it existed, so a FIFO there hung
the command. It now checks the stat as runs.scan does and exits 2.

Refs #94

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

* fix(runs): say a runs root that cannot be listed cannot be searched for a run

With results/ unlistable, resolve() said no run had the name, though
nothing was looked up. It now says the root cannot be listed, as runs
show RUN_ID does.

Refs #94

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

* test(runs): pin a run that a plain directory of its name does not hide

--eval eval reads the run named eval under the root rather than the
eval/ directory eval score writes to; say so in docs/runs.md and the
docstring, and test it. Test run.v1 on a run found by its run_id too.

Refs #94

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

* refactor(runs): move the no-run error out of _find_run

The unlistable-root case took _find_run to complexity 11, over the
growth cap; the error it raises is now built by _no_run.

Refs #94

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

* test(runs): build the run.v1 refusal's expected path from the path

The pattern held results/r-1/run.json, which the message spells with
backslashes on Windows.

Refs #94

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

* fix(runs): look a run up by its run.json only, not by a copy of it

A run directory holding a backup of its record (previous-run.json)
made a lookup by name report two runs, the same directory twice:
the scan selects every run.v1 document. Only a file named run.json
is a run's record now.

Refs #94

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

* fix(report): a run's report takes the run's answers for its Q&A sidecar

report eval --eval RUN read the run's eval, but the sidecar looked
for answers in answers/ next to eval/, which a run directory does not
have: every answer in r.qa.json was null although the run lists its
answers. resolve_with gives the run's answers with its eval, and
report eval passes them to both report pages.

Refs #94

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

* test(runs): pin the end of a running run's refusal when it lists no file

Refs #94

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

* test(runs): pin that an empty value in a run directory is not that run

Refs #94

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

* test(runs): pin that a value that cannot be looked at goes to the reader

Refs #94

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

* docs(runs): say that subjects run writes a run directory, with no eval

Main now has subjects run writing a run directory (#1494): the line
that no command writes one was no longer true. The fragment also says
that a run's report takes the run's answers.

Refs #94

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

* fix(report): a run's answers that cannot be picked do not refuse its report

3aff61a looked the run's answers up with the same checks as its eval,
so a run listing two answers (one per cell) or answers whose file is
gone made report eval --eval RUN exit 2 with advice --eval cannot
follow. The answers are taken only when the run lists exactly one
file; otherwise the sidecar goes without them, as for a run that
lists none.

Refs #94

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

* fix(report): a run without answers to take does not read answers/ beside its eval

f1538d1 gave the report of a run that lists no answers, two or gone
ones a sidecar without answers, but resolve_with returned None for
them, as for a file, so both report pages still read the answers/
next to the run's eval/: answers the run did not list went into
.qa.json. resolve_with now returns "" for such a run, and the
sidecar takes no answers for it.

Refs #94

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

* test(runs): name the beside tests after the "" they assert

6dd595c made resolve_with give "" for a run whose beside artifact
cannot be taken, and None only for a file, but two tests kept "none"
in their names. They say "empty" now.

Refs #94

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

* test(runs): judge a run's answers with the current --judge flag

Main moved eval score pointwise to --judge PROVIDER/MODEL; the old
--judge-provider/--judge-model pair now exits 2 with 'moved:', so the
test stopped before the judge after the merge of main.

Refs #94

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

* test(report): patch answers_by_id in eval_io, where the sidecar reads it

The merge of main moved the sidecar's answer lookup into
report/eval_io.py (answers_for_sidecar), so eval_report no longer
imports answers_by_id and the test's monkeypatch found no attribute.

Refs #94

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

---------

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Co-authored-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants