mask_channels: make the --json staging deletable when a replace fails (MASK-CHANNELS-STAGE-CLEANUP) #782

Open
github-bot wants to merge 1 commit from github-bot/gh-782 into main AGit
Owner

@⁠djrolfes on GitHub · 2026-11-24 13:45 UTC · original
djrolfes:djrolfes/mask-channels-stage-cleanup → main · +50 −6 · 2 files · 1 commits · open

Claimed in the coordination issue as: MASK-CHANNELS-STAGE-CLEANUP (#14)

Depends on: none

Fixes: none (the work item is the finding in issue #14; there is no separate issue to close)

Independent branch update

Head 9a3ee25fd, based on e18b59a5b, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so Depends on: none is accurate. Retested on Linux: 10 tests pass, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against 5da72d19f. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted.

What and why

tools/mask_channels.py publishes --json through a staging file that is chmod'ed to the destination's permission bits before os.replace. When the replace fails over a read-only report on Windows, the staged file is read-only, so the TemporaryDirectory cleanup cannot delete it: the staging folder is stranded beside the report and the cleanup's PermissionError masks the real failure, so the tool's one-ERROR:-line promise breaks exactly when it matters.

This publishes through a named staging file (mkstemp next to the destination, same folder creation and same report content) with an explicit cleanup in a finally: make the staged file writable (0o600) before unlinking and suppress the cleanup error, so a failed write is still one ERROR: line and exit 2, the old report stays in place, and a KeyboardInterrupt mid-write still cleans up. The shape is the one navmesh_index.py and bvh_index.py already use for their staging cleanup.

Tested

  • python3 -I tests/test_mask_channels.py: 10 tests OK, including the new test_failed_replace_of_read_only_report_removes_writable_temp, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a 0o444 report, asserts exactly one ERROR: line naming the replace error, the old report untouched, no .mask-json- staging file left behind, and that the staged file was made deletable before unlinking).
  • python3 -m compileall -q tools/mask_channels.py tests/test_mask_channels.py clean; tests/test_report_paths.py and tests/test_text_write_line_endings.py still OK.
  • python3 -I scripts/check_no_game_data.py tools/mask_channels.py tests/test_mask_channels.py passes; synthetic images only.

GPUs tested: n/a (standard-library tool; no game files, nothing online)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
**@⁠djrolfes** on GitHub · 2026-11-24 13:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/782) `djrolfes:djrolfes/mask-channels-stage-cleanup` → `main` · +50 −6 · 2 files · 1 commits · open Claimed in the coordination issue as: MASK-CHANNELS-STAGE-CLEANUP (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Depends on: none Fixes: none (the work item is the finding in issue #14; there is no separate issue to close) ### Independent branch update Head `9a3ee25fd`, based on `e18b59a5b`, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so `Depends on: none` is accurate. Retested on Linux: **10 tests pass**, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against `5da72d19f`. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted. ### What and why `tools/mask_channels.py` publishes `--json` through a staging file that is chmod'ed to the destination's permission bits before `os.replace`. When the replace fails over a read-only report on Windows, the staged file is read-only, so the `TemporaryDirectory` cleanup cannot delete it: the staging folder is stranded beside the report and the cleanup's `PermissionError` masks the real failure, so the tool's one-`ERROR:`-line promise breaks exactly when it matters. This publishes through a named staging file (`mkstemp` next to the destination, same folder creation and same report content) with an explicit cleanup in a `finally`: make the staged file writable (`0o600`) before unlinking and suppress the cleanup error, so a failed write is still one `ERROR:` line and exit 2, the old report stays in place, and a `KeyboardInterrupt` mid-write still cleans up. The shape is the one `navmesh_index.py` and `bvh_index.py` already use for their staging cleanup. ### Tested - `python3 -I tests/test_mask_channels.py`: 10 tests OK, including the new `test_failed_replace_of_read_only_report_removes_writable_temp`, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a `0o444` report, asserts exactly one `ERROR:` line naming the replace error, the old report untouched, no `.mask-json-` staging file left behind, and that the staged file was made deletable before unlinking). - `python3 -m compileall -q tools/mask_channels.py tests/test_mask_channels.py` clean; `tests/test_report_paths.py` and `tests/test_text_write_line_endings.py` still OK. - `python3 -I scripts/check_no_game_data.py tools/mask_channels.py tests/test_mask_channels.py` passes; synthetic images only. GPUs tested: n/a (standard-library tool; no game files, nothing online) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
The staged file is chmod'ed to the destination's bits before os.replace, so on
Windows a failed replace over a read-only report strands a read-only staging
file the TemporaryDirectory cleanup cannot delete, and the cleanup error
masked the real one. Publish through a named staging file with an explicit
cleanup that makes it writable before unlinking and suppresses the cleanup
error, so a failure is still one ERROR: line and exit 2; the old report and
the created-folder behavior are unchanged. Same shape as navmesh_index's and
bvh_index's staging cleanup.

Regression test in the style of test_navmesh_index's failed-replace test: it
fails against the old code on the made-deletable assertion. Synthetic images
only; no game data.

Claimed in the coordination issue as MASK-CHANNELS-STAGE-CLEANUP (issue #14).
AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:21:13 +00:00
Author
Owner

@⁠djrolfes on GitHub · 2026-11-25 19:45 UTC · original

Rebuilt this branch independently on main e18b59a5b: 9a3ee25fd, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 10 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.

**@⁠djrolfes** on GitHub · 2026-11-25 19:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/782#issuecomment-7172726952) Rebuilt this branch independently on main e18b59a5b: 9a3ee25fd, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 10 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/782/head:github-bot/gh-782'
git switch 'github-bot/gh-782'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-782'
git switch 'github-bot/gh-782'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-782'
git switch 'github-bot/gh-782'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-782'
git switch 'main'
git merge --squash 'github-bot/gh-782'
git switch 'main'
git merge --ff-only 'github-bot/gh-782'
git switch 'main'
git merge 'github-bot/gh-782'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.