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

Closed
djrolfes wants to merge 1 commit from upstream-pr/782 into main
djrolfes commented 2026-11-24 13:45:24 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-24T13:45:24Z.


Claimed in the coordination issue as: MASK-CHANNELS-STAGE-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133242472)

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)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473340881 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/782). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-24T13:45:24Z. --- Claimed in the coordination issue as: MASK-CHANNELS-STAGE-CLEANUP (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133242472) 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)
djrolfes commented 2026-11-25 19:45:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-11-25T19:45:29Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7172726952 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/782#issuecomment-7172726952). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-11-25T19:45:29Z. --- 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.
MoonEyes commented 2026-11-30 11:37:44 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T11:37:44Z.


Closing as no longer needed, at the owner's request (MoonEyes). Checked on main d367675c7:

  • The failure this fixes starts from a staged file made read-only on Windows. main no longer does that: _write_json_report in tools/mask_channels.py calls os.chmod only under if os.name != "nt".
  • Reproduced the remaining case on Windows 11, Python 3.14.0: a read-only file in a TemporaryDirectory, then an OSError. The folder is removed and the OSError is the one that comes out, so nothing is stranded and nothing is masked. Not tried on Python 3.12.

The branch also conflicts with main. Thank you for the work; please reopen it if you can show the failure on current main.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7277295416 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/782#issuecomment-7277295416). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T11:37:44Z. --- Closing as no longer needed, at the owner's request (MoonEyes). Checked on `main` `d367675c7`: - The failure this fixes starts from a staged file made read-only on Windows. `main` no longer does that: `_write_json_report` in `tools/mask_channels.py` calls `os.chmod` only under `if os.name != "nt"`. - Reproduced the remaining case on Windows 11, Python 3.14.0: a read-only file in a `TemporaryDirectory`, then an `OSError`. The folder is removed and the `OSError` is the one that comes out, so nothing is stranded and nothing is masked. Not tried on Python 3.12. The branch also conflicts with `main`. Thank you for the work; please reopen it if you can show the failure on current `main`. AI-assisted (Claude Code).

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!782
No description provided.