Skip to content

fix(build): downloads cache mount follows the task's stage user - #79

Merged
atrawog merged 2 commits into
mainfrom
feat/downloads-cache-ownership
Jul 20, 2026
Merged

atrawog merged 2 commits into
mainfrom
feat/downloads-cache-ownership

Conversation

@atrawog

@atrawog atrawog commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary of changes

EmitDownload always emitted a SHARED root-owned cache mount
(--mount=type=cache,id=charly-tmp-downloads,dst=/tmp/downloads) for the
content-addressed downloads cache. The first root-stage download made the
shared backing root-owned; after that, EVERY non-root stage's download
failed with curl: (23) client returned ERROR on write — a uid-1000 stage
cannot write into a root-owned cache dir. Reproduced serially on any box
with a non-root download step (e.g. the coder images' installer downloads);
the host's shared cache is still polluted with root-owned files today, so
every non-root download build was broken.

Concrete edits (the entire diff is accounted for here):

  • deploykit/tasks_emit.go: the downloads mount now follows the task's
    stage user via the new taskRunsAsRoot — root RunAs, or a root image
    build user when RunAs is empty (a task RUN inherits the stage's USER).
    Non-root stages get an uid/gid-owned cache
    (id=charly-tmp-downloads-uid<uid>, uid=/gid= — the same per-uid
    ownership the pixi/npm caches already use); root stages keep the shared
    form. TaskCacheMounts (candy-declared cache: paths) uses the same
    decision — it previously mapped an empty RunAs to root via
    ResolveUserSpec's USER-directive mapping and shared the same latent bug.
  • deploykit/tasks_emit_test.go: TestTaskRunsAsRoot (the stage-user
    matrix) + TestEmitDownload_DownloadsCacheOwnership (non-root → owned
    mount, root → shared mount, no uid-scoped id for root).
  • CHANGELOG/2026.201.1237.md: the placeholder entry (merge-time CalVer is
    finalized by the pr-validator).

Change class

charly-or-sdk Go — build-engine emission fix in sdk deploykit. Consumer:
the superproject charly PR (test updates + sdk gitlink bump), landing after
this per B2.

How R10-tested — exact gate, commands, and pasted output

  • The gate for this change class: sdk standalone battery (GOWORK=off
    tidy/verify/build/vet/test) + live build proof with the consumer binary.
  • Eval beds run: N/A — the proof is the live image build against a root-polluted host cache, not a disposable bed.
  • Fresh rebuild: consumer binary rebuilt with the fix; go tool nm bin/charly | grep taskRunsAsRoot present (content marker).
  • Did the CHANGED code path execute live? yes — a previously
    curl-23-failing image (openclaw-full) builds past the download step
    with a root-owned shared cache present on the host (the new
    charly-tmp-downloads-uid1000 backing is fresh and writable).
  • Concurrency (shared-state changes only): the cache mount IS shared
    state; the fix gives each uid its own backing (correct isolation instead
    of a shared root-owned dir), no lock introduced.
$ GOWORK=off go test ./deploykit/ -run 'TestTaskRunsAsRoot|TestEmitDownload_DownloadsCacheOwnership' -v
--- PASS: TestTaskRunsAsRoot (0.00s)
--- PASS: TestEmitDownload_DownloadsCacheOwnership (0.00s)
$ GOWORK=off go mod tidy && git status --short     # (empty — no-op)
$ GOWORK=off go mod verify && go build ./... && go vet ./... && go test ./...   # all ok
# live proof (root-polluted shared cache present on host):
$ podman build ... charly-tmp-downloads probe (before fix)
touch: cannot touch '/tmp/downloads/probe-write-test': Permission denied   # uid=1000 blocked
$ bin/charly -C box/cachyos box build openclaw-full                        # (with fix)
(passes the claude.ai/install.sh download step that previously curl-23'd)

Attribution tier

analysed on a live system — the changed emission path executed live in a
real build against the polluted cache, but no disposable-bed roster ran.

Harness rulebook compliance — state HOW each is satisfied (or N/A — <reason>)

  • R0 skills: git-workflow + go + generate loaded by path; B2
    producer→consumer order.
  • R1 RCA + zero warnings: the failure was root-caused to the mount's
    missing ownership (permission denied reproduced in isolation), not treated
    as a flake.
  • R2 no out-of-scope: the sibling with the same latent bug
    (TaskCacheMounts' empty-RunAs root mapping) is fixed in the SAME commit.
  • R3 no duplication: one ownership decision (taskRunsAsRoot) used by
    both emitters; the pixi/npm owned-mount pattern reused, no new mechanism.
  • R4 no workaround: correct per-uid cache ownership, not a purge/retry.
  • R5 hard cutover + grep: no transitional form; the shared id remains
    only for root stages.
  • R6 git safety: branch off fresh origin/main; status checked.
  • R7 runtime gate: the changed emission executed live in a real build.
  • R8 artifact invariants: emitted Containerfile carries the owned mount
    (proven by unit tests + the live build).
  • R9 binary == source + deps: consumer binary rebuilt; content marker
    present; no new OS deps.
  • R10 disposable + coverage: coverage that fails without the change
    (TestEmitDownload_DownloadsCacheOwnership — the mount form assertion);
    live repro of the failure mode now passes.
  • RDD / ADE / SDD: RDD — the failure was reproduced in isolation
    (root-owned cache → uid-1000 permission denied) before the fix, and the
    fix is proven against that same polluted state. ADE/SDD N/A.
  • Hard cutover: one atomic fix; no TODO/deferred scope; one squash on
    main.
  • Kernel/plugin boundary law: the emission lives in sdk deploykit (its
    canonical home); no core surface touched.
  • Disposable-only autonomy: N/A.
  • Clean architecture + Go gates: gofmt clean, go vet clean,
    go test ./... green, golangci-lint run ./... 0 issues.
  • CHANGELOG: CHANGELOG/2026.201.1237.md staged (placeholder — the
    pr-validator finalizes it at merge).

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)

EmitDownload always emitted a shared root-owned cache mount for the content-addressed downloads cache: the first root-stage download made the backing root-owned, after which every non-root stage's download failed with curl: (23) write error — reproduced serially on any box with a non-root download step. The mount now follows the task's stage user via the new taskRunsAsRoot (root RunAs, or a root image build user when RunAs is empty): non-root stages get an uid/gid-owned cache (id=charly-tmp-downloads-uid<uid>, the pixi/npm-cache ownership pattern); root stages keep the shared form. TaskCacheMounts uses the same decision — it previously mapped an empty RunAs to root via ResolveUserSpec and shared the same latent bug.

Verified: TestTaskRunsAsRoot + TestEmitDownload_DownloadsCacheOwnership; full GOWORK=off battery green; live proof: a previously curl-23-failing image builds past the download step with a root-owned shared cache present on the host.

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)
@atrawog

atrawog commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — APPROVED ✅

Bound identities (verified live, read-only):

  • PR head: 63a1f6e99fdf30db68064dd9cfc89a6259c9cb27 (git ls-remote origin refs/heads/feat/downloads-cache-ownership, = local checkout HEAD)
  • Protected base: sdk main = b0627c4640233a1c09a83a09380bdf3f552dfbfa (live ls-remote; merge-base --is-ancestor origin/main HEAD = yes, branch not BEHIND)
  • Policy source: superproject protected main = cc74415af7eb770246f12260a20e9a58eb09a72f (advanced from envelope-time 8f10543; AGENTS.md verified byte-identical between protected main and this worktree); plugins gitlink c794cb73 = plugins main = clean checkout
  • sdk working tree: git status --short empty before and after my gate re-runs

Change class: charly/sdk Go (build-emission fix in deploykit).

Checklist

# Rule Verdict Evidence (all re-run by me, not taken from the author)
0 Security & anti-tampering (T1–T4) PASS 3-file diff matches the description exactly (CHANGELOG + deploykit/tasks_emit.go + new tasks_emit_test.go; +121/−3); no secrets, no network/egress, no dep or pin changes (go.mod untouched, GOWORK=off go mod tidy is a no-op), no hook/validator/protection files touched, no embedded directives
1 Description complete PASS Every template section filled with HOW-lines + pasted output; live-proof paste is thin but I corroborated it independently at the artifact boundary (stronger than the paste)
2 Change-class gate matches evidence PASS (at claimed tier) Unit tests + full standalone battery + fresh-rebuild live build of the maximal affected image against the exact failing environment. No fraud class (no dry-run, no bare go test, no "will test"). Bed-coverage considered: the diff touches build-time emission only; a pod/vm bed's marginal exercise (runtime deploy) cannot fail on this diff, and the host's root-polluted cache — the actual failing condition — is exactly what the live build ran against. Tier honestly capped at analysed on a live system
3 Attribution tier vs proof PASS Ceiling set independently: analysed on a live system (changed emission path executed live in a real build; no disposable-bed roster). Matches the PR's claim; not inflated
4 R0 skills honored PASS Author: git-workflow + go + generate. Validator loaded: pr-validator spec, git-workflow, go, check (R10 matrix), strict-policy — no contradiction found
5 R1 RCA + zero warnings PASS Failure root-caused to cache-mount ownership with an isolated permission-denied repro, not dismissed as flake. My re-runs: zero warnings, zero errors
6 R2 no out-of-scope split PASS The same-mechanism sibling (TaskCacheMounts empty-RunAs root mapping) is fixed in the SAME commit
7 R3 no duplication PASS ONE ownership decision (taskRunsAsRoot) shared by both emitters; reuses the existing pixi/npm OwnedCacheMount mechanism — no new parallel mechanism
8 R4 no workaround PASS Per-uid cache ownership is the root fix; no purge/retry/sleep/magic shim
9 R5 hard cutover + grep PASS Purely additive (taskRunsAsRoot new; no renames/removals — nothing to sweep); no transitional form (shared id remains only for root stages, the intended final state)
10 R6/R8/R9 PASS R6: clean tree, no destructive ops. R8: emitted Containerfile verified at the artifact boundary — box/cachyos/.build/openclaw-full/Containerfile lines 294/511 carry the shared root mount for the root pixi/uv stages, line 575 carries id=charly-tmp-downloads-uid1000,dst=/tmp/downloads,uid=1000,gid=1000 under USER 1000 for the claude.ai download (the previously curl-23 step). R9: consumer binary rebuilt — go tool nm bin/charly contains deploykit.taskRunsAsRoot (content marker); no new OS deps
11 R10 coverage + live PASS (at claimed tier) TestEmitDownload_DownloadsCacheOwnership asserts the new mount forms and would fail on the old always-shared emission; TestTaskRunsAsRoot pins the decision matrix. Live: ghcr.io/opencharly/openclaw-full 2026.201.1238 (7.8 GB) tagged minutes before this validation — the build passed the claude.ai download step that previously curl-23'd, with the root-polluted shared cache present on the host
12 RDD / ADE / SDD PASS RDD: failure reproduced in isolation before the fix, fix proven against the same polluted state. ADE: N/A (no candy edit). SDD: N/A (no schema/*.cue, proto, or generated file touched; spec tests incl. TestGenReproducible green in my run)
13 Concurrency + anti-cheat PASS No failure-under-load dismissed; no flake/transient framing anywhere. The shared-state aspect is fixed by per-uid isolation (per-id BuildKit cache ids), not by a lock or serialization
14 Hard cutover, one atomic commit PASS Exactly ONE commit (63a1f6e) atop b0627c4; no TODO/Phase-2/deferred scope
15 Architecture gate PASS placement: CORRECT — build emission lives in sdk deploykit (its canonical home since P8); no core surface touched; no alias files; no new kit imports; taskRunsAsRoot is kind-agnostic emission logic, no kind-word switch. Per-item trace: no charly/*.go in the diff (sdk-only)
16 Disposable-only autonomy N/A No destroy/rebuild of any target; the image build is additive
17 Go gates re-run PASS gofmt -l . empty; GOWORK=off go mod tidy no-op + go mod verify all verified + go build ./... + go vet ./... clean; GOWORK=off go test ./... all ok (incl. deploykit, spec); golangci-lint run ./... (v2.12.2, isolated GOLANGCI_LINT_CACHE, since removed) = 0 issues
18 CHANGELOG present PASS CHANGELOG/2026.201.1237.md placeholder: filename matches ^\d{4}\.\d{3}\.\d{4}\.md$; head -1 byte-equals # 2026.201.1237 — …; no collision with main CHANGELOG or v* tags

Comments considered

None — the PR carries no comments or reviews (verified via gh pr view 79 --json comments,reviews).

Cross-PR interactions considered

Observation (verified-non-blocking)

taskRunsAsRoot's comment models an empty RunAs as "a task RUN inherits the stage's USER (the image build user)". The emitted truth in EmitTasks (tasks_render.go:57,68-77 + the USER root candy-boundary resets in candy_steps.go) is that an empty-RunAs task runs as root (directive "0"). The chosen behavior for that latent case (uid-owned cache on uid-1000 images) is nonetheless safe: root bypasses mount ownership, the flat download cache stays uid-writable, and non-root ${USER} tasks remain protected from pollution — which is the fix's actual goal. A full candy sweep confirms every in-repo download task declares run_as: explicitly (root or ${USER}), so the branch has no live trigger. Recorded for the record; not a merge blocker.

Decision

Compliant on every applicable item at the honestly-claimed tier. The changed emission path executed live in a fresh full build of the maximal affected image against the exact failing environment (host root-polluted shared cache), and I verified the fix at the emitted-artifact boundary, in the built binary (content marker), and through my own full gate re-runs (fmt/vet/build/test/lint, all zero-warning).

Merge-time CalVer finalization (placeholder rename + H1 re-stamp), status re-post on the new head, squash-merge, and the sdk Go-module tag (v0.<YYYYDDD>.<HHMM stripped>) follow per protocol.

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)
@atrawog
atrawog merged commit 2e2ad01 into main Jul 20, 2026
@atrawog
atrawog deleted the feat/downloads-cache-ownership branch July 20, 2026 13:16
atrawog added a commit to opencharly/charly that referenced this pull request Jul 20, 2026
Bumps the sdk submodule to the merged opencharly/sdk#79 squash (2e2ad01, tag v0.2026201.1313) — the downloads-cache ownership fix, producer leg of this cutover — and the charly/go.mod require to the same version. Assembly re-gated on the merged tree: full go test ./... ok, go vet clean, golangci-lint 0 issues, task build:binary rebuilt (2026.201.1241, taskRunsAsRoot present), box validate exit 0.

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)
atrawog added a commit to opencharly/charly that referenced this pull request Jul 20, 2026
Consumer leg of opencharly/sdk#79 (merged, tag v0.2026201.1313): the
downloads cache mount now follows the task's stage user — non-root stages
get a uid/gid-owned cache (id=charly-tmp-downloads-uid<uid>, uid=/gid=),
root stages keep the shared form — fixing the curl-23 class where one
root-stage download permanently broke every non-root stage's download.

- charly/tasks_test.go: EmitDownload mount-form assertions updated to the
  corrected contract (uid1000-owned for the non-root testResolvedBox); new
  TestEmitDownload_DownloadsCacheRootShared pins the root/shared case.
- sdk gitlink + charly/go.mod require bumped to the merged sdk commit
  2e2ad01 (v0.2026201.1313) per B2 producer→consumer order.
- CHANGELOG finalized at the merge-time CalVer 2026.201.1353.

Validated by a fresh pr-validator: full core Go gate re-run green on both
the candidate and the final merged tree (go test ./..., go vet,
golangci-lint 0 issues, task build:binary + nm content marker,
task cue:gen no-drift, charly box validate); producer behavior live-proven
against the exact failing environment (host root-polluted shared cache).

Assisted-by: Kimi Code (Moonshot K3; analysed on a live system)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant