'Failed to install platform-tools ... IncompleteBody' from cargo-build-sbf: rerun with --force-tools-install to clear the cached tarball
Symptom: anchor build / anchor test fails during the build step with something like
ERROR cargo_build_sbf] Failed to install platform-tools: Unable to write
"~/.cache/solana/v1.41/platform-tools/tmp-platform-tools-linux-x86_64.tar.bz2":
Custom { kind: Other, error: reqwest::Error { kind: Body,
source: hyper::Error(Body, Custom { kind: UnexpectedEof, error: IncompleteBody }) } }and it keeps failing identically on every retry, which makes it look like a permissions or disk problem.
Real cause: the SBF toolchain (platform-tools) is downloaded on first build into ~/.cache/solana/<version>/platform-tools/. The connection dropped mid-download (common on WSL2, VPNs, or flaky networks — IncompleteBody is a truncated HTTP body, not a filesystem error). A partial tmp-*.tar.bz2 is left behind in that directory. Why plain retries then keep failing identically is not established — a reused partial download and a transfer that keeps breaking look the same from outside — so force a fresh install rather than theorising about it.
Fix: force a clean re-download of the toolchain from inside the project:
cargo build-sbf --force-tools-installIf that still fails, delete the stale artifacts first and retry: remove ~/.cache/solana/v*/platform-tools* (and, on older installs, the copy under ~/.local/share/solana/install/releases/<release>/solana-release/bin/sdk/sbf/dependencies/platform-tools/). Reinstalling solana-cli and anchor-cli, then --force-tools-install, is the sledgehammer that also works.
What makes it non-obvious: the error names a *write* failure, so the instinct is to chase file permissions or free space, when the transfer is what broke; and nothing in the message hints that a cached partial download is being reused or that a --force-tools-install flag exists. Note the cache path is versioned, so bumping the Solana/Agave version can also make the problem 'disappear' for unrelated reasons.
Source: adapted from a Stack Exchange answer by Uaná Gasparim (question by Uaná Gasparim), https://solana.stackexchange.com/questions/16453/anchor-cargo-build-failed-to-install-platform-tools — CC BY-SA 4.0
Some source context for the 'why do retries fail' question (agave v2.1.0 sdk/cargo-build-sbf + download-utils, read, not run). download_file() streams into 'tmp-<name>' next to the destination, and on a body error returns exactly 'Unable to write "...tmp-platform-tools-linux-x86_64.tar.bz2": ...IncompleteBody' WITHOUT deleting the tmp file. install_if_missing() then only auto-cleans the tools dir when it is EMPTY ('This can happen if package download failed on previous run'), so a dir holding a partial tmp-*.tar.bz2 is not cleaned by a plain retry. --force-tools-install is the code path that does remove_dir_all on it, and in 2.x it also removes the sdk/sbf/dependencies symlink, which matches your fix and your manual-delete fallback. The current crate (solana-cargo-build-sbf 4.0.0, toolchain.rs) has the same empty-dir-only cleanup. I haven't established whether the exact identical-error loop comes from that leftover or from the network, so treat that part as open, as you say.