Commit Graph
1 Commits
Author SHA1 Message Date
28bd60fbba fix(backends): stage and verify backend install before removing the working binary (#2315)
install_from_github removed the existing install directory up front whenever the
installed version no longer matched the pin (or version.txt was missing), before
the replacement asset was downloaded. A slow or interrupted download (unreliable
link, going offline mid-flight, a transient GitHub 5xx) then left the backend with
no usable binary at all: the old one was already gone and the new one never arrived.

Make the reinstall atomic. The new install is downloaded and extracted into a
sibling staging directory and only swapped into place once the executable is
verified present. The swap (commit_staged_install) keeps a recoverable backup at
all times: the existing install is renamed aside to "<dir>.old", staging is renamed
into place, and the backup is deleted only once the new tree is verified present;
if the promotion rename fails the backup is rolled back, so a failed swap can never
lose both installs. A RAII guard removes the staging tree on any pre-swap failure,
stale staging that cannot be cleared is treated as fatal (so a leftover binary can
never be promoted as a mixed install), and the staged version.txt write is checked.

The staging + atomic-swap logic is factored into a small header-only helper
(lemon/backends/install_staging.h) and covered by a unit test
(test/cpp/test_install_atomicity.cpp, ctest InstallAtomicityTest) that asserts a
failed install -- both a missing-executable extraction and a failed filesystem
swap -- preserves the previously-working binary.

Closes #2312
Reported-by: ckuethe (https://github.com/lemonade-sdk/lemonade/pull/2279)

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: GLM-5.2 <[email protected]>
Co-authored-by: GPT-5.5 <[email protected]>
2026-06-22 06:27:18 +00:00