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

Open
opened 2026-11-26 20:19:09 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/782
Author: @djrolfes
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: djrolfes/mask-channels-stage-cleanup


📝 Commits (1)

  • 9a3ee25 mask_channels: make the --json staging deletable when a replace fails

📊 Changes

2 files changed (+50 additions, -6 deletions)

View changed files

📝 tests/test_mask_channels.py (+34 -0)
📝 tools/mask_channels.py (+16 -6)

📄 Description

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)

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/782 **Author:** [@djrolfes](https://github.com/djrolfes) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `djrolfes/mask-channels-stage-cleanup` --- ### 📝 Commits (1) - [`9a3ee25`](https://github.com/ubiquitarianism/leonida/commit/9a3ee25fd0581680c20ae90ab41ba01fea3b24e6) mask_channels: make the --json staging deletable when a replace fails ### 📊 Changes **2 files changed** (+50 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_mask_channels.py` (+34 -0) 📝 `tools/mask_channels.py` (+16 -6) </details> ### 📄 Description 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#821
No description provided.