story_index: make the staging file deletable when a replace fails (STORY-INDEX-STAGE-CLEANUP) #789

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

@⁠djrolfes on GitHub · 2026-11-24 13:50 UTC · original
djrolfes:djrolfes/story-index-stage-cleanup → main · +47 −3 · 2 files · 1 commits · open

Claimed in the coordination issue as: STORY-INDEX-STAGE-CLEANUP (#14)

Depends on: none

Fixes: none (the work item is the finding pattern in issue #14; there is no separate issue to close)

Independent branch update

Head 692b65cb1, based on e18b59a5b, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so Depends on: none is accurate. Retested on Linux: 34 tests pass, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against 5da72d19f. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted.

What and why

tools/story_index.py's write_output stages the report in a TemporaryDirectory next to the destination and chmods the staged file to the destination's permission bits before os.replace. When the replace fails over a read-only report on Windows, the staged file is read-only, so the context-manager cleanup cannot delete it: the staging directory is stranded beside the report and the cleanup's PermissionError replaces the real error, breaking the tool's {out}: {error} reporting at exactly the interesting moment.

The cleanup now runs in a finally: make the staged file writable (0o600) before the directory is cleaned up, and let one delete failure pass (suppress(OSError)) so the caller's except OSError reports the replace error and exits 2. A successful publish is byte-for-byte unchanged, and a failed one still leaves the prior report intact — the behavior the two existing partial-write tests already pin down. The shape is the one navmesh_index.py and bvh_index.py use for their staging cleanup.

Tested

  • python3 -I tests/test_story_index.py: 34 tests OK, including the new test_failed_replace_of_read_only_report_makes_stage_deletable, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a 0o444 report, asserts the stage was made deletable, the prior report untouched, and no staging directory stranded).
  • The two existing partial-staged-write tests still pass unchanged (test_csv_partial_staged_write_keeps_prior_bytes_and_cleans_up, test_json_partial_staged_write_keeps_prior_bytes_and_cleans_up).
  • python3 -m compileall -q tools/story_index.py tests/test_story_index.py clean; python3 -I scripts/check_no_game_data.py tools/story_index.py tests/test_story_index.py passes; synthetic archives only.

GPUs tested: n/a (standard-library tool; no game files, nothing online)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a)
**@⁠djrolfes** on GitHub · 2026-11-24 13:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/789) `djrolfes:djrolfes/story-index-stage-cleanup` → `main` · +47 −3 · 2 files · 1 commits · open Claimed in the coordination issue as: STORY-INDEX-STAGE-CLEANUP (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Depends on: none Fixes: none (the work item is the finding pattern in issue #14; there is no separate issue to close) ### Independent branch update Head `692b65cb1`, based on `e18b59a5b`, contains exactly one topic commit. Removed the accidentally inherited #771 concurrency change and all sibling cleanup commits; this PR is now genuinely independent, so `Depends on: none` is accurate. Retested on Linux: **34 tests pass**, Python compileall, changed-file scanner and diff checks pass. Clean merge-tree against `5da72d19f`. Original head preserved; branch updated with an explicit lease. A passing label check is not full CI, and no hosted-suite pass is claimed. AI-assisted. ### What and why `tools/story_index.py`'s `write_output` stages the report in a `TemporaryDirectory` next to the destination and chmods the staged file to the destination's permission bits before `os.replace`. When the replace fails over a read-only report on Windows, the staged file is read-only, so the context-manager cleanup cannot delete it: the staging directory is stranded beside the report and the cleanup's `PermissionError` replaces the real error, breaking the tool's `{out}: {error}` reporting at exactly the interesting moment. The cleanup now runs in a `finally`: make the staged file writable (`0o600`) before the directory is cleaned up, and let one delete failure pass (`suppress(OSError)`) so the caller's `except OSError` reports the replace error and exits 2. A successful publish is byte-for-byte unchanged, and a failed one still leaves the prior report intact — the behavior the two existing partial-write tests already pin down. The shape is the one `navmesh_index.py` and `bvh_index.py` use for their staging cleanup. ### Tested - `python3 -I tests/test_story_index.py`: 34 tests OK, including the new `test_failed_replace_of_read_only_report_makes_stage_deletable`, which fails against the old code on the made-deletable assertion (it mocks the replace as failing over a `0o444` report, asserts the stage was made deletable, the prior report untouched, and no staging directory stranded). - The two existing partial-staged-write tests still pass unchanged (`test_csv_partial_staged_write_keeps_prior_bytes_and_cleans_up`, `test_json_partial_staged_write_keeps_prior_bytes_and_cleans_up`). - `python3 -m compileall -q tools/story_index.py tests/test_story_index.py` clean; `python3 -I scripts/check_no_game_data.py tools/story_index.py tests/test_story_index.py` passes; synthetic archives only. GPUs tested: n/a (standard-library tool; no game files, nothing online) AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a)
The staged report carries the destination's bits, so on Windows a failed
os.replace over a read-only report leaves a read-only stage the TemporaryDirectory
cleanup refuses to delete, masking the real error with a cleanup failure. The
cleanup now makes the staged file writable before deleting and lets one delete
failure go, so the caller reports the replace; a successful publish is
unchanged, and the prior report stays byte-for-byte intact on failure. Same
shape as navmesh_index's and bvh_index's staging cleanup.

Regression test in the style of the failed-replace tests there: mocks the
replace as failing over a 0o444 report and fails against the old code on the
made-deletable assertion. Synthetic archives only; no game data.

Claimed in the coordination issue as STORY-INDEX-STAGE-CLEANUP (issue #14).
AI-assisted.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:21:27 +00:00
Author
Owner

@⁠djrolfes on GitHub · 2026-11-25 19:45 UTC · original

Rebuilt this branch independently on main e18b59a5b: 692b65cb1, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 34 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.

**@⁠djrolfes** on GitHub · 2026-11-25 19:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/789#issuecomment-7172728125) Rebuilt this branch independently on main e18b59a5b: 692b65cb1, exactly one cleanup commit. Removed #771 and sibling cleanup commits rather than adding a false dependency. 34 focused tests, compileall, changed-file scan and diff checks pass; clean merge-tree against 5da72d19f. Explicit old-head lease used; prior head preserved. No full hosted CI result is inferred from a label check. AI-assisted.
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/789/head:github-bot/gh-789'
git switch 'github-bot/gh-789'

Merge

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