Skip to content

feat(runs): runs baseline save|list|rm with a compare-and-swap --expect-previous - #1184

Open
vlad-perevezentsev wants to merge 26 commits into
intel:mainfrom
vlad-perevezentsev:feat/runs-baseline
Open

vlad-perevezentsev wants to merge 26 commits into
intel:mainfrom
vlad-perevezentsev:feat/runs-baseline

Conversation

@vlad-perevezentsev

Copy link
Copy Markdown
Contributor

Summary

Adds the baselines of #94 R3 (§2.3: "A baseline is a named pointer to a run, like a git tag … --expect-previous RUN_ID makes the save a compare-and-swap, so two nightlies cannot race on the pointer"), over the runs root that runs list reads (results/, or DOKIMI_RUNS_DIR).

  • runs baseline save NAME RUN points NAME at RUN, a run_id that some artifact under the root carries. The run is found by the scan, the same way runs show RUN_ID finds it. A run_id no artifact carries exits 2. A baseline that already exists is moved, and the output line says what it held before (before:).
  • --expect-previous RUN_ID saves only while NAME points to RUN_ID. If it points elsewhere, or the baseline does not exist, the save exits 4 and the pointer stays as it was. Exit 4 is invalid, which §2.6 lists for "a stale baseline". With --json the document has status: failed, verdict: invalid and reason: stale_baseline, plus expected and found under data. Of two nightlies that read the same pointer, one wins and the other exits 4.
  • Names can carry a namespace (skill/a@main): segments of letters, digits, ., _, @ or -, joined by /, 1-128 characters. Two kinds of name are refused, because Windows and macOS would read them as something else: a name Windows reserves for a device (con, nul.txt), and a name that differs from a saved one only in case (Main beside main). rm MAIN does not remove main.
  • runs baseline list prints each baseline with its run and when it was saved. runs baseline rm NAME removes the pointer and keeps the run. All three commands take --json (cli_output.v1).
  • On disk a baseline is the file <root>/.baselines/<NAME>. A / in the name is written %2F, and the file holds one line: the run_id.
  • runs gc --keep-baselines now also keeps the runs these pointers hold, as well as the runs of the baseline save copies it already kept. While it removes, it holds the same lock, so a save waits and then finds the run gone instead of pointing at it.
    • The lock file .baselines/.lock is made if missing. --dry-run takes no lock.
    • A pointer that cannot be read exits 2 before anything is removed. So does a .baselines/ that cannot be listed or locked, such as a file at that path.
  • The old store is left as it is. runs baseline does not read or change the copies that baseline save --from-eval writes under baselines/eval/. The baseline:NAME readers move in R-10.
  • --expect-previous is a canonical flag of the baseline concept in cli_flags.py. existing_root() moves from commands/runs.py to runs/scan.py, so both command modules use it.

Refs #94 R3

Changed output

These are new commands. runs gc --keep-baselines keeps more runs than before: the runs a pointer holds. Nothing else changes output.

$ python cli.py runs baseline save skill/a@main 20261101T000000Z-0000000a
saved baseline skill/a@main -> 20261101T000000Z-0000000a (1 artifact); before: none
$ python cli.py runs baseline save skill/a@main 20261102T000000Z-0000000b --expect-previous 20261101T000000Z-0000000a
saved baseline skill/a@main -> 20261102T000000Z-0000000b (1 artifact); before: 20261101T000000Z-0000000a
$ python cli.py runs baseline save skill/a@main 20261101T000000Z-0000000a --expect-previous 20261101T000000Z-0000000a
Error: baseline skill/a@main holds 20261102T000000Z-0000000b, not 20261101T000000Z-0000000a as --expect-previous says: another save moved it, so nothing was saved
                                                                                    # exit 4
$ python cli.py runs baseline list
NAME          RUN                        SAVED (UTC)
skill/a@main  20261102T000000Z-0000000b  2026-11-24 17:03

1 baseline under results/
$ python cli.py runs gc --older-than 0d --keep-baselines --dry-run
...
would remove 1 run older than 0d under results/: 1 artifact, 3,521 bytes
kept 1 run older than 0d that a baseline holds: 20261102T000000Z-0000000b (skill/a@main)
$ python cli.py runs baseline save ../x 20261101T000000Z-0000000a
Error: '../x' is not a baseline name: ...                                           # exit 2

Exit codes, also in the docs/runs.md table:

Exit Case
0 Saved, listed or removed
2 A bad name, RUN or --expect-previous; a run no artifact carries; no such baseline; no root; a .baselines/ that cannot be listed or locked
4 The --expect-previous conflict
5 A pointer that could not be written or removed

Evidence

  • tests/test_runs_baseline.py: 50 tests on a tmp runs root, against docs/runs.md "Baselines" and its exit-code rows. The runs suites together (baseline, rm/gc, scan, show): 288 passed, 1 skipped (the Windows junction test). The tests cover:
    • save, list and rm of a namespaced name, the pointer file's content, and list --json;
    • a save that moves the pointer and reports what it held;
    • CAS: success, a conflict on a moved pointer, on a missing baseline and on a pointer that holds no run id (exit 4, pointer unchanged, the --json fields);
    • two real cli.py processes. The test holds the lock and waits until /proc/locks shows both processes waiting on it, then releases. One process exits 0, the other 4, and the pointer holds the winner's run. This test is Linux only;
    • 16 refused names (../x, a//b, .hidden, a., a:b, a\b, "", 129 characters, con, NUL.txt, com1 …) and 7 accepted ones (128 characters, 43 segments, console);
    • the case rule for save and for rm;
    • refused runs, a write that fails (exit 5, the old pointer kept), rm of a missing baseline, and no root;
    • store entries that are not pointers;
    • runs list does not walk .baselines/;
    • gc --keep-baselines: it keeps a pointer's run, removes nothing when a pointer cannot be read, waits on the lock a test holds before removing anything (real process, Linux), takes no lock with --dry-run or without --keep-baselines, and exits 2 when .baselines is a file or a read-only directory with no lock.
  • Mutations by hand, each killed:
    • no CAS check;
    • no flock;
    • no pointers in gc;
    • the scan walks .baselines/;
    • no case check in save, and none in rm;
    • no device-name check;
    • no trailing-dot check;
    • a pointer with no run id read as valid;
    • gc under a null lock context, or with the lock taken always, or with the lock taken under --dry-run.
  • make ci-local --offline on the first commit (5c347a2): 0 failed.
    • Changed-line coverage was 90% (293 lines).
    • Mutation of changed lines: 35 of 40 killed. Of the 5 survivors, 4 are equivalent or cannot be seen here, and 1 is a test gap:
      • range(2)→range(3) for the list column widths: the third width is never used;
      • _HEAD 256→257: a pointer is at most 129 bytes;
      • range(10)→range(11) for COM/LPT: it would also refuse com10, which no test names;
      • check_name returning None: no caller uses its return value;
      • required=True on the baseline subparsers flipped to False is a gap. A bare runs baseline would then crash with AttributeError: 'Namespace' object has no attribute 'func', and no test runs the group without a subcommand. Today it exits 2 with argparse's usage error.
  • On the last commit: slot ci --quick (lint, mypy, CLI snapshot, the whole suite) 0 failed, 27576 passed. The full make ci-local --offline on it runs before publishing.
  • Not run: Windows (msvcrt.locking, the case-insensitive file system), macOS, a network file system's flock, and the other Python versions of the matrix.

Not in this PR

  • runs rm RUN_ID and runs gc without --keep-baselines still remove a run a baseline points to, which leaves the pointer dangling. runs baseline list does not check that the run still exists.
  • RUN given as a run name (--name, once feat(runs): run directories: run.json, and a result.v1 when a run is stopped #1150 lands), and --from RUN (R-8).
  • baseline:NAME in compare, and the move of the baseline save/compare readers (R-10).
  • runs export|import (the rest of R3).
  • baseline save --from-eval copies are not listed by runs baseline list.

Open questions

  • Exit 4 with reason: stale_baseline for a CAS conflict is my reading of §2.6, where invalid lists "a stale baseline". Is that the code we want, or should a lost race have its own code?
  • A save without --expect-previous moves an existing baseline, the way a plain pointer write would. Should it instead refuse, as git tag does without -f?
  • --expect-previous "" is refused as not a run id (exit 2), so there is no "create only if absent" form. The first nightly cannot race-proof its first save. Should there be such a form?

Checklist

  • Tests added/updated and pytest passes: tests/test_runs_baseline.py; slot ci --quick 0 failed
  • ruff, mypy, and schema checks pass: ci-local static and typecheck jobs pass
  • Docs updated: docs/runs.md (new "Baselines" section, --keep-baselines, exit-code rows), docs/quickstart.md (exit 4), docs/documentation-index.md, docs/reference/cli-interface.json regenerated
  • Self-reviewed per "Before opening a PR" in AGENTS.md: mutations above; bad inputs (../x, con.x, a run that does not exist, a second rm, .baselines as a file and read-only)
  • Each new raise/exit and test names the doc, contract or issue it traces to: docs/runs.md "Baselines" and its exit-code table, CLI API: the evaluation loop at the top level, subject and eval groups below, one enforced flag vocabulary (proposal v2.1) #94 §2.3/§2.6
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header: runs/baseline.py, commands/runs_baseline.py, tests/test_runs_baseline.py, the fragment

…vious

A baseline is a named pointer to a run, like a git tag (intel#94 §2.3, R3):
the file .baselines/<NAME> under the runs root holds the run_id, with
'/' in a namespaced name (skill/a@main) written %2F. RUN is a run_id
some artifact under the root carries, found by the scan as runs show
finds it. The pointer is replaced through write_text_atomic (intel#697).

Save and rm hold .baselines/.lock (flock, msvcrt on Windows), so
--expect-previous RUN_ID is a compare-and-swap: a baseline that does
not point to RUN_ID exits 4 (invalid, a stale baseline, §2.6) and is
left as it was, and of two nightlies that read the same pointer one
wins. A name Windows reserves for a device, or one that differs from a
saved one only in case, is refused.

runs gc --keep-baselines now keeps the runs these pointers hold as
well as those of the baseline save copies, and holds the same lock
while it removes. runs list does not walk .baselines/. The old
baseline save store under baselines/eval/ is left as it is.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
scan.BASELINES_DIR sat beside commands/baseline.BASELINES_DIR (the old
copies under baselines/eval/) in commands/runs.py, and runs/baseline.py
aliased it as STORE. It is now scan.BASELINE_POINTERS, used directly.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
save refuses a name that differs from a saved one only in case, since
Windows and macOS open them as one file, but rm read and unlinked the
path as given: there, rm MAIN removed main. rm now looks for the exact
file name in the store's listing under the lock and exits 2 otherwise,
naming the other spelling.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
gc took the baselines' lock only when .baselines/ existed, so a first
runs baseline save made alongside it could point at a run gc was
removing. It now takes the lock whenever it keeps baselines and removes
(not with --dry-run), making .baselines/.lock if missing; the docs drop
the exception. The rm/gc tests' file listing leaves the store out.

Refs intel#94

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

When the saves never waited on the lock, wait_until failed and the
Popen objects were never waited, so pytest blamed the next test for a
ResourceWarning. The processes now run in a context manager that kills
and waits any still running; the lock wait is a helper of its own.

Refs intel#94

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

docs/runs.md says gc holds the lock while it removes; with it replaced
by a null context every test still passed. A gc process now waits on
the lock the test holds and removes nothing until it is released, and
gc with --dry-run or without --keep-baselines takes no lock.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The gc row named only a manifest or copy that cannot be read; a pointer
that cannot be read, or a .baselines/ that cannot be listed, exits 2
too. runs baseline list exits 2 for a .baselines/ it cannot list (a
file, no permission), and 0 for an entry that is not a pointer.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Since gc --keep-baselines takes the lock even before the first save,
locked() ran its mkdir and open with no handling: a file at .baselines
or a read-only store without .lock printed a traceback and exited 5,
where docs/runs.md says exit 2. locked() now raises InputError
('.baselines/: cannot lock: not a directory'), for gc, save and rm.

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 24, 2026 17:53
@vlad-perevezentsev vlad-perevezentsev self-assigned this Nov 24, 2026
@github-actions github-actions Bot added the cli-interface-change Changes dokimi's user-facing CLI surface label Nov 24, 2026
@github-actions

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 baseline`
    + option `--help/-h`
+ added command `dokimi runs baseline list`
    + option `--help/-h`
    + option `--json`
+ added command `dokimi runs baseline rm`
    + argument `name`
    + option `--help/-h`
    + option `--json`
+ added command `dokimi runs baseline save`
    + argument `name`
    + argument `run`
    + 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.

@exai-bot

exai-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

🔍 OpenCodeReview found 1 issue(s) in this PR.

CI at e5db012: 21 passing, 4 skipped.

By label: 1 should fix

Label Location Finding
should fix baseline.py:146 Impact: a valid concurrent baseline save or removal can fail with exit 5 on Windows merely because runs baseline list is reading th...
Test notes (2)
  • dokimi/dokimi/runs/baseline.py:154: With if len(data) > _HEAD: # what follows the first 256 bytes would not be read changed to if len(data) >= _HEAD: # what follows the first 256 bytes would not be read, the tests still pass: dokimi/tests/test_runs_baseline.py, dokimi/tests/test_runs_rm_gc.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
  • dokimi/dokimi/runs/baseline.py:118: With raise changed to raise raise, the tests still pass: dokimi/tests/test_runs_baseline.py, dokimi/tests/test_runs_rm_gc.py. If this condition matters, a test should pin it.
Review details
  • Commit reviewed: e5db012 against merge base f8b5e1d
  • Coverage: 14 files in 3 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 847k tokens (575k from cache), 2m3s
  • Tool calls: 63 (33 file_read, 11 pr_threads, 6 code_search, 5 file_read_diff, 3 local_check_results, 2 ci_log_search, 2 ci_status, 1 code_comment)
  • Runs baseline documentation and CLI reference: 5 files
  • Runs baseline implementation, CLI integration, and tests: 7 files
  • Run removal and garbage collection: 2 files

Comment thread dokimi/dokimi/runs/baseline.py Resolved
Comment thread dokimi/dokimi/runs/baseline.py Resolved
Comment thread dokimi/tests/test_runs_baseline.py Resolved
@codecov-commenter

codecov-commenter commented Nov 24, 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 92.55014% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.11%. Comparing base (f8b5e1d) to head (e5db012).

Files with missing lines Patch % Lines
dokimi/dokimi/runs/baseline.py 91.78% 14 Missing and 4 partials ⚠️
dokimi/dokimi/commands/runs_baseline.py 90.24% 6 Missing and 2 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1184      +/-   ##
==========================================
- Coverage   96.15%   96.11%   -0.04%     
==========================================
  Files         498      500       +2     
  Lines       65973    66306     +333     
  Branches    11456    11491      +35     
==========================================
+ Hits        63436    63732     +296     
- Misses       1569     1595      +26     
- Partials      968      979      +11     
Files with missing lines Coverage Δ
dokimi/dokimi/cli_flags.py 100.00% <ø> (ø)
dokimi/dokimi/cli_routes.py 97.89% <ø> (ø)
dokimi/dokimi/commands/runs.py 100.00% <100.00%> (ø)
dokimi/dokimi/runs/rm.py 99.01% <100.00%> (+0.13%) ⬆️
dokimi/dokimi/runs/scan.py 99.03% <100.00%> (+0.02%) ⬆️
dokimi/dokimi/commands/runs_baseline.py 90.24% <90.24%> (ø)
dokimi/dokimi/runs/baseline.py 91.78% <91.78%> (ø)

... and 6 files with indirect coverage changes

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

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
_read() opened every store entry in blocking mode, so a FIFO named like
a pointer hung runs baseline list, rm and save, and gc
--keep-baselines while it held the lock. It now opens with O_NONBLOCK
and refuses what fstat says is not a regular file, so list names it
unreadable, gc and save exit 2, and rm removes it.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
The case rule reads the store's names, and a listing that failed (a
store the user may write but not read) was taken as no other spelling:
save Main went through beside main, and rm exited 5. Both now exit 2,
'.baselines/: cannot list: <reason>', through one listing helper that
list uses too.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Both tests started the cli.py processes and only then took the lock,
so a process that got it first saved (or removed) and exited, and the
wait for two waiters timed out on correct code. The test now holds the
lock before Popen, waits for the waiters, then releases it; _cli()
still kills what is left.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
1a2b63c kept a FIFO pointer from blocking, but gc --keep-baselines
then reads baselines/eval/manifest.json and each copy it lists in
blocking mode, under the baselines' lock: a FIFO there hung gc and
every runs baseline save or rm behind it. Both are now looked up
first and refused (exit 2) when they are not a regular file.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Comment thread dokimi/dokimi/runs/baseline.py Resolved
Comment thread dokimi/dokimi/runs/baseline.py Resolved
Comment thread dokimi/dokimi/runs/baseline.py Resolved
runs rm PATH removed any file under the root, .baselines/.lock too:
removed while a save or gc held it, the next save locked a new inode
and ran beside them, and a pointer removed this way skipped the lock
and the case rule. A path that resolves into .baselines/ now exits 2
and names runs baseline rm.

Refs intel#94

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

_read() took the first 256 bytes and stripped them, so a run id padded
with spaces past byte 256 and followed by anything else read as that
run id: list and gc trusted it, and --expect-previous matched it. A
pointer longer than that now cannot be read: list names it, gc and save
exit 2.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
A dangling symlink in .baselines/ is listed as unreadable and stops gc
--keep-baselines, but rm read it, got nothing (its target is missing)
and said there was no such baseline. The name is in the store's
listing, so rm now removes the link like any pointer it cannot read.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
75432c9 compared the first part of the resolved path with
'.baselines', but contained() resolves directories: through a
.baselines that links to a directory under the root, or spelled in
another case on a case-insensitive file system, the lock resolved
under another name and was removed. A file whose directory is the
store by device and inode is now refused too.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
ed03185 dropped the 'missing' branch to let rm unlink a link to
nothing, but _read() also returns None for a pointer a process that
does not lock removed after the listing: unlink then raised
FileNotFoundError and rm exited 5 as an infra error. unlink's
FileNotFoundError is now 'no baseline NAME' (exit 2); a link to
nothing still goes, since unlink does not follow it.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Since ed03185 and 1a2b63c, rm is how an entry that list names as
unreadable, and that stops gc --keep-baselines, goes: a link to nothing,
a FIFO, a file over 256 bytes, text that is not UTF-8. The rm bullet now
says so, On disk states the 256-byte limit of 06296a2, and the test
cites the line it checks.

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 6af90e1)

  • Contract: changed. errors dokimi/dokimi/commands/runs.py:367; errors dokimi/dokimi/commands/runs_baseline.py:26
  • Responsibility: candidate. delegate cmd_runs_gc in dokimi/dokimi/commands/runs.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The baseline, removal, scan and show suites passed on Linux (303 passed, one skipped), including the two-process compare-and-swap test. Please address the baseline store boundary before merge. I also found a small consistency issue in the timestamp returned by list.

Comment thread dokimi/dokimi/runs/baseline.py Resolved
Comment thread dokimi/dokimi/runs/baseline.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
store() returned <root>/.baselines as spelled, so a symlink out of the
root sent save, rm and gc --keep-baselines's lock there, and list read
pointers from there, against the root boundary in docs/runs.md. store()
now refuses a store whose resolved path is outside the root (exit 2)
before anything reads or writes it; a link to a directory under the
root is still used.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
_entry() read the pointer, then looked up its mtime by path: a save in
between gave a row with the old run id and the new save's time. The
mtime now comes from fstat of the file descriptor the run id was read
from.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
860e1a9 checked the store directory only. A pointer that links out of
the root was read (list showed it, gc --keep-baselines kept its run),
and a .lock that links out was created and locked there. Pointers and
the lock are now opened with O_NOFOLLOW after an islink check: a linked
pointer is unreadable (rm removes the link), a linked lock exits 2.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
860e1a9 refused a store that resolves outside the root but took one
linked to the root or to a run's directory: there rm NAME removed a
run's file (rm eval.json through .baselines -> a) and, linked to the
root, every run directory read as a bad pointer, so gc
--keep-baselines always exited 2. dokimi makes the store as a plain
directory, so any link (a symlink or a junction) is now refused with
exit 2.

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 8aeed81)

  • Contract: changed. errors dokimi/dokimi/commands/runs.py:367; errors dokimi/dokimi/commands/runs_baseline.py:26
  • Responsibility: candidate. delegate cmd_runs_gc in dokimi/dokimi/commands/runs.py
  • Dependency: none
  • Review depth: check the changed surface: callers, docs, tests pin new behaviour
  • Coverage gaps: none

The pointer ID and saved timestamp now come from one open file descriptor. The new baseline-store check covers symlinks, but one supported Windows version still lacks junction detection at that call site. I reviewed the path checks statically and checked CI.

Comment thread dokimi/dokimi/runs/baseline.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 small thing I've marked fix before merge (in the line comments) and fix what napetrov's thread on dokimi/dokimi/runs/baseline.py:70 still points out? I'll approve once that's done.
I'll approve once that's done.

What I checked on 8aeed81:

  • When I broke the changed code on purpose, the tests missed 9 of 12 breakages.
  • The 130 changed tests pass, and fail on main as expected.
  • The full test suite passes with main merged in (31,941 tests), apart from failures main has too.
  • It merges cleanly onto main.

Comment thread dokimi/dokimi/commands/runs_baseline.py Resolved
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
store() tested a junction with os.path.isjunction, which Python 3.11
lacks, so there the fallback never refused one, against docs/runs.md.
It now uses the scan's own link check, made public as scan.is_link,
which reads st_reparse_tag on every version.

Refs intel#94

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
def _read_with_mtime(path: Path) -> tuple[str, float] | None:
""":func:`_read`, and the mtime of the file it read: one open file, so both are of one save."""
try: # O_NONBLOCK: opening a FIFO with no writer would wait for one
fd = _open_unlinked(path, os.O_RDONLY | getattr(os, "O_NONBLOCK", 0))

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 · should fix
Impact: a valid concurrent baseline save or removal can fail with exit 5 on Windows merely because runs baseline list is reading the pointer.

Trigger: pause a listing after this open, then save over (or remove) the same baseline.

Evidence: _open_unlinked() uses ordinary os.open, whose Windows CRT handle does not share delete access; listing takes no shared lock and keeps that handle open through fstat and reading. write_text_atomic() calls os.replace without retrying sharing violations, and remove() similarly calls unlink, so the mutation lock does not prevent this reader/writer conflict.

Fix: Use a Windows reader that permits delete sharing, or otherwise coordinate readers and mutations while preserving list's read-only contract; add a Windows regression test holding the reader open during replacement/removal.

Workaround: serialize listing with saves/removals externally, or retry the failed mutation after listing finishes.

Should fix: A run shows it; it was not judged to be met in ordinary use.

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

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

python proof_c1.py save

What the proof does: Calls the real listing and save handler in a fixed interleaving, using stand-ins for Windows handle sharing and locking, and checks that saving succeeds while the listing reads the original pointer.

The problem shows as the output ASSERTION: listing must not block a baseline mutation.

Script: dokimi/proof_c1.py (125 lines).

Error: baseline main: cannot write: simulated Windows sharing violation
Traceback (most recent call last):
  File "/tmp/tmp.gWaDXvT7Ll/dokimi/proof_c1.py", line 118, in <module>
    assert status == [0], 'ASSERTION: listing must not block a baseline mutation'
           ^^^^^^^^^^^^^
AssertionError: ASSERTION: listing must not block a baseline mutation

This branch has not been deployed

No deployments
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