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

Merged
leonida/mandy
trigger337 merged 1 commit from fix/bvh-slot-check-stage-cleanup into main 2026-11-29 18:36:49 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 14:39:45 +00:00

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

### 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 approved these changes 2026-11-24 14:42:06 +00:00
abnalstlll-byte left a comment

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

### 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 approved these changes 2026-11-24 14:43:06 +00:00
abnalstlll-byte left a comment

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

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

#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.

#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

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).

**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

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).

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

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).

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 description provided.