Skip to content

fix(container): confirm an image-resolution miss against a fresh list - #82

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/resolve-retries-on-a-stale-image-cache
Aug 30, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/resolve-retries-on-a-stale-image-cache

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

A group bed with two image-backed members cannot check its second member. That is why no such bed exists yet — the existing multi-member beds (check-group, check-builder-vm) use local: members with no image, so nothing had ever exercised this path.

ListLocalImages serves a 5-minute persistent cache, and ResolveLocalImage resolves a short name from it. The bed phase order is build A → check A → build B → check B. Checking A repopulates the cache from a snapshot taken before B was tagged, so checking B — a separate process, and now a cache hit — cannot see its own freshly built image:

charly: error: image "punktfunk-host:check-punktfunk-fleet-2026.242.1217" is not available locally.
               Run 'charly box pull punktfunk-host:check-punktfunk-fleet-2026.242.1217' to fetch it first

A stale hit is harmless — it names an image that exists. A stale miss is not. So a miss is now confirmed against reality before it is believed: drop the cache, gather once more.

How the cause was established

The failure is deterministic — two consecutive runs of check-punktfunk-fleet, same failure at the same step, FAIL after 113ms (far too fast to be a real check).

The image was demonstrably present. From the host member's own build log, 113ms before the failure:

579:[7/7] COMMIT ghcr.io/opencharly/punktfunk-host:check-punktfunk-fleet-2026.242.1217
581:Successfully tagged ghcr.io/opencharly/punktfunk-host:check-punktfunk-fleet-2026.242.1217

and afterwards, from the store:

$ podman image exists punktfunk-host:check-punktfunk-fleet-2026.242.1217  ->  exists

So neither the build nor the tag nor podman's short-name resolution was at fault. The discriminator is in the two members' check-image logs:

client check-image: 1 "listing local images (first run — may take a moment)" line   -> cache MISS -> fresh list -> PASS
host   check-image: 0 such lines                                                    -> cache HIT  -> stale list -> FAIL

The passing member fetched a fresh list; the failing one was served the snapshot the passing member had just written. Confirmed by inspecting the cache at ~/.config/charly/cache/images.json, which holds no punktfunk-host:check-punktfunk-fleet-* entry.

How tested

New guards, and the negative control reproduces the production error text exactly:

$ go test ./container/ -run TestResolveLocalImage_ -v
--- PASS: TestResolveLocalImage_RetriesOnStaleCacheMiss
--- PASS: TestResolveLocalImage_GenuineAbsenceStillFails
--- PASS: TestResolveLocalImage_CacheHitDoesNotRefetch
ok  	github.com/opencharly/spec/container	0.003s

Negative control — retry removed:

--- FAIL: TestResolveLocalImage_RetriesOnStaleCacheMiss (0.00s)
    a stale-cache miss must be re-checked against a fresh list, got:
    image not found in local storage: punktfunk-host:check-punktfunk-fleet-2026.242.1217

That is the same error, on the same ref, that killed the bed.

The other two guards exist so the fix cannot drift into something worse. GenuineAbsenceStillFails keeps "confirm the miss" from becoming "retry until something turns up" — a real absence still reports ErrImageNotLocal, after exactly one confirmation. CacheHitDoesNotRefetch keeps the fast path fast: a hit never triggers a second enumeration, which matters because that enumeration is ~9s on a large store.

Build, vet and the full package on the committed tree:

$ go build ./container/   -> exit 0
$ go vet ./container/     -> exit 0
$ go test ./container/
ok  	github.com/opencharly/spec/container	14.371s

End to end: the bed that could not get past step 4

Built charly against this branch (go mod edit -replace github.com/opencharly/spec => …) and re-ran the same bed. Before, on two consecutive runs:

[check-image-punktfunk-fleet-host] FAIL after 113ms: exit 1: charly subcommand exited 1
FAIL (steps=4)

After:

[image-build-punktfunk-fleet-client] PASS after 3m6.987s
[check-image-punktfunk-fleet-client] PASS after 23.856s
[image-build-punktfunk-fleet-host]   PASS after 2m55.28s
[check-image-punktfunk-fleet-host]   PASS after 25.883s   <- was FAIL after 113ms
[bring-up-members]                   PASS after 28.753s

Both members now build, check and come up. 25.9s versus 113ms is the difference between running the checks and failing to find the image.

Rulebook compliance

  • R1 (RCA) — root-caused from the two members' logs and the store, and the obvious explanations (build failed / tag missing / podman short-name resolution) were each tested and eliminated before the cache was blamed.
  • R2 (no deferral) — found while building check-punktfunk-fleet; fixed here rather than worked around in the bed.
  • R3 (no duplication) — the candidate gather is extracted once and reused for both passes; no second resolution path.
  • R4 (no workarounds) — the resolver is corrected. The workaround would have been to disable the cache, or to sleep, or to have the bed pre-warm it.
  • R6 (git safety) — feature branch, no force-push, no hook bypass.
  • R7 (prove the gate) — unit tests, negative control, and the before/after bed phases pasted above.

Change classification

  • Change class: runtime/code change (image resolution + regression tests)
  • Verification gate: deterministic unit tests with a passing negative control, plus the previously-failing bed getting past the step on a binary built from this branch
  • Attribution tier: fully tested and validated — the defect was reproduced deterministically, the changed path executed live in the bed that exposed it, and the guard fails without the fix

Assisted-by: Claude Code Anthropic Opus 5 (fully tested and validated)

A group bed with two image-backed members cannot check its second member.

ListLocalImages serves a 5-minute persistent cache, and ResolveLocalImage
resolves a short name from it. The bed phase order is: build A, check A, build
B, check B. Checking A repopulates the cache from a snapshot taken BEFORE B was
tagged, so checking B — a separate process, and now a cache HIT — cannot see its
OWN freshly built image:

    charly: error: image "punktfunk-host:check-punktfunk-fleet-2026.242.1217"
                   is not available locally.

Reproduced deterministically on consecutive runs of check-punktfunk-fleet, with
the tag demonstrably present in the store and in the build log
("Successfully tagged ghcr.io/opencharly/punktfunk-host:check-punktfunk-fleet-…"
113ms earlier). The discriminator is in the two members' logs: the PASSING
member logs "listing local images (first run — may take a moment)" — a cache
miss, so a fresh list — and the FAILING one logs nothing, a cache hit.

A stale HIT is harmless: it names an image that exists. A stale MISS is not — it
reports "not available locally" for an image built seconds ago. So confirm a
miss against reality before believing it: drop the cache and gather once more.

The candidate gather is split into gatherResolverCandidates so the resolver can
run it twice, and the election into electResolvedImage. Both families are
returned because the newest-BUILD staleness probe spans them.

The retry cannot mask a real absence (the second gather is authoritative) and
does not slow the fast path (a hit never re-fetches) — both properties are
tested, not merely asserted.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6
@github-actions

Copy link
Copy Markdown

Review — PASS

Head SHA: a9e1064010fa (branch: fix/container-stale-cache-miss)

Security screen: PASS — no secrets, exfiltration, scope mismatch, weakened guardrails, or supply-chain changes. The diff only adds a cache-invalidation + re-gather on resolution miss and extracts two helpers; no embedded directives aimed at the reviewer.

Checklist: All applicable rules PASS or NA.

  • A1/A2/A3 — Body is complete: summary accounts for the change, How tested names the runtime gate with pasted unit-test output, a negative control, and a fresh-rebuild end-to-end bed run (the previously-failing check-image-punktfunk-fleet-host step now passes on a binary built from this branch). Attribution tier fully tested and validated is justified — the changed re-gather path executed live in the bed. Body ends with the correct *Assisted-by:* footer.
  • B5 (R1) — Detailed RCA from the two members' logs and the store; build/tag/short-name explanations each tested and eliminated before blaming the cache. No forbidden framing.
  • B6 (R2) — Fixed in-tree, no deferral.
  • B7 (R3) — Candidate gather extracted once (gatherResolverCandidates) and reused for both passes; no duplicated resolution path.
  • B8 (R4) — Resolver corrected; no sleep/poll/cache-disable workaround.
  • B12 (R10) — Three regression tests in the diff, each with a purpose; negative control proves the guard fails without the fix; GenuineAbsenceStillFails and CacheHitDoesNotRefetch bound the fix against drift. Test logic is internally consistent with the production code (2 calls on miss, 1 on hit, ErrImageNotLocal on genuine absence).
  • B16 (Architecture) — Placement CORRECT: image-resolution logic stays in the container package (core layer for this concern); helpers are same-file extractions, no new sdk-kit imports into core, no alias files.
  • B18 — Diff is gofmt-clean; no dead code, unused params, or shadowing visible; package-level var reassignment in tests is a standard DI pattern.
  • B13/B14/B15/B17 — NA (no candy/schema changes; no forbidden concurrency framing; single atomic commit; no autonomous destroy).

No comments on the thread to disposition.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 12:37
@github-actions
github-actions Bot merged commit 65217a0 into main Aug 30, 2026
1 of 2 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
github-actions Bot pushed a commit that referenced this pull request Aug 30, 2026
…mage (#83)

main is red. #82 split ResolveLocalImage into a gather and an election, and the
election kept a shortName parameter it never reads — the name filtering all
happens in gatherResolverCandidates, before election.

    container/local_image_coneb.go:505:82: electResolvedImage - shortName is
    unused (unparam)

Caught by the golangci-lint gate added in #78, one commit after it landed, on
its own author. That is the gate working exactly as intended: without it this
would have sat on main until it blocked whoever touched this repo next, because
the pre-commit hook lints the WHOLE repo rather than the diff.

I ran `go build ./container/`, `go vet ./container/` and `go test ./container/`
before #82 but not `golangci-lint run ./...` — the one check that would have
seen it.

Claude-Session: https://claude.ai/code/session_016fnPmYiC6ZkqXSi6D8PAP6

Co-authored-by: atrawog <[email protected]>
@aitrawog
aitrawog deleted the fix/resolve-retries-on-a-stale-image-cache branch September 25, 2026 19:10
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