world_index: restore write mode before unlink on replace failure and publish mode (WORLD-INDEX-STAGE-CLEANUP) #889

Open
github-bot wants to merge 1 commit from github-bot/gh-889 into main AGit
Owner

@⁠trigger337 on GitHub · 2026-11-24 14:58 UTC · original
trigger337:fix/world-index-stage-cleanup → main · +32 −5 · 2 files · 1 commits · open

Overview

In tools/world_index.py, apply published_mode(destination) in _staged_entity_report before 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.replace failure causes a PermissionError [WinError 5], leaving stranded temporary files behind and masking underlying exceptions.

Changes

  1. tools/world_index.py: Import published_mode, apply it to staged before replacement, and restore write mode before os.unlink in finally:.
  2. tests/test_world_index.py: Add test_staged_entity_report_restores_write_mode_on_replace_failure asserting write mode restoration on replace failure.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 14:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/889) `trigger337:fix/world-index-stage-cleanup` → `main` · +32 −5 · 2 files · 1 commits · open ### Overview In `tools/world_index.py`, apply `published_mode(destination)` in `_staged_entity_report` before 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.replace` failure causes a `PermissionError` [WinError 5], leaving stranded temporary files behind and masking underlying exceptions. ### Changes 1. `tools/world_index.py`: Import `published_mode`, apply it to `staged` before replacement, and restore write mode before `os.unlink` in `finally:`. 2. `tests/test_world_index.py`: Add `test_staged_entity_report_restores_write_mode_on_replace_failure` asserting write mode restoration on replace failure. agent: yes AI-assisted: yes
Apply published_mode(destination) in _staged_entity_report before atomic replacement,
and restore write permission (0o600) before unlinking in finally block
when replace fails, preventing Windows PermissionError [WinError 5] and
stranded temporary files.

agent: yes
AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:26:29 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-25 08:37 UTC · original

Two failures on Windows with this PR. Windows 11, Python 3.14, python -I tests/test_world_index.py:

  • main 3f81d46ac: Ran 46 tests, OK.
  • this PR (head of pull/889): Ran 47 tests, FAILED (failures=2).
  1. test_creates_a_verbatim_placement_report_directory (existing test, passes on main): AssertionError: 2 != 0. The tool prints
    ERROR: [Errno 2] No such file or directory: '\\?\C:\...\Temp\tmp...\reports\.mode-<hex>.probe'.
    The new os.chmod(staged, published_mode(destination)) reaches file_mode.new_file_mode() for a new report, and its probe file cannot be created at that \\?\-prefixed path in reports\. On main the staged file only got mode & 0o777 when a mode was known, so this path was never taken.
  2. test_staged_entity_report_restores_write_mode_on_replace_failure (new test): AssertionError: 438 != 384. On Windows os.chmod only sets or clears the read-only flag, so chmod(..., 0o600) reads back as 0o666. The assertion needs a POSIX-only guard, or it should check the write bit (stat.S_IWRITE) as the removed os.name == "nt" branch did.

The other changes (os.rmdir / chmod failures tolerated in finally) look fine to me. I did not measure on real data: world_index needs a raw RPF9 package or carved .bin files, which my work folder does not keep.

AI-assisted: yes (Claude Code ran the tests; I checked them).

**@⁠MoonEyes** on GitHub · 2026-11-25 08:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/889#issuecomment-7157275985) Two failures on Windows with this PR. Windows 11, Python 3.14, `python -I tests/test_world_index.py`: - main 3f81d46ac: `Ran 46 tests`, `OK`. - this PR (head of `pull/889`): `Ran 47 tests`, `FAILED (failures=2)`. 1. **`test_creates_a_verbatim_placement_report_directory` (existing test, passes on main)**: `AssertionError: 2 != 0`. The tool prints `ERROR: [Errno 2] No such file or directory: '\\?\C:\...\Temp\tmp...\reports\.mode-<hex>.probe'`. The new `os.chmod(staged, published_mode(destination))` reaches `file_mode.new_file_mode()` for a new report, and its probe file cannot be created at that `\\?\`-prefixed path in `reports\`. On main the staged file only got `mode & 0o777` when a mode was known, so this path was never taken. 2. **`test_staged_entity_report_restores_write_mode_on_replace_failure` (new test)**: `AssertionError: 438 != 384`. On Windows `os.chmod` only sets or clears the read-only flag, so `chmod(..., 0o600)` reads back as `0o666`. The assertion needs a POSIX-only guard, or it should check the write bit (`stat.S_IWRITE`) as the removed `os.name == "nt"` branch did. The other changes (`os.rmdir` / `chmod` failures tolerated in `finally`) look fine to me. I did not measure on real data: `world_index` needs a raw RPF9 package or carved `.bin` files, which my work folder does not keep. AI-assisted: yes (Claude Code ran the tests; I checked them).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/889/head:github-bot/gh-889'
git switch 'github-bot/gh-889'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-889'
git switch 'github-bot/gh-889'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-889'
git switch 'github-bot/gh-889'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-889'
git switch 'main'
git merge --squash 'github-bot/gh-889'
git switch 'main'
git merge --ff-only 'github-bot/gh-889'
git switch 'main'
git merge 'github-bot/gh-889'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.