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

Merged
trigger337 merged 1 commit from upstream-pr/834 into main 2026-11-29 18:36:43 +00:00
trigger337 commented 2026-11-24 14:22:03 +00:00 (Migrated from github.com)

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


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473958629 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:22:03Z. --- 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 commented 2026-11-24 14:26:17 +00:00 (Migrated from github.com)

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

Review: APPROVED


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
<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041007957 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#pullrequestreview-6041007957). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:26:17Z. **Review:** APPROVED --- ### 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 commented 2026-11-24 14:28:23 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041050046 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#pullrequestreview-6041050046). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:28:23Z. **Review:** APPROVED --- 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 (Migrated from github.com)

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


#834 | head 2cb6ed8821 (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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246052107 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#issuecomment-7246052107). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:29:08Z. --- #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 (Migrated from github.com)

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


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246239429 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#issuecomment-7246239429). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:44:38Z. --- **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 (Migrated from github.com)

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


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260489622 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#issuecomment-7260489622). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:26:51Z. --- 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 (Migrated from github.com)

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


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260618472 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/834#issuecomment-7260618472). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:36:40Z. --- 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 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!834
No description provided.