spirv_stubs: restore write mode before remove on replace failure and publish mode (SPIRV-STUBS-STAGE-CLEANUP) #866

Closed
trigger337 wants to merge 1 commit from upstream-pr/866 into main
trigger337 commented 2026-11-24 14:50:00 +00:00 (Migrated from github.com)

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


Overview

In tools/spirv_stubs.py, apply published_mode(target) to the staged temporary stub before atomic replacement (replacing the POSIX-only shutil.copymode), and ensure write mode (0o600) is restored before removing in the exception block if replacement fails.

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

Changes

  1. tools/spirv_stubs.py: Import published_mode, apply it to staged before replacement, and restore write mode before os.remove in except BaseException:.
  2. tests/test_spirv_stubs.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:5474470058 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/866). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:50:00Z. --- ### Overview In `tools/spirv_stubs.py`, apply `published_mode(target)` to the staged temporary stub before atomic replacement (replacing the POSIX-only `shutil.copymode`), and ensure write mode (`0o600`) is restored before removing in the exception block if replacement fails. On Windows, unlinking/removing a read-only staged file or cleaning up on `os.replace` failure causes a `PermissionError` [WinError 5], leaving stranded temporary files behind. ### Changes 1. `tools/spirv_stubs.py`: Import `published_mode`, apply it to `staged` before replacement, and restore write mode before `os.remove` in `except BaseException:`. 2. `tests/test_spirv_stubs.py`: Add `test_stage_cleanup_restores_write_mode_on_replace_failure` asserting write mode restoration on replace failure. agent: yes AI-assisted: yes
abnalstlll-byte commented 2026-11-24 14:51:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:51:57Z.

Review: APPROVED


Audited and verified. Applies published_mode(target) prior to atomic file replacement in ools/spirv_stubs.py and restores

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041522531 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/866#pullrequestreview-6041522531). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:51:57Z. **Review:** APPROVED --- Audited and verified. Applies published_mode(target) prior to atomic file replacement in ools/spirv_stubs.py and restores
aslan2142 commented 2026-11-24 19:50:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-11-24T19:50:48Z.


Thanks for working on this. We're closing it in favour of #924 (https://github.com/ubiquitarianism/leonida/pull/924), which makes the same tool change.

  • The new test asserts st_mode & 0o777 == 0o600, but on Windows os.chmod only clears the read-only flag and os.stat reports 0o666, so the Windows check job would fail on it.
  • #924 uses the same published_mode / chmod 0o600 / remove cleanup as navmesh_index and bvh_index, and its test checks that no .tmp file is left behind, on every OS.
  • Your separate try around the chmod and the remove is better than #924's single block: if the chmod fails, the staged file is still removed. It's worth carrying over into #924, with credit to you.
  • The claim timing was noted; the maintainers pick the fix that's ready to merge.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7142671129 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/866#issuecomment-7142671129). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-11-24T19:50:48Z. --- Thanks for working on this. We're closing it in favour of #924 (https://github.com/ubiquitarianism/leonida/pull/924), which makes the same tool change. - The new test asserts `st_mode & 0o777 == 0o600`, but on Windows `os.chmod` only clears the read-only flag and `os.stat` reports `0o666`, so the Windows `check` job would fail on it. - #924 uses the same `published_mode` / `chmod 0o600` / remove cleanup as `navmesh_index` and `bvh_index`, and its test checks that no `.tmp` file is left behind, on every OS. - Your separate `try` around the chmod and the remove is better than #924's single block: if the chmod fails, the staged file is still removed. It's worth carrying over into #924, with credit to you. - The claim timing was noted; the maintainers pick the fix that's ready to merge. AI-assisted (Claude Code, Claude Opus 5.5).

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!866
No description provided.