Skip to content

fix(repo): refuse a --cache-root, --cache or $DOKIMI_REPO_CACHE that is not a usable directory with exit 2 - #891

Open
antonwolfy wants to merge 2 commits into
intel:mainfrom
antonwolfy:fix/cache-path-usable
Open

antonwolfy wants to merge 2 commits into
intel:mainfrom
antonwolfy:fix/cache-path-usable

Conversation

@antonwolfy

Copy link
Copy Markdown
Contributor

Summary

Two unusable cache paths still reached an unguarded mkdir, the cause #765 fixed for --cache-dir. On main:

Input Output on main Exit
eval check <repo> --cache-root <regular file> (and repo run) building dokimi/toy:... (tasks removed), then ✗ [Errno 20] Not a directory: '<file>/build-cache' 1
eval check <repo> --cache build-cache=<regular file> (and repo run) the image is built, then ✗ [Errno 17] File exists: '<file>' 1
DOKIMI_REPO_CACHE=<regular file> dokimi repo fetch file:///.../nothere@HEAD (and scan, reach, eval check) ✗ [Errno 17] File exists: '<file>' 1

Neither message names the flag or the variable, and the image is built before the first two fail. Now each is refused up front with exit 2, naming the setting and the path, e.g. --cache-root /p/file is not a directory; pass a directory the build caches can be kept in and $DOKIMI_REPO_CACHE /p/file is not a directory; pass a directory the repository clones can be cached in.

For #826 the PR takes the first fix option (check with the shared usable_cache_dir before the image build), because it fails before anything is exported or built. For #827 it takes the first option too (check the variable in _cache_dir), because every repo command that clones goes through it and it needs no change to repos/source.py, which open PR #783 edits.

Closes #826
Closes #827

Not fixed here, and not the same cause: the three other sites that make a cache directory from a setting (DOKIMI_RESPONSE_CACHE, XDG_CACHE_HOME for the CLI work dir, $HOME for the Harbor export cache) already name the problem or are not a dokimi setting; nothing to track.

Changes

  • commands/cache_dir.py: usable_cache_dir takes a keyword label (default --cache-dir) that starts each of its four messages; every existing message is unchanged. New constant CACHE_USE.
  • commands/repo_run.py (eval check and repo run: --cache-root or --cache naming a regular file exits 1 with a bare [Errno 20] after the image build #826): _check_cache_paths(args, manifest) is called in _context right after the manifest is known and before the export and the image build. It checks --cache-root, each --cache NAME=PATH for a cache the manifest declares (label --cache NAME), and <--cache-root>/<name> for each declared cache without an override. A --cache naming an undeclared cache keeps its existing message. eval check and repo run let the InputError through their ValueError handler, which would otherwise print it as ✗ ... with exit 1.
  • commands/repo.py (DOKIMI_REPO_CACHE naming a regular file makes repo commands exit 1 with a bare [Errno 17] #827): _cache_dir checks a non-empty $DOKIMI_REPO_CACHE with usable_cache_dir (label $DOKIMI_REPO_CACHE) when --cache-dir is unset or empty. A flag that is given wins and the variable is not looked at.
  • Help text of eval check, repo run and eval tasks generate, docs/repo-evaluation-contract.md (the exit-2 paragraph of eval check / repo run and §9 Running) and docs/quickstart.md name the new cases.
  • Tests: tests/test_repo_run_cache_paths_usable.py, tests/test_repo_cache_env_usable.py, tests/test_cache_dir_label.py. No existing test changed.
  • Changelog fragments (Fixed), one per issue.

Risk

Inputs that were taken before are refused now with exit 2: a --cache-root, --cache or $DOKIMI_REPO_CACHE that is a regular file, below one, or (for --cache-root) holds a regular file named after a cache. These failed later with exit 1 anyway, except for a $DOKIMI_REPO_CACHE next to a local-directory source or a command that never clones (for example repo validate of a local path), which used to ignore the variable and now exit 2, as --cache-dir does since #765. A read-only existing directory still passes. The default cache root (no --cache-root) is not checked in _context; it follows $DOKIMI_REPO_CACHE, which _cache_dir now checks earlier in the same command. The diff touches repo_run.py only in the helper, its one call, two except InputError: raise lines and one help string, to merge cleanly with the open PRs on that file: #781, #782, #787 and #810 add flags and _run_locked lines (#810 also edits the repo run exception handlers, next to the except InputError: raise line), and #783 edits _context around _require_grade; none changes the lines this diff edits, so a textual conflict is possible only at the handler of repo run.

Testing

On Linux, at 18360fd (on main a98a0e7):

  • make ci-local: 36 passed, 0 failed, 14 skipped (steps that need a PR job, micromamba, semgrep, the fuzz run and the other-Python matrix legs). 22751 tests passed, 19 skipped; changed-line coverage 100% (25 lines); mutation of changed lines: 4 of 4 killed.
  • On main's code the new tests fail where the bug is: test_repo_run_cache_paths_usable.py 8 failed, 5 passed (assert 1 == 2: exit 1, not 2, after building ...), test_repo_cache_env_usable.py 6 failed, 2 passed (same), test_cache_dir_label.py 3 failed, 1 passed (TypeError: no label parameter).
  • Mutants: 16 single breaks of the new code (each check dropped, the call moved after the build, a label ignored, the variable unchecked, winning over the flag, or returned unchecked, the handlers' re-raise dropped, ...) each fail at least one new test.
  • Not run: the other Python versions (3.11, 3.12, 3.14), real docker.

Open questions

None.

Revert

A plain revert restores the old behaviour (exit 1 with a bare [Errno ...], after the image build for the first two). Nothing is stored.

Checklist

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)

…ctory with exit 2, before the image build (intel#826)

`eval check` and `repo run` made each cache directory with `mkdir(parents=True, exist_ok=True)` after the image build, so a `--cache-root` or `--cache NAME=PATH` naming a regular file (or lying below one, or a `--cache-root` holding a regular file named after a cache) ended in `✗ [Errno 20] Not a directory` with exit 1, and the message did not name the flag.

`_context` now checks those paths with the shared `usable_cache_dir` right after the manifest is known and before the export and the build, and raises `InputError` naming the flag, the path and what to pass, so the command exits 2. `usable_cache_dir` takes the name of the setting as a `label` keyword (default `--cache-dir`, so every existing message is unchanged). A `--cache` naming no cache of the manifest keeps its existing message. `repo run` and `eval check` let the `InputError` through their `ValueError` handler instead of printing it as a failed run.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
… with exit 2 naming the variable (intel#827)

With no `--cache-dir`, `default_cache_dir()` returned `$DOKIMI_REPO_CACHE` unchecked and `ensure_clone` then ran `mkdir(parents=True, exist_ok=True)` on it, so a variable naming a regular file ended in `✗ [Errno 17] File exists` with exit 1, and the message did not name the variable.

`_cache_dir` in `commands/repo.py` now checks a non-empty `$DOKIMI_REPO_CACHE` with `usable_cache_dir` when `--cache-dir` is unset, labelled `$DOKIMI_REPO_CACHE`, so every repo command that clones (they all go through `_cache_dir`) exits 2 before any clone, with the variable and the path in the message. A `--cache-dir` that is given wins and the variable is not looked at; an empty variable counts as unset; `repos/source.py` is untouched.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 17, 2026 20:36
@antonwolfy antonwolfy self-assigned this Nov 17, 2026
@exai-bot

exai-bot commented Nov 17, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 11 selected item(s).

CI at `18360fd`: 6 failing, 24 passing, 3 skipped

All six failing checks report the same file-length ratchet violation: repo.py measures 802 lines against an 800-line cap. This change adds seven lines to that file; the GitHub tests run the PR merge commit (8e2f2f2), explaining why CI reports more lines than the 797-line reviewed head. Shortening the cache-path documentation by two lines preserves behavior and brings the reported merged file...

Check Status Assessment
Test Linux Python 3.11 failing at step Install the package and run ci/test.py Caused by this PR. The seven-line addition to repo.py pushes the CI tree over the production file-length cap; the sole failed test is the growth ratchet. Fix proposed, not run: repo.py:608-611.
Test Linux Python 3.14 failing at step Install the package and run ci/test.py Caused by this PR. The same seven-line addition exceeds the 800-line cap in the CI tree; this is not a Python-version-specific failure. Fix proposed, not run: repo.py:608-611.
Test Linux Wheels Python 3.11 failing at step Install the wheel and run ci/test.py Caused by this PR. The wheel test job fails the same source-tree growth ratchet after this change adds seven lines to repo.py. Fix proposed, not run: repo.py:608-611.
Test Linux Wheels Python 3.14 failing at step Install the wheel and run ci/test.py Caused by this PR. The wheel test job fails the same growth ratchet because the expanded repo.py exceeds the production cap. Fix proposed, not run: repo.py:608-611.
Tests (py3.11) failing at step Run tests Caused by this PR. The PR merge tree exceeds the cap after the seven-line addition; removing this addition would leave the measured file at 795 lines. Fix proposed, not run: repo.py:608-611.
Tests (py3.14) failing at step Run tests Caused by this PR. This job reports the identical 802-line violation introduced by expanding repo.py, with no other failed tests. Fix proposed, not run: repo.py:608-611.
Review details
  • Commit reviewed: 18360fd against merge base a98a0e7
  • Coverage: 11 files in 2 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 324k tokens (219k from cache), 42s
  • Tool calls: 24 (14 file_read, 5 code_search, 2 ci_status, 2 file_read_diff, 1 local_check_results)
  • Usable cache paths in commands and generated tasks: 7 files
  • Repository cache environment usability and contract: 4 files

@codecov-commenter

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 91.30435% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.78%. Comparing base (a98a0e7) to head (18360fd).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
dokimi/dokimi/commands/repo_run.py 87.50% 0 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     #891      +/-   ##
==========================================
- Coverage   95.79%   95.78%   -0.02%     
==========================================
  Files         429      430       +1     
  Lines       56842    57164     +322     
  Branches     9787     9858      +71     
==========================================
+ Hits        54452    54754     +302     
- Misses       1487     1496       +9     
- Partials      903      914      +11     
Files with missing lines Coverage Δ
dokimi/dokimi/commands/cache_dir.py 100.00% <100.00%> (ø)
dokimi/dokimi/commands/repo.py 98.98% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/commands/tasks_generate.py 93.63% <ø> (ø)
dokimi/dokimi/commands/repo_run.py 96.43% <87.50%> (+0.63%) ⬆️

... and 12 files with indirect coverage changes

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

Comment on lines +608 to 611
With no ``--cache-dir``, a non-empty ``$DOKIMI_REPO_CACHE`` is checked the same way and returned, so a bad
variable is a usage error naming it (#827); a flag that is given wins and the variable is not looked at.
An existing read-only directory passes on purpose: a populated one replays without writing. An empty one
is not told apart without the clone URL, so its clone fails later with exit 1.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

CI check Test Linux Python 3.11 fails: The seven-line addition to repo.py pushes the CI tree over the production file-length cap; the sole failed test is the growth ratchet. Proposed fix, not run by the bot.

CI check Test Linux Python 3.14 fails for the same reason.

CI check Test Linux Wheels Python 3.11 fails for the same reason.

CI check Test Linux Wheels Python 3.14 fails for the same reason.

CI check Tests (py3.11) fails for the same reason.

CI check Tests (py3.14) fails for the same reason.

Suggested change
With no ``--cache-dir``, a non-empty ``$DOKIMI_REPO_CACHE`` is checked the same way and returned, so a bad
variable is a usage error naming it (#827); a flag that is given wins and the variable is not looked at.
An existing read-only directory passes on purpose: a populated one replays without writing. An empty one
is not told apart without the clone URL, so its clone fails later with exit 1.
Without the flag, non-empty ``$DOKIMI_REPO_CACHE`` is checked and returned; a bad value is a usage error naming it (#827). The flag wins.
Read-only directories pass for cached replay; an empty one cannot be detected without the clone URL and fails later with exit 1.

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

None yet

Projects

None yet

3 participants