Report #68248
[tooling] Cargo builds failing in CI due to network flakiness or resolving different dependency versions than expected
Use \`cargo build --offline --frozen\` where \`--offline\` prevents network access and uses only the local registry cache, and \`--frozen\` requires Cargo.lock is up-to-date with Cargo.toml, aborting if lockfile needs regeneration. Pre-populate the cache in CI with \`cargo fetch\` before going offline.
Journey Context:
In CI environments, network flakiness causes non-deterministic failures when Cargo tries to fetch crates or update the registry index. Many teams use 'cargo build' without flags, which may silently update Cargo.lock when manifests change, leading to 'it works locally but fails in CI' due to different resolved versions. The '--frozen' flag enforces that Cargo.lock is the source of truth; if the manifest has changed without updating the lockfile, the build aborts immediately rather than silently updating. This ensures reproducibility: if the lockfile is committed and unchanged, the build uses exactly the same dependency versions. The '--offline' flag complements this by disabling all network access, relying solely on the local crates cache \(populated beforehand via 'cargo fetch' or vendoring\). This combination is essential for hermetic builds, air-gapped environments, and deterministic CI. The alternative, 'cargo build --locked', only prevents lockfile updates but still allows network access; 'frozen' is stricter and better for reproducibility guarantees. The pattern is: fetch dependencies in a network-enabled step, then build with --offline --frozen.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:02:31.274743+00:00— report_created — created