feat(labctl): harden Talos image build reliability#65
Merged
Conversation
Make `labctl bootstrap talos image build` resilient enough for durable clusters, not just disposable bootstrap. Mirrors the IncusOS path's SHA256 verification while adding the protections it lacks. - Atomic downloads: stream archive into a sibling .tmp-* file via os.CreateTemp, hash-on-stream against the published Image Factory sidecar (`<asset>.sha256`), and os.Rename only when the digest matches. A corrupt cached archive is detected on every run and redownloaded. Same atomic pattern is now used for the decompressed boot image. - Bound xz decompression to MaxBootImageBytes (4 GiB) using the same io.LimitReader pattern incusosimage already uses. - HTTP client gets explicit ResponseHeaderTimeout (30s) and IdleConnTimeout (90s) via httpupstream.NewHTTPClient instead of http.DefaultClient. No top-level Timeout — long downloads use context cancellation. Both Talos and IncusOS paths benefit. - Retry with exponential backoff (5 attempts, 500ms..16s, ±20% jitter) on connection errors, 5xx, and 429. 4xx and ctx errors are permanent. - Result now carries BootArtifactSHA256 and ConfigArtifactSHA256; --json output exposes them so operators can verify before flashing. Tests cover atomic-write commit, redownload-on-corrupt-cache, sidecar-mismatch rejection (with no leaked .tmp- file), retry on 5xx, no-retry on 4xx, and SHA256 sidecar parsing edge cases. testscript fixture now serves the matching .sha256 sidecar and asserts the new digest fields. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This was referenced May 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
labctl bootstrap talos image buildresilient enough for durable clusters, not just disposable bootstrap. Closes the asymmetry between the Talos and IncusOS paths: the IncusOS sibling already verifies SHA256 and bounds xz decompression; Talos didn't.This is PR 1 of 5 from the session 057 reliability+flexibility plan. Code-only; no schema impact.
What changed
.tmp-*file viaos.CreateTemp, hash on stream against the Image Factory<asset>.sha256sidecar,os.Renameonly when the digest matches. Corrupt cached archives are detected on every run and redownloaded. Same atomic pattern now applies to the decompressed boot image.httpupstream.NewHTTPClientsetsResponseHeaderTimeout=30sandIdleConnTimeout=90s. No top-levelTimeout— long downloads rely on context cancellation. Both Talos and IncusOS paths benefit from the explicit client.cenkalti/backoff/v4(already an indirect dep, now promoted to direct).MaxBootImageBytes = 4 GiBviaio.LimitReader, mirroring the existing IncusOS pattern atincusosimage/service.go:210.BootArtifactSHA256andConfigArtifactSHA256are populated from the streamed hashes and exposed in--jsonoutput so operators can verify before flashing.Why now
Session 056 shipped the Talos build slice (PR #64) yesterday. A code review (session 057) found that the cache silently served corrupt archives, the HTTP client had no timeouts, and there was no upper bound on xz decompression — none of which were caught because the IncusOS sibling already does them right and operators never compared. Fixing them before durable-cluster work begins is cheaper than fixing them after.
Out of scope
output.dirtightening (PR 3).POST /schematics(PR 5).Test plan
go test ./...fromtools/labctl/— all pass.moon run labctl:check --summary minimal— format, lint, test pass.moon ci --summary minimalfromplatform/— all actions pass includinglabctl:image-smoke.service_test.go— atomic commit, corrupt-cache redownload, sidecar-mismatch rejection (no leaked.tmp-*), sidecar fetch error propagation.client_test.go(new) — sha256 parsing edge cases, retry on 5xx, no-retry on 4xx, ctx-cancel exit.--jsonoutput.🤖 Generated with Claude Code