Skip to content

fix(container): bound and report the local image enumeration - #76

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/bound-and-report-image-listing
Aug 30, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/bound-and-report-image-listing

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Addresses opencharly/charly#475 — and corrects that issue's root cause, which I wrote and which the measurements below disprove.

podman images --format json walks the whole local store, so its cost scales with the store rather than with what the caller wants. Unbounded, a degraded store is indistinguishable from a hang: no log line, an empty run directory, and only a podman images child process as evidence. That is what was reported — a check-image step sitting 25+ minutes with nothing naming the cause.

This bounds the call (killing the process group on expiry) and makes the cost legible:

listing local images via podman: timed out after 4m0s — the local image store is large
or contended; prune it (charly clean) or retry when builds are idle

and, when a completed listing was slow:

charly: listed 1170 local images in 9.003s — consider pruning the image store

What this does not do. It does not make a large store fast. The enumeration is inherently O(store), and the 5-minute cache above it is what keeps consecutive runs cheap. What it fixes is a slow store presenting as a silent stall.

The issue's stated root cause is wrong — measured

charly#475 says the store was "10,865 images, of which 10,607 were untagged (97.6%)" and frames the fix as avoiding an unfiltered enumeration. I set out to add --filter dangling=false and measured first. Both halves of that plan collapse:

$ podman images --all --format '{{.Id}}' | wc -l        ->  12585
$ podman images --filter dangling=true --format '{{.Id}}' | wc -l  ->    402     (3.2%, not 97.6%)

$ time podman images --format json                      ->  9003 ms, 17408384 bytes
$ time podman images --filter dangling=false --format json  -> 13569 ms, 15776571 bytes

Filtering dangling images is 50% slower, because the filter costs more than the 402 rows it removes. The 97.6%-untagged figure does not describe this store.

Where the cost actually is — 1,170 image IDs carrying 12,585 tag names across 177 repositories:

   1141  ghcr.io/opencharly/arch
    611  ghcr.io/opencharly/arch-builder
    464  ghcr.io/opencharly/cachyos
    423  ghcr.io/opencharly/fedora-nonfree
    414  ghcr.io/opencharly/fedora

I also checked whether retention was blind to them — a plausible cause, since charlyImageTags skips images without ai.opencharly.box:

image IDs with ai.opencharly.box label: 876
image IDs WITHOUT it:                   294
tag names on labelled images:          5565
tag names on UNLABELLED images:          17   <- so retention is NOT blind to them

So the store is not full of junk retention cannot see; it is full of accumulated CalVer tags retention simply has not pruned. That is an operational matter, not an enumeration bug — which is why this PR fixes the legibility of the slow path and does not pretend to make it fast.

How tested

New regression guard — a fake engine that never answers, the shape of a saturated store:

$ go test ./container/ -run TestDefaultListLocalImages_FailsFastOnHungEngine -v
--- PASS: TestDefaultListLocalImages_FailsFastOnHungEngine (0.20s)
ok  	github.com/opencharly/spec/container	0.203s

It asserts more than "it returned": the error has to contain timed out and prune, so the message keeps telling the operator what to do.

Negative control — bound removed, exec.Command restored:

--- FAIL: TestDefaultListLocalImages_FailsFastOnHungEngine (10.01s)
    local_image_timeout_test.go:48: defaultListLocalImages did not return within 10s
    — the call is still unbounded
FAIL	github.com/opencharly/spec/container	10.013s

Build and full package on the committed tree:

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

Rulebook compliance

  • R1 (RCA) — the reported cause was tested rather than trusted, and disproved: dangling images are 3.2% not 97.6%, filtering them is slower, and retention can see 5,565 of the 5,582 tags. The fix addresses what the measurements actually support.
  • R2 (no deferral) — charly#475 was mine, filed instead of fixed; this closes that gap, and the corrected measurements go back onto the issue rather than staying in a PR body.
  • R3 (no duplication) — one bounded enumeration; the existing 5-minute cache is untouched and remains the mechanism that keeps repeat calls cheap.
  • R4 (no workarounds) — no retry, no sleep, no pruning behind the operator's back: the call is bounded and the condition is reported.
  • R6 (git safety) — feature branch, no force-push, no hook bypass.
  • R7 (prove the gate) — timings, store composition, label coverage, the test and its negative control are all pasted above.

Change classification

  • Change class: runtime/code change (container image enumeration + regression test)
  • Verification gate: deterministic unit test with a passing negative control, plus measured store data on a live host
  • Attribution tier: fully tested and validated — the guard fails without the change, the full package passes with it, and every claim about the store is a pasted measurement rather than an estimate

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

`podman images --format json` walks the whole local store, so its cost scales
with the store rather than with what the caller wants. Unbounded, a degraded
store is indistinguishable from a hang: the caller writes no log line, the run
directory stays empty, and the only evidence is a `podman images` child process.
Reported as a `check-image` step sitting 25+ minutes with no error naming why.

Bound the call and kill the process group on expiry, and say what happened:

  listing local images via podman: timed out after 4m0s — the local image store
  is large or contended; prune it (charly clean) or retry when builds are idle

Also report the cost when a completed listing took more than 2s, since the
number is what tells an operator to prune:

  charly: listed 1170 local images in 9.003s — consider pruning the image store

Measured on a workstation store while writing this: 1,170 image IDs carrying
12,585 tag names, ~9s and ~17MB of JSON per call, on every cache miss.

Note this does NOT make a large store fast — the enumeration is inherently
O(store) and the cache above it is what keeps consecutive runs cheap. What it
fixes is a slow store presenting as a silent stall.

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

Copy link
Copy Markdown

Review — PASS

Head SHA: d99b7607dcfe39f11c53e3b980899fa2e2d23300 (branch: fix/container-image-enumeration)

Security screen: PASS — no scope mismatch (diff matches description exactly), no secrets/exfiltration, no network egress, no weakened guardrails, no supply-chain changes. The syscall.Kill(-pid) targets the spawned podman images process group only.

Checklist: All applicable rules PASS or NA.

  • A1/A3 — Body fully accounts for the diff (timeout bound, process-group kill, cost reporting, regression test). How-tested names the gate, pastes the test pass, the negative control (fails at 10.01s without the bound), and the full package run. Attribution tier fully tested and validated is justified: the unit test executes the changed timeout branch and the negative control proves the test fails without the change. Assisted-by: footer present in exact form.
  • A2/R10 — Library-level helper change; the deterministic unit test with a passing negative control is the appropriate gate (a bed run would not add proof beyond what the negative control establishes). Coverage ships: the new test fails without the change.
  • R1 — RCA is genuine and measured: the reported dangling-image cause was tested and disproved (3.2% not 97.6%; filtering is 50% slower); the real cause (accumulated CalVer tags) is identified. No forbidden framing.
  • R2/R5/B15 — No deferral; charly#475 is closed by this change. One atomic commit.
  • R3/R4 — No duplication; no sleep/retry/pruning workaround — the call is bounded and reported. Timeout is a named, test-configurable package var.
  • B16 placement — CORRECT: the fix stays in the container core package where the enumeration already lives; no capability moved into core, no alias growth, no new sdk-kit import.
  • B18 — gofmt-clean, no lint-visible issues; Setpgid + Kill(-pid) correctly kills the whole process group; ctx.Err() check correctly distinguishes timeout from other failures.
  • B13/B17 — No candy/schema changes (NA); no autonomous destroy (NA).
  • Comment intake — No comments on the thread.

Verdict: PASS


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

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 10:42
@github-actions
github-actions Bot merged commit b6495f7 into main Aug 30, 2026
1 check passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
@aitrawog
aitrawog deleted the fix/bound-and-report-image-listing 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