Skip to content

fix(deploykit): derive a candy's COPY source from its resolution origin, not its name - #478

Merged
github-actions[bot] merged 2 commits into
mainfrom
feat/candy-copy-source-origin
Nov 1, 2026
Merged

github-actions[bot] merged 2 commits into
mainfrom
feat/candy-copy-source-origin

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A candy DECLARED IN an imported namespace lives in that namespace's own fetched checkout, OUTSIDE the importing project's tree. Its build-context COPY source was nevertheless emitted as the project-relative candy/<name>/, so the image build died with "/candy/<name>": not found and the candy was never staged. Measured live on a project importing distro-cachyos as a namespace and building its cachyos.cachyos box:

# pre-fix: charly `bin/charly` 2026.293.1809, sdk v0.2026293.417
$ charly -C <repro> box generate cachyos.cachyos   # exit 0
$ grep 'COPY .*cachyos-base-check' .build/cachyos.cachyos/Containerfile
6:COPY candy/cachyos-base-check/ /
$ ls .build/_candy/cachyos-base-check
ls: cannot access '.../.build/_candy/cachyos-base-check': No such file or directory   # never staged

# fixed: charly 7bb19d0a rebuilt against THIS branch's sdk (head 1341a5b)
$ charly -C <repro> box generate cachyos.cachyos   # exit 0
$ grep 'COPY .*cachyos-base-check' .build/cachyos.cachyos/Containerfile
6:COPY .build/_candy/cachyos-base-check/ /
$ ls .build/_candy/cachyos-base-check
charly.yml                                          # staged, so the COPY resolves

The repro project is the whole config, pinned to a cached namespace tag:

repo: github.com/opencharly/copysource-repro
defaults: {platform: [linux/amd64], tag: auto, registry: ghcr.io/opencharly, build: [pac]}
import:
  - cachyos: '@github.com/opencharly/distro-cachyos:v2026.274.2120'

Mechanism. loaderkit.projectCandiesScanned folds each imported namespace by recursing with the namespace's OWN RootDir, and that same parameter was also the root the "outside the project → mark Remote" check compared against. A candy inside the namespace's checkout is therefore INSIDE the comparison root, so it stayed Remote=false; deploykit.CandyCopySource fell through to its name-derived candy/<name>/, and plugin-build's staging (keyed on the same Remote flag) never copied it into the build context.

Fix (final state of this branch).

  • loaderkit/project_candies.go — thread TWO roots through the fold: rootDir still anchors each namespace's relative from: paths, while the new projectRoot is the unchanged TOP-LEVEL project directory and is what the Remote marking compares against. An imported-namespace candy is now Remote=true and is staged like an @github ref. The outside-root test is exact (.. or a ../ prefix), in both the loader and the renderer, so a project-local directory literally named ..<x> is not misclassified.
  • deploykit/candy_stage.go — candyOrigin is the ONE origin predicate (Remote, or a resolved directory outside the build root) and it returns BOTH the staged verdict and the project-relative directory; candyCopySource is the ONE origin→COPY-source mapping built on it, with no duplicated guard and no dead branch. candySourceDir is the shared directory resolver.
  • deploykit/builder_support.go — BuildStageContext calls the same mapping from the layer in hand instead of re-deriving the candy's map key (CandyMapKey(layer) returned an EMPTY key for a Remote candy with no RepoPath, i.e. an imported-namespace candy, so the lookup dereferenced a nil layer).
  • deploykit/candy_stage.go (rootCopySources) — the other name-derived candy-path site uses the same predicate and directory resolver.

Diff: 6 files, +293/−34 — deploykit/builder_support.go, deploykit/builder_support_test.go, deploykit/candy_stage.go, deploykit/candy_stage_test.go, loaderkit/project_candies.go, loaderkit/project_candies_test.go. No spec change; schema/wire types untouched. The round-1 review RCA is in this PR's thread.

How tested

Everything below ran on this branch's committed head; the fence's first commands name the exact tree:

$ git rev-parse HEAD HEAD^{tree} origin/main
1341a5bded337b0fd66ed04f9156afb1ffbadeb7     # HEAD
264b1427500d63405d60829b7451e02c7cb983d6     # HEAD^{tree}
352755df2e0464b3eb08bfec196006fe9f322ec8     # origin/main (git fetch origin main, exit 0)
$ git status --porcelain | wc -l
0
$ git log --oneline origin/main...HEAD
1341a5b fix(deploykit): one origin predicate for the COPY source, and its builder-stage control
2a2e4a0 fix(deploykit): derive a candy's COPY source from its resolution origin, not its name

Gate = the sdk CI workflow (.github/workflows/ci.yml), run at the CI-pinned Go (go.mod go 1.26.8, GOTOOLCHAIN=go1.26.8); each command's own exit code:

$ test -z "$(gofmt -l .)"; echo $?
0
$ go vet ./...; echo $?
0
$ go build ./...; echo $?
0
$ go test ./...; echo $?
0
$ go test -count=1 ./deploykit/ ./loaderkit/; echo $?
ok  	github.com/opencharly/sdk/deploykit	30.325s
ok  	github.com/opencharly/sdk/loaderkit	1.396s
0
$ golangci-lint v2.13.2 run ./...; echo $?
0 issues.
0
$ for a in amd64 arm64 arm 386; do GOOS=linux GOARCH=$a CGO_ENABLED=0 go build ./...; echo $?; done
0
0
0
0
$ go mod tidy; sha256sum go.mod go.sum    # run twice
tidy1_exit=0 tidy2_exit=0; before == tidy1 == tidy2 (diff exit 0 both); git status go.mod go.sum -> empty

R7 — every changed line has a test that FAILS without the change. The committed tests were copied onto a pristine origin/main (352755d) worktree and run there (nothing else changed):

$ go test ./loaderkit/ ./deploykit/ -run 'TestProjectCandiesScanned_ImportedNamespaceCandyIsRemote|TestCandyCopySource' -count=1; echo $?
1
--- FAIL: TestProjectCandiesScanned_ImportedNamespaceCandyIsRemote
    imported-namespace candy is not marked Remote ... Remote:false
    CandyCopySource = "candy/cachyos-base-check", want a .build/_candy/cachyos-base-check-staged source
        FROM scratch AS cachyos-base-check
        COPY candy/cachyos-base-check/ /
--- FAIL: TestCandyCopySource_ImportedNamespaceOrigin
    CandyCopySource("cachyos-base-check") = "candy/cachyos-base-check", want ".build/_candy/cachyos-base-check.2026.300.1129"
FAIL

$ go test ./deploykit/ -run 'TestBuildStageContext_ImportedNamespaceCopySource' -count=1; echo $?
1
--- FAIL: TestBuildStageContext_ImportedNamespaceCopySource
panic: runtime error: invalid memory address or nil pointer dereference
... deploykit.(*Generator).CandyCopySource(0x..., {0x0, 0x0})    # empty CandyMapKey -> nil layer
FAIL

On this head both commands exit 0. The two arms that already worked are pinned and still pass on both trees: a project-local candy at the default location (candy/pixi) and an @github ref (.build/_candy/cuda.2026.167.1200), plus an inside-the-project candy anchored elsewhere (layers/anchored) and the version-less remote fallback (.build/_candy/nover).

Live path exercised on the final source. charly box generate ran the changed render + host-fs staging path end to end with a fresh build of charly 7bb19d0a whose replace github.com/opencharly/sdk => points at this branch's sdk at head 1341a5b (go version -m bin/charly shows => .../copysource/sdk (devel)), with plugin-build v0.2026293.926 compiled in. generate exited 0, emitted COPY .build/_candy/cachyos-base-check/ /, and created .build/_candy/cachyos-base-check/charly.yml. A full charly box build was not attempted (it needs a ghcr credential and the unrelated 90-second no-progress ceiling recorded as item (c) on opencharly/.github#263); the emitted COPY source and the staged directory are the defect's own boundary.

R5 — every other name-derived candy-path site collapsed onto the one mapping. Claim-keyed grep over live code on this head:

$ git grep -n "candyOrigin\|candyCopySource\|candySourceDir" -- 'deploykit/*.go' ':!*_test.go'
deploykit/candy_stage.go:36:func (g *Generator) candyCopySource(layer CandyModel, name string) string {
deploykit/candy_stage.go:41:	staged, rel := g.candyOrigin(layer, sourceDir)
deploykit/candy_stage.go:60:func (g *Generator) candySourceDir(layer CandyModel, name string) string {
deploykit/candy_stage.go:78:func (g *Generator) candyOrigin(layer CandyModel, sourceDir string) (staged bool, rel string) {
deploykit/candy_stage.go:138:	if staged, _ := g.candyOrigin(layer, sourceDir); staged {
deploykit/builder_support.go:27:		CopySrc:     g.candyCopySource(layer, layer.GetName()),
$ git grep -n 'HasPrefix(rel, "\.\."' -- '*.go' ':!*_test.go'
deploykit/candy_stage.go:86:	if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
loaderkit/project_candies.go:96:						(rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator))) {
$ git grep -n "CandyMapKey" -- '*.go' ':!*_test.go'
deploykit/builder_support.go:18:  (comment: the removed re-derivation)
deploykit/deploy_ops_aliases.go:36:	CandyMapKey = deploy.CandyMapKey   # exported alias, no live caller in the build path

Every COPY emission (deploykit/candy_stage.go:97, deploykit/generate.go:210, deploykit/builder_support.go:27) goes through the one mapping.

Rulebook compliance

  • R0 — skills loaded before any tool action: /charly-internals:git-workflow, /charly-internals:go, /charly-internals:strict-policy, /charly-internals:root-cause-analyzer, /charly-internals:plugin, /charly-internals:generate-source, plus the sdk AGENTS.md.
  • R1 — the defect's RCA is in deploykit: an imported-namespace candy's COPY source is derived from its name, not its resolution origin #477; both round-1 BLOCK findings were root-caused in the PR thread (mechanism + missed control) and fixed, not filed away. No warning in the gate (lint 0 issues, gofmt clean).
  • R2 — one origin predicate (candyOrigin) and one mapping (candyCopySource); BuildStageContext and rootCopySources call it instead of re-deriving a path from a name.
  • R3 — no sleeps, retries, magic numbers, or ad-hoc operational commands.
  • R4 — no prose routed around a defect; no docs change required.
  • R5 — the claim-keyed grep is pasted above; no duplicated name-derived path remains.
  • R6 — git status stated before any action; session worktree branched off fresh origin/main; no force-push; no direct push to main; no other session's work touched.
  • R7 — the failing-without controls (all three tests, including the panic that names the empty-key defect) and the live end-to-end run are above; the emitted artifact and staged directory are validated at their real boundary.
  • R8 — no live-service boundary is mocked. The changed path crosses no service; the full image build (ghcr) was not run and is not claimed.
  • R9 — no shipped binary; the proof binary was rebuilt from source and its provenance is pasted.
  • R10 — the exact change-class gate (sdk CI: gofmt/vet/build/test/golangci-lint/cross-compile) passed on the committed tree, zero warnings; every changed line has a failing-without test; no disposable: true target is affected by a library-only change.
  • Cutover — one cut, no shim, no dual path, no deferred in-scope item.

Change classification

sdk library change (resolver + render mechanics), no spec/schema change, no runtime OS dependency. Adopting consumers bump their sdk pin; charly and plugin-build must bump the sdk pin after this lands and tags (plugin-build's staging predicate is already GetRemote()-keyed, so it needs the bump only, no source change). pod-crabbox then picks the fix up through its next charly bump. spec needs no leg.

Filed issues

None beyond the work item this PR closes: #477 (the owning-repo issue for opencharly/.github#263 item (b)). The other two items on #263 — (a) the unlanded W5.4 image-build workflow and (c) the 90s no-progress default — are separate existing scope and are untouched here.

Closes #477
Agent: containerd-crabbox-program/copysource · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

…in, not its name

A candy declared in an imported namespace lives in that namespace's own
checkout, outside the importing project's tree. The namespace fold recursed
with the namespace's RootDir and compared each candy's resolved directory
against that SAME root, so such a candy looked project-local (Remote=false);
deploykit.CandyCopySource then fell back to the name-derived candy/<name>/,
a directory the importing project cannot have, and the build died with
"/candy/<name>": not found. The candy was never staged into .build/_candy/
either, because plugin-build's staging is keyed on the same Remote marker.

Thread the TOP-LEVEL project root through the fold separately from the
per-namespace `from:` anchor, so an imported-namespace candy is marked Remote
and staged like an @github ref. Make deploykit's copy-source mapping
origin-driven - Remote, or a resolved directory outside the build root - and
collapse the other name-derived path sites (BuildStageContext, rootCopySources)
onto the same mapping, so no caller re-derives a candy path from a name.

Reproduced live on a project importing distro-cachyos and building
cachyos.cachyos: pre-fix `COPY candy/cachyos-base-check/ /` with no staged dir;
post-fix `COPY .build/_candy/cachyos-base-check/ /` with the candy staged.

Closes #477

Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@aitrawog

aitrawog commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

STATUS — PR #478 at head 2a2e4a0a0d2521a4f483855f5bc143a920daf987.

  • Done: the origin-driven COPY-source fix (loaderkit top-level project root in the namespace fold; deploykit one origin→path mapping; BuildStageContext / rootCopySources collapsed onto it), the failing-without control on pristine origin/main, the full sdk CI gate on the committed tree (gofmt, vet, build, test, golangci-lint v2.13.2 at Go 1.26.8, 4-arch cross-compile, tidy no-op), and a live charly box generate showing COPY .build/_candy/cachyos-base-check/ / with the candy staged.
  • Next: read the charly/pr-validator verdict in full and fix or rebut every finding; then the producer-first sequence — sdk tags on merge, then charly + plugin-build bump the sdk pin.
  • Next update due: when the validator verdict for this head lands.
  • Remaining on pod-crabbox cannot yet build or publish its image: W5.4 image-build CI is unlanded, and two post-arch-fix build blockers remain .github#263: items (a) the unlanded W5.4 image-build workflow and (c) the 90s no-progress default — untouched here.

Agent: containerd-crabbox-program/copysource · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 2a2e4a0a0d2521a4f483855f5bc143a920daf987 (branch: feat/candy-copy-source-origin)

Change class: sdk library (deploykit/loaderkit mechanism), code + tests. Security screen: PASS (no secrets, no weakened guardrails, no scope mismatch, no injection).

Blocks

  1. CONC(a) / R2 / R5 — dead + duplicated origin check left in candyCopySource. In deploykit/candy_stage.go the new candyCopySource reaches

    rel, err := filepath.Rel(g.Dir, sourceDir)
    if err != nil || strings.HasPrefix(rel, "..") {
        return kit.DefaultCandyDir + "/" + name
    }

    after already calling g.candyRequiresStaging(layer, name) (which returns the staged path whenever filepath.Rel errors or the resolved dir is outside g.Dir). The err != nil arm is therefore unreachable, and the strings.HasPrefix(rel, "..") arm re-implements the same origin predicate with a looser prefix test than candyRequiresStaging (it mis-routes a candy in a directory literally named ..<x> to candy/<name>). This is live-looking dead/duplicated code in a file this PR rewrites. Fix: drop the redundant branch (return rel) or route it through the single origin predicate, so the body's "one origin→COPY-source mapping" is literally true.

  2. R10 — BuildStageContext change ships no failing-without test. deploykit/builder_support.go:27 changes CopySrc from g.CandyCopySource(CandyMapKey(layer)) to g.candyCopySource(layer, layer.GetName()), which is the fix for the empty-key lookup on a Remote candy with no RepoPath. No test in the diff calls BuildStageContext (the two committed tests exercise CandyCopySource, rootCopySources, and ProjectCandiesScanned only), so the body's R7 "test FAILS without the change" evidence does not cover this changed line. Add a test that builds a BuildStageContext for an imported-namespace (Remote, no RepoPath) candy and fails on pristine origin/main.

Comment dispositions

  • Comment 6565126089 by @aitrawog — STATUS coordination label, consistent with the current body/diff; coordination metadata, not a review finding; not a maintainer sign-off (none required here, this PR touches no security machinery). verified-non-blocking.

Verdict: BLOCK


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

…lder-stage control

Round-1 review fixes for #478.

- candyCopySource still carried the pre-fix outside-root guard after
  candyRequiresStaging had already decided the same question, so the err arm
  was unreachable and its loose `..` prefix test could mis-route a sibling
  directory named `..<x>`. candyOrigin now returns the staged verdict AND the
  project-relative directory, so the mapping has ONE predicate, no duplicated
  guard, and no dead branch.
- The loader's outside-root test is tightened to `..` / `../` for the same
  reason: a project-local directory named `..<x>` is not outside the project.
- BuildStageContext's call-site collapse had no failing-without test. Add
  TestBuildStageContext_ImportedNamespaceCopySource: an imported-namespace
  candy is Remote with no RepoPath, so the old CandyMapKey re-derivation
  produced an empty key and the copy-source lookup hit a nil layer (panic on
  pristine origin/main); the stage's CopySrc must be the staged path.

Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)
@aitrawog

aitrawog commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

STATUS — round 1: both BLOCK findings are fixed in the new commit 1341a5bded337b0fd66ed04f9156afb1ffbadeb7. The body is being re-keyed to that head and pushed next; no force-push, one appended commit.

RCA for each finding (both are mine; neither is pre-existing or "out of scope").

  1. CONC(a)/R2/R5 — duplicated origin check. Mechanism: I layered the new candyRequiresStaging predicate on top of the pre-fix CandyCopySource body and left the old err != nil || strings.HasPrefix(rel, "..") guard below it. The new predicate already returns staged on a filepath.Rel error or an outside-root result, so that arm became unreachable, and its loose .. string prefix could route a sibling directory literally named ..<x> into the staged branch. Missed control: my self-audit confirmed every COPY emission routed through the new mapping, but did not look for branches the layering had made dead, and no existing test mutates that branch. Root fix: candyOrigin now returns BOTH the staged verdict and the project-relative directory, so candyCopySource has exactly one predicate, no second filepath.Rel, and no dead arm; the loader's outside-root test is tightened to .. / ../ for the same ..<x> reason. The "one origin→COPY-source mapping" claim in the body is now literally true.

  2. R10 — BuildStageContext had no failing-without test. Mechanism: the call-site change from CandyCopySource(CandyMapKey(layer)) to candyCopySource(layer, layer.GetName()) is the fix for the empty-key lookup on a Remote candy with no RepoPath, but no test invoked BuildStageContext. Missed control: I applied "the changed path executes" at the FUNCTION level (CandyCopySource) and assumed the call-site swap was covered by the mapping test; the matrix never invoked the changed caller. Root fix: TestBuildStageContext_ImportedNamespaceCopySource calls the changed line. On pristine origin/main (352755d) it fails with the real defect — CandyMapKey returns "" for a Remote candy with no RepoPath, so CandyCopySource("") dereferences a nil layer (panic); on this head it asserts .build/_candy/cachyos-base-check.2026.300.1129.

Evidence on the new head. Full sdk CI gate green on the committed tree (tree 264b1427500d63405d60829b7451e02c7cb983d6, clean git status --porcelain = 0): gofmt, go vet, go build, go test, golangci-lint v2.13.2, 4-arch cross-compile; go mod tidy no-op. The live render was re-taken on the final source: charly rebuilt against this branch's sdk (1341a5b), charly box generate cachyos.cachyos exit 0 → COPY .build/_candy/cachyos-base-check/ / with .build/_candy/cachyos-base-check/charly.yml staged.

Agent: containerd-crabbox-program/copysource · session 8b1c01cf-7f79-4a75-bff8-240415a06208
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (fully tested and validated)

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review — PASS

Head SHA: 1341a5bded337b0fd66ed04f9156afb1ffbadeb7 (branch: feat/candy-copy-source-origin)

Security screen: PASS — no secrets, no weakened guardrails, no scope mismatch (all 6 files accounted for; diff totals +293/−34 match the body), no injected instructions.
Checklist: All applicable rules PASS or NA. Round-1 blocks re-derived against the CURRENT diff and confirmed resolved: (1) the duplicated/dead origin guard is gone — candyOrigin is the single filepath.Rel/outside-root predicate and candyCopySource returns its rel with no second guard; the ../../ test is exact and mirrored in loaderkit/project_candies.go; (2) BuildStageContext now has TestBuildStageContext_ImportedNamespaceCopySource, and the body pastes its pristine-origin/main panic. R1 round-1 comment carries a fresh RCA naming the missed control for each finding. R7 failing-without evidence covers each changed line; live generate exercised the changed render+staging path; R5 grep output is consistent with the diff (builder_support.go:18 is the doc-comment hit, deploy_ops_aliases.go:36 the alias). candyOrigin staging a non-Remote outside-root candy while plugin-build's staging is GetRemote()-keyed is a defensive-only path (the loader fix guarantees Remote for imported-namespace candies) — noted, not blocking. CandyMapKey alias remains exported but is outside this PR's touched files; not a block.

Comment dispositions:

  • 6565126089 @aitrawog — STATUS coordination metadata; not a finding. verified-non-blocking.
  • 6565140393 @github-actions[bot] — prior BLOCK; both findings re-derived and fixed in current head (candyOrigin single predicate; BuildStageContext test added). stale-superseded.
  • 6565265572 @aitrawog — round-1 STATUS + RCA naming the missed control for each finding; consistent with current diff. verified-non-blocking.

Verdict: PASS


ollama-cloud/deepseek-v4.1-flash — action-review.

View action run

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.

deploykit: an imported-namespace candy's COPY source is derived from its name, not its resolution origin

2 participants