world_index: restore write mode before unlink on replace failure and publish mode (WORLD-INDEX-STAGE-CLEANUP) #889
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/889"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:58:10Z.
Overview
In
tools/world_index.py, applypublished_mode(destination)in_staged_entity_reportbefore atomic replacement, 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.replacefailure causes aPermissionError[WinError 5], leaving stranded temporary files behind and masking underlying exceptions.Changes
tools/world_index.py: Importpublished_mode, apply it tostagedbefore replacement, and restore write mode beforeos.unlinkinfinally:.tests/test_world_index.py: Addtest_staged_entity_report_restores_write_mode_on_replace_failureasserting write mode restoration on replace failure.agent: yes
AI-assisted: yes
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-25T08:37:51Z.
Two failures on Windows with this PR. Windows 11, Python 3.14,
python -I tests/test_world_index.py:3f81d46ac:Ran 46 tests,OK.pull/889):Ran 47 tests,FAILED (failures=2).test_creates_a_verbatim_placement_report_directory(existing test, passes on main):AssertionError: 2 != 0. The tool printsERROR: [Errno 2] No such file or directory: '\\?\C:\...\Temp\tmp...\reports\.mode-<hex>.probe'.The new
os.chmod(staged, published_mode(destination))reachesfile_mode.new_file_mode()for a new report, and its probe file cannot be created at that\\?\-prefixed path inreports\. On main the staged file only gotmode & 0o777when a mode was known, so this path was never taken.test_staged_entity_report_restores_write_mode_on_replace_failure(new test):AssertionError: 438 != 384. On Windowsos.chmodonly sets or clears the read-only flag, sochmod(..., 0o600)reads back as0o666. The assertion needs a POSIX-only guard, or it should check the write bit (stat.S_IWRITE) as the removedos.name == "nt"branch did.The other changes (
os.rmdir/chmodfailures tolerated infinally) look fine to me. I did not measure on real data:world_indexneeds a raw RPF9 package or carved.binfiles, which my work folder does not keep.AI-assisted: yes (Claude Code ran the tests; I checked them).
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-29T00:44:09Z.
Independent verification on Windows 11 (
10.0.26200, x64) with4822bcf9demerged ontoorigin/main(e66c65b950,0merge conflicts), tested under bothPython 3.12.10andPython 3.14.5to re-check both Windows 11 + Python 3.14 failures reported in#7157275985:origin/main+#889tests/test_world_index.py):python -I tests/test_world_index.py:Ran 47 tests,FAILED (failures=1)(test_staged_entity_report_restores_write_mode_on_replace_failure:origin/mainpassedstat.S_IWRITE=0o200rather than0o600) on bothPython 3.12.10andPython 3.14.5.4822bcf9demerged ontoorigin/main):python -I tests/test_world_index.py:Ran 48 tests,OKon bothPython 3.12.10(0.55 s) andPython 3.14.5(0.52 s) — bothtest_creates_a_verbatim_placement_report_directoryandtest_staged_entity_report_restores_write_mode_on_replace_failurenow pass cleanly on Windows 11.python -I tests/test_file_mode.py:Ran 5 tests,OK (skipped=2)on both Python versions.world_index._staged_entity_report(out)against an existing0o444entities.jsonlraisesPermissionError([WinError 5]) onos.replace, restores write permission infinally:, unlinksstaged, and removes.world-index-*with0stranded temporary directories on bothPython 3.12.10andPython 3.14.5.tools/world_index.py:42addssys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))directly above the existing_TOOLS_DIRsys.pathsetup at lines46-48(from file_mode import published_modecould sit below line48).published_mode(destination)raisedFileNotFoundErrorintest_creates_a_verbatim_placement_report_directory(now caught bytry ... except OSError: pass):file_mode.published_mode()callsos.path.abspath(path), which invokes Win32GetFullPathNameWeven on\\?\verbatim paths and strips trailing spaces/dots from directory names (\\?\...\reports \entities.jsonl->\\?\...\reports\entities.jsonl). Sinceopen(staged, "w")already creates new files withopen()'s default mode (unlikeNamedTemporaryFile's0o600), ignoringOSErrorthere leaves new verbatim-path files with the expected default mode.git diff --check,python -I -m compileall -q,python -I scripts/check_no_game_data.py,python -I tests/test_ci_registration.py(18/18), andpython -I tests/test_text_write_line_endings.py(3/3) all exited0.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:31:34Z.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main
53b77df14: red 1 failure (WorldIndexTest.test_staged_entity_report_restores_write_mode_on_replace_failure) / green 48 OK.4822bcf9d,python -I tests/test_world_index.pyfrom the repository root.AssertionError: False is not true : [], no chmod restore of the write mode is recorded when the replace fails.git merge --no-ffof this PR, no conflict): 48 run, OK, 5 skips.Red = main + only the test files from this PR (
git checkout pr-889 -- tests/test_world_index.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.AI-assisted: Claude Code (Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T08:34:10Z.
Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/889#issuecomment-7248839254
The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up.
AI-assisted: Claude Code
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T18:59:35Z.
Merging. Head
4822bcf9dhas red/green verdicts from reviewers other than the author (above), merges cleanly withmaine5042dd50, does not force a rebase of #2566, and carries a claim ID. Remaining main CI reds (translator-testsmesh,semantic-testsf16) are pre-existing. Merged by MoonEyes.AI-assisted (Claude Code).