bink_play: clean up failed cache writes (BINK-CACHE-CLEANUP) #568
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!568
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/568/head"
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?
@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 UTCClaimed in the coordination issue as: BINK-CACHE-CLEANUP
What and why
A failed write or final replacement leaves
bink_names.*.partin 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.python -I tests/test_bink_play.py: 10 passed.python -I tests/test_text_write_line_endings.py: 3 passed.git diff --check: passed.GPUs tested: n/a — standard-library tests with synthetic names only, no game data, codec or GPU needed.
AI-assisted: yes, Codex.
@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 commit09867f4939ca43f535a3cda0bd43af045a7a60c9.Verdict: Looks good overall (one small Windows FD-cleanup gap noted below) — wrapping
mkstemp->os.replaceintry ... finally: Path(name).unlink(missing_ok=True)cleanly removes this writer's own.partstaging file after write/os.replacefailures or interrupts while leaving concurrent writers' staging files alone.Checks run locally
main(21625bca):git merge-tree --write-tree upstream/main HEADexited0;git diff --check upstream/main...HEADclean.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.pyis 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.pyandpython -m compileall -q tools tests: clean (exit0).Windows edge-case probes
bink_names.mainfailing (exit1) cleans up.tmp.csvwithout touching.part, and successful cache publication leaves onlynames.csv.open(fd, ...)takes ownership (tools/bink_play.py:86-96): Ifopen(fd, "w", ...)raises before creating the file wrapper (probed on Windows 11 by raisingOSErrorwhenopen()is called with the integerfdfrommkstemp),fdis still open whenfinally: Path(name).unlink(missing_ok=True)executes. On Windows 11 thatunlinkraisesPermissionError: [WinError 32](sharing violation), masking the original error in__context__and leaving both the open handle and the.partfile behind. Closingfdon anopen(fd, ...)failure before runningPath(name).unlink(missing_ok=True)would close that gap on Windows.AI-assisted: yes
@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 main58be9cdf8and 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.