bink_play: clean up failed cache writes (BINK-CACHE-CLEANUP) #568

Manually merged
github merged 1 commit from gh-pr/568/head into gh-pr/568/base 2026-11-26 09:09:01 +00:00
Owner

@⁠JiyouProt on GitHub · 2026-11-24 08:34 UTC · original
JiyouProt:codex/bink-cache-cleanup → main · +97 −7 · 2 files · 1 commits · merged 2026-11-24 12:47 UTC

Claimed in the coordination issue as: BINK-CACHE-CLEANUP

What and why

A failed write or final replacement leaves bink_names.*.part in the persistent cache directory. Repeated failures accumulate incomplete files even though the previous cache is still usable.

Clean up the unique staging path in a finally block after the file handle is closed, including on interruption. Successful publication still uses the existing atomic replacement. Only the current writer's temporary file is removed.

Three synthetic regressions cover a write error, replacement errors/interruption, and an outer save failing after an overlapping inner save successfully publishes. They verify the old or newly published cache survives and an unrelated .part neighbor stays untouched. All three fail against the original source.

This is independent of #566 (uncached lookup storage). The production patch applies cleanly on that head; the new tests live in a separate file so the test additions do not collide.

Tested

Windows 11 build 26300.9974, Python 3.14.3, based on main 1c93c86970.

  • python -I tests/test_bink_play_cache_write.py: 3 passed.
  • Existing python -I tests/test_bink_play.py: 10 passed.
  • python -I tests/test_text_write_line_endings.py: 3 passed.
  • Integration with #566: 14 lookup tests + 3 cache-publication tests passed; no conflicting hunks.
  • compileall, changed-file no-game-data scan and git diff --check: passed.
  • Shared translator-suite run on the same main base (translator, semantic tests and runner unchanged by either cache fix): 465 files, 6,107 tests, 0 files failed in 515 s with 8 jobs and SPIRV-Tools available.

GPUs tested: n/a — standard-library tests with synthetic names only, no game data, codec or GPU needed.

AI-assisted: yes, Codex.

  • One topic, based on current main at task start and merges cleanly.
  • No game data, keys or decryption.
  • No translation rule changed.
**@⁠JiyouProt** on GitHub · 2026-11-24 08:34 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/568) `JiyouProt:codex/bink-cache-cleanup` → `main` · +97 −7 · 2 files · 1 commits · merged 2026-11-24 12:47 UTC Claimed in the coordination issue as: [BINK-CACHE-CLEANUP](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### What and why A failed write or final replacement leaves `bink_names.*.part` in the persistent cache directory. Repeated failures accumulate incomplete files even though the previous cache is still usable. Clean up the unique staging path in a finally block after the file handle is closed, including on interruption. Successful publication still uses the existing atomic replacement. Only the current writer's temporary file is removed. Three synthetic regressions cover a write error, replacement errors/interruption, and an outer save failing after an overlapping inner save successfully publishes. They verify the old or newly published cache survives and an unrelated .part neighbor stays untouched. All three fail against the original source. This is independent of #566 (uncached lookup storage). The production patch applies cleanly on that head; the new tests live in a separate file so the test additions do not collide. ### Tested Windows 11 build 26300.9974, Python 3.14.3, based on main 1c93c8697078c3ccbd6f374caf5bb3ab0b6bc8e4. - `python -I tests/test_bink_play_cache_write.py`: 3 passed. - Existing `python -I tests/test_bink_play.py`: 10 passed. - `python -I tests/test_text_write_line_endings.py`: 3 passed. - Integration with #566: 14 lookup tests + 3 cache-publication tests passed; no conflicting hunks. - compileall, changed-file no-game-data scan and `git diff --check`: passed. - Shared translator-suite run on the same main base (translator, semantic tests and runner unchanged by either cache fix): **465 files, 6,107 tests, 0 files failed** in 515 s with 8 jobs and SPIRV-Tools available. GPUs tested: n/a — standard-library tests with synthetic names only, no game data, codec or GPU needed. AI-assisted: yes, Codex. - [x] One topic, based on current main at task start and merges cleanly. - [x] No game data, keys or decryption. - [x] No translation rule changed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:08:59 +00:00
github manually merged commit 09867f4939 into gh-pr/568/base 2026-11-26 09:09:01 +00:00
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-24 12:27 UTC · original

Reviewed on Windows 11 x64 (Python 3.14.7, CPU only, synthetic fixtures only — no game files) against head commit 09867f4939ca43f535a3cda0bd43af045a7a60c9.

Verdict: Looks good overall (one small Windows FD-cleanup gap noted below) — wrapping mkstemp -> os.replace in try ... finally: Path(name).unlink(missing_ok=True) cleanly removes this writer's own .part staging file after write/os.replace failures or interrupts while leaving concurrent writers' staging files alone.

Checks run locally

  • Clean merge with main (21625bca): git merge-tree --write-tree upstream/main HEAD exited 0; git diff --check upstream/main...HEAD clean.
  • python -I tests/test_bink_play.py -v: 10 tests, OK.
  • python -I tests/test_bink_play_cache_write.py -v: 3 tests, OK.
  • python -I tests/test_ci_registration.py -v: 15 tests, OK (tests/test_bink_play_cache_write.py is auto-discovered by the stdlib test loop).
  • python -I tests/test_text_write_line_endings.py: 3 tests, OK.
  • python -I scripts/check_no_game_data.py tools/bink_play.py tests/test_bink_play_cache_write.py and python -m compileall -q tools tests: clean (exit 0).

Windows edge-case probes

  1. Clean & early-exit paths: Confirmed bink_names.main failing (exit 1) cleans up .tmp.csv without touching .part, and successful cache publication leaves only names.csv.
  2. Failure before open(fd, ...) takes ownership (tools/bink_play.py:86-96): If open(fd, "w", ...) raises before creating the file wrapper (probed on Windows 11 by raising OSError when open() is called with the integer fd from mkstemp), fd is still open when finally: Path(name).unlink(missing_ok=True) executes. On Windows 11 that unlink raises PermissionError: [WinError 32] (sharing violation), masking the original error in __context__ and leaving both the open handle and the .part file behind. Closing fd on an open(fd, ...) failure before running Path(name).unlink(missing_ok=True) would close that gap on Windows.

AI-assisted: yes

**@⁠kirigayakazima** on GitHub · 2026-11-24 12:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/568#issuecomment-7131468135) Reviewed on Windows 11 x64 (`Python 3.14.7`, CPU only, synthetic fixtures only — no game files) against head commit `09867f4939ca43f535a3cda0bd43af045a7a60c9`. **Verdict: Looks good overall (one small Windows FD-cleanup gap noted below)** — wrapping `mkstemp` -> `os.replace` in `try ... finally: Path(name).unlink(missing_ok=True)` cleanly removes this writer's own `.part` staging file after write/`os.replace` failures or interrupts while leaving concurrent writers' staging files alone. ### Checks run locally - Clean merge with `main` (`21625bca`): `git merge-tree --write-tree upstream/main HEAD` exited `0`; `git diff --check upstream/main...HEAD` clean. - `python -I tests/test_bink_play.py -v`: **10 tests, OK**. - `python -I tests/test_bink_play_cache_write.py -v`: **3 tests, OK**. - `python -I tests/test_ci_registration.py -v`: **15 tests, OK** (`tests/test_bink_play_cache_write.py` is auto-discovered by the stdlib test loop). - `python -I tests/test_text_write_line_endings.py`: **3 tests, OK**. - `python -I scripts/check_no_game_data.py tools/bink_play.py tests/test_bink_play_cache_write.py` and `python -m compileall -q tools tests`: clean (exit `0`). ### Windows edge-case probes 1. **Clean & early-exit paths**: Confirmed `bink_names.main` failing (exit `1`) cleans up `.tmp.csv` without touching `.part`, and successful cache publication leaves only `names.csv`. 2. **Failure before `open(fd, ...)` takes ownership (`tools/bink_play.py:86-96`)**: If `open(fd, "w", ...)` raises before creating the file wrapper (probed on Windows 11 by raising `OSError` when `open()` is called with the integer `fd` from `mkstemp`), `fd` is still open when `finally: Path(name).unlink(missing_ok=True)` executes. On Windows 11 that `unlink` raises `PermissionError: [WinError 32]` (sharing violation), masking the original error in `__context__` and leaving both the open handle and the `.part` file behind. Closing `fd` on an `open(fd, ...)` failure before running `Path(name).unlink(missing_ok=True)` would close that gap on Windows. AI-assisted: yes
Author
Owner

@⁠JiyouProt on GitHub · 2026-11-24 20:19 UTC · original

Thanks for the Windows fd-ownership edge case. It is now covered by the open follow-up #840 from @⁠trigger337 (head d6cee3e10), so I have not duplicated that work. I checked its changes and merged it locally with main 58be9cdf8 and our still-open --no-cache PR #566: clean merge, 16/16 bink_play tests and 3/3 cache-write tests pass on Windows / Python 3.14.3. Synthetic fixtures only; no game data or GPU. #840 still needs maintainer review/merge. AI-assisted with Codex.

**@⁠JiyouProt** on GitHub · 2026-11-24 20:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/568#issuecomment-7143361818) Thanks for the Windows fd-ownership edge case. It is now covered by the open follow-up #840 from @⁠trigger337 (head d6cee3e10), so I have not duplicated that work. I checked its changes and merged it locally with main 58be9cdf8 and our still-open --no-cache PR #566: clean merge, 16/16 bink_play tests and 3/3 cache-write tests pass on Windows / Python 3.14.3. Synthetic fixtures only; no game data or GPU. #840 still needs maintainer review/merge. AI-assisted with Codex.
This discussion has been locked. Commenting is limited to contributors.
No description provided.