Skip to content

fix(catalog): catalog eval receipts keep the group and mode of the files a rerun replaces - #1348

Merged
xaleryb merged 3 commits into
intel:mainfrom
antonwolfy:fix/catalog-receipts-owner
Nov 28, 2026
Merged

xaleryb merged 3 commits into
intel:mainfrom
antonwolfy:fix/catalog-receipts-owner

Conversation

@antonwolfy

@antonwolfy antonwolfy commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#1220: catalog eval --out-dir stages its four receipts (catalog.json, plan.json, result.json, report.md) as new files and _replace_receipts renames them over the previous ones, so a rerun loses their group and mode, the same cause as #1067 and #1165. On main, with out/catalog.json at 0o640 in a supplementary group (4) and a newly staged catalog.json, _replace_receipts(out, staged, backup) leaves group 1000 and mode 0o644 (the staged file's mode); a 0o600 report.md comes back 0o644.

Fix option taken: the first one the issue lists. The old receipt's stat is read once it is moved aside, and the staged file gets its mode and, where the user may, its group before the rename. This keeps the move-aside rollback, which the existing tests pin, and the directory is still never renamed or removed. Staging with write_text_atomic straight into out would change what those rollback tests observe and what _write_error leaves behind.

Closes #1220

Changes

  • dokimi/atomic_write.py: new keep_owner_group_mode(path, old). It gives a file the user owns the group (root: also the owner) of old through _keep_owner_and_group, then its mode with os.chmod, last, as _publish does. A user who may not give the group keeps the file's own group without an error.
  • dokimi/commands/catalog_eval.py: _replace_receipts calls it through a small _keep_previous_owner for each staged name whose previous receipt was moved aside. A name with no previous file, or a previous one that is not a regular file, is placed as before (umask mode).
  • keep_owner_group_mode also removes the system.posix_acl_access the staged file inherited from the output directory's default ACL before the os.chmod, as _publish does, so the chmod's mask does not activate a named user the previous receipt never granted.
  • dokimi/commands/catalog_eval.py: the rollback removes a placed receipt through _unlink_receipt, which makes a read-only one writable first, as Windows refuses to unlink a read-only file and a previous read-only receipt now gives a read-only new one.
  • Tests in tests/test_catalog_eval_cli.py: group and mode kept (skips when the user has no supplementary group), mode alone, a refused group change publishes in the user's own group with the mode kept, no inherited ACL entry on the new receipt, and a first run keeps the staged mode.
  • Tests in tests/test_catalog_eval_rollback.py: a failed swap restores the previous receipts when the unlink of a read-only new one is refused, and a previous receipt that is a link is replaced without taking its target's mode.
  • Changelog fragment (Fixed).

Risk

A rerun now leaves the receipts with the group and mode the previous ones had, not the umask mode: a receipt made read-only or group-private stays so. The rollback still restores the old inodes, which kept their group and mode, and _RollbackFailed still names the kept backup; it now also clears the read-only mode of a new receipt before removing it. As root, a refused chown or chmod of a staged receipt raises and the previous receipts are put back, where the file was left in the root's group before. Open PRs #1190, #1247 and #1324 also change catalog_eval.py, but only its InputError import line and _emit; this PR adds one import line and _keep_previous_owner, so a merge with them is trivial.

Testing

On a Linux review host, at 9abefde6 (on main 16738246):

  • make ci-local: 38 passed, 0 failed, 15 skipped (docker smoke, pinned Claude Code, jobs conditional on a PR, matrix legs, conda-forge, atheris fuzz, semgrep). 30121 tests passed, 23 skipped; with the catalog eval tests, catalog_eval.py has no uncovered or partial changed line.
  • On main's code the new tests fail: 3 failed, 2 passed of the selected five; the first assertion is (1000, '0o644') == (4, '0o640') for the issue's repro.
  • Mutants: dropping the os.chmod fails the group and mode, mode and refused-group tests; dropping the group change fails the group and mode test ((1000, '0o640') == (4, '0o640')); making a first run chmod the staged file to 0o600 fails the first-run test; calling the plain unlink in the rollback again makes the swap raise _RollbackFailed ([Errno 13] read-only) instead of the injected failure, and dropping the regular-file check fails the linked-receipt test.
  • Not run: the other Python versions (3.11, 3.12, 3.14), Windows (the read-only unlink refusal is simulated by a patched Path.unlink), and a run as root.

Open questions

None.

Revert

A plain revert restores the old behaviour (rerun receipts get the umask mode and the user's primary group). 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)

…les a rerun replaces (intel#1220)

_replace_receipts renamed freshly staged files over the previous catalog.json, plan.json, result.json and report.md, so a 0o640 receipt in a supplementary group came back 0o664 in the user's primary group.

The staged file now gets the previous receipt's mode and, where the user may, its group (root also the owner) before the rename, through the new dokimi.atomic_write.keep_owner_group_mode, which reuses _keep_owner_and_group and sets the mode last. The move-aside rollback is unchanged, a receipt with no previous file keeps the umask mode, and a group the user may not give is skipped without an error.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy
antonwolfy requested a review from a team as a code owner November 27, 2026 18:34
@antonwolfy antonwolfy self-assigned this Nov 27, 2026
@codecov-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

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

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1348      +/-   ##
==========================================
+ Coverage   96.19%   96.21%   +0.02%     
==========================================
  Files         499      509      +10     
  Lines       66465    67786    +1321     
  Branches    11542    11767     +225     
==========================================
+ Hits        63933    65222    +1289     
- Misses       1563     1578      +15     
- Partials      969      986      +17     
Files with missing lines Coverage Δ
dokimi/dokimi/atomic_write.py 98.76% <100.00%> (+0.06%) ⬆️
dokimi/dokimi/commands/catalog_eval.py 98.96% <100.00%> (+0.09%) ⬆️

... and 38 files with indirect coverage changes

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

@exai-bot

exai-bot commented Nov 27, 2026 •

Copy link
Copy Markdown

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

CI at 9abefde: 21 passing, 4 skipped.

Test notes (3)
  • dokimi/tests/test_catalog_eval_rollback.py: dokimi/tests/test_catalog_eval_rollback.py passes at the head and also at the merge base, where the code this pull request changes is still as it was. No test in it fails without the change, so none of them would notice if the change were undone.
  • dokimi/dokimi/commands/catalog_eval.py:116: With try: path.unlink(missing_ok=True) changed to try: pass, the tests still pass: dokimi/tests/test_catalog_eval.py, dokimi/tests/test_catalog_eval_cli.py, dokimi/tests/test_catalog_eval_rollback.py. If this condition matters, a test should pin it.
  • dokimi/dokimi/commands/catalog_eval.py:136: With _unlink_receipt(out / name) changed to pass, the tests still pass: dokimi/tests/test_catalog_eval.py, dokimi/tests/test_catalog_eval_cli.py, dokimi/tests/test_catalog_eval_rollback.py. If this condition matters, a test should pin it.
Review details
  • Commit reviewed: 9abefde against merge base a7fcdf9
  • Coverage: 3 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 87k tokens (40k from cache), 25s
  • Tool calls: 8 (5 file_read, 1 ci_status, 1 code_search, 1 local_check_results)
  • small change set: 3 files

Comment thread dokimi/dokimi/atomic_write.py Resolved
Comment thread dokimi/dokimi/commands/catalog_eval.py Resolved
The staged receipt inherits an access ACL from the output directory's
default ACL; the chmod that restores the old mode widened its mask, so a
named user the old receipt never granted could read it. Drop the
inherited access ACL before the chmod, as _publish does.

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

xaleryb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor
  • Ran on Linux, Python 3.13, on the head merged with current main: the full suite, ruff, mypy, bandit -ll, the growth and comment-block checks, docs check --strict, and a real catalog eval rerun on a 0o640 catalog.json in group adm and a 0o600 report.md. Both kept their mode and group; on main they came back 0o664 in the user's group. A rerun that fails leaves the old receipts byte-identical.
  • The inherited-ACL thread on atomic_write.py:273 reproduces. Setup: the out dir has a default ACL user:12345:r-x,mask::--- and the old report.md is 0o640 with no ACL. On main user 12345 cannot read the new receipt. At the head the chmod widens the mask to r--, so user 12345 can read it. Expected: the receipt keeps the ACL state of the one it replaces.
  • Commit to push: a7fcdf9 drops the inherited access ACL before the chmod, as _publish does. It adds a test that sets a real ACL and fails without the fix, plus one sentence in the PR's changelog fragment.
  • The Windows read-only rollback thread on catalog_eval.py:122 does not reproduce on Linux. Left to the author to confirm on Windows.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

13 mutants of the lines this PR changes, at 9abefde: 8 killed, 5 survived, 0 waived, 0 inconclusive, 0 timed out, 0 errors, 0 not run.

A survivor is a change to that line that the tests covering it do not notice: add an assertion that fails on it or, if the change cannot alter behaviour, put # mutation-ok[<operator>]: <reason> at the end of the line or alone on the line above.

Line Operator Was Became Tests run
dokimi/dokimi/atomic_write.py:272 delete-statement os.close(fd) pass 16
dokimi/dokimi/commands/catalog_eval.py:116 delete-statement path.unlink(missing_ok=True) pass 2
dokimi/dokimi/commands/catalog_eval.py:119 delete-statement path.unlink(missing_ok=True) pass 1
dokimi/dokimi/commands/catalog_eval.py:136 delete-statement _unlink_receipt(out / name) pass 2
dokimi/dokimi/commands/catalog_eval.py:119 flip-bool True False 1

Warn-only: a survivor does not fail the job yet. Updated on every push; the full report is in the ci run summary.

…efore restoring the old ones

A staged receipt now takes the mode of the one it replaces, so a read-only previous receipt makes a read-only new one. Windows refuses to unlink a read-only file, so the rollback of a later failed rename stopped with _RollbackFailed and left a partial set. The rollback now makes the placed receipt writable before it removes it. Settles the review thread on catalog_eval.py:122.

Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
@antonwolfy

Copy link
Copy Markdown
Contributor Author
  • Ran on Linux, Python 3.13, on the head merged with current main: the full suite, ruff, mypy, bandit -ll, the growth and comment-block checks, docs check --strict, and a real catalog eval rerun o

@xaleryb (#1348 (comment)): The ACL thread is already fixed by a7fcdf9 (see 4722748478). The Windows thread did not reproduce on Linux as the comment says, since Linux unlinks a read-only file; it is fixed in 9abefde against a simulated Windows refusal (see 4722748483).

@antonwolfy
antonwolfy requested a review from xaleryb November 28, 2026 12:19

@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 9abefde. A catalog eval rerun keeps the mode and group of the receipts it replaces, a failed rerun leaves them intact, and no inherited default ACL widens access (our commit); the author's last commit makes a read-only new receipt writable before the rollback removes it, which settles the Windows thread. Checks are green on this head. Windows smoke had not started (the hosted Windows queue was stuck); every other check passed.

@xaleryb
xaleryb merged commit 3b35e6b into intel:main Nov 28, 2026
25 checks passed
@antonwolfy
antonwolfy deleted the fix/catalog-receipts-owner branch November 28, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catalog eval: the receipts it rewrites lose their group and mode (_replace_receipts renames new files over them)

4 participants