Skip to content

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

Merged
ubiquitarianism merged 1 commit into
ProjectLeonida:mainfrom
JiyouProt:codex/bink-cache-cleanup
Nov 24, 2026
Merged

ubiquitarianism merged 1 commit into
ProjectLeonida:mainfrom
JiyouProt:codex/bink-cache-cleanup

Conversation

@JiyouProt

Copy link
Copy Markdown
Contributor

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 1c93c86.

  • 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 bink_play: honor --no-cache without persistent storage (BINK-NO-CACHE) #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.

@kirigayakazima

Copy link
Copy Markdown
Contributor

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

@ubiquitarianism
ubiquitarianism merged commit 43bbd57 into ProjectLeonida:main Nov 24, 2026
1 check passed
@JiyouProt

Copy link
Copy Markdown
Contributor Author

Thanks for the Windows fd-ownership edge case. It is now covered by the open follow-up #840 from @trigger337 (head d6cee3e), so I have not duplicated that work. I checked its changes and merged it locally with main 58be9cd 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants