Skip to content

feat(staging): content-address the candy staging dir, not its ref - #444

Merged
github-actions[bot] merged 3 commits into
mainfrom
fix/content-addressed-candy-staging
Nov 26, 2026
Merged

github-actions[bot] merged 3 commits into
mainfrom
fix/content-addressed-candy-staging

Conversation

@aitrawog

@aitrawog aitrawog commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

CandyStageDirName keyed the build staging directory by <name>.<version>, so a ref-only change —
the same candy content at a new tag or branch — produced a different COPY source path and
invalidated every BuildKit layer beneath it. Measured on the openwebui image: 2400 s cold, 90 s for
the same tree, 683 s for the same content at a new ref
.

This addresses the directory by the candy's content: <name>.<sha256[:16]> over the sorted
relative paths, each regular file's executable bit and bytes (symlink targets included; .git,
mtimes, owners and the other permission bits excluded — git applies the umask to those, so they differ
between checkouts of identical content). Consequences:

  • Identical content at two refs shares one directory → the Containerfile's COPY source and its
    layer key stay stable, so a ref-only change reuses the cached pixi stage instead of re-executing it.
  • Different content gets a different directory → two versions never clobber each other; the stager
    already installs atomically (kit.InstallDirAtomic, renameat2 RENAME_EXCHANGE).
  • No source dir / unreadable walk → falls back to the version-keyed name, so a caller never stages
    under an address it could not derive.

The stager (plugin-build's createRemoteCandyCopies, host_prep.go:180) and the COPY source
(sdk/deploykit's CandyCopySource, candy_stage.go:41) both call this ONE function, so the name is
derived in one place — the change is a single implementation, not a second naming path.

Head: f3c26fca7922381246f52d0ca0b7f95b22fc1176
Diff: 4 files changed, 226 insertions(+), 6 deletions(-)

  • deploy/deploy_ops.go — CandyStageDirName derives the content address
  • deploy/content_hash.go — dirContentHash, the deterministic walk (new)
  • deploy/deploy_ops_candykey_test.go — the existing fakeCandy gains GetVersion/GetSourceDir
  • deploy/content_hash_test.go — the three witnesses (new)

How tested

$ GOWORK=off go test ./deploy/ -run 'TestCandyStageDirName' -v
=== RUN   TestCandyStageDirName_SameContentSameName
--- PASS: TestCandyStageDirName_SameContentSameName (0.00s)
=== RUN   TestCandyStageDirName_DifferentContentDifferentName
--- PASS: TestCandyStageDirName_DifferentContentDifferentName (0.00s)
=== RUN   TestCandyStageDirName_FallsBackToVersion
--- PASS: TestCandyStageDirName_FallsBackToVersion (0.00s)
=== RUN   TestCandyStageDirName_UmaskInsensitive
--- PASS: TestCandyStageDirName_UmaskInsensitive (0.00s)
ok  	github.com/opencharly/spec/deploy	0.005s

The umask witness fails on the previous mode-string hash (measured):

--- FAIL: TestCandyStageDirName_UmaskInsensitive
    a umask-only permission difference changed the address: "demo.b180ac0f4f4524c9" vs "demo.eeed8032efc87ec1"

It asserts both directions: two trees of identical content with different file/directory permissions
produce ONE address, and flipping the executable bit changes it.

The same-content test is the regression witness: two separate checkouts of identical content at
two versions must produce the SAME directory (and it asserts the name is no longer name.version);
the different-content test asserts they must NOT collide.

A compile-compat check of the consumer (sdk) against this module — it does not itself prove the changed branch, the in-module witnesses do:

$ GOWORK=off go test ./deploykit/ -run 'CandyStage|CopySource'
ok  	github.com/opencharly/sdk/deploykit	0.012s
$ GOWORK=off go build ./...   &&   GOWORK=off go vet ./deploy/
rc=0

Spike

Candidate Run + result
A — keep <name>.<version> the status quo: a ref change re-copies to a new path and invalidates the layers (2400 s cold → 90 s same tree → 683 s new ref, measured on openwebui)
A2 — bind-mount the candy instead of COPY not a viable candidate: it moves the COPY source to a live path outside the image, so no in-image layer key exists to stabilise — stated as a rejection, not spiked
B — content-address the directory (winner) the three witnesses above: identical content → one name, different content → different names, no source dir → version fallback

The cross-repo proof (producer-first)

spec is a Go-module dependency of charly, so the end-to-end measurement — two builds of identical
content at two refs, comparing the pixi stage duration against the 683 s baseline — runs at the
consumer's leg: this PR merges and tags, charly bumps its spec requirement to that tag, the binary
is rebuilt, and the two builds are pasted there. That is the sanctioned producer-first order
(/charly-internals:git-workflow B6), not a deferral of this change's own gate: this PR's gate is the
unit witnesses above, which fail without the change.

Rulebook compliance

  • R0 — /charly-internals:go, /charly-internals:design and /charly-internals:git-workflow
    loaded.
  • R1 — the slowness this fixes is filed as opencharly/charly#1289; no new finding is parked.
  • R2 — one naming implementation; the stager and the COPY source already call it.
  • R3 — no workaround: the name is derived from content, not from a cache hint.
  • R4 — the behaviour is documented in the pixi skill's cache section (layer-pixi#6).
  • R5 — the version-keyed name survives only as the documented fallback.
  • R6 — branch off fresh origin/main; no force-push.
  • R7 — three witnesses that fail without the change; the build proof is the consumer leg.
  • R8 — no service boundary involved.
  • R9 — no binary involved in this module.
  • R10 — the unit gate for the contract module is pasted; the two-ref build measurement is the
    consumer leg, sequenced by producer-first.
  • R11 — no wire/schema shape changes; a helper plus one function body.
  • R12 — three candidates above, each with its run or its measured rejection.
  • DISP — no deploy or destroy.

Change classification

No breaking change to a wire shape. The staging directory NAME changes, so the first build after
the change re-executes the layers once (a new COPY source); after that, ref-only changes reuse them.

Breaking change + rollback: none — reverting restores the version-keyed name.

Filed issues

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

CandyStageDirName keyed the build staging directory by <name>.<version>, so a
ref-only change (same candy content, a new tag or branch) produced a different
COPY source path and invalidated every BuildKit layer below it — measured on
the openwebui image: 2400s cold, 90s same tree, 683s for the same content at a
new ref.

Address the directory by the candy's CONTENT instead: <name>.<sha256[:16]> over
the sorted relative paths, modes and file bytes (symlink targets included,
.git and volatile metadata excluded). Identical content at two refs now shares
one directory, so the COPY source and its layer key stay stable; different
content still gets a different directory, so two versions never clobber each
other (the stager installs atomically via kit.InstallDirAtomic). An empty or
unreadable source dir falls back to the version-keyed name.

The stager (plugin-build's createRemoteCandyCopies) and the Containerfile COPY
source (sdk/deploykit/CandyCopySource) both call this ONE function, so the name
is derived in one place.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)
@github-actions

Copy link
Copy Markdown

Review — BLOCK

Head SHA: 3e2b298a39ab8d67cf8d0a0a7f8d9f7deb1ae7ba (branch: fix/content-addressed-candy-staging)

Change class: code (Go library) — spec/deploy (no binary/beds in this module; consumer leg sequenced producer-first).

Security screen: PASS — no secrets, no egress, no obfuscation, no guardrail/spec/rulebook weakening, no new deps.

Blocks

  1. R1 / R7 — the content address is umask-sensitive, so the body's "identical content → one directory" claim is false across checkouts, and the test cannot catch it.
    deploy/content_hash.go:58 writes info.Mode().String() for every entry — regular files and directories. Git checkout applies the process umask to file and directory modes (e.g. 0644 vs 0664, 0755 vs 0775), so two checkouts of identical content under different umasks produce different mode strings → different dirContentHash → different CandyStageDirName → a different COPY source (the exact layer-invalidating outcome the PR is meant to eliminate). This directly contradicts the Summary's unconditional "Identical content at two refs shares one directory" and the comment's "Volatile metadata is deliberately excluded." content_hash_test.go's writeCandy builds both trees under the same process umask, so the witness passes regardless and does not prove the claim.
    Fix: hash the executable bit (or ignore permission bits entirely) rather than the full mode string, and add a test that varies file/directory permissions and asserts the hash is unchanged.

Non-blocking notes

  • R12: candidate A2 (bind-mount) is rejected by reasoning with no pasted command output/exit code, and candidate A is a measured baseline rather than a spike. The spike-equivalent exemption is present and named (the same-content regression test fails without the fix), so R12 is satisfied — but the table would be stronger with pasted output for A2, or A2 removed with an explicit "not a viable candidate" note.
  • R10 (tool-limited): the pasted consumer output ok github.com/opencharly/sdk/deploykit does not show the sdk checkout's spec dependency resolving to this branch (no replace/version shown), so it is not verifiable as exercising the changed code. The in-module unit tests are the primary proof, so this is a gap in supplementary evidence, not itself a block.

Verdict: BLOCK


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

View action run

The content address hashed `info.Mode().String()` for every entry. Git applies
the process umask to permission bits, so two checkouts of identical content can
differ there (0644 vs 0664) and would hash differently — the exact
layer-invalidating outcome this change exists to remove. Hash only whether a
file is executable; a directory's mode is irrelevant to the staged content.

New witness: two trees of identical content with different file directory
permissions must produce ONE address (fails on the old mode hash), and flipping
the executable bit must change it.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: 6f32a43186f7a310afb6c148adf2b28cdf26f028 (branch: fix/content-addressed-candy-staging)

Security screen: PASS — content-hash walker only reads the candy source dir; no secrets, egress, network, obfuscation, dep changes, or guardrail/spec weakening.
Checklist: All applicable rules PASS or NA (code/Go-library class; no binary/beds in this module, consumer leg sequenced producer-first).
Placement: CORRECT — dirContentHash sits beside the existing CandyStageDirName in spec/deploy; one implementation both consumers call, no capability-into-core move.

Comment intake

  • Comment 7203599045 (github-actions bot, at prior SHA 3e2b298): its blocking finding — mode-string hashing is umask-sensitive — is stale-superseded. The current diff hashes only the executable bit (0o111) for regular files/symlinks and contributes nothing for directories, and TestCandyStageDirName_UmaskInsensitive varies 0644/0664 and 0755/0775 and asserts one address, then flips the exec bit and asserts a changed address. Its non-blocking notes are also addressed: A2 is now labelled "not a viable candidate … stated as a rejection, not spiked," and the body concedes the sdk output is a compile-compat check only ("the in-module witnesses do" prove the branch). verified-non-blocking.

Non-blocking notes

  • The symlink branch (Readlink target contribution) is untested; a tree differing only in a symlink target would exercise it. Core content-addressing and the exec-bit behavior are covered, so this is a coverage nicety, not a gate failure.
  • The 2400 s / 90 s / 683 s figure is the status-quo baseline; the post-fix end-to-end measurement is correctly deferred to the charly consumer leg under producer-first, and this PR's own gate (unit witnesses that fail without the change) is present.

Verdict: PASS


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

View action run

@github-actions

Copy link
Copy Markdown

Auto-merge was NOT armed for head 6f32a43186f7a310afb6c148adf2b28cdf26f028.

Class: 1 — at least one check run on this head did not pass. Fix it and push; auto-merge arms on the next PASS.

This is reported as a comment because a failing validate / arm check run would make the
pull request permanently unstable and block every later arming attempt
(opencharly/.github#313). The arm job therefore reports success and this comment is its alarm.

Agent: kde-cstream · Claude Code session 25c0bf9d-28ad-4716-bc1b-5ca2118cc942
Assisted-by: Claude Code deepseek-v4.1-flash (analysed on a live system)

The go job's golangci-lint runs errcheck, which flagged every unchecked
io.WriteString and f.Close in content_hash.go. Route the hash writes through a
checked helper, and check both the copy error and the close error.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: f3c26fca7922381246f52d0ca0b7f95b22fc1176 (branch: fix/content-addressed-candy-staging)

Security screen: PASS — content-hash walker only reads the candy source dir; no secrets, egress, network, obfuscation, dep changes, or guardrail/spec/rulebook weakening.
Checklist: All applicable rules PASS or NA (Go-library change class; no binary/beds in this module; consumer leg sequenced producer-first).
Placement: CORRECT — dirContentHash sits beside the existing CandyStageDirName in spec/deploy; one shared implementation both consumers call, no capability-into-core move, no alias-file growth.

Comment intake

  • 7203599045 (BLOCK at 3e2b298): its blocking finding — hashing the full Mode().String() is umask-sensitive — is stale-superseded. Current content_hash.go hashes only 0o111 for regular files/symlinks and contributes nothing for directories, and TestCandyStageDirName_UmaskInsensitive varies 0644/0664 + 0755/0775 (asserting one address) then flips the exec bit (asserting a changed address). verified-non-blocking.
  • 7203712229 (PASS at 6f32a43): grants nothing; independently re-derived against current head. Its non-blocking notes (symlink target untested; 2400/90/683 is the status-quo baseline, post-fix measurement deferred to the consumer leg) still hold. verified-non-blocking.
  • 7203741897 (arm-unarmed, class 1 at 6f32a43): CI status is not this gate's concern (the workflow's own check-run gate handles it, and branch protection enforces only validate / validate); also stale vs the current head. stale-superseded.

Non-blocking notes (not gate failures; recommend at the consumer leg)

  • dirContentHash writes file content raw with no length prefix, so the byte stream is not strictly injective: a single file a→b\x00c\x00-\x00d can hash identically to files a→b + c→d. Practically unreachable for text candy sources, but length-prefixing content would fully honor the "different content → different directory" claim.
  • The symlink-target branch (os.Readlink) has no witness; a tree differing only in a symlink target would exercise it.
  • The two call sites (plugin-build stager and sdk/deploykit CandyCopySource) are asserted to pass the same GetSourceDir, but this is not demonstrated here — if either passes a layer without SourceDir it falls back to version-keyed and the COPY source would diverge. Verify both populate SourceDir on the same candy at the consumer leg.
  • The 2400/90/683 s figures have no pasted command output; they are motivation, not contradicted by the diff.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) November 26, 2026 21:34
@github-actions
github-actions Bot merged commit 619b6a4 into main Nov 26, 2026
4 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Nov 26, 2026
github-actions Bot pushed a commit to opencharly/charly that referenced this pull request Nov 26, 2026
…1293)

* chore(deps): spec v0.2026330.2134 (content-addressed candy staging)

Advance the contract module to the tag carrying CandyStageDirName's content
addressing (opencharly/spec#444): a candy's build staging directory is now
named by its content, so a ref-only change reuses the same COPY source instead
of invalidating the layers beneath it.

`GOWORK=off go build ./...` passes on the new requirement; the end-to-end
two-ref build measurement is the next leg.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (analysed on a live system)

* chore(deps): keep the tools modules on the shared spec pin

The canonical-pin gate (tools/gomod-canonical) requires every module in this
repo to require the same spec version. The charly module moved to
v0.2026330.2134; bump the three tools modules to it as well, and re-tidy.

Agent: cdi-audit · Claude Code session f760307f-53b4-4f48-87da-00f95e5300ed
Assisted-by: Claude Code deepseek-v4.1-flash:cloud (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