Skip to content

feat(runs): run directories: run.json, and a result.v1 when a run is stopped - #1150

Merged
xaleryb merged 42 commits into
intel:mainfrom
vlad-perevezentsev:feat/run-directory-core
Nov 28, 2026
Merged

xaleryb merged 42 commits into
intel:mainfrom
vlad-perevezentsev:feat/run-directory-core

Conversation

@vlad-perevezentsev

@vlad-perevezentsev vlad-perevezentsev commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #94 R2 (stage R, run directories; design comment R-0 on #94).

Until now a run had no directory of its own. Its plan, result and artifacts went wherever each command's output flags pointed. A run stopped by SIGTERM, Ctrl-C or the spend cap left no result.v1 at all. This PR adds the module that gives a run its own directory, plus its record kind run.v1. No command writes a run directory yet: the command families move to it one per PR (R-3 arms, R-4 subjects, R-5 evaluate/benchmark, R-6 answers/score, R-7 diagnostics).

results/<run_id or name>/      or the run's --out-dir (#591: --out-dir is the run directory)
  run.json         run.v1: envelope, argv, started_at/finished_at, name,
                   status running|complete|incomplete|failed, stop {reason, detail},
                   artifacts [{kind, path}] with paths relative to the directory
  plan.v1.json     when the run has a plan
  result.v1.json   one status per planned cell, written on a stop too
  arms.v1.json …   the run's own artifacts, <schema_version>.json
  • dokimi.runs.rundir.open_run(root, name=None, out_dir=None) -> RunDir makes the directory and writes run.json with status: running. A run never writes into another run's directory:

    • an existing directory is refused; an out_dir may be an empty directory;
    • run.json is created exclusively, so of two runs racing for one directory only one gets it;
    • a name is one path segment of run id characters, and a name together with out_dir is refused;
    • a directory that cannot be made, listed or written (a parent is a file, no permission) is an InputError.
  • RunDir.artifact_path(kind), write_plan(plan), record_cell(cell_id, status), finish(status). finish("complete") is refused while a planned cell has no measured status, as result.v1 defines completeness. write_plan saves under the run's lock and keeps its own copy of the plan; write_plan and record_cell are refused once the run has ended. A stop that lands once plan.v1.json is published still leaves the result.

  • As a context manager, the block's end is recorded:

    The block status stop.reason
    ends with every planned cell measured complete -
    ends with cells left incomplete -
    SIGTERM or SIGHUP incomplete terminated
    KeyboardInterrupt incomplete interrupted
    SpendCapReached incomplete spend_cap / no_price
    RunStopped (a usage limit, no login) incomplete run_stopped
    any other exception failed error

    With a plan, result.v1.json is written in every case. Cells without a status are not_run, with the stop in detail, and runner.plan.completeness reads such a result as incomplete.

  • Signals use the CLI's own handler; this PR adds no second one. The handler of process.install_signal_handlers kills the child process groups as before, keeping its deferral while a child is being registered. Before the kills it tells the run that the signal came (a notice: an end that reads it afterwards is terminated, an end already being written is kept), and after them it runs the hooks in the new dokimi/process_hooks.py; process.py gains two calls. An open run directory's hook raises ShuttingDown in the block. The record is written, then the signal is delivered again through the same handler, so the process exits as it did before (died of SIGTERM, 143). Only a run opened on the main thread is stopped this way.

  • New kind run in SCHEMA_VERSIONS and runs/kinds.py (time started_at, counts artifacts), and runs list --kind run in the CLI snapshot. runs list shows a run directory as one run, because every file in it carries the run's run_id.

  • docs/run-directories.md (in the index and the site nav) describes the layout, the rules and the stops.

Evidence

  • tests/test_runs_rundir.py, new (60 tests with the parametrized cases). The module is new, so on main they cannot import it. Each cites the line of docs/run-directories.md it checks. They cover:
    • creating the directory, a taken name refused, a shared run_id refused, bad names, --out-dir empty or holding files, the exclusive-claim race, a parent that is a file, no permission;
    • artifacts listed in run.json by relative path;
    • each stop reason, with result.v1.json loaded through load_artifact (so validated against result.v1) and checked with completeness();
    • SIGTERM and SIGHUP through process.install_signal_handlers: the record is written before the earlier handler runs, and process._closing is back to False after;
    • a signal deferred inside _spawn, and a signal whose ShuttingDown the block caught;
    • a real child process under the CLI's handler that still dies of SIGTERM (returncode == -15) after writing the record;
    • runs list --json listing the directory as one run with kinds arms, plan, result, run.
  • Mutations (scripts/mutate_changed.py --base upstream/main) on the first commit: 40 mutants, 35 killed, 2 errors, 3 survived. Two survivors were flag resets in __exit__ that nothing could observe; I removed those lines. The third was the parents=True of the parent mkdir, now killed by an out-dir two levels deep.
  • make ci-local --offline on cff0589d1f1, before the rebase: 0 failed. After review round 5, slot ci --quick (lint, mypy, the whole suite) on ab5b048: 0 failed, 27590 passed, 81 skipped.
  • Not run: Windows. The child-process SIGTERM test is skipped there, since a process dies of a signal only on POSIX, and so is the permission test.

Open questions

Not in this PR

  • Wiring any command, and the --name flag in cli_flags.py: R-3 onwards.
  • runs baseline save --expect-previous: R-9. --from RUN: R-8. (runs rm and runs gc --older-than came to main in feat(runs): runs rm and runs gc --older-than --keep-baselines #1147.)
  • run.json lists artifacts when the run ends, not while it runs. A SIGKILLed run keeps status: running with an empty list; its files still group by run_id.
  • A library caller that installs no process.install_signal_handlers() gets no record on a signal (documented).

Revert

A plain revert. No command writes run.v1 yet, so no stored file depends on it. The one shared change is the hook call in process._on_signal, which does nothing while no hook is added.

Checklist

  • Tests added/updated and pytest passes: test_runs_rundir.py, plus the run.v1 rows in test_runs_scan.py and test_runs_show.py; the whole suite passes (above)
  • ruff, mypy, and schema checks pass: ci-local static and typecheck, schema_compat against the base
  • Docs updated: docs/run-directories.md, docs/architecture.md (process_hooks.py), index, nav, CLI snapshot
  • Self-reviewed per "Before opening a PR" in AGENTS.md: mutations above, list_new_error_paths.py, check_growth.py (process.py 790 of 800 lines)
  • Each new raise/exit and test names the doc, contract or issue it traces to: docs/run-directories.md, result.v1, CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94 R2
  • No ad-hoc run artifacts committed: only tests/fixtures/artifacts/run.v1.json
  • New files carry the SPDX license header

…stop

A run had no directory of its own: its plan, result and artifacts
went wherever each command's output flags pointed, and a run stopped
by SIGTERM, Ctrl-C or the spend cap left no result at all.

dokimi.runs.rundir.open_run(root, name=None, out_dir=None) makes the
run's directory, <root>/<name or run_id>/ or the given --out-dir
(intel#591), and writes run.json, a new run.v1 artifact: the envelope, argv,
started_at/finished_at, name, status, stop and the artifacts by path
relative to the directory. A run never writes into another run's
directory: an existing one is refused (an output directory may be
empty), run.json is created exclusively, a name is one path segment
of run id characters, and a name with an output directory is refused.

RunDir.artifact_path(kind) gives <schema_version>.json in the
directory, write_plan() saves plan.v1.json and record_cell() a cell's
status. In a with block, a stop (KeyboardInterrupt, SpendCapReached,
RunStopped, SIGTERM) writes result.v1.json with not_run on the cells
left and run.json status incomplete with the reason; any other error
makes it failed. SIGTERM kills the child process groups as the CLI's
handler does, then the record is written and the signal goes back to
the handler that was there, so the process exits as before.

runs list groups a run directory as one run (scan groups by run_id).
No command writes a run directory yet: the families follow (R-3...).

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A1: RunDir installed its own SIGTERM handler that
copied part of process._on_signal. It raised inside process._spawn,
where the CLI's handler defers the signal until the new child is in
_live, so that child was never killed; with an earlier handler that
returns, process._closing stayed True after the block and every later
process.run raised ShuttingDown; and SIGHUP left run.json "running".

dokimi.process_hooks holds callbacks the handler of
install_signal_handlers runs after kill_children (and so after the
spawn deferral). RunDir adds one on the main thread for the block: it
raises ShuttingDown, the record is written, and the signal is
delivered again through the same handler, which then resets _closing
or ends the process as before. SIGHUP is recorded the same way.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A4: when code in the block caught the ShuttingDown a
signal raised, __exit__ saw no exception and finished the run as
complete or incomplete with no stop, though the process then died of
the signal. A run a signal stopped now ends incomplete, terminated,
whatever left the block.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A3: _end set the status in memory before it wrote
run.json, so a stop or an error inside that write left run.json
"running" for good while __exit__ took the run as ended and recorded
nothing. The ended record is now written first and kept after; a
failed write leaves the run running, and the stop is recorded.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A2: the parent mkdir ran outside the try, so a runs
root or an output directory's parent that is a file raised a raw
FileExistsError (NotADirectoryError deeper down), and a root with no
write permission a PermissionError: a traceback once a leaf is wired,
not exit 2. Both mkdirs now raise InputError naming the directory.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A5: record_cell checked a cell id against a list under
the lock every worker shares, so recording a whole plan was O(n^2).
The ids are a dict in plan order, which also drops the dedupe the
result used to do.

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 November 23, 2026 15:57
@vlad-perevezentsev vlad-perevezentsev self-assigned this Nov 23, 2026
@codecov-commenter

codecov-commenter commented Nov 23, 2026 •

Copy link
Copy Markdown

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

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.20%. Comparing base (f8b5e1d) to head (e31f070).
⚠️ Report is 41 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1150      +/-   ##
==========================================
+ Coverage   96.15%   96.20%   +0.05%     
==========================================
  Files         498      501       +3     
  Lines       65973    66875     +902     
  Branches    11456    11617     +161     
==========================================
+ Hits        63436    64340     +904     
+ Misses       1569     1563       -6     
- Partials      968      972       +4     
Files with missing lines Coverage Δ
dokimi/dokimi/artifacts.py 95.91% <ø> (ø)
dokimi/dokimi/process.py 91.13% <100.00%> (+0.05%) ⬆️
dokimi/dokimi/process_hooks.py 100.00% <100.00%> (ø)
dokimi/dokimi/runs/kinds.py 100.00% <ø> (ø)
dokimi/dokimi/runs/rundir.py 100.00% <100.00%> (ø)

... and 63 files with indirect coverage changes

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

@exai-bot

exai-bot commented Nov 23, 2026 •

Copy link
Copy Markdown

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

CI at `e31f070`: 7 still running, 13 passing, 3 skipped
Check Status
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 (4a88721): 1 medium

Open threads from the bot: 1

Comment thread dokimi/dokimi/runs/rundir.py Resolved
Comment thread dokimi/dokimi/runs/rundir.py Resolved
Comment thread dokimi/dokimi/runs/rundir.py Resolved
Comment thread dokimi/dokimi/runs/rundir.py Resolved
@github-actions github-actions Bot added the cli-interface-change Changes dokimi's user-facing CLI surface label Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

CLI interface change detected

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

~ `dokimi runs list` parameters changed:
    ~ changed option `--kind`: choices: ["'answers'", "'arms'", "'baseline_manifest'", "'catalog_eval'", "'checklist'", "'cli_routes'", "'cross_judge'", "'dashboard'", "'docling_sources'", "'docs_run'", "'dokimi_config'", "'effective_instructions'", "'eval'", "'eval_coverage'", "'explore_runs'", "'grounding'", "'guidance_reach'", "'headroom'", "'judge_validity'", "'judge_wording'", "'leak'", "'matrix_rollup'", "'need_graph'", "'novelty'", "'novelty_atoms'", "'novelty_retest'", "'opportunities'", "'pairwise'", "'persona_analysis'", "'personas'", "'plan'", "'plugin_delta'", "'question_panel'", "'question_quality'", "'questions'", "'ragas'", "'reach_matrix'", "'redteam'", "'repo_budget'", "'repo_environment'", "'repo_hits_judged'", "'repo_ledger'", "'repo_readiness'", "'report_qa'", "'report_summary'", "'result'", "'run_context'", "'security_report'", "'skill_coverage'", "'skill_discovery'", "'skill_evidence'", "'subject_scorecard'", "'task_inspect'", "'task_runs'", "'tool_preference'"] -> ["'answers'", "'arms'", "'baseline_manifest'", "'catalog_eval'", "'checklist'", "'cli_routes'", "'cross_judge'", "'dashboard'", "'docling_sources'", "'docs_run'", "'dokimi_config'", "'effective_instructions'", "'eval'", "'eval_coverage'", "'explore_runs'", "'grounding'", "'guidance_reach'", "'headroom'", "'judge_validity'", "'judge_wording'", "'leak'", "'matrix_rollup'", "'need_graph'", "'novelty'", "'novelty_atoms'", "'novelty_retest'", "'opportunities'", "'pairwise'", "'persona_analysis'", "'personas'", "'plan'", "'plugin_delta'", "'question_panel'", "'question_quality'", "'questions'", "'ragas'", "'reach_matrix'", "'redteam'", "'repo_budget'", "'repo_environment'", "'repo_hits_judged'", "'repo_ledger'", "'repo_readiness'", "'report_qa'", "'report_summary'", "'result'", "'run'", "'run_context'", "'security_report'", "'skill_coverage'", "'skill_discovery'", "'skill_evidence'", "'subject_scorecard'", "'task_inspect'", "'task_runs'", "'tool_preference'"]

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

Review point on intel#1150: the changelog fragment and the docs index said
a stopped run's directory still gets result.v1.json, but a run with no
plan writes none (a result is a status per planned cell), as
docs/run-directories.md and test_a_stopped_run_without_a_plan_writes_no_result
say. Both now say run.json is incomplete and a run with a plan has its
result.

Refs intel#94

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

Review point on intel#1150: for an existing empty --out-dir, only
FileExistsError was caught around listing it and creating run.json, so
a directory without write permission (or one that cannot be listed)
raised a raw PermissionError, which cli.main does not turn into exit 2.
Every OSError of the claim is now an InputError naming the directory.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review point on intel#1150: write_plan saved plan.v1.json before it took
the run's lock, so a finish in another thread could end the run in
between, with no plan and so no result.v1.json, after which the plan
was installed on the ended run. The save now happens under the lock,
and an ended run refuses a plan with ValueError.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review point on intel#1150: write_plan kept the dict save_artifact returned,
a shallow copy that shares nested objects with the caller's plan. A
caller that changed either one after the save (a budget field) changed
the in-memory plan the result is hashed from, so run.json said complete
while plan.v1.json and result.v1.json did not match. The run now keeps
a deep copy of what was written.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review point on intel#1150: __exit__ removed the signal hook before it wrote
the end of a block that ended normally, so a SIGTERM during that write
went straight to the default handler, and a Ctrl-C there had no
recovery: run.json stayed "running" with no result.v1.json. The hook
now stays on until the end is written, and a stop that lands while it
is written ends the run as that stop (interrupted, terminated, ...)
before it goes on; a signal is then delivered again as before.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A6: dc3ce18 deep-copied the plan after save_artifact
had put plan.v1.json on disk and before the run took it in, so a stop
landing in the copy (Ctrl-C, or ShuttingDown from the signal hook)
ended the run with plan.v1.json listed and no result.v1.json. The plan
is now copied before the save, and only an assignment follows it; the
caller gets its own copy of what was written.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A7: 26a8d6e qualified the fragment and the docs index,
but the module docstring of dokimi.runs.rundir still said every stop
writes result.v1.json. It now says run.json is incomplete and, when the
run has a plan, result.v1.json marks the cells left not_run, as
docs/run-directories.md does.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/runs/rundir.py Resolved
Comment thread dokimi/dokimi/runs/rundir.py Resolved
Comment thread dokimi/dokimi/runs/rundir.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review point on intel#1150: record_cell changed a cell after finish had
written result.v1.json, so the call succeeded and the measurement never
reached the result. It now raises ValueError once the run has ended,
as finish and write_plan do.

Refs intel#94

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

Review point on intel#1150: a block that ended normally chose complete or
incomplete from the cells, released the lock, then wrote the result
from the cells again. A cell recorded in between (a worker replacing a
status) made finish refuse "complete" and the run end failed, or end
incomplete beside a complete result. The status is now chosen in _end,
from the same result it writes, under one lock.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review point on intel#1150: save_artifact publishes plan.v1.json with
os.replace and does more before it returns, and the run took the plan
in only after that. A stop in between (Ctrl-C, or ShuttingDown from
the signal hook) ended the run with the plan on disk and no
result.v1.json. On an exception out of the save, the run now checks
whether plan.v1.json holds this plan (by its digest) and, if so, takes
it before the stop goes on, so the result covers it; a stop before the
publish leaves no plan and no result, and an earlier plan still on
disk stays the run's.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A10: write_plan's handler for an exception out of the
save called stamp(), whose run_id() raises again when DOKIMI_RUN_ID is
malformed, so the caller got a fresh InputError without the note on
where save_artifact kept the payload. The handler now compares the file
with the plan by plan_digest, which leaves the envelope out, and takes
the plan itself; nothing in it can raise a new error.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A9: no test told the digest check in write_plan's stop
handler from "the file exists": a second write_plan stopped before it
published took the new plan while plan.v1.json still held the first,
and the result no longer matched it. The new test stops the second
save before and after publishing, and checks the result matches the
plan on disk (incomplete, not invalid, with that plan's cells).

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A11: docs/run-directories.md said only that a second
finish is refused; since 36f9345 and 8d3dd5c write_plan and
record_cell raise ValueError after the end as well. The page now says
so.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A15: since 81e0fb5 _end replaces the status with
incomplete, terminated whenever a signal came, so _how_ended's own
signal branch was computed and overwritten at once; two places built
the same stop. The rule now lives in _end only.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A13: the signal handler killed the child groups first
and reached the run's hook only after, so a worker whose child the
kill ended could record its cell and finish the run complete (or
incomplete with no stop) in between, before the run knew of the
signal. process_hooks gains notices, which the handler calls before
kill_children; a run directory's notice records the signal, so any end
written from then on is incomplete, terminated. The raising hook still
runs after the kills.

Refs intel#94

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

Copy link
Copy Markdown
Contributor Author

Change class: CONTRACT (head fddd6c2) - Contract: changed. defaults dokimi/dokimi/runs/rundir.py:40; errors dokimi/dokimi/runs/rundir.py:56 - Responsibility: candidate. policy dokimi/docs/archit…

@napetrov Thanks. On the responsibility note: the new dokimi/process_hooks.py is in the foundation layer of tests/test_import_architecture.py next to dokimi.process, and docs/architecture.md says what it holds; dokimi.runs.rundir stays in the tracks layer with dokimi.runs. The changed surface (open_run's defaults and its InputError refusals) is pinned by tests/test_runs_rundir.py, each test citing its line of docs/run-directories.md.

Comment on lines +181 to +183
if self._signal is not None: # read under the lock: a signal before it wins over any status chosen earlier
status, stop = "incomplete", {"reason": "terminated",
"detail": f"{signal.Signals(self._signal).name}: the run stops"}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

bug · medium
Must-fix: the signal check still misses a worker already finalizing.

Impact: run.json can remain complete with stop: null after SIGTERM stopped the run.

Trigger: pause a worker's finish("complete") inside completeness or the result save, after this check; deliver/catch SIGTERM on the main thread; then release and join the worker before context exit.

Evidence: _on_notice writes _signal without taking _lock, so it can run during this locked section. The worker never checks the signal again before publishing ended, and _end_unless_ended subsequently skips the now-ended run. The existing regression covers a worker waiting before lock acquisition, not this remaining interleaving. Coordinate signal notices with terminal publication, or repair a finalization overtaken by a notice, and add an event-gated regression asserting the reloaded record is incomplete/terminated.

Workaround: finalize on the main thread while hooks remain installed.

Severity justification: medium because this is a bounded but material wrong persisted verdict and lost termination reason.

This proof replaces part of the code with stand-ins (monkeypatch): it shows the code path, not the real dependency or platform.

Shown by running: exit 1 (at the head) · exit 2 (at the merge base, which cannot run it) · exit 0 (at the head with the fix)

python -m pytest -q -p no:randomly -p no:cacheprovider tests/test_proof_c1.py

What the proof does: Pauses a worker's finish("complete") inside the run.json save, delivers the SIGTERM notice on the main thread, then checks the reloaded run.json is incomplete/terminated.

The problem shows as the output SIGNAL LOST.

Script: dokimi/tests/test_proof_c1.py (33 lines).

E       assert ('complete' == 'incomplete'
E         
E         - incomplete
E         ? --
E         + complete)

tests/test_proof_c1.py:32: AssertionError
=========================== short test summary info ============================
FAILED tests/test_proof_c1.py::test_signal_during_worker_finish - AssertionEr...
1 failed in 0.57s

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'd keep this end as it is rather than turn it terminated. It was decided under the run's lock from cells all measured before the signal, so the run had finished when it was stopped; any end that reads the signal after the notice (2d31f02, before the kills) is incomplete, terminated. docs/run-directories.md now states it: an end another thread is already writing when the signal comes is kept. Making the handler wait for that end, which I tried, can deadlock the handler and hold back the kills, so the notice stays a plain assignment; a test pins this case (complete, stop null, the signal delivered again).

Review point on intel#1150: the notice recorded the signal without the
run's lock, so it could land while a worker's finish was inside _end,
past its signal check, and the end was written as it had been decided
with no trace of when the signal came. The notice now takes the lock:
an end already being written finishes first (it was decided from cells
measured before the signal, so it stands), and any end after the
notice is incomplete, terminated. docs/run-directories.md says so.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fixes for A17 and A18: 255a912 made the notice take the run's
lock inside the signal handler. That could deadlock (a worker in _end
needs artifacts' _run_id_lock, which the main thread may hold when the
signal lands), it held back kill_children for as long as a save took,
and a SIGINT while waiting raised out of a notice. It also changed no
recorded result: _end reads the signal once under its lock, so an end
already past that read was kept before as well.

The notice is a plain assignment again. The rule stays as
docs/run-directories.md states it: an end another thread is already
writing when the signal comes is kept. The lock-order test is replaced
by one that pins that behaviour: a worker held inside its run.json
save, SIGTERM returns at once, the end stays complete with no stop, the
result matches the plan and the signal is delivered again.

Refs intel#94

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

Copy link
Copy Markdown
Contributor Author

Change class: CONTRACT (head fddd6c2) - Contract: changed. defaults dokimi/dokimi/runs/rundir.py:40; errors dokimi/dokimi/runs/rundir.py:56 - Responsibility: candidate. policy dokimi/docs/archit…

@napetrov Following up on both requests: the stop state is now read inside the finalization lock (81e0fb5, thread r4677759326), and the run learns of the signal before the child groups are killed (2d31f02). Main is merged in 13f8ede: cli-interface.json was regenerated with both main's new commands and the run kind, and documentation-index.md keeps both main's runs rm/gc line and the run-directories entry.

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

  • Contract: changed. defaults dokimi/dokimi/runs/rundir.py:40; errors dokimi/dokimi/runs/rundir.py:56
  • Responsibility: candidate. policy dokimi/docs/architecture.md; policy dokimi/tests/test_import_architecture.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The previous cancellation case is fixed. I repeated the worker finish while the main thread held the run lock, delivered the stop notice, and got incomplete with stop.reason set to terminated. The documented rule for an end already being written also matches the tests. The four focused suites passed (306 passed, one skipped). Please resolve the current conflict with main in test_import_architecture.py and rerun CI. The Python 3.14 log reports a runner shutdown.

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

Copy link
Copy Markdown
Contributor Author

Change class: CONTRACT (head ab5b048) - Contract: changed. defaults dokimi/dokimi/runs/rundir.py:40; errors dokimi/dokimi/runs/rundir.py:56 - Responsibility: candidate. policy dokimi/docs/archit…

@napetrov Thanks for re-running it. Main is merged in d5b8fcd: test_import_architecture.py keeps both main's dokimi.llm_sampling and dokimi.yaml_unique and the PR's dokimi.process_hooks in the foundation layer, and cli-interface.json, documentation-index.md and mkdocs.yml keep both sides too, so CI reruns on the merged head.

Comment thread dokimi/dokimi/runs/rundir.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…hind

Review point on intel#1150: open_run claimed the directory with an empty
run.json and then saved the record; when that save failed (a full
disk), the raw OSError went out of open_run, which cli.main does not
turn into exit 2, and the empty run.json stayed, so the same name or
output directory was refused on every retry. A failed first save now
removes the empty run.json, and the directory when open_run made it,
then raises; an OSError becomes an InputError naming run.json.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A22: one BaseException handler with an isinstance
check for OSError wrote two cases as one. An OSError is now its own
clause (released, then an InputError), and anything else is released
and re-raised. No behaviour change.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Review fix for A19: only the OSError half of open_run's handler for a
failed first save was tested, so narrowing it back to OSError left the
suite green and a Ctrl-C there would again leave the empty run.json.
The test now also interrupts the save with KeyboardInterrupt, for a
named run and an empty --out-dir, and checks nothing is left and a
retry works.

Refs intel#94

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

Review fix for A20: open_run's release removed run.json only when it
was still empty, so a Ctrl-C after save_artifact had published the
record (its stale-file cleanup, its return) left a run.json saying
running that no caller could end, and the same name was then refused
for good. The claim is exclusive, so run.json is this call's own
whatever it holds: the release now removes it. The test adds that
case; docs/run-directories.md says a stop while run.json is written
leaves nothing behind too.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
…rror or a stop

Review fix for A21: the docstring said any failed first write leaves
nothing behind, but a record save_artifact refuses (a malformed
DOKIMI_RUN_ID in library use; cli.main refuses it earlier) is kept at
run.json.rejected, which the refusal names, so the directory is not
empty after it. The promise now covers a filesystem error or a stop,
and says where a refused record stays; a test pins that the claim is
released and run.json.rejected is what is left.

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 4a88721)

  • Contract: changed. defaults dokimi/dokimi/runs/rundir.py:41; errors dokimi/dokimi/runs/rundir.py:62
  • Responsibility: candidate. policy dokimi/docs/architecture.md; policy dokimi/tests/test_import_architecture.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The previous first-save issue is fixed, including interruption after the record is published. Seven focused tests passed. The exclusive creation of the run marker still has a separate retry failure, confirmed with a simulated full disk on that operation.

if not (empty_ok and path.is_dir() and not any(path.iterdir())):
raise InputError(taken) from None
made = False
with open(path / RUN_FILE, "x", encoding="utf-8"):

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.

blocking: If the exclusive creation of run.json fails after the named directory was made, _claim raises without releasing that empty directory. I simulated ENOSPC at the open(..., "x") call. Retrying open_run with the same name after restoring writes returns “already exists”. The documented first-write retry should also work here. Please remove the directory only when this invocation successfully created it and it is still empty, and cover failure at the claim step.

When the exclusive create of run.json failed (a full disk), _claim kept
the directory it had just made, so a retry with the same name was refused
as "already exists", against docs/run-directories.md. It now removes the
directory it made; an output directory that was there stays.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
runs rm and runs gc remove a run's files and keep its directory, so the
emptied results/<name>/ refused every later run with that name. A name,
like an output directory, may now take an empty directory: the exclusive
create of run.json still decides which run owns it.

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

artifact_path handed out plan.v1.json; a plan saved there stayed unknown
to the run, which then ended complete with none of its cells measured,
and wrote no result on a stop. It now refuses plan, result and run, the
kinds the run writes itself, and points at write_plan.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
A block that left through sys.exit was recorded failed, error, even for
sys.exit(0) after every cell was measured. Codes 0, None, 1 (a failed
verdict) and 3 (inconclusive) now end the run by its cells, as
exit_codes.py defines them; other codes stay failed.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
A ThreadPoolExecutor's exit waits for every queued item, so a signal in a
pool-based block was recorded, and the process exited, only after the
whole queue ran. The doc now says the block cancels pending futures.

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

xaleryb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor
  • Ran: head 4a88721 merged with main 8d9d1ea, plus the commits below. Python 3.13 full suite: 30391 passed, 1 failed (the known missing mcp module, which also fails on main). ruff, mypy, bandit, the growth and comment-block checks, and docs check --strict all pass.
  • e7aaf630d: when the exclusive create of run.json fails (ENOSPC), the directory _claim made is now removed, and a retry with the same name works. This answers the open thread at rundir.py:109.
  • 8e12e5c5f: runs rm r-1 left results/<name>/ empty, and open_run(name=<name>) then failed with "already exists". A name may now take an empty directory; the exclusive create of run.json still decides the owner.
  • 9c941577c: save_artifact('plan', plan, run.artifact_path('plan')) gave a complete run with 6 unmeasured cells. artifact_path now refuses plan, result and run.
  • ed1c17bfc: sys.exit(0) after every cell was measured was recorded failed/error. Exit codes 0, None, 1 and 3 now end the run by its cells (exit_codes.py); other codes still end it failed.
  • e31f0709b: a SIGTERM in a ThreadPoolExecutor block drained the whole queue (8.3 s instead of 0.5 s). The docs now say the block must cancel its pending futures.
  • Left for the author: apply cancel_futures in arm_runner when the arms family moves to run directories.

@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 e31f070. A stopped run is recorded as stopped and never reads as complete; our commits clean up a run.json that could not be written (the open thread at rundir.py:109), let a removed run name be reused, refuse plan/result through artifact_path and grade exit codes by the cells. Left for later: cancel_futures in arm_runner when the arms family moves to run directories. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

@xaleryb
xaleryb merged commit e98ee18 into intel:main Nov 28, 2026
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