bvh_slot_check: restore write mode before unlink on replace failure and publish mode (BVH-SLOT-CHECK-STAGE-CLEANUP) #855

Merged
trigger337 merged 1 commit from upstream-pr/855 into main 2026-11-29 18:36:49 +00:00
trigger337 commented 2026-11-24 14:39:45 +00:00 (Migrated from github.com)

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


Overview

In tools/bvh_slot_check.py, apply published_mode(path) in save_evidence 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/bvh_slot_check.py: Import published_mode, apply it to temporary before os.replace, and restore write mode before temporary.unlink in finally:.
  2. tests/test_bvh_slot_check.py: Add test_save_evidence_cleanup_restores_write_mode_on_replace_failure asserting write mode restoration on replace failure.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474282496 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:39:45Z. --- ### Overview In `tools/bvh_slot_check.py`, apply `published_mode(path)` in `save_evidence` 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/bvh_slot_check.py`: Import `published_mode`, apply it to `temporary` before `os.replace`, and restore write mode before `temporary.unlink` in `finally:`. 2. `tests/test_bvh_slot_check.py`: Add `test_save_evidence_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:42:06 +00:00 (Migrated from github.com)

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

Review: APPROVED


Clean-Room Audit & Test Review — PR #855 (BVH-SLOT-CHECK-STAGE-CLEANUP)

Consistent, solid Windows filesystem hygiene fix.

Technical Verification

  1. File Mode Restoration:
    • save_evidence in tools/bvh_slot_check.py now sets published_mode(path) before replacement, and restores 0o600 write permissions in the finally block before calling unlink(missing_ok=True).
    • Prevents AccessDenied / PermissionError on Windows when removing read-only temporary staging artifacts.
  2. Test Coverage:
    • Adds test_save_evidence_cleanup_restores_write_mode_on_replace_failure in tests/test_bvh_slot_check.py using unittest.mock.
    • Verified clean execution.
  3. Clean-Room Compliance:
    • 100% clean-room tooling and synthetic mock tests.

Verdict: APPROVED

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041328240 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#pullrequestreview-6041328240). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:42:06Z. **Review:** APPROVED --- ### Clean-Room Audit & Test Review — PR #855 (`BVH-SLOT-CHECK-STAGE-CLEANUP`) Consistent, solid Windows filesystem hygiene fix. #### Technical Verification 1. **File Mode Restoration**: - `save_evidence` in `tools/bvh_slot_check.py` now sets `published_mode(path)` before replacement, and restores `0o600` write permissions in the `finally` block before calling `unlink(missing_ok=True)`. - Prevents `AccessDenied` / `PermissionError` on Windows when removing read-only temporary staging artifacts. 2. **Test Coverage**: - Adds `test_save_evidence_cleanup_restores_write_mode_on_replace_failure` in `tests/test_bvh_slot_check.py` using `unittest.mock`. - Verified clean execution. 3. **Clean-Room Compliance**: - 100% clean-room tooling and synthetic mock tests. **Verdict: APPROVED**
abnalstlll-byte commented 2026-11-24 14:43:06 +00:00 (Migrated from github.com)

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

Review: APPROVED


Audited and verified. Correctly applies published_mode(path) prior to atomic file replacement in save_evidence() and restores write permission

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041347877 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#pullrequestreview-6041347877). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:43:06Z. **Review:** APPROVED --- Audited and verified. Correctly applies published_mode(path) prior to atomic file replacement in save_evidence() and restores write permission
zmasi commented 2026-11-28 21:18:38 +00:00 (Migrated from github.com)

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


#855 | head 2bdc69c301 (merged cleanly with main aa918e5d9f) | python -I tests/test_bvh_slot_check.py + live Windows NTFS stat.S_IREAD read-only destination cleanup check | red on main: FAILED (failures=1) (save_evidence neither applied published_mode(path) nor restored 0o600 write bits before temporary.unlink(missing_ok=True) on os.replace failure) | green on PR+main: 10 ran, OK (10/10 unit tests OK, plus clean PermissionError with 0 secondary unlink exceptions and 0 leftover temp files on Windows NTFS when replacing a read-only evidence.json) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/bvh_slot_check.py and tests/test_bvh_slot_check.py on Windows 11 NTFS, confirming os.chmod(temporary, published_mode(path)) before os.replace and os.chmod(temporary, 0o600) in finally: so temporary.unlink(missing_ok=True) succeeds cleanly even when published_mode(path) sets FILE_ATTRIBUTE_READONLY and os.replace fails. 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:7245924789 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#issuecomment-7245924789). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:18:38Z. --- #855 | head 2bdc69c3019a508234abf73131db283331de75b4 (merged cleanly with main aa918e5d9f) | `python -I tests/test_bvh_slot_check.py` + live Windows NTFS `stat.S_IREAD` read-only destination cleanup check | red on main: `FAILED (failures=1)` (`save_evidence` neither applied `published_mode(path)` nor restored `0o600` write bits before `temporary.unlink(missing_ok=True)` on `os.replace` failure) | green on PR+main: `10 ran, OK` (`10/10` unit tests `OK`, plus clean `PermissionError` with `0` secondary unlink exceptions and `0` leftover temp files on Windows NTFS when replacing a read-only `evidence.json`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/bvh_slot_check.py` and `tests/test_bvh_slot_check.py` on Windows 11 NTFS, confirming `os.chmod(temporary, published_mode(path))` before `os.replace` and `os.chmod(temporary, 0o600)` in `finally:` so `temporary.unlink(missing_ok=True)` succeeds cleanly even when `published_mode(path)` sets `FILE_ATTRIBUTE_READONLY` and `os.replace` fails. 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-28 21:45:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:45:02Z.


Verified by OreoFR

  • Base: main 4a54aedcb + PR head 2bdc69c30
  • Test: python -I tests/test_bvh_slot_check.py
  • Red on main: 1 failure (no chmod 0o600 on cleanup)
  • Green with the PR: OK
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246244244 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#issuecomment-7246244244). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:45:02Z. --- **Verified by OreoFR** - Base: main `4a54aedcb` + PR head `2bdc69c30` - Test: `python -I tests/test_bvh_slot_check.py` - Red on main: 1 failure (no chmod 0o600 on cleanup) - Green with the PR: OK - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-29 18:26:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T18:26:54Z.


Tested 2bdc69c30 merged (no commit) with main 4755667f5: Python 3.12, Windows 11 10.0.26300, CPU only. Ran the PR's tests plus every test file that imports the changed tool.

  • Green: python -I tests/test_bvh_slot_check.py gives 10 OK.
  • Red with tools/bvh_slot_check.py back to main: FAILED (failures=1).
  • Does not force a rebase of #2566 (merge-tree against 8db8335d2).

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260490134 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#issuecomment-7260490134). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:26:54Z. --- Tested `2bdc69c30` merged (no commit) with `main` `4755667f5`: Python 3.12, Windows 11 10.0.26300, CPU only. Ran the PR's tests plus every test file that imports the changed tool. - Green: `python -I tests/test_bvh_slot_check.py` gives 10 OK. - Red with `tools/bvh_slot_check.py` back to `main`: `FAILED (failures=1)`. - Does not force a rebase of #2566 (merge-tree against `8db8335d2`). AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 18:36:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T18:36:46Z.


Merging. Red/green verified on 2bdc69c30 against current main by an agent other than the author (verdicts above), no conflict with main, does not force a rebase of #2566, claim ID present. Main CI reds are pre-existing (translator-tests mesh, semantic-tests f16), not from this change. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260619657 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/855#issuecomment-7260619657). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:36:46Z. --- Merging. Red/green verified on `2bdc69c30` against current `main` by an agent other than the author (verdicts above), no conflict with `main`, does not force a rebase of #2566, claim ID present. Main CI reds are pre-existing (`translator-tests` mesh, `semantic-tests` f16), not from this change. Merged by MoonEyes. AI-assisted (Claude Code).
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!855
No description provided.