fix(prompts): a failed rebuild of the button pictures keeps the last good file #486
No reviewers
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
3 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!486
Loading…
Reference in a new issue
No description provided.
Delete branch "jarynclouatre/Longshot:fix/prompt-cache-keep-good"
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?
Type: fix · Risk: low · Tested on: Linux x86-64 (game-free checks only) · Needs: none
Why
When a start writes the button prompts' cache again (after the Button prompts face or a binding changed) and the write fails part way, for example on a full disk,
cache/prompts/Common.bntx.zs(orCommon.blarc.zs) is left cut short while its key file still holds the old setting's key. Back on the old setting the key matches, the file exists, and the cut file is given to the game at every start.write_patchedinhost/prompts.copensoutwithfopen(out, "wb"), which empties the old file before the new one is known good. On a failure the old key stays, and the reuse check is only "key equal and the file exists".None filed. Found reading
write_patched.How to reproduce
Seen on: found reading the code; not seen in the game
Settings and switches: Change the Button prompts face or a binding, then return to the old setting.
Steps: Start with a cached file, change the face or a binding, and start again with a write that fails part way, for example on a full disk. Return to the old setting and start again.
Expected: A failed rewrite leaves the last good file available for the old setting.
Actual: The file is cut short while its key still holds the old setting's key, so the cut file is given to the game at every start on that setting.
What changed
The button pictures are written to a temporary file before replacing the cached file. A failed write keeps the last good file, and an interrupted replacement leaves no key so the next start writes again.
host/prompts.c,write_patched): writes toout.tmpbeside the file, with every write and thefclosechecked. Then it removes the key file, moves the temporary file overout(MoveFileExAwithMOVEFILE_REPLACE_EXISTING) and writes the new key. On any failure the temporary file is deleted and the old file and its key stay as they were, which is still a valid pair. A stop between the steps leaves no key, so the next start writes again. Both callers (textures and layouts) go through this function, and each has its own key file.tests/test_prompt_cache_errors.pycompileswrite_patchedand its zstd helpers fromhost/prompts.c, with the three Windows file calls as stand-ins on POSIX calls. Setting A is written; setting B's write fails at a file size limit (RLIMIT_FSIZE, SIGXFSZ ignored); A's file bytes and key are unchanged and no.tmpis left; A again serves the same bytes; B with room replaces file and key, and the file holds the game's bytes with B's run. Skipped on Windows (no file size limit there).tests/test_mods_size_table.py's routing fixture buildsprompts.cover pieces ofhost/posix/win32_posix.cand now takes itsDeleteFileAandMoveFileExAtoo.Measurements
Verdict: the new checks fail on main and pass here; the suite has no new failures.
Hardware: none used (game-free checks on a Linux x86-64 PC, gcc 15.2, Python 3.14)
Scene: none, the game was not run
Method: 2026-11-14.
python3 -I -B tests/run_all.py --jobs 4, two runs each (main twice, then the branches of this batch in turn, twice). The new test also ran against main'shost/prompts.c. Branch:fix/prompt-cache-keep-good.How to reproduce: the commands above in a checkout of each commit
9c9d69edd690b06btests/run_all.py(run 1, run 2)test_bake_portability.py,test_walk_key.pytests/test_prompt_cache_errors.pyFAIL: a failed write of setting B changed setting A's file (200000 bytes, was 300019)test_bake_portability.pyfails here for a missing Python module (zstandard).test_walk_key.py's fixture doesn't link on main (undefined reference to hos_oot_autoload_input).Flags and settings
None.
Testing
Tested: the game-free suite on a Linux PC, as in Measurements.
host/prompts.ccompiles (-fsyntax-only -Wall -Wextra) with llvm-mingw 20261104's x86_64-w64-mingw32-clang with no warnings, as main's, and whole with gcc intests/test_mods_size_table.py's fixture.Not tested: the game, and a full disk on Windows.
Must be tested: None.
Risks
What could break: #218 changes the
fopencalls in the same function tohos_fopen_*; whichever lands second needs a small rebase.Turning it off: Reverting the commit puts the write in place back.
Compatibility: A rewrite now needs room for a second copy of the file for a moment (a few MB).
Checklist
Everyone
type(scope): description) of the status line's type.main.python -I -B tests/run_all.pypasses (any failure that also fails onmainis named).third_party/untouched (a new folder with aPROVENANCE.mdinstead).When it applies
mainand passing here.tests/that reads changed source updated in this PR, not weakened.WIP: fix(prompts): a failed rebuild of the button pictures keeps the last good fileto fix(prompts): a failed rebuild of the button pictures keeps the last good filePublished test-only supplement:
NitnekLeBorgne/Longshot@49e496dd42I prepared a one-file, test-only supplement to your existing cache-publication fix:
tests/test_prompt_cache_publication.py. It does not changehost/prompts.cor replace your PR. The test compiles the realwrite_patched, its raw-zstd helpers and run-order helpers from the selected source, with explicitly named POSIX stand-ins for the file calls.The added cases use only 300,000 synthetic bytes, and cover both cache naming conventions:
DeleteFileAonly on the key path: return false, preserve A/key, never callMoveFileExA, and allow temporary-file cleanup and a later retry.MoveFileExAafter the key was really deleted: return false, preserve A's data, leave the key absent, clean up the temporary file, and rebuild B/key on retry.Measurements are functional test output, not FPS. Against the pinned earlier main
543846ebb08ded4ce75d364403bc4dcf24e83e85, the missing-source assertion fails: the last-good 300,019-byte cache is truncated to zero bytes. The unchanged owner headd690b06b182d24b9056fcf55905720b06c2621e7passes all six family/scenario combinations. The same final test bytes were replayed in two main/head/main/head rounds. Baseline replay selects only missing-source and stops at its firstCommon.bntxpreservation failure; no baseline pass is claimed for the other scenarios or family.Your existing
tests/test_prompt_cache_errors.pyalso passes unchanged in a separate bounded replay of itsRLIMIT_FSIZEcase. One private, unshipped mutant that ignores a refused key deletion is rejected by the new test; that is a sensitivity control, not a defect in your head.Reproduce from the owner head with the supplemental patch applied:
Linux x86-64, Python 3.14.9, GCC 13.3.0. This validates a sliced-source unit fixture, not native Win32, whole-caller execution, a full PR build, current-main integration or a game run. Full-suite prerequisites such as
zstandard,fontTools, shader tools and other toolchains were not provisioned. Main moved to1be60eae813865b0845fb8bb05b1d7cb9b39e51fduring the private work; that newer main was not tested or merged into this fixture. The owner head remained unchanged at the final anonymous cache-busted GET.Frozen patch SHA-256:
709fc76ba90a3dcb766feedd148c442e7be614893c4fc0947951ca79828bb770.The branch adds only that test above your unchanged pinned head; it does not replace your production fix or claim current-main integration. The historical main hashes above describe the retained private runs. Separate independent specification and quality reviews passed on the unchanged test bytes; this is not full-PR approval.
Assisted-by: Hermes Agent (OpenAI GPT-6.1-sol)
Co-Authored-By: Claudia (OpenAI GPT-6.1-sol)
Read the diff and the surrounding
write_patched; nothing was run.write_patchednow writesout.tmp, checks every write and thefclose, and only then removes the key file, moves the temporary file overoutand writes the new key. Each failure path leaves a consistent state:MoveFileExAandMOVEFILE_REPLACE_EXISTINGexist in both the Windows API and the POSIX shim (host/posix/windows.h,host/posix/win32_posix.c). The size-table fixture pulling in the two shim functions is the right test update.tmpbuffer isMAX_PATH + 8andsnprintftruncates safely. A stale.tmpleft by a hard kill is truncated by the nextfopen(..., "wb").The new
tests/test_prompt_cache_errors.pycompiles the real function, fails on main for the stated reason (cut file served on the old key) and passes here. The description backs the diff, and the "Not tested" line (game, full disk on Windows) is honest. Risk is low. The only game-visible effect is the cache rewrite on a settings change, and the fix stops that rewrite from corrupting the old pair.Merge order with the sibling PRs: #485 edits other hunks of
host/prompts.c(first_pad,current_binds,cmap4_bind) and other tests, so I see no overlap with this PR. The #218fopentohos_fopen_*note in Risks is the only likely small rebase. NitnekLeBorgne's test-only supplement is a separate branch and does not block this one.