Skip to content

imagecache: add CachedImage for digest refs already on disk - #4025

Open
yuekui2 wants to merge 2 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/2-cached-image
Open

yuekui2 wants to merge 2 commits into
agent-substrate:mainfrom
yuekui2:ipp-upstream/2-cached-image

Conversation

@yuekui2

@yuekui2 yuekui2 commented Nov 20, 2026 •

Copy link
Copy Markdown

Part of #4023.

CachedImage returns a digest ref's image when the cache holds all of it, without a registry call, and nil otherwise. atelet uses it in #4028 to serve cached images before asking the plugin.

CachedImage counts its hits and failures in ate.imagecache.requests, but not its misses. The caller then either pulls through EnsureImage, which counts the miss, or gets the image without a pull. CachedImage and EnsureImage share the digest parse, the hit check and the hit log.

Testing: new table rows in TestCachedImage, including a corrupt record, which check what each lookup counts. go test -race ./internal/imagecache/....

I used an AI agent to port this commit from our fork, address review comments, and draft this description. I reviewed the code and commit message.

CachedImage returns a digest-pinned image that is complete in the store
without contacting the registry, and nil otherwise. A caller can then
serve such images locally and send the rest elsewhere.
Comment thread internal/imagecache/imagecache.go Outdated
Comment on lines +452 to +458
img, err := s.cachedImageHit(digest)
if err != nil {
return nil, err
}
if img != nil {
s.recordRequest(ctx, ateattr.ImageCacheOutcomeHit, nil)
slog.InfoContext(ctx, "Image cache hit", slog.String("ref", ref), slog.String("digest", digest.String()))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the error path this returns without recordRequest, and in #4028 the caller returns that error directly, so EnsureImage never counts it either. Should this record the error outcome? A miss that the plugin then serves is also never counted, is that intended for the hit ratio?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the error path was a bug. CachedImage now records it, so atelet's early return is counted. The uncounted miss is intended: if the plugin declines, EnsureImage counts the miss, so counting it here would count it twice. A plugin-served image causes no pull, so it isn't a cache miss. It shows in ate.imageprovider.requests. I documented this in the CachedImage comment and both registry notes.

// complete on disk, with no network I/O. It returns (nil, nil) on a miss and
// for refs that are not digest-pinned or do not parse, so the caller can fall
// back to EnsureImage, which reports the parse error.
func (s *Store) CachedImage(ctx context.Context, ref string) (*Image, error) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repeats EnsureImage's digest-parse and hit path. Have you considered a shared helper so the logging and metric handling can't drift between the two?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. pinnedDigest and lookup are shared, so the digest parse, the hit check and the hit log are in one place. Each caller still calls recordRequest, because EnsureImage counts misses and CachedImage doesn't.

CachedImage now records a failed lookup. A miss is still not counted,
because the caller counts it or gets the image without a pull.
pinnedDigest and lookup are shared with EnsureImage.

This branch has not been deployed

No deployments
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.

2 participants