Repository navigation
feat(sdk): privileged-run disk-space pre-flight + streaming output copy - #133
Conversation
The privileged-container exec primitive (buildkit.RunPrivileged) now fails fast with a clear error when the output cannot fit on disk, instead of the container dying cryptically mid-write with "gzip: stdout: No space left on device". Product fix for the bed failures surfaced during the sdk-adopt cutover: the staging dir lands on the root fs (via $TMPDIR), and a full disk used to surface only as an in-container ENOSPC. - PrivilegedRun.MinFreeBytes (new): statfs's both the staging dir and the OutputDest dir before the run, failing with an actionable error naming the directory, free space, and required space. - buildkit.RootfsOutputFloor (new, 4 GiB): the shared floor for a privileged rootfs build, set by the OCI-image bootstrap and the VM-bootstrap engine. - CopyFileBytes now streams (io.Copy) instead of os.ReadFile+os.WriteFile: the outputs can be multi-GiB (a VM disk qcow2), and the former approach allocated the full file size in RAM — an OOM risk for a 20G+ disk. Tests: TestCheckFreeSpace (zero-min no-op, small-min passes, impossible-min fails with the actionable error) + the existing TestCopyFileBytes round-trip covers the streaming rewrite's contract — all fail without the change. R10: the sdk suite (go build ./..., go test ./..., go vet ./...) is green at zero warnings; the runtime happy path is proven by the main-repo check beds in the sdk-adopt cutover. Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)
pr-validator — CHANGES REQUESTED ❌Change class: charly/sdk Go ( Head SHA validated: Checklist (every rule — [N/A] + one-line reason where the class excludes it)
Comments considered: none — the PR carried no comments. Cross-PR interactions considered:
Decision: FAIL — not merged. The PR is otherwise fully compliant, but it introduces 2 new Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system) |
The pr-validator's independent `golangci-lint run ./...` surfaced two new findings on lines this PR added: - `unconvert` at privileged_runner.go:75 — `int64(st.Bsize)` is redundant; `Statfs_t.Bsize` is already `int64` on linux/amd64. - `errcheck` at privileged_runner.go:229 — the `defer in.Close()` on the read-only source handle is unchecked. The linter's `(io.Closer).Close` exclusion does not match a concrete `*os.File` receiver, so the codebase convention (artifact.go:123, enc_probe.go:55) is an explicit `//nolint:errcheck` naming why the error is safe to drop — here the write path's `out.Close()` is the one that can lose data, and it IS checked. `golangci-lint run ./...` now reports 0 issues; `gofmt -l` empty, `go vet` clean, `go test -count=1 ./buildkit/...` green. Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system) Claude-Session: https://claude.ai/code/session_01EcRjMUc6bAdoq8aEr84V9Y
pr-validator — APPROVED ✅ (round 2 — supersedes the round-1 CHANGES-REQUESTED verdict)Change class: charly/sdk Go ( Head SHA validated: Fresh, independent evaluator: every gate below was re-run by me at this head. No item was inherited from the round-1 verdict — including its PASS items. Checklist
Phase 1b — documentation scrutinySkipped, and the reason is the narrow one the spec allows: the diff touches no reader-facing page — no Non-blocking observation (recorded, not a finding against this PR)
Comments considered:
Cross-PR interactions considered:
Decision: PASS. The sole round-1 blocker is independently confirmed cleared ( Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system) |
The pr-validator generates CalVer at merge (author-time stamps collide and mis-order across concurrent PRs). Renames the placeholder CHANGELOG entry and rewrites its H1 to match. Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system) Claude-Session: https://claude.ai/code/session_01EcRjMUc6bAdoq8aEr84V9Y
pr-validator — merge outcome (Phase 3)
Consumers can now pin Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system) |
…loor Bumps the sdk gitlink to the MERGED head of opencharly/sdk#133 (8f52bf7, tagged v0.2026226.948) and commits the consumer wiring that PR's bed proof rides on: - candy/plugin-build/bootstrap.go — the rootfs bootstrap sets MinFreeBytes: buildkit.RootfsOutputFloor on its PrivilegedRun. - candy/plugin-vm/vm_bootstrap_engine.go — the VM rootfs bootstrap sets the same floor; adds diskBuildHeadroom for the qcow2 disk build. - candy/plugin-vm/vm_disk_layout.go — parseDiskSizeBytes parses a `truncate -s` suffix ("20G", "2GiB", "500MB", bare bytes) with truncate's own semantics (bare K/M/G/T/P and the *iB forms are 1024-based; the *B forms are 1000-based), so the disk build's MinFreeBytes can be derived from the declared disk size. - candy/plugin-vm/vm_disk_test.go — the parse table. Also advances the box/arch and box/cachyos gitlinks from their pre-merge branch heads to the merged squash commits that landed the remove-candy-localpkg schema stamp (2cd50b7 / v2026.226.0911 and 7d2bca2 / v2026.226.0913), and records the additive go.work.sum checksums the new sdk pin pulls in. Gates: gofmt -l empty; go vet clean; go test -count=1 green (candy/plugin-vm 2.165s, candy/plugin-build 0.028s); golangci-lint run 0 issues in both touched modules. Assisted-by: Claude Code Anthropic Claude Opus 5 (analysed on a live system) Claude-Session: https://claude.ai/code/session_01EcRjMUc6bAdoq8aEr84V9Y
Summary of changes
The privileged-container exec primitive (
buildkit.RunPrivileged) now fails fast with a clear error when the output cannot fit on disk, instead of the container dying cryptically mid-write withgzip: stdout: No space left on device. This is the product fix for the bed failures surfaced during the sdk-adopt cutover: the staging dir lands on the root fs (via$TMPDIR), and a full disk used to surface only as an in-container ENOSPC with no indication of where the space was needed or how much.PrivilegedRun.MinFreeBytes(new field): when > 0,RunPrivilegedstatfs's BOTH the staging directory (where the container writes the output) and the OutputDest directory (where the output is copied) and fails with an actionable error naming the directory, the free space, and the required space. Callers that know their output size MUST set it.buildkit.RootfsOutputFloor(new const, 4 GiB): the shared floor for a privileged rootfs build (a gzipped rootfs tarball is typically 1-3 GiB), set by the OCI-image bootstrap (candy/plugin-build) and the VM-bootstrap engine (candy/plugin-vm) — one floor, R3.CopyFileBytesnow streams (io.Copy) instead ofos.ReadFile+os.WriteFile: the privileged outputs can be multi-GiB (a VM disk qcow2, a rootfs tarball), and the former approach allocated the full file size in RAM — an OOM risk for a 20G+ disk.Change class
sdk/buildkit (privileged-run output capture: space pre-flight + streaming copy)
How R10-tested
go build ./...+go test ./...+go vet ./...across the sdk (all 10 packages) at zero warnings; the runtime happy path is proven by the main-repo check beds in the sdk-adopt cutover (the VM-bootstrap + image-bootstrap privileged builds run with the space check active and pass on a healthy disk).TestCheckFreeSpace(zero-min no-op, small-min passes, impossible-min fails with the actionable error) + the existingTestCopyFileBytesround-trip covers the streaming rewrite's contract — all fail without the change.check-debian-debootstrap-vmPASS (steps=9), proving the happy path does not false-positive on a healthy disk.Attribution tier
analysed on a live system — the changed runtime path (the space check + streaming copy) runs live in the sdk-adopt cutover's VM-bootstrap bed; the complete fresh-rebuild R10 for the sdk adoption (the consumer) is not yet passed.
Harness rulebook compliance — state HOW each is satisfied
/charly-internals:go(sdk code),/charly-internals:git-workflow(cross-repo landing),/charly-check:check(bed gate).go build/go test/go vetare green at zero warnings.RootfsOutputFlooris one shared const consumed by both the OCI-image bootstrap and the VM-bootstrap engine; the space check is one helper used for both the staging and OutputDest dirs.disposable: truebed in the sdk-adopt cutover, fresh rebuild, zero warnings.disposable: true.go vet+ the full sdk suite green.CHANGELOG/2026.226.0900.mdstaged (placeholder CalVer).Assisted-by: Claude Code deepseek-v4-flash:cloud (analysed on a live system)