native_pso_hashes: restore write mode before unlink on replace failure and publish mode (NATIVE-PSO-HASHES-STAGE-CLEANUP) #845

Merged
trigger337 merged 1 commit from upstream-pr/845 into main 2026-11-28 11:09:33 +00:00
trigger337 commented 2026-11-24 14:29:46 +00:00 (Migrated from github.com)

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


Overview

In tools/native_pso_hashes.py, apply published_mode(out) before atomic replacement, 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/native_pso_hashes.py: Import published_mode, apply it before os.replace, and restore write permissions before unlinking.
  2. tests/test_native_pso_hashes.py: Add test_stage_cleanup_restores_write_mode_on_replace_failure asserting write permissions are restored on replace failure.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474102852 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/845). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:29:46Z. --- ### Overview In `tools/native_pso_hashes.py`, apply `published_mode(out)` before atomic replacement, 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/native_pso_hashes.py`: Import `published_mode`, apply it before `os.replace`, and restore write permissions before unlinking. 2. `tests/test_native_pso_hashes.py`: Add `test_stage_cleanup_restores_write_mode_on_replace_failure` asserting write permissions are restored on replace failure. agent: yes AI-assisted: yes
abnalstlll-byte commented 2026-11-24 14:31:10 +00:00 (Migrated from github.com)

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

Review: APPROVED


Consistent staging file permissions and atomic replacement hygiene:

  • Permission Lifecycle Guard:
    • Sets os.chmod(tmp.name, published_mode(out)) prior to os.replace.
    • In inally:, defensively restores
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041105685 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/845#pullrequestreview-6041105685). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:31:10Z. **Review:** APPROVED --- ### Clean-Room Peer Review for PR #845 (native_pso_hashes: restore write mode before unlink on replace failure and publish mode) Consistent staging file permissions and atomic replacement hygiene: - **Permission Lifecycle Guard**: - Sets os.chmod(tmp.name, published_mode(out)) prior to os.replace. - In inally:, defensively restores
abnalstlll-byte commented 2026-11-24 14:39:31 +00:00 (Migrated from github.com)

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

Review: APPROVED


Audited and verified. Applies published_mode(out) before atomic replacement and restores write permission

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041276678 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/845#pullrequestreview-6041276678). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:39:31Z. **Review:** APPROVED --- Audited and verified. Applies published_mode(out) before atomic replacement and restores write permission
MoonEyes commented 2026-11-28 11:09:30 +00:00 (Migrated from github.com)

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


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238364781 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/845#issuecomment-7238364781). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T11:09:30Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
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!845
No description provided.