Skip to content

feat(runs): runs export | import, a verified bundle that moves a run - #1521

Merged
xaleryb merged 32 commits into
intel:mainfrom
vlad-perevezentsev:feat/runs-export-import
Dec 3, 2026
Merged

xaleryb merged 32 commits into
intel:mainfrom
vlad-perevezentsev:feat/runs-export-import

Conversation

@vlad-perevezentsev

@vlad-perevezentsev vlad-perevezentsev commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The last part of #94 R3 (§2.3, "Baselines survive ephemeral CI runners", D9 (b)). A baseline pointer under results/ goes away with the CI runner that made it. runs export writes one run directory (#1150) as a single file, and runs import checks that file and puts the run under the runs root of another machine. With --as it also points a runs baseline (#1184) at the run. Refs #94 R3.

$ dokimi runs export baseline:main > baseline.tgz          # the record job
exported run 20261123T101500Z-1a2b3c4d from nightly-7/: 4 files, 6,954 bytes; plan sha256:6bbd76a2…, result sha256:fc5d04c6…
$ dokimi runs import baseline.tgz --as main                # the next runner, no results/ yet
imported run 20261123T101500Z-1a2b3c4d into results/nightly-7/: 4 files, 6,954 bytes; plan sha256:6bbd76a2…, result sha256:fc5d04c6…
saved baseline main -> 20261123T101500Z-1a2b3c4d; before: none
  • runs export RUN|baseline:NAME writes the bundle to stdout and a one-line summary to stderr. RUN is a run_id whose artifacts include a run.json; baseline:NAME is the run a baseline points to. The bundle holds run.json and every artifact it lists (the plan, the result and the run's own artifacts). An artifact that carries the run_id but that run.json does not list is left out, and stderr says so (left out: 1 artifact …).
  • The bundle is a gzipped tar. bundle.json comes first (new schema run_bundle.v1, not an artifact kind), then the run's files under run/. bundle.json names the run and its address, which per CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94 is the plan's plan_digest plus the sha256 of result.v1.json, and gives the sha256 and size of every file. The tar holds no time, owner or mode, so a run always makes the same tar. The .tgz bytes come from zlib, so a different zlib build may compress them differently. bundle.json is the same on every machine.
  • runs import BUNDLE reads the bundle into memory and writes nothing until every check passes ("import never trusts it blindly", CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94):
    • only regular members are read, bundle.json first, then exactly the files it lists, each with its sha256 and size;
    • refused: symlinks, hard links, directories, FIFOs and devices; absolute paths, .. segments, \, : and the other characters Windows refuses (<>"|?*), Windows device names (CON, nul.json, CONIN$, COM¹, as ntpath.isreserved lists them), segments ending in . or a space; a path listed twice; two paths that differ only in case or in Unicode normalization; two spellings of one directory (Sub/a.json beside sub/b.json); a file and a path under it;
    • the unpacked stream is capped at 256 MiB, so a gzip bomb stops at the cap;
    • run.json must be a valid run.v1 that lists exactly the bundle's files and no second run record, with a name (or run_id) Windows can make a directory of;
    • each artifact must pass the schema of its kind, carry the run's run_id, and be one runs list finds (a .json name, JSON that opens with its schema_version), so the run can be exported again;
    • the result's plan_digest must be the digest of the plan, and bundle.json's run and address must match the run's.
  • Where the run goes: <runs root>/<name>, or <runs root>/<run_id> for a run with no name, as run directories are named. The files are written to a staging directory beside the target, which no runs command reads, then renamed into place. From the scan for the run_id to the rename the import holds .baselines/.lock, so of two imports of one run at once the second finds the first's run. results/ is created when it is missing (a fresh runner, also when another import makes it meanwhile); a DOKIMI_RUNS_DIR that does not exist is refused. If the same run is already there with the same files, nothing is written and the exit code is 0. An import never replaces a run: another run with the bundle's run_id anywhere under the root, or a directory of that name that holds anything, exits 2. The error names the file that differs.
  • --as NAME [--expect-previous RUN_ID] points the baseline through runs/baseline.py's save, with the same compare-and-swap as runs baseline save. If the pointer has moved, the exit code is 4 (stale_baseline), the pointer is left as it was and the run stays imported. A bad name, a name that differs from a saved one only in case, or a .baselines/ that is a link or cannot be locked exits 2 before the run is written. A pointer that cannot be written after the run is exits 5 and says the run is imported.
  • runs/baseline.py and runs/rundir.py are not changed. The code is in the new dokimi/runs/bundle.py and dokimi/commands/runs_bundle.py. commands/runs.py gets one import and one register line, cli_routes.py two registry lines, and cli_flags.py registers --as under the baseline concept.

Changed output

New commands only: runs export and runs import (--json: cli_output.v1, kind runs import). New exit-code rows are in docs/runs.md:

Case Exit
exported; imported, or the run is already there with the same files 0
export: no run directory, not exactly one plan and one result, a listed file missing / not regular / leading out, a stdout that is a terminal; import: any failed check, another run with the run_id, a taken directory, a bad --as / --expect-previous 2
--as NAME --expect-previous RUN_ID and NAME does not point to RUN_ID 4
the run or the pointer could not be written 5

Evidence

  • tests/test_runs_bundle.py, 51 test functions. They cover:
    • a round trip from one root to a fresh working directory; the re-export of the imported baseline is the same bytes;
    • a member tampered after export is refused, and nothing is written;
    • malicious members are refused, and nothing is written: an absolute path, .., \, a symlink, a hard link, a FIFO, a device, a directory, a member not listed;
    • a re-signed bundle (hashes recomputed) is refused for: an artifact that fails its schema, a result of another plan, a result of another run, a run with no result, a bundle.json naming another address, paths that differ only in case, a path listed twice;
    • an import into an existing identical run is a no-op (same mtimes, no staging directory left); a different run with the same run_id and a taken directory are refused;
    • the size cap, both for one member and for the stream;
    • not a gzip, an empty tar, a FIFO as BUNDLE, bundle.json not first, a listed file missing;
    • --expect-previous exiting 4 with the run imported; bad --as and --expect-previous flags refused before writing; a case-only --as; a store that cannot be locked;
    • export refusals: a missing file, a link out, a symlink, a FIFO, an unreadable file, over the cap, a bundle.json past its schema caps, a run with no run directory, a run without a plan, a terminal stdout;
    • a run with no name going to <root>/<run_id>; --json fields;
    • review round 1: Windows characters and device names in paths and in the run's name; two imports of one run in two threads, held between scan and write (both cases fail without the lock); a results/ made by another import meanwhile; a run.json or artifact with reordered keys, leading whitespace or a non-.json name; a pointer write that fails (exit 5); a case-twin baseline saved between the write and the save (exit 2, the run imported).
    • review round 2: a scan at the moment of the rename finds none of the staged run; two spellings of one directory (by case, by Unicode normalization) refused. Each fails without its fix.
  • Mutations, each caught by a test (16 in total). Round one: a symlink member accepted, the sha check dropped, the run_id check dropped, the "same run" check dropped, .. allowed, the plan_digest check dropped, the case check dropped, the stream cap dropped. Then: no store pre-check, no catch of a late save refusal, the inside check, the S_ISREG check, a plan-only count, name or run_id, the export cap, the export manifest check.
  • Bad inputs to runs import: a directory, a missing file, an empty file and a Windows-style path each exit 2 with a message. Bad inputs to runs export: a name that is not a run id, baseline:BAD., a missing baseline and an unknown run_id each exit 2 as well.
  • An independent review found 8 points, all fixed in their own commits: the nested list mkdocs --strict rejected; a case-only --as refused only after the write; untested export refusals; an export that no import could read (past run_bundle.v1's 1000-file and 1024-character caps); an error that named the wrong file; a FIFO BUNDLE that blocked; the "same bytes on every machine" claim (it depends on zlib); a duplicate path in bundle.json.
  • make ci-local --offline on 94d84af2: 0 failed, 27 passed, 22 skipped (network, Windows smoke, matrix legs). The suite: 32692 passed, 132 skipped. Changed-line coverage is 92% of 414 lines. The uncovered lines are mostly refusal branches such as an unknown kind in run.json, an artifact that is not a JSON object, or a rename race.
  • Mutation of changed lines: 80 of 378 mutants, 69 killed, 11 survived (the gate warns only). The survivors:
    • the cap constants (256/1024/8 MiB bumped by one);
    • stdout.flush();
    • results/'s mkdir, whose deletion the next write covers by making the parent;
    • two clauses of the case-only --as pre-check, which baseline.save repeats after the write;
    • the (empty) branch of before:;
    • three default-value flips (written=False in the --json data, two field/repr defaults).
  • Review round 1 (after merging main at 488ecca): slot ci --quick (lint, mypy, the whole suite): 0 failed, 33407 passed, 132 skipped. Mutations: the lock dropped, the exist_ok dropped, the leading-schema_version check dropped, the .json name rule dropped, the device-name stem and its rstrip, the ? character and the run-name check each fail a new test.
  • Not run: Windows and macOS. The case, device-name and trailing-dot refusals and the rmdir before the rename exist for them, but they are tested only on Linux.

Open questions

  • --as is explicit. CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94's pr-check recipe says runs import baseline.tgz and then uses baseline:main. Here the recipe needs runs import baseline.tgz --as main. The bundle does not record the baseline name it was exported under, so the address depends on the run only. Should import set that name by itself?
  • The checks prove integrity, not who made the bundle. Someone who rebuilds a bundle whole, bundle.json included, passes the hash checks. Schemas, run_id and plan_digest still have to hold. Should import take an expected address (--expect-address), from a workflow that keeps the export's output where a PR cannot write?

Not in this PR

Checklist

  • Tests added/updated and pytest passes: tests/test_runs_bundle.py (51), and tests/test_cli_output.py's leaf set takes runs import
  • ruff, mypy, and schema checks pass: make ci-local --offline (above); new run_bundle.v1.json with its fixture in tests/fixtures/artifacts/
  • Docs updated: docs/runs.md (new section and exit codes), docs/run-directories.md, docs/reference/cli-interface.json, changelog fragment (Added)
  • Self-reviewed per "Before opening a PR" in AGENTS.md: the mutations, bad inputs and review above
  • Each new raise/exit and test names the doc, contract or issue it traces to: docs/runs.md "Moving a run" and CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94 §2.3, cited in the messages, docstrings and test comments
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (the two JSON files are exempt as JSON)

A baseline pointer under results/ goes with the ephemeral CI runner
that made it (intel#94 §2.3). `runs export RUN|baseline:NAME > bundle.tgz`
writes the run directory (run.json, its plan, result and the artifacts
it lists) as a gzipped tar led by bundle.json (run_bundle.v1), which
gives the run's address, the plan_digest and the result's sha256, and
the sha256 and size of every file. The tar holds no time, owner or
mode, so one run always exports to the same bytes.

`runs import BUNDLE [--as NAME [--expect-previous RUN_ID]]` reads it
into memory and writes nothing until it holds: only regular members at
the paths bundle.json lists (no links, devices, FIFOs, directories,
absolute or `..` paths, or paths equal but for case), each with its
hash, under a 256 MiB cap on the unpacked stream; run.json lists
exactly the files, each artifact passes its schema and carries the
run's run_id, the result names the plan's digest. The run goes to
<root>/<name or run_id> through a staging directory and a rename; the
same run already there is a no-op, another run with the run_id or a
taken directory exits 2. --as points a baseline at it through
runs/baseline.py's save, with --expect-previous as a compare-and-swap
(exit 4).

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
mkdocs build --strict read the three checks under runs import at
depth 1 while GitHub reads them at depth 2: indent them 4 spaces, with
a blank line before and after the nested list.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A name that differs from a saved baseline only in case, or a
.baselines/ that is a link or cannot be locked, was refused by
baseline.save only after the run was written, with a message that did
not say so. Check them through baseline.listed before the write, and
report a save that still refuses after it (a read-only store) as
"run X is imported, but ..." with the import's data.

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

Export of a run whose listed file is missing, a symlink, a FIFO, behind
a link out of the directory, unreadable or over the cap exits 2 with
nothing on stdout; a re-signed bundle whose run.json lists no result is
refused; a run with no name goes to <root>/<run_id>, and --as --json
carries data.baseline.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
verified() did not apply run_bundle.v1's caps (1000 files, a path of
1024 characters), so a run past them exported fine and no import could
read its bundle. collect() now checks the manifest against the schema,
as import checks it first.

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

The refusal named the newest artifact with the run_id, which may be
identical to the bundle's. Name the first artifact with the run_id the
bundle does not hold, else the first bundle file the directory does not
hold as it is.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
runs import opened BUNDLE before looking at it, so a FIFO with no
writer blocked for good. Stat it first and refuse what is not a
regular file, as runs show does.

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

The tar of a run is deterministic, but the .tgz is zlib's deflate
output: CPython's Windows builds use zlib-ng, which compresses to other
bytes. Name bundle.json (the address and each file's sha256) as what
is the same on every machine, in runs.md, the fragment and write().

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The case check compared a path only with another spelling, and the
members were matched through a dict, so a second entry for a path
silently replaced the first.

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 20: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 ebc628a was not reviewed. This PR has reached its review limit (6 reviews).

CI at `ebc628a`: 5 still running, 16 passing, 3 skipped
Check Status
Mutation of changed lines still running
Package install smoke test (py3.11) still running
Test Linux Python 3.14 still running
Test Linux Wheels Python 3.14 still running
Tests (py3.14) still running

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

Last review (620507d): no findings

Open threads from the bot: 1

Comment thread dokimi/docs/runs.md Resolved
Comment thread dokimi/dokimi/runs/bundle.py Resolved
Comment thread dokimi/dokimi/runs/bundle.py Resolved
Comment thread dokimi/dokimi/runs/bundle.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 93.56223% with 30 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.47%. Comparing base (ec3913a) to head (ebc628a).

Files with missing lines Patch % Lines
dokimi/dokimi/runs/bundle.py 91.88% 20 Missing and 8 partials ⚠️
dokimi/dokimi/commands/runs_bundle.py 98.23% 1 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    #1521      +/-   ##
==========================================
- Coverage   96.49%   96.47%   -0.03%     
==========================================
  Files         535      537       +2     
  Lines       71587    72051     +464     
  Branches    12365    12438      +73     
==========================================
+ Hits        69080    69511     +431     
- Misses       1532     1553      +21     
- Partials      975      987      +12     
Files with missing lines Coverage Δ
dokimi/dokimi/cli_flags.py 100.00% <ø> (ø)
dokimi/dokimi/cli_routes.py 98.52% <ø> (ø)
dokimi/dokimi/commands/runs.py 100.00% <100.00%> (ø)
dokimi/dokimi/runs/scan.py 99.05% <100.00%> (+0.02%) ⬆️
dokimi/dokimi/commands/runs_bundle.py 98.23% <98.23%> (ø)
dokimi/dokimi/runs/bundle.py 91.88% <91.88%> (ø)

... and 5 files with indirect coverage changes

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

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

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

CLI interface change detected

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

+ added command `dokimi runs export`
    + argument `run`
    + option `--help/-h`
+ added command `dokimi runs import`
    + argument `bundle`
    + option `--as`
    + option `--expect-previous`
    + option `--help/-h`
    + option `--json`

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

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Tests miss 6 of 58 small breaks of the lines this PR changes, and the check was not complete

At ebc628a: 52 caught · 6 missed · 22 not tried in time

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/runs_bundle.py:37 delete-statement sys.stdout.buffer.flush() → pass 74
dokimi/dokimi/commands/runs_bundle.py:78 drop-clause args.as_name is None or not root.exists() → (args.as_name is None) 18
dokimi/dokimi/commands/runs_bundle.py:82 drop-clause p.name != args.as_name and p.name.casefold() == folded → (p.name != args.as_name) 2
dokimi/dokimi/commands/runs_bundle.py:129 flip-bool False → True 16
dokimi/dokimi/commands/runs_bundle.py:155 take-branch "none" if saved.previous is None else plain(saved.previous) or "(empty)" → ("none") 2
dokimi/dokimi/runs/bundle.py:52 bump-int 256 → 257 20

Not the whole picture:

  • 22 breaks were not tried before the time budget ran out
  • 379 more breaks of covered changed lines were over the limit and not tried
  • 65 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.

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

Nine focused round-trip, conflict and idempotency tests passed. I also exercised two concurrent imports with verified bundles. Concurrent imports can publish duplicate run IDs under different directory names.

Comment thread dokimi/dokimi/runs/bundle.py Resolved

@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 (in the line comments) and fix what the bot's thread on dokimi/docs/runs.md:381, the bot's thread on dokimi/dokimi/runs/bundle.py:88, the bot's thread on dokimi/dokimi/runs/bundle.py:100 and the bot's thread on dokimi/dokimi/runs/bundle.py:277 still point out? Then push and I'll take another look.
There's 1 optional suggestion in the line comments; take it or leave it.

What I checked on 94d84af:

  • When I changed the code on purpose, the tests still passed for 5 of 12 changes, and no test pins these down yet (non-blocking): dokimi/dokimi/commands/runs_bundle.py:103 (the handled error is raised again), dokimi/dokimi/commands/runs_bundle.py:106 (the handled error is raised again), dokimi/dokimi/commands/runs_bundle.py:109 (the handled error is raised again) and 2 more.
  • The 169 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (36,254 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/dokimi/commands/runs_bundle.py Resolved
Comment thread dokimi/docs/run-directories.md Resolved
rundir writes one run record per directory, its run.json, and never lists
kind run. Import took such a bundle with exit 0, and the run then could not
be exported again ("has 2 run.json files"). It now exits 2.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
A run.json that lists x.json and x.json/y.json passed every check, then
failed in the staging write with exit 5 "cannot write: File exists", the
exit docs/runs.md keeps for a disk that cannot be written. _check_paths now
refuses it with exit 2 before anything is written, also across case.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
_check_paths folded case only, so the NFC and NFD spellings of one name
both passed, and macOS would write them to one file after both were
checked. The key is now NFC, then casefold. docs/runs.md lists this check
and the path-under-a-file check.

Signed-off-by: Alexander Rybkin <alexander.rybkin@intel.com>
The mkdir of the default runs root ran before the OSError handler of
install, so a denied results/ crashed with a traceback. It now goes
through the same infra exit as a run that cannot be written.

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

collect() checked the manifest against its schema caps only, so a run with
many long artifact paths exported with exit 0 and a bundle.json over the
1 MiB import reads it under, which import then refused. Export now checks
the serialized size write() produces.

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

A re-signed bundle with a file run.json does not list, an artifact of an
unknown kind, or one path listed twice had no test: each check could be
dropped with the suite green, and the first lets unchecked bytes into the
imported run directory.

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

The bundle holds run.json and what it lists; the left-out line named only
artifacts carrying the run_id, so a report or other file in the run
directory stayed behind without a word. Export now names them on a second
left-out line, and docs/runs.md says so.

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

The address is the plan digest and the result sha256 only. A bundle with
run.json or another artifact edited and bundle.json re-signed imports with
exit 0 and prints the same address, so comparing it proves nothing there.

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

xaleryb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor
  • Ran: head 94d84af merged with main 512e517, plus feat(subjects): subjects run writes a run directory with its plan and result #1494 on top. Full suite, gates and crafted re-signed bundles.
  • Open, bundle.py:452 (napetrov): two concurrent imports of one run_id under two names -> both written, two run.json files, and the next export fails -> expected: the second import refuses. Two imports of the same bundle -> the second exits 5 'Directory not empty' -> expected: exit 0, nothing written. One lock under the root around scan and publish, with a re-scan under the lock, closes both.
  • Open, bundle.py:88: CON.json and arms?.json pass safe_path -> expected: refused, because export goes through the same check.
  • Pushed:
    • 86f04c8: refuse a second run record (it imported, then could not be exported).
    • 34ddd5a: refuse x.json next to x.json/y.json (exit 5 -> 2).
    • da1cb5c: refuse NFC/NFD twins.
    • 4a9f47e: a results/ that cannot be made -> one line, not a traceback.
    • d337d51: export refuses a bundle.json over 1 MiB.
    • f2687a7: tests for three untested refusals.
    • 4299448: name unlisted run-directory files at export.
    • 5f75c5e: the address does not cover run.json, so the doc no longer offers it as proof.
  • Left for the author: the import lock, Windows reserved names, and a bundle.json sha256 for --expect-address.

Comment thread dokimi/docs/runs.md Resolved
Comment thread dokimi/dokimi/commands/runs_bundle.py Resolved
Comment thread dokimi/dokimi/runs/bundle.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 5f75c5e)

  • Contract: changed. errors dokimi/dokimi/commands/runs_bundle.py:31; errors dokimi/dokimi/commands/runs_bundle.py:67
  • Responsibility: candidate (count signal only, no file:line)
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

I rechecked the concurrent import finding on this revision. Two valid imports with the same run ID and different names both returned written=True and left two run.json files. Nine focused bundle tests passed, including the revised root-creation error case. The duplicate-ID issue still blocks approval.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A run.v1 artifact path or run name may hold ?, <, >, ", |, * or be a
device name such as CON or nul.json, which Linux and macOS write and
Windows refuses. Export wrote such a run and import accepted it, then
could not write it on Windows (exit 5). safe_path now refuses these
characters and device names in every segment, and verified() checks
the name of the run's directory with it, so export and import refuse
the run (exit 2) before anything is written.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
install() scanned the root for the bundle's run_id and then renamed the
run into place with nothing held between the two. Two imports of one
run under two names both found no run, and both wrote it: two run.json
files for one run_id, which export then refuses. Two imports under one
name made the second fail with exit 5 (Directory not empty) instead of
the no-op an identical run is.

install() now holds .baselines/.lock, the lock baseline saves take,
from the scan to the rename, so the second import finds the first's
run. A store that cannot be locked (a read-only .baselines/) now
refuses the import before the run is written; it was refused only by
the save after it.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Two imports on a fresh runner both found no results/; the one that made
it second failed with exit 5 (cannot make it: File exists) and wrote
no run. _import_root() now makes the default root with exist_ok, so the
second goes on; a file at results/ still fails.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
scan() finds an artifact by a name that ends in .json and JSON that
opens with its schema_version. A bundle re-signed after its run.json
was rewritten with sorted keys passed every import check, and the run
it wrote could not be listed or exported again ("has no run
directory"); a reordered artifact dropped out of the run's files the
same way.

verified() now refuses a listed file that scan() would skip, through
scan.artifact_version(), the rule scan() applies by name and first
bytes, so export and import check what runs list reads.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The paragraph said every save that fails once the run is written exits
2, while the command and the exit-code table give 5 for a pointer that
cannot be written. Say which is which, and pin the 5 with a test.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
safe_path() took the device names CON, PRN, AUX, NUL, COM0-9 and
LPT0-9, but Windows also reserves CONIN$, CONOUT$ and COM/LPT with a
superscript digit, which run.v1 allows in an artifact path. Use the set
of CPython's ntpath.isreserved (3.13), keeping COM0 and LPT0.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Since install() takes the lock first, no test reached the InputError
branch of _point(), which docs/runs.md promises: a baseline saved
meanwhile whose name differs only in case makes the save refuse once
the run is written, with exit 2 and 'run ... is imported, but'.

Refs intel#94

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

Copy link
Copy Markdown
Contributor Author

@xaleryb Thanks for the commits. The three items left: the import lock is 7f3813f (both cases you describe: a second name is refused, the same name is the no-op), the Windows reserved names and characters are a9609c6 and 012a706. For --expect-address, a trusted digest of bundle.json checked at import would be a new flag; I'd propose it as a follow-up issue rather than grow this PR.

Comment thread dokimi/dokimi/runs/bundle.py Resolved
Comment thread dokimi/dokimi/runs/bundle.py Resolved
The import writes a run into .<name>.<hex>.import under the runs
root and renames it into place, but scan() walked that directory, so
runs list, runs export and the run_id check of another import saw
part of a run before the rename. scan() now skips such a directory
at the root, as it skips .baselines; a run's own name never starts
with a dot.

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
_check_paths() compared whole paths only, so Sub/a.json and
sub/b.json passed. Windows and macOS write both into one directory;
a later scan reads Sub/b.json, which the bundle does not list, so an
identical second import exited 2 instead of being the no-op, and
runs export reported the file as left out. A bundle (and a run on
export) that spells one directory in two cases or two Unicode
normalizations is now refused.

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 c353702)

  • Contract: changed. errors dokimi/dokimi/commands/runs_bundle.py:31; errors dokimi/dokimi/commands/runs_bundle.py:67
  • Responsibility: candidate (count signal only, no file:line)
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

Nothing to fix in this pass. The bundle tests exercise round-trip export/import, schema and digest checks, duplicate imports, and baseline updates.

Checked the diff, input edges, prior feedback, and focused offline tests on Linux/Python 3.11 (213 passed in 18.84s).

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The bad-path contract that came in with main (intel#1492) reads the operand
as a path, since its help names run.json, and failed the command as one
whose path parameter is never reached. RUN is a run_id or
baseline:NAME, so list it in NOT_PATHS.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/runs/bundle.py Resolved
bytes; ``None`` when there is none."""
for path, data in sorted(bundle.files.items()):
try:
if not stat.S_ISREG(os.lstat(directory / path).st_mode) or (directory / path).read_bytes() != data:

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 · not shown by a run
Impact: importing a small valid bundle can exhaust memory instead of refusing a differing destination artifact.

Trigger: after installing a run, replace its arms.v1.json with a multi-gigabyte sparse file beginning with zero bytes, then import the original bundle again.

Evidence: scan() skips that file after its bounded header read, but still discovers run.json, so _install() reaches this unconditional read_bytes() and allocates the entire oversized file.

Fix: Compare the lstat size with len(data) first, and bound the subsequent read to len(data) + 1 to handle growth. Add an oversized-destination regression.

Workaround: remove or repair the oversized artifact before retrying.

Not shown by a run: The proof step did not check this finding.

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.

This needs the installed run's arms.v1.json replaced by a multi-gigabyte file before the same bundle is imported again, and the harm is bounded: the import uses memory or fails, nothing is written or lost. I'd leave it out of this PR and open a follow-up issue: _first_difference compares the lstat size with the bundle's before reading, and reads at most len(data) + 1 bytes.

Comment thread dokimi/tests/test_runs_bundle.py Resolved
tarfile parses a PAX sparse map with int(), so a malformed one raises
ValueError while the archive is read; runs import let it through as an
infrastructure crash (exit 5, a traceback). It is now refused like any
other archive that is not a run bundle (exit 2).

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The test makes the run's directory 'con' first, which Windows refuses,
so it fails in its setup there before export is reached.

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 620507d)

  • Contract: changed. errors dokimi/dokimi/commands/runs_bundle.py:31; errors dokimi/dokimi/commands/runs_bundle.py:67
  • Responsibility: candidate (count signal only, no file:line)
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

0 new must-fix findings. Nothing to fix in this round. The new test classifies the unreadable tar header as an input error. The Windows skip is scoped to fixture creation using the reserved con name.

Checked the diff, input edges, and focused offline Linux tests (focused: 216 passed in 19.24s). Checked bundle import/export on Linux. Windows and macOS filesystem behavior was not run. The agent-run fault-harness failure reproduces on the base.

  • Fixed on head by 7f3813f0. The run-ID lock regression passes for both concurrent import cases. Earlier thread
  • Fixed on head by a609097e. The malformed-header regression passes. Earlier thread
  • Fixed on head by 620507d0. The Windows skip is scoped to the reserved fixture name. Earlier thread

@antonwolfy antonwolfy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Export and import hold up: nothing is written until every check passes, the staging directory is invisible to scan(), and the lock covers both the run_id scan and the rename. The earlier review rounds are fixed at this head, and I found nothing new to add.

What I ran, on a Linux review host at 620507d:

  • make ci-local: 37 passed, 1 failed, 16 skipped. 34,046 tests passed, changed-line coverage 95% of 466 lines, mkdocs build and pip-audit pass.
  • The one failure is test_cli_fault_contract.py::test_a_bad_path_is_refused_as_the_quickstart_says[agent run]: agent run refuses the filler x for --agent (expected AGENT=MODEL). It fails the same way on the PR's base, and the PR only adds a runs export entry to NOT_PATHS.
  • Mutation of changed lines: 80 mutants, 70 killed, 10 survived. The survivors are the cap constants, stdout.flush() and clauses of the case-only --as pre-check, which baseline.save repeats; none decides an exit code.

Checked, no issues

  • Commits: all 29 non-merge commits carry Signed-off-by.
  • Path rules: safe_path and _check_paths agree between export and import, and verified() applies the same checks on both sides, so an export no import would read is refused.
  • Atomicity: _publish stages beside the target, and scan() skips .<name>.<hex>.import at the root only; run names start with an alphanumeric character in run.v1, so no run name can match.
  • Docs and wiring: docs/runs.md exit codes match runs_bundle.py, the new schema has its fixture, and the changelog fragment is present.

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

xaleryb commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

@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 ebc628a. runs export | import moves a run as a verified bundle; re-run on the head merged with main: two parallel imports of one run_id now serialise (one writes, the other refuses), a repeated import exits 0, Windows-reserved names and paths such as CON.json and arms?.json are refused, and our eight commits still hold. Full suite and gates are green. Windows smoke had not started (the hosted Windows queue was stuck); every other check 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.

7 participants