Run directories¶
A run directory keeps one run's record, plan, result and artifacts together, and
it still holds a result when the run is stopped part way: a signal, Ctrl-C or
the spend cap (#94 ยง2.3, stage R2).
The module that writes it is dokimi/runs/rundir.py. subjects run writes
one (see below); the other command families move to it one by one in later
PRs, each with its --out-dir and a run name.
Layout¶
results/20261123T101500Z-1a2b3c4d/
run.json the run's record (run.v1)
plan.v1.json the cells the run promises to measure, when it has a plan
result.v1.json one status per planned cell, written on a stop too
arms.v1.json the run's own artifacts, each <schema_version>.json
- Where. Under the runs root (
results/, orDOKIMI_RUNS_DIR), in a directory named by the run's name when it has one, else by itsrun_id(dokimi.artifacts.run_id). An output directory given to the run (--out-dir, #591) is the run directory itself, in place of either. - No clobbering. A run never writes into another run's directory. The
directory must not exist yet, or be empty: an empty output directory, or a
run's directory
runs rmorruns gcemptied, so its name can be used again. A name already taken under the root is refused, and so is arun_iddirectory that holds a run (two commands sharing oneDOKIMI_RUN_ID).run.jsonis created exclusively, so of two runs that race for one directory only one gets it. A name together with an output directory is refused: a name is unique only under the root. So is a directory that cannot be made: a runs root or a parent of the output directory that is a file. Whenrun.jsonitself cannot be written (a full disk), or a stop lands while it is written, nothing is left behind, so the same name or output directory can be tried again. - Names have the characters of a run id: 1-128 letters, digits,
.,_or-, starting with a letter or a digit, so a name is one path segment. - Artifacts are
<schema_version>.jsonin the directory, one per kind (RunDir.artifact_path; it refusesplan,resultandrun, which the run writes itself: the plan throughwrite_plan). A cell's own artifact may sit in a subdirectory;RunDir.add_artifactlists it. They carry the run's envelope like any artifact, soruns listgroups them, withrun.json, as one run.
run.json¶
run.v1 (dokimi/schemas/run.v1.json), written when the directory is
made and again when the run ends:
| Key | What |
|---|---|
run_id, dokimi_version |
the run envelope, as on every artifact |
name |
the run's name, null when it has none |
argv |
the command line after the program name |
started_at, finished_at |
ISO 8601 UTC; finished_at is null while the run runs |
status |
running, complete, incomplete or failed |
stop |
{reason, detail} when the run ended on a stop or an error, else null |
artifacts |
[{kind, path}], each path relative to the directory with / separators |
artifacts lists the files the run asked a path for and wrote, as the run
ends; while the run runs it is empty.
How a run ends¶
| The run | status |
stop.reason |
result.v1.json |
|---|---|---|---|
| finishes with every planned cell measured | complete |
- | every cell's status |
| finishes with cells left unmeasured | incomplete |
- | the cells left are not_run |
| gets SIGTERM or SIGHUP | incomplete |
terminated |
the cells left are not_run |
gets Ctrl-C (KeyboardInterrupt) |
incomplete |
interrupted |
the cells left are not_run |
hits its --max-usd cap, or a call with no price |
incomplete |
spend_cap, no_price |
the cells left are not_run |
| stops on a run-wide CLI failure (a usage limit, no login) | incomplete |
run_stopped |
the cells left are not_run |
calls sys.exit with 0, 1 (a failed verdict) or 3 (inconclusive) |
as its cells say, complete or incomplete |
- | as above |
| raises any other error, or exits with another code | failed |
error |
the cells left are not_run |
A run without a plan writes no result.v1.json: a result is a status per
planned cell, tied to its plan by plan_digest. A cell left not_run by a stop
says why in its detail. result.v1 has no status of its own;
runner.plan.completeness reads a result with not_run cells as incomplete, and
a run is refused complete while a planned cell has no measured status.
A signal is recorded through the CLI's own handler for SIGTERM and SIGHUP
(dokimi.process.install_signal_handlers; a library caller installs it
itself). The handler first tells the run that the signal came, so an end any
thread writes from then on is terminated; then it kills the child process
groups and stops the run's block (dokimi.process_hooks); the record is written, and the signal is
delivered again, so the process exits as it did before (status 143 for SIGTERM
under the CLI). Only a run opened on the main thread is stopped this way, and a
signal the process ignores stays ignored. A run a signal stopped is recorded
terminated even when code in its block caught the stop, and even when the
block then calls finish itself. An end another thread is already writing when
the signal comes is kept: it was decided from cells measured before the signal.
subjects run¶
subjects run runs in a run directory: --out-dir DIR, else <runs root>/<run_id>.
--out FILE and --out-md FILE also write the scorecard and its report there; a FILE in this
run's directory or in another run's (one holding a run.json) is refused before any cell runs.
So is a --work-output-dir in (or under) another run's directory, or one where a path the work
writes (the task-runs files, a cell's directory, a file a harness writes in it outside the agent's
work/) is a symlink into one.
results/20261201T101500Z-1a2b3c4d/
run.json, plan.v1.json, result.v1.json
subject_scorecard.v2.json, subject_scorecard.v2.md
matrix.cells.json the matrix the cells run
<product>/matrix-rollup.json one per suite.products entry, with cells/<matrix cell>.json (arms.v1)
work/task-runs.json when suite.tasks run (not under --work-output-dir)
A product whose directory name would be one of these names (result.v1.json,
work, ...) is refused (exit 2) before the run starts.
A planned cell is one awareness arm of one matrix cell over one product's
questions (arm <matrix cell>/<arm>, task the product), and one work harness
on one task and rep (arm work/<harness>). An awareness arm has no verdict of
its own, so a cell whose arm answered a question is inconclusive and one that
answered none, or whose matrix cell stopped on a run-wide failure, is
infra_error. Each matrix cell is recorded once its file is saved, so a stop in
a later cell keeps it. A work cell is pass or fail by its
verifier, infra_error when the row has no verdict, not_run under
--work-dry-run, and is recorded once it ends, so a stop in a later one
keeps it too. A harness named twice in --work-harnesses runs once, and
two suite.tasks with one name are refused (exit 2), since a plan's cell ids
are unique. A run-wide failure in an arms cell (a usage limit, no login)
exits 1, so the run ends incomplete by its cells, with no stop.
In code¶
from dokimi.runs.rundir import open_run
from dokimi.runs.scan import runs_root
with open_run(runs_root().path, name="nightly-7") as run:
run.write_plan(plan) # plan.v1, saved as plan.v1.json
for cell in plan["cells"]:
status = measure(cell) # pass, fail, inconclusive, ...
run.record_cell(cell["cell_id"], status)
save_artifact("arms", arms, run.artifact_path("arms"))
# the block ended: run.json says complete, result.v1.json has every cell
A block that ends normally finishes the run unless it called
run.finish(status) itself: complete when every planned cell has a measured
status, else incomplete. A block that raises records the stop and lets the
exception go on. A run ends once: a second finish, or a write_plan or
record_cell after the end, is refused.
A block that waits on a thread pool cancels the work still queued as it
unwinds (pool.shutdown(wait=False, cancel_futures=True), then the exception
goes on): a ThreadPoolExecutor's own exit waits for every queued item, so
after a signal the record, and the exit, would come only once the whole queue
has run.