rsc8_audio: restore writable mode before removing staging file on failure (RSC8-AUDIO-RO-CLEANUP) #724

Merged
kirigayakazima merged 1 commit from upstream-pr/724 into main 2026-11-28 07:36:44 +00:00
kirigayakazima commented 2026-11-24 12:57:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-24T12:57:50Z.


Claimed in the coordination issue as: RSC8-AUDIO-RO-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132063463

What and why

Hardens _atomic_write_text in tools/rsc8_audio.py when publishing a report fails:

  • Before os.replace(tmp, path), _atomic_write_text runs os.chmod(tmp, published_mode(path)), which copies 0o444 onto tmp when the destination report is read-only.
  • On Windows NTFS, if os.replace(tmp, path) then raises PermissionError, the cleanup handler previously called os.remove(tmp) directly while tmp was still read-only, hitting PermissionError (swallowed) and leaking .rsc8_audio.<rand>.part in the output directory.
  • Restores os.chmod(tmp, 0o600) (guarded by except OSError: pass) before os.remove(tmp) so failed publishes over read-only targets clean up their staging file cleanly.

Adds 2 synthetic regression tests in tests/test_rsc8_audio.py (AwcAndArchiveScanTest):

  • test_failed_replace_over_readonly_report_cleans_staging_file
  • test_windows_readonly_report_failure_cleans_staging_file (Windows NTFS os.replace over 0o444)

Tested

Windows 11 x64 (10.0.26100), Python 3.14.7, CPU only, synthetic test inputs only (no game files). Commit 01f04caccf6f75a6c0d764cf4317767795604e97.

  • python -I tests/test_rsc8_audio.py -v:
    • against upstream/main (21625bca) with the two new tests: both fail (ran=2 failures=2 errors=0, leaking .rsc8_audio.<rand>.part);
    • with the fix: 51 tests, OK (0 skipped).
  • python -I tests/test_ci_registration.py: 15 tests, OK.
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/rsc8_audio.py tests/test_rsc8_audio.py, python -m compileall -q tools tests, git diff --check: exit 0.

GPUs tested: n/a

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: no translator change)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5472586869 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/724). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-24T12:57:50Z. --- Claimed in the coordination issue as: RSC8-AUDIO-RO-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132063463 ### What and why Hardens `_atomic_write_text` in `tools/rsc8_audio.py` when publishing a report fails: - Before `os.replace(tmp, path)`, `_atomic_write_text` runs `os.chmod(tmp, published_mode(path))`, which copies `0o444` onto `tmp` when the destination report is read-only. - On Windows NTFS, if `os.replace(tmp, path)` then raises `PermissionError`, the cleanup handler previously called `os.remove(tmp)` directly while `tmp` was still read-only, hitting `PermissionError` (swallowed) and leaking `.rsc8_audio.<rand>.part` in the output directory. - Restores `os.chmod(tmp, 0o600)` (guarded by `except OSError: pass`) before `os.remove(tmp)` so failed publishes over read-only targets clean up their staging file cleanly. Adds 2 synthetic regression tests in `tests/test_rsc8_audio.py` (`AwcAndArchiveScanTest`): - `test_failed_replace_over_readonly_report_cleans_staging_file` - `test_windows_readonly_report_failure_cleans_staging_file` (Windows NTFS `os.replace` over `0o444`) ### Tested Windows 11 x64 (`10.0.26100`), Python `3.14.7`, CPU only, synthetic test inputs only (no game files). Commit `01f04caccf6f75a6c0d764cf4317767795604e97`. - `python -I tests/test_rsc8_audio.py -v`: - against `upstream/main` (`21625bca`) with the two new tests: both fail (`ran=2 failures=2 errors=0`, leaking `.rsc8_audio.<rand>.part`); - with the fix: **51 tests, OK** (0 skipped). - `python -I tests/test_ci_registration.py`: **15 tests, OK**. - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/rsc8_audio.py tests/test_rsc8_audio.py`, `python -m compileall -q tools tests`, `git diff --check`: exit `0`. GPUs tested: n/a 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: no translator change)
abnalstlll-byte commented 2026-11-24 13:15:45 +00:00 (Migrated from github.com)

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

Review: APPROVED


LGTM. Clean staging file chmod/cleanup on write failure in
sc8_audio.py with cross-platform and Windows-specific unit tests in est_rsc8_audio.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039843812 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/724#pullrequestreview-6039843812). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T13:15:45Z. **Review:** APPROVED --- LGTM. Clean staging file chmod/cleanup on write failure in sc8_audio.py with cross-platform and Windows-specific unit tests in est_rsc8_audio.py.
abnalstlll-byte commented 2026-11-24 13:26:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:26:39Z.

Review: APPROVED


Audited and verified. Clean-room compliant.

  • Restores 0o600 writable mode before deleting staging file in tools/rsc8_audio.py.
  • Regression tests pass.
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6039999936 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/724#pullrequestreview-6039999936). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T13:26:39Z. **Review:** APPROVED --- Audited and verified. Clean-room compliant. - Restores 0o600 writable mode before deleting staging file in tools/rsc8_audio.py. - Regression tests pass.
tiguan26 commented 2026-11-25 04:02:33 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T04:02:33Z.

Review: APPROVED


Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051685472 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/724#pullrequestreview-6051685472). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T04:02:33Z. **Review:** APPROVED --- Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change. AI-assisted (Claude).
MoonEyes commented 2026-11-28 07:36:35 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T07:36:35Z.


Red/green: the new test fails on main (2 failed) and passes with this PR (51 passed).
Full suite with this PR merged together with seven others in one batch matches main (pytest, translator suite, ctest without the game) on Windows 11 with an RTX 4060, except xmem_write_watch, a test that depends on free host memory and has also failed on plain main.
AI-assisted (Claude Code, Claude Opus 5.5). Thank you!

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7236049671 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/724#issuecomment-7236049671). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T07:36:35Z. --- Red/green: the new test fails on main (2 failed) and passes with this PR (51 passed). Full suite with this PR merged together with seven others in one batch matches main (pytest, translator suite, ctest without the game) on Windows 11 with an RTX 4060, except xmem_write_watch, a test that depends on free host memory and has also failed on plain main. AI-assisted (Claude Code, Claude Opus 5.5). Thank you!
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!724
No description provided.