world_build: restore write mode before unlink on replace failure in _write_json_atomic (WORLD-BUILD-STAGE-CLEANUP) #816

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

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


When writing world JSON atomically, if os.replace fails (for instance due to permission errors), resetting os.chmod to 0o600 ensures unlinking the temporary file does not fail on Windows with PermissionError.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473752847 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:09:43Z. --- When writing world JSON atomically, if os.replace fails (for instance due to permission errors), resetting os.chmod to 0o600 ensures unlinking the temporary file does not fail on Windows with PermissionError. agent: yes AI-assisted: yes
abnalstlll-byte commented 2026-11-24 14:24:08 +00:00 (Migrated from github.com)

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

Review: APPROVED


Clean-room verified (zero game data). Correct atomic staging cleanup on Windows read-only files (chmod 0o600 before removal in _write_json_atomic). Unit tests pass (tests/test_world_build.py: 12/12 WorldBuildStagingTest PASS).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6040965586 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#pullrequestreview-6040965586). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:24:08Z. **Review:** APPROVED --- Clean-room verified (zero game data). Correct atomic staging cleanup on Windows read-only files (chmod 0o600 before removal in _write_json_atomic). Unit tests pass (tests/test_world_build.py: 12/12 WorldBuildStagingTest PASS).
tiguan26 commented 2026-11-25 03:58:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:58:56Z.

Review: APPROVED


Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change.

AI-assisted (Claude).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051660583 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#pullrequestreview-6051660583). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:58:56Z. **Review:** APPROVED --- Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change. AI-assisted (Claude).
zmasi commented 2026-11-28 21:29:04 +00:00 (Migrated from github.com)

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


#816 | head d90e4b213f (merged cleanly with main aa918e5d9f) | python -I tests/test_world_build.py + live unmocked Windows NTFS stat.S_IREAD world.json leak check | red on main: FAILED (failures=1) AND live NTFS reproduction leaked .world-8jl6rgtt.tmp (_write_json_atomic copied FILE_ATTRIBUTE_READONLY onto tmp_path via published_mode(path), then os.replace failed on read-only world.json and os.remove(tmp_path) silently failed under except OSError: pass) | green on PR+main: 69 ran, OK (69/69 unit tests OK, and 0 .world-*.tmp leftovers on live Windows NTFS when replacing a read-only world.json) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yes

Audited tools/world_build.py and tests/test_world_build.py on Windows 11 NTFS, reproducing the real read-only .world-*.tmp leak on main and confirming os.chmod(tmp_path, 0o600) before os.remove(tmp_path) eliminates the leftover staged file cleanly. 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:7246051307 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#issuecomment-7246051307). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T21:29:04Z. --- #816 | head d90e4b213f82d12ab45250ddc0b3c6a110d35e7a (merged cleanly with main aa918e5d9f) | `python -I tests/test_world_build.py` + live unmocked Windows NTFS `stat.S_IREAD` `world.json` leak check | red on main: `FAILED (failures=1)` AND live NTFS reproduction leaked `.world-8jl6rgtt.tmp` (`_write_json_atomic` copied `FILE_ATTRIBUTE_READONLY` onto `tmp_path` via `published_mode(path)`, then `os.replace` failed on read-only `world.json` and `os.remove(tmp_path)` silently failed under `except OSError: pass`) | green on PR+main: `69 ran, OK` (`69/69` unit tests `OK`, and `0` `.world-*.tmp` leftovers on live Windows NTFS when replacing a read-only `world.json`) | Windows 11 (`10.0.26200.9974`), Python 3.12.10 | AI-assisted: yes Audited `tools/world_build.py` and `tests/test_world_build.py` on Windows 11 NTFS, reproducing the real read-only `.world-*.tmp` leak on `main` and confirming `os.chmod(tmp_path, 0o600)` before `os.remove(tmp_path)` eliminates the leftover staged file cleanly. 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:43:56 +00:00 (Migrated from github.com)

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


Verified by OreoFR

  • Base: main 4a54aedcb + PR head d90e4b213
  • Test: python -I tests/test_world_build.py
  • Red on main: 1 failure (no chmod 0o600 before unlink)
  • Green with the PR: 69 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:7246230944 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#issuecomment-7246230944). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:43:56Z. --- **Verified by OreoFR** - Base: main `4a54aedcb` + PR head `d90e4b213` - Test: `python -I tests/test_world_build.py` - Red on main: 1 failure (no chmod 0o600 before unlink) - Green with the PR: 69 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:48 +00:00 (Migrated from github.com)

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


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

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7260488825 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#issuecomment-7260488825). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:26:48Z. --- Tested `d90e4b213` 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: 7 files, all OK (`test_world_build.py` 69 OK; 4 skipped in total). - Red with `tools/` back to `main`: `tests/test_world_build.py` `FAILED (failures=1)`; the other 6 files unchanged. - Does not force a rebase of #2566 (merge-tree against `8db8335d2`). AI-assisted (Claude Code).
MoonEyes commented 2026-11-29 18:36:28 +00:00 (Migrated from github.com)

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


Merging. Red/green verified on d90e4b213 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:7260615812 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/816#issuecomment-7260615812). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T18:36:28Z. --- Merging. Red/green verified on `d90e4b213` 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!816
No description provided.