Skip to content

fix(sdk): an unresolvable build-config COPY is a generate error, not an emitted directive - #337

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/polymorphism-truth-headercopy
Oct 3, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/polymorphism-truth-headercopy

Conversation

@aitrawog

@aitrawog aitrawog commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Relates to opencharly/charly#764 — the init-polymorphism defect class. This is the third
instance
of that class, one layer below the two #336 already fixed (the missing fetch, the missing
injection).

Summary

sdk/deploykit/header_copy_remote.go makes a build-config asset referenced by a remotely-included
build.yml — the init header_file — reachable from the image build. It probed the asset in the
project tree, then in every remote candy's repo@version cache root, and returned relPath
unchanged when both missed
:

// before
return relPath, nil // not in any remote cache root; leave as authored

The caller (rewriteHeaderCopyForRemote, reached from deploykit/init.go:257) puts that value
straight into the emitted COPY <src>, so a miss produced a directive naming a source that had just
been proven absent, and the image build then died inside the engine with
copier: stat: "<relPath>": no such file or directory — naming neither the candy nor the cache root.
That is exactly the P1 symptom this wave is about.

RCA — is the fallthrough ever correct?

No, and that is what makes the fix safe. dir is the build context a COPY <src> resolves
against: deploykit/generate.go writes the Containerfile to g.BuildDir/<box>/Containerfile with
g.BuildDir = filepath.Join(dir, ".build") (render_generator_from_project.go:160), and the build
runs with dir as its context. That is exactly why the materialized branch returns
.build/_buildconfig/<relPath> — a dir-relative path, not a buildDir-relative one. Both probes
in the function therefore test the very path a COPY <relPath> would resolve to.

Once both probes have missed, the directive cannot do anything but fail. The fallthrough was
reachable only when the COPY was already doomed, so turning it into a generate-time error is a
pure fail-fast: it can never reject a build that would otherwise have succeeded, and it converts an
opaque engine error into one that reports the asset and every root that was searched.

What changed

  • deploykit/header_copy_remote.go (+31/−4) — the cache roots are bound once
    (roots := remoteBuildConfigCacheRoots(candies)) instead of being recomputed in the loop header,
    and the fallthrough becomes a hard error naming the asset, the project-tree path that was tried,
    and every cache root searched. When there is no remote candy at all the message says
    no remote candy is in the resolved set rather than printing an empty list. The doc comments now
    state the build-context invariant the reasoning rests on, and that a non-COPY line still passes
    through as-authored (the new error must not over-fire).
  • deploykit/header_copy_remote_test.go (new, 169 lines) — six tests covering: the missing
    asset being a hard error that names asset + local path + searched root; the no-remote-candy
    wording; the remote cache root still materializing to a dir-relative source that really exists
    there; the local project asset still passing through unchanged; the wrapper propagating rather
    than swallowing; and non-COPY lines passing through verbatim.

How tested

All of the following was run on the final committed tree, 86962b0
(git rev-parse HEAD → 86962b0f68e4bbe15c78d6b2ca0bbad7eb820c11), after the fail-without-change
round-trip below had been restored — git status --short was empty first. The repo's own gate, per
its AGENTS.md:

$ gofmt -l .            # prints nothing
$ go build ./...
$ go vet ./...
$ go test -count=1 ./...
ok      github.com/opencharly/sdk        0.330s
ok      github.com/opencharly/sdk/agentkit     0.668s
ok      github.com/opencharly/sdk/buildkit     0.021s
ok      github.com/opencharly/sdk/candywalk    0.013s
ok      github.com/opencharly/sdk/charlylib    0.028s
ok      github.com/opencharly/sdk/checkkit     0.010s
ok      github.com/opencharly/sdk/cmd/charly-lib-gen   0.009s
ok      github.com/opencharly/sdk/deploykit    6.101s
ok      github.com/opencharly/sdk/enginekit    0.008s
?       github.com/opencharly/sdk/internal/spectest     [no test files]
ok      github.com/opencharly/sdk/kit       11.506s
ok      github.com/opencharly/sdk/llmkit        1.999s
ok      github.com/opencharly/sdk/loaderkit     3.212s
ok      github.com/opencharly/sdk/packagekit    0.054s
ok      github.com/opencharly/sdk/vmshared      0.127s
ok      github.com/opencharly/sdk/workflowkit   0.012s

Plus the CI cross-compile matrix (.github/workflows/ci.yml):

$ for a in amd64 arm64 arm 386; do GOOS=linux GOARCH=$a CGO_ENABLED=0 go build ./... ; done
GOARCH=amd64 OK
GOARCH=arm64 OK
GOARCH=arm OK
GOARCH=386 OK

The test fails without the change

git checkout HEAD~1 -- deploykit/header_copy_remote.go (fix reverted, test kept):

$ go test -count=1 -run 'TestMaterializeBuildConfigAsset|TestRewriteHeaderCopyForRemote' ./deploykit/
--- FAIL: TestMaterializeBuildConfigAsset_MissingAssetIsAHardError (0.00s)
    header_copy_remote_test.go:49: an asset present in no cache root and not in the project tree must be a hard error, not `COPY templates/supervisord.header.conf` (which resolves to /tmp/TestMaterializeBuildConfigAsset_MissingAssetIsAHardError919261708/001/templates/supervisord.header.conf, just proven absent); got ("templates/supervisord.header.conf", nil)
--- FAIL: TestMaterializeBuildConfigAsset_NoRemoteCandySaysSo (0.00s)
    header_copy_remote_test.go:125: an unresolvable asset must error even with no remote candy in the resolved set
--- FAIL: TestRewriteHeaderCopyForRemote_UnresolvableSourceIsAnError (0.00s)
    header_copy_remote_test.go:143: a COPY whose source resolves nowhere must not be emitted as-authored; got ("COPY templates/supervisord.header.conf /etc/supervisord.header.conf", nil)
FAIL
FAIL    github.com/opencharly/sdk/deploykit    0.024s
FAIL
exit=1

The failure text is the defect itself: the old code returns the unresolvable relPath with a nil
error, and the wrapper emits the doomed COPY verbatim.

Restore verified — git checkout HEAD -- deploykit/header_copy_remote.go then:

$ git status --short
[empty]

Why a unit test is the right boundary here (R7a)

This function crosses no live-service boundary: it is a filesystem stat plus a cp, with no
network, no gh call, no engine call. R7a requires the live-or-skip discipline for a boundary that
talks to a real service and explicitly keeps "pure/deterministic in-repo logic unit-testable
normally". No mock or stub of any external service is involved — the tests exercise the real exported
mechanism against real temporary trees. There is no LIVE_-gated test in deploykit today, because
none of its surface needs one.

The live end-to-end path

RewriteHeaderCopyForRemote is wired by NewRenderGeneratorFromProject and driven by a plugin over
the reverse channel. Its success branches are unchanged by this PR (same inputs → same outputs);
only the previously-unreachable-and-doomed branch changes behaviour. Driving it end to end against a
real charly requires a charly binary built against this sdk, which is the consumer leg held behind
opencharly/charly#762 — so that run is downstream of this PR, not a substitute for it.

Rulebook compliance

  • R0 — skills first. Loaded before the first tool call: /charly-internals:plugin (its "when to
    use" names sdk/** code explicitly), /charly-internals:go, /charly-internals:install-plan (the
    three the sdk AGENTS.md lists), /charly-internals:git-workflow (before any git/PR action),
    /charly-internals:root-cause-analyzer (the RCA above is its 8 steps).
  • R1 — RCA every anomaly. The RCA is the Summary's "is the fallthrough ever correct?" section:
    expected behaviour (the fallthrough leaves the directive as-authored), actual (it emits a directive
    that cannot resolve), mechanism (both probes test the same path the COPY resolves to, so a double
    miss is a guaranteed engine failure), missed control (nothing ever asserted the asset existed),
    blast radius (any project whose remote build.yml names a header asset no cache root carries),
    root cause (a "not found" branch that returned success), root fix (fail where both paths are still
    known), documented (here + charly#764).
  • R2/R5 — finish the cutover, delete legacy. The silently-emitting fallthrough is removed
    outright; no compatibility shim or toggle is added.
  • R3 — no duplication. No new copy of the build-context rule: the fix reuses
    remoteBuildConfigCacheRoots and states the invariant in the doc comment over the single
    implementation.
  • R4/R4a — no workarounds; fix the product first. This is the product fix, in the owning repo
    (sdk), one layer below the two #336 landed. The symptom it removes was previously "worked
    around" only by the operator reading an engine log.
  • R6 — Git safety. No force-push, no hook bypass. git status --short is empty after every step;
    the fail-without-change round-trip was done with git checkout <ref> -- <path> and verified
    restored, never with a stash.
  • R7 — prove the gate, not the plan. The gate was run on the committed tree and its output is
    pasted above; the fail-without-change run proves the test is not vacuous.
  • R7a — live or skip, never fake. No live-service boundary is crossed (above); no mock or fake of
    one is introduced.
  • R8 — preserve emitted artifacts. The success path's emitted directive is byte-identical; only
    the failure path changes, and it changes from a silently-broken artifact to no artifact plus an
    error.
  • R9 — binary equals source. No binary or generated artifact is committed; the diff is source
    plus test.
  • R10 — fresh disposable proof; check-coverage. The final gate ran from the committed tree after
    the round-trip restore, not from an edited state, and the change ships a test that fails without it.
  • Rule 1/2 (umbrella) — never edit inside a submodule. All of this landed in a session worktree,
    .worktrees/polymorphism-truth/sdk, on feat/polymorphism-truth-headercopy; the sdk submodule's
    tracked checkout stays detached at its gitlink.
  • Rule 9 — session-scoped ownership. No other session's file, branch, worktree or PR was touched.
    The search-first check found no existing thread for this defect in sdk; #334/#310 are other
    sessions' PRs and were left alone.
  • Rule 10 — read the live state and write the body before the push. This body was written for the
    head 86962b0 before the push; charly#764's live comments were read first and are answered by the
    STATUS comment posted alongside.

Change classification

  • Change class: mechanism bug fix in the render-generate path (sdk/deploykit). No schema, wire
    type, or public API change; no new dependency; no pin touched.
  • Verification gate: the sdk repo's own full gate — gofmt -l / go build ./... /
    go vet ./... / go test -count=1 ./... (all 16 packages) plus the CI
    cross-compile matrix (linux/{amd64,arm64,arm,386}, CGO_ENABLED=0) — run in full on the final
    committed tree 86962b0, output pasted above, plus a test that fails without the change.
  • Attribution tier: fully tested and validated.
  • On the umbrella gate: ./charly/bin/charly task verify is the umbrella's gitlink pinning
    audit, and this PR touches no gitlink — it changes one sdk library function, so that gate is not
    this change's gate. I ran it anyway to check, and it cannot execute in this checkout:
    charly: error: command "task": load project: …/opencharly/charly.yml: schema 2026.261.1747 is required (found ""). Run: charly migrate. RCA (measured, not assumed): the umbrella's charly
    submodule checkout is detached at its gitlink 48d03519 = v2026.275.0315, which predates the
    #749/#754 cutover fix that lets charly load a manifest without the retired version: stamp.
    So the umbrella's entire task … maintenance surface is unusable — and a
    charly/scripts/bootstrap-charly.sh rebuild reproduces it exactly
    , because that script builds
    from charly/, i.e. from the same stale gitlink. The remedy is an umbrella pin bump, which is
    a gitlink-change class and must not ride along in this diff. Owning batch:
    opencharly/opencharly#330
    (already filed, carrying this RCA) — the same routing the umbrella
    harness-config PR carries. Surfaced here rather than parked; out of scope for an sdk-only PR.

Agent: polymorphism-truth · session 9c898e99-b5d7-4f3e-a472-62c4ecbcd18f
Assisted-by: Claude Code DeepSeek V4.1 (flash) (fully tested and validated)

…an emitted directive

materializeBuildConfigAsset probed a build-config asset in the project tree and then in
every remote candy's repo@version cache root, and returned relPath unchanged when both
missed — emitting `COPY <relPath>` into a Containerfile whose build context IS the probed
`dir`. That directive can only fail inside the engine, with a `copier: stat:
"<relPath>": no such file or directory` naming neither the candy nor the cache. This is
the third instance of the "the init runtime was never materialized" defect class this
wave exists for; the first two were the missing fetch and the missing injection.

`dir` is the build context the emitted COPY resolves against: the Containerfile is
written to buildDir/<box>/Containerfile and the build runs with `dir` as its context,
which is exactly why the materialized branch returns a `.build/_buildconfig/...` path
relative to `dir` rather than to buildDir. Both probes therefore test the very path that
a `COPY <relPath>` would resolve to, so the fallthrough was reachable ONLY when the COPY
was already doomed — failing there is a pure fail-fast conversion that can never reject a
build which would otherwise have succeeded.

The error names the asset, the project-tree path that was tried, and every cache root
that was searched, so the failure is diagnosable without the engine log.
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown

Review — PASS

Head SHA: 86962b0f68e4bbe15c78d6b2ca0bbad7eb820c11 (branch: feat/polymorphism-truth-headercopy)
Change class: sdk Go mechanism fix (deploykit/header_copy_remote.go) + new unit test — no schema/wire/API/dependency/pin change.

Security screen: PASS (T1–T4 clear — no spec/rulebook/guardrail edit, no secrets or egress, no new deps or @github ref changes, no embedded directives in body/diff).
Checklist: All applicable rules PASS or NA. A2/A3 — the changed (error) branch is exercised by a unit test that fails without the change; the function crosses no live-service boundary (filesystem stat/cp), so R7a's unit-test discipline governs and no bed is required. B12 — test ships and is proven non-vacuous by the pasted fail-without-change output, whose three FAILs exactly match the three tests that require the new error. Diff/body counts reconcile (+31/−4, +169), and the pasted gate output names the real package set. B16 placement: CORRECT (sdk kit mechanism, no core creep, no alias growth, no new core→kit import).
Comment thread: empty (0 comments) — nothing to disposition.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) October 3, 2026 11:36
@github-actions
github-actions Bot merged commit 59d75ab into main Oct 3, 2026
6 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Oct 3, 2026
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