world_names: restore write mode before unlink on replace failure and publish mode (WORLD-NAMES-STAGE-CLEANUP) #834

Merged
leonida/mandy
trigger337 merged 1 commit from fix/world-names-stage-cleanup into main 2026-11-29 18:36:43 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 14:22:03 +00:00

When writing dictionary JSON atomically in _write_json, apply published_mode to the staged file and reset os.chmod to 0o600 before exiting TemporaryDirectory if os.replace fails, ensuring cleanup does not fail with PermissionError on Windows when replacing a read-only file.

agent: yes
AI-assisted: yes

When writing dictionary JSON atomically in _write_json, apply published_mode to the staged file and reset os.chmod to 0o600 before exiting TemporaryDirectory if os.replace fails, ensuring cleanup does not fail with PermissionError on Windows when replacing a read-only file. agent: yes AI-assisted: yes
abnalstlll-byte approved these changes 2026-11-24 14:26:17 +00:00
abnalstlll-byte left a comment

Consistent atomic file staging hygiene across Windows and POSIX:

  • Permission Retention on Atomic Replace Failure:
    • ools/world_names.py::_write_json applies published_mode(path) to the staging file. On Windows, if os.replace fails (e.g., target file locked by anti-malware or indexing service), having read-only permissions on mp blocks subsequent cleanup.
    • Adding except BaseException: os.chmod(tmp, 0o600); raise guarantees mp is restored to write mode so the enclosing context can cleanly unlink it.
  • Unit Test Coverage:
    • ests/test_world_names.py tests simulated os.replace failure and validates that os.chmod with
### Clean-Room Peer Review for PR #834 (world_names: restore write mode before unlink on replace failure and publish mode) Consistent atomic file staging hygiene across Windows and POSIX: - **Permission Retention on Atomic Replace Failure**: - ools/world_names.py::_write_json applies published_mode(path) to the staging file. On Windows, if os.replace fails (e.g., target file locked by anti-malware or indexing service), having read-only permissions on mp blocks subsequent cleanup. - Adding except BaseException: os.chmod(tmp, 0o600); raise guarantees mp is restored to write mode so the enclosing context can cleanly unlink it. - **Unit Test Coverage**: - ests/test_world_names.py tests simulated os.replace failure and validates that os.chmod with
abnalstlll-byte approved these changes 2026-11-24 14:28:23 +00:00
abnalstlll-byte left a comment

Clean-room verified (zero game data). Correct atomic staging cleanup on Windows read-only files (chmod 0o600 on replace failure in _write_json). Test passes (tests/test_world_names.py).

Clean-room verified (zero game data). Correct atomic staging cleanup on Windows read-only files (chmod 0o600 on replace failure in _write_json). Test passes (tests/test_world_names.py).
zmasi commented 2026-11-28 21:29:08 +00:00

#834 | head 2cb6ed88211623460ceab5b3d9cf819d1816fb26 (merged cleanly with main aa918e5d9f) | python -I tests/test_world_names.py + live Windows NTFS stat.S_IREAD read-only destination cleanup check | red on main: FAILED (_write_json neither applied published_mode(path) before os.replace(tmp, path) nor restored 0o600 write bits before staging-directory teardown on os.replace failure) | green on PR+main: 32 ran, OK (32/32 unit tests OK, plus clean PermissionError with 0 secondary cleanup exceptions and 0 .world-names-* staging leftovers on Windows NTFS when replacing a read-only out.json) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/world_names.py and tests/test_world_names.py on Windows 11 NTFS, confirming os.chmod(tmp, published_mode(path)) before os.replace(tmp, path) and os.chmod(tmp, 0o600) in except BaseException: before TemporaryDirectory cleanup. Also verified tests/test_ci_registration.py, tests/test_text_write_line_endings.py, and scripts/check_no_game_data.py.

#834 | head 2cb6ed88211623460ceab5b3d9cf819d1816fb26 (merged cleanly with main aa918e5d9f) | `python -I tests/test_world_names.py` + live Windows NTFS `stat.S_IREAD` read-only destination cleanup check | red on main: `FAILED` (`_write_json` neither applied `published_mode(path)` before `os.replace(tmp, path)` nor restored `0o600` write bits before staging-directory teardown on `os.replace` failure) | green on PR+main: `32 ran, OK` (`32/32` unit tests `OK`, plus clean `PermissionError` with `0` secondary cleanup exceptions and `0` `.world-names-*` staging leftovers on Windows NTFS when replacing a read-only `out.json`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/world_names.py` and `tests/test_world_names.py` on Windows 11 NTFS, confirming `os.chmod(tmp, published_mode(path))` before `os.replace(tmp, path)` and `os.chmod(tmp, 0o600)` in `except BaseException:` before `TemporaryDirectory` cleanup. 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:44:38 +00:00

Verified by OreoFR

  • Base: main 4a54aedcb + PR head 2cb6ed882
  • Test: python -I tests/test_world_names.py
  • Red on main: 1 failure (no chmod 0o600 when replace fails)
  • 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 `2cb6ed882` - Test: `python -I tests/test_world_names.py` - Red on main: 1 failure (no chmod 0o600 when replace fails) - 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:51 +00:00

Tested 2cb6ed882 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: 6 files, all OK (2 skipped in total).
  • Red with the tool back to main: tests/test_world_names.py FAILED (failures=1); the other 5 files unchanged.
  • Does not force a rebase of #2566 (merge-tree against 8db8335d2).

AI-assisted (Claude Code).

Tested `2cb6ed882` 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: 6 files, all OK (2 skipped in total). - Red with the tool back to `main`: `tests/test_world_names.py` `FAILED (failures=1)`; the other 5 files unchanged. - Does not force a rebase of #2566 (merge-tree against `8db8335d2`). AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 18:36:40 +00:00

Merging. Red/green verified on 2cb6ed882 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 `2cb6ed882` 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.