fix(setup): a failed update gives the installed Builder its tools back #447
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
4 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!447
Loading…
Reference in a new issue
No description provided.
Delete branch "jarynclouatre/Longshot:fix/setup-reused-tools-back"
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
On an ordinary (not portable) Builder install, an update that fails part way (a download or unpack error, or the setup closed) leaves the installed Builder without its tools: it can no longer build, and the next update downloads them all again (llvm-mingw alone is 191 MB).
reuse_partinbuilder/setup/setup.cmoves the folders of the parts that did not change (Python, llvm-mingw, emsdk) out of the installed version intoversions\<tag>.part(if (!g_home.portable) return MoveFileW(from, to) != 0;). Nothing moves them back when the new version is not published, and the next start removes the staging folder with them (rmtree(install)inwork).How to reproduce
Seen on: found reading the code; not run on Windows. Game-free checks on Linux x86-64.
Settings and switches: an ordinary (not portable) Builder install.
Steps: Start an update, then have it fail part way with a download or unpack error, or close setup before the new version is published. Start the installed Builder or try the update again.
Expected: The installed Builder gets its unchanged tools back; after setup was closed, its next start restores them before removing the staging folder.
Actual: The installed Builder has no tools and can no longer build; the next update downloads them all again (llvm-mingw alone is 191 MB).
What changed
A failed update returns the unchanged tools it moved out of the installed Builder. If setup was closed, its next start returns them before removing the staging folder.
builder/setup/setup.c): the move stays (it keeps an update small and quick).note_reused:reuse_partnames each folder in the staging folder'sreused.txtbefore it moves it. A setup stopped between the two leaves a name whose folder is still in the installed version, and nothing moves. When the name cannot be written the part is downloaded instead.restore_reused: moves the folders named inreused.txtback into the installed version (current.txt), only where that version has none, so a part this attempt downloaded and unpacked (perhaps half) never goes into it. Names are checked withlist_name_ok, as the setup list's are.failcalls it once the staging has begun (g_staged), andworkcalls it before it removes an old staging folder, which covers a setup that was closed. After the version is publishedreused.txtis deleted from it.tests/test_setup_tool_merge.py): case 5 runs the realreuse_partandrestore_reusedover a POSIX stand-in: an ordinary update moves an unchanged Python folder over and lists it; (a) after a failure the installed version has it again, bytes the same, and the staging has none; (b) a second attempt moves it over again, no download; (c) a stopped setup: the next start's restore and removal of the staging leave the installed version whole; (d) a folder this attempt unpacked, not listed, stays in the staging; (e) a listed folder whose move failed is not replaced; (f) portable still copies and lists nothing. The stand-in'sCreateFileWgained an append mode andWriteFile; the extractor skips a declaration ahead of its definition.tests/test_portable_setup_transaction.pyextractsnote_reusedwithreuse_partand checks the ordinary move'sreused.txt;tests/test_setup_runtime_paths.pydeclaresg_stagedfor the publication block it extracts.Measurements
Verdict: case 5 fails on main and passes 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; branch
fix/setup-reused-tools-back.python3 -I -B tests/run_all.py, two runs each, interleaved (main, PR, the other branch, twice). Case 5 also runs against main'ssetup.c, with no-op stand-ins for the two new functions.How to reproduce: the commands above in a checkout of each commit
5e072fc880f44a4ftests/run_all.py(run 1, run 2)test_bake_portability.py,test_menu_keys.py,test_module_ids.py,test_pad_layout.pytests/test_setup_tool_merge.pycase 5after a failed update the installed version has no Pythontest_bake_portability.pyfails here for a missing Python module (zstandard).test_menu_keys.pydoesn't build with g++ andtest_pad_layout.py's fixture lackshost/hold_toggle.h, both on main since #137 (#331 and #338 fix them).test_module_ids.pylooks for a source marker that main no longer has.Flags and settings
None.
Testing
Tested: the game-free suite on a Linux PC, as in Measurements.
setup.ccompiles (-fsyntax-only -Wall -Wextra) with llvm-mingw 20261104's x86_64-w64-mingw32-clang with the same 6 warnings as main's. The Windows-only setup checks (test_portable_setup_transaction,test_setup_runtime_paths,test_portable_setup_start,test_setup_runtime,test_portable_setup_paths,test_setup_tar_diagnostics) and the Windows variant oftest_setup_tool_merge's fixture build with that compiler (-Werror).Not tested: those Windows-only checks were built but not run (no Windows PC for them here); the setup itself on Windows: an update of an ordinary install with the network cut after the first parts.
Must be tested: None.
Risks
What could break: A setup that was closed (not failed) gives the folders back at its next start, before anything is downloaded; the installed Builder started on its own before then still lacks them. A failed move back leaves the folder in the staging, where the next start tries again before removing it (as before this change, it would then be downloaded).
Turning it off: Reverting the commit is enough.
Compatibility: Failed updates restore the installed Builder's reused tools; portable homes still copy as before and write no list.
Checklist
Everyone
type(scope): description) of the status line's type.can't be run by hand is in Testing's Not testable by hand, with why.
in Risks.
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(setup): a failed update gives the installed Builder its tools backto fix(setup): a failed update gives the installed Builder its tools backCode review only (read the diff and
setup.caround it; nothing was run).What I checked and found sound:
fail()after the staging begins goes throughrestore_reusedonce (g_stagedis cleared first, so a failure inside the restore can't loop), andg_stagedis cleared right afterpublish_install, so a late failure can't pull folders out of a published version.reused.txtbefore the move, so a death between the two leaves a name whose folder is still in the installed version, and the restore's "source missing" / "destination exists" checks make that a no-op. A part this attempt downloaded is never listed, so it can't be moved into the installed version.MoveFileW,CreateFileW,home_path); the names read back fromreused.txtgo throughlist_name_ok, as the setup list's do. NoCP_ACP.One gap, not a regression (this is strictly better than main), so a comment and not a block:
restore_reusedinworkonly looks atversions\<this tag>.part. If setup is closed mid-update and a newer release is published before the next run, the next setup is for a different tag: it never visits the old<oldtag>.part, its ownreuse_partfinds no tools in the installed version and downloads them all again (the 191 MB the PR is about), and the old staging with the real folders sits there for good. The description says "its next start restores them", which holds only for the same tag. A small fix would be to walkversions\*.partat the start ofworkand callrestore_reused(versions, <that name minus .part>, <that dir>)for each, before thermtree. Worth doing here or as a follow-up; I left it alone because it changes behaviour.Nit-free otherwise. Not marking it approved only because the setup itself was never run on Windows (the description says so, and it lists no must-test), so this stays a comment for a human to take the gap above or not; I see nothing else that should block a merge.
Review findings retained as an ordinary comment. I am following this PR as a watcher; another reviewer should make the final approval decision. The code findings and validation gaps below still need consideration.
Code-only review of
80f44a4f384eea7c5d2c602101b7278d157cae40; no builds, tests, generators or runtime runs performed by me. COMMENT, pending native Windows recovery evidence; no confirmed newly introduced merge blocker found.The ordinary update journals a destination before moving it, restores only when staging has it and the installed version lacks it, and clears the rollback hook immediately after publication. Portable reuse remains a separate copy; no hard-link sharing is introduced. I read the full diff, surrounding failure/publication/pruning paths, all changed fixtures, and the existing review.
Two limits should stay explicit:
builder/setup/setup.c:737–738: recovery visits only this release's<tag>.part. As the earlier review notes, restarting with a different release does not restore the abandoned release's tools. A successful later install'sprune()eventually deletes that staging directory (:599–604), so it does not necessarily remain forever. This is an incomplete fix of an existing path, not a new regression.builder/setup/setup.c:555ignores a failed restore move;:738then deletes staging regardless. If the old destination cannot be recreated or renamed into, recoverable tool files can still be discarded and require downloading again. The PR acknowledges this existing limitation. A useful follow-up is to return restoration status and retain unresolved journal entries/directories, with a fixture that injects a restore failure and verifies the files survive cleanup.The author reports Linux fixture/suite runs (474 passed, four named baseline failures, 83 skipped) and Windows cross-compilation. Case 5 invokes
restore_reuseddirectly; it does not exercise the realfail()hook or interrupted setup process. Before approval I would want Windows execution of the authored fixtures plus an ordinary update interrupted after reuse and a failed-download rollback, checking byte preservation and successful reuse on retry. “Must be tested: None” does not establish that evidence. No game/GPU run is needed for this installer-only change.Overlap: PR 286 retries tool-placement/publication moves and adjusts the same publication error branch. It complements this rollback change; neither replaces the other. No required merge order identified, but preserve both changes around
publish_installwhen combining them. Cached forge state says mergeable; substantive CI jobs are pending/blocked, not passing.A failed update puts the unchanged tools back into the installed Builder, and a setup that was closed puts them back at its next start before the staging folder is removed. I read head
80f44a4f. That path is right, and this is a comment, not an approval.The name is written to
reused.txtbefore the folder is moved.failclearsg_stagedand restores once, so a failure inside the restore does not loop.g_stagedis cleared after a successful publish, so a later failure cannot pull folders out of a version that is already installed. A folder this attempt unpacked is not on the list, so it is not moved into the installed version. Portable homes still copy and write no list. The names read back go throughlist_name_ok.It does not apply onto main
544229a2. #1138 added the Windows error to the publish failure and amove_retry. A rebase keeps that error code, keepsg_staged = NULLafter a successful publish, and keepsmove_retryin the lists the tests extract, besidenote_reusedandrestore_reused.restore_reusedlooks only at this release'sversions\<tag>.part. If setup is closed and the next run is a newer tag, that staging folder is never visited, the installed Builder still has no tools, and the next update downloads them again. The description's "next start" holds for the same tag.The setup itself was not run on Windows. The game-free case covers the failure, the retry and a stopped setup.
Brought up to the ready-for-review standard (#1454): the checklist's Everyone list has two new boxes, added here from what this PR's description and comments show (please check they match what you know).
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.