shader_disasm: restore write mode before unlink on replace failure and publish mode (SHADER-DISASM-STAGE-CLEANUP) #861

Merged
trigger337 merged 2 commits from upstream-pr/861 into main 2026-12-01 15:05:18 +00:00
trigger337 commented 2026-11-24 14:46:51 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:46:51Z.


Overview

In tools/shader_disasm.py, apply published_mode(out_file) to the staged temporary listing before os.replace, and ensure write mode (0o600) is restored before unlinking in the finally: block if replacement fails.

On Windows, unlinking a read-only staged file or cleaning up on os.replace failure causes a PermissionError [WinError 5], leaving stranded temporary files behind and masking underlying exceptions.

Changes

  1. tools/shader_disasm.py: Import published_mode, apply it to listing.name before os.replace, and restore write mode before os.unlink in finally:.
  2. tests/test_shader_disasm.py: Add test_stage_cleanup_restores_write_mode_on_replace_failure asserting write mode restoration on replace failure.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474411239 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:46:51Z. --- ### Overview In `tools/shader_disasm.py`, apply `published_mode(out_file)` to the staged temporary listing before `os.replace`, and ensure write mode (`0o600`) is restored before unlinking in the `finally:` block if replacement fails. On Windows, unlinking a read-only staged file or cleaning up on `os.replace` failure causes a `PermissionError` [WinError 5], leaving stranded temporary files behind and masking underlying exceptions. ### Changes 1. `tools/shader_disasm.py`: Import `published_mode`, apply it to `listing.name` before `os.replace`, and restore write mode before `os.unlink` in `finally:`. 2. `tests/test_shader_disasm.py`: Add `test_stage_cleanup_restores_write_mode_on_replace_failure` asserting write mode restoration on replace failure. agent: yes AI-assisted: yes
zmasi commented 2026-11-28 21:18:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T21:18:42Z.


#861 | head b229d27a66 (merged cleanly with main aa918e5d9f) | python -I tests/test_shader_disasm.py + live Windows NTFS stat.S_IREAD read-only destination cleanup check | red on main: FAILED (failures=1) (one() neither applied published_mode(out_file) nor restored 0o600 write mode before os.unlink(listing.name) on os.replace failure) | green on PR+main: 35 ran, OK (35/35 unit tests OK, plus clean PermissionError with 0 secondary unlink exceptions and 0 leftover .disasm-*.tmp files on Windows NTFS when replacing a read-only sample.s) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/shader_disasm.py and tests/test_shader_disasm.py on Windows 11 NTFS, confirming os.chmod(listing.name, published_mode(out_file)) before os.replace and os.chmod(listing.name, 0o600) in finally: so os.unlink(listing.name) removes the staged listing cleanly even when published_mode(out_file) copies FILE_ATTRIBUTE_READONLY and os.replace raises PermissionError. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, and scripts/check_no_game_data.py.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245925657 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7245925657). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:18:42Z. --- #861 | head b229d27a6639a68fd3921141803e5a896e4e0f66 (merged cleanly with main aa918e5d9f) | `python -I tests/test_shader_disasm.py` + live Windows NTFS `stat.S_IREAD` read-only destination cleanup check | red on main: `FAILED (failures=1)` (`one()` neither applied `published_mode(out_file)` nor restored `0o600` write mode before `os.unlink(listing.name)` on `os.replace` failure) | green on PR+main: `35 ran, OK` (`35/35` unit tests `OK`, plus clean `PermissionError` with `0` secondary unlink exceptions and `0` leftover `.disasm-*.tmp` files on Windows NTFS when replacing a read-only `sample.s`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/shader_disasm.py` and `tests/test_shader_disasm.py` on Windows 11 NTFS, confirming `os.chmod(listing.name, published_mode(out_file))` before `os.replace` and `os.chmod(listing.name, 0o600)` in `finally:` so `os.unlink(listing.name)` removes the staged listing cleanly even when `published_mode(out_file)` copies `FILE_ATTRIBUTE_READONLY` and `os.replace` raises `PermissionError`. Also verified `tests/test_ci_registration.py`, `tests/test_text_write_line_endings.py`, and `scripts/check_no_game_data.py`.
OreoFR commented 2026-11-29 01:31:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:31:39Z.


Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (DisasmOutputCollisionTest.test_stage_cleanup_restores_write_mode_on_replace_failure) / green 35 OK.

  • PR head b229d27a6, python -I tests/test_shader_disasm.py from the repository root.
  • Red (main + only this PR's test files): 35 run, 1 failure, 0 skips. Main does not restore the write mode of the staged file when the replace fails.
  • Green (main + git merge --no-ff of this PR, no conflict): 35 run, OK, 0 skips.
  • Skips: none.
  • Verdict: READY.

Red = main + only the test files from this PR (git checkout pr-861 -- tests/test_shader_disasm.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.

AI-assisted: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7248840263 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7248840263). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T01:31:39Z. --- Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (`DisasmOutputCollisionTest.test_stage_cleanup_restores_write_mode_on_replace_failure`) / green 35 OK. - PR head b229d27a6, `python -I tests/test_shader_disasm.py` from the repository root. - Red (main + only this PR's test files): 35 run, 1 failure, 0 skips. Main does not restore the write mode of the staged file when the replace fails. - Green (main + `git merge --no-ff` of this PR, no conflict): 35 run, OK, 0 skips. - Skips: none. - Verdict: READY. Red = main + only the test files from this PR (`git checkout pr-861 -- tests/test_shader_disasm.py`); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched. AI-assisted: Claude Code (Claude Opus 5.5).
OreoFR commented 2026-11-29 08:34:17 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T08:34:17Z.


Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7248840263

The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up.

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7253190485 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7253190485). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-29T08:34:17Z. --- Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7248840263 The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up. AI-assisted: Claude Code
trigger337 commented 2026-11-30 10:41:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-30T10:41:08Z.


@OreoFR Merged latest main and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 37 tests pass.

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275937110 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7275937110). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-30T10:41:08Z. --- @OreoFR Merged latest `main` and registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 37 tests pass. AI-assisted: yes
aslan2142 commented 2026-12-01 11:39:14 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:39:14Z.

Review: APPROVED


Reviewed the diff against main: tools/shader_disasm.py:349-358 cleanly applies published_mode and restores 0o600 before os.unlink on failure, covered by tests/test_shader_disasm.py:507-527. Clean-room verified. Approving; please merge current main for a fresh green CI run before merge.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130477412 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#pullrequestreview-6130477412). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:39:14Z. **Review:** APPROVED --- Reviewed the diff against `main`: `tools/shader_disasm.py:349-358` cleanly applies `published_mode` and restores `0o600` before `os.unlink` on failure, covered by `tests/test_shader_disasm.py:507-527`. Clean-room verified. Approving; please merge current `main` for a fresh green CI run before merge. *(AI-assisted review.)*
MoonEyes commented 2026-12-01 12:31:27 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T12:31:27Z.


Verified by MoonEyes (another person than the author) on head 45c15d052 merged with main c60ce461a: Windows 11, Python 3.14, CPU only. I read the whole diff. tests/test_shader_disasm.py 37 OK; with tools/shader_disasm.py back to main, 1 failure. Neighbours OK, except one error in tests/test_rdna2_decode.py that is the same on plain main here (no llvm-mc).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311254142 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7311254142). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T12:31:27Z. --- Verified by MoonEyes (another person than the author) on head `45c15d052` merged with `main` `c60ce461a`: Windows 11, Python 3.14, CPU only. I read the whole diff. `tests/test_shader_disasm.py` 37 OK; with `tools/shader_disasm.py` back to `main`, 1 failure. Neighbours OK, except one error in `tests/test_rdna2_decode.py` that is the same on plain `main` here (no llvm-mc). AI-assisted (Claude Code).
MoonEyes commented 2026-12-01 12:37:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-01T12:37:56Z.


Closing and reopening this so that CI runs again on the current main. Nothing else changes, the head stays 45c15d052. MoonEyes's agent.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311418597 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/861#issuecomment-7311418597). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-01T12:37:56Z. --- Closing and reopening this so that CI runs again on the current `main`. Nothing else changes, the head stays `45c15d052`. MoonEyes's agent.
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!861
No description provided.