Skip to content

feat: cache SHA384 entries#298

Open
upils wants to merge 7 commits into
canonical:mainfrom
upils:cache-bins
Open

feat: cache SHA384 entries#298
upils wants to merge 7 commits into
canonical:mainfrom
upils:cache-bins

Conversation

@upils

@upils upils commented May 22, 2026

Copy link
Copy Markdown
Collaborator
  • Have you signed the CLA?

The Binstore only publishes SHA3-384 hashes for bins. This PR enables storing entries in the cache using
SHA3-384 hashes, so it can store bins. Consumers of the cache package must now explicitly select the
algorithm to be used to create/write/read an entry.

@upils upils requested a review from Copilot June 1, 2026 12:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR extends the internal cache to support multiple hashing algorithms (SHA-256 and SHA3-384) and updates callers/tests to specify which algorithm to use.

Changes:

  • Introduced hashAlgo with SHA-256 and SHA3-384 support, plus hash construction via newHash.
  • Updated cache APIs (Create, Write, Open, Read) to take an algorithm parameter and adjusted archive fetch code accordingly.
  • Added a test verifying SHA3-384 entries are isolated from SHA-256 entries.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
internal/cache/cache.go Adds multi-algorithm hashing support, updates cache APIs, and expires entries across algorithm directories.
internal/cache/cache_test.go Updates tests to pass the algorithm and adds SHA3-384 isolation coverage.
internal/archive/archive.go Updates cache usage in archive fetch path to specify SHA-256 algorithm.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/cache/cache.go
Comment thread internal/cache/cache.go
Comment thread internal/cache/cache.go
Comment thread internal/cache/cache.go
Comment thread internal/cache/cache.go
Signed-off-by: Paul Mars <[email protected]>
@upils upils changed the title feat: cache SHA3-384 entries feat: cache SHA384 entries Jun 15, 2026

@niemeyer niemeyer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Underlying logic is good, thanks. Needs polishing in terms of terminology.

Comment thread internal/cache/cache.go

const (
SHA256 hashAlgo = "sha256"
SHA384 hashAlgo = "sha384"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Public values/functions/etc with private types is an anti pattern.

Also, this already had a name, right above: digestKind. Note how the entire public API below talks about a "digest", not a "hash". The hash is the internal Go types and values used to construct them locally. The overall PR needs to be fixed to make the terminology clear and less conflicting.

Note that if you want to change everything to be "hash", I'm fine with that too. We just cannot sit in the middle and use both terms with no clear lines. If you do that, please don't use "algo" as there are better terms that are naturally short.

Comment thread internal/cache/cache.go
err := os.MkdirAll(filepath.Join(c.Dir, digestKind), 0755)
h, err := newHash(algo)
if err != nil {
return &Writer{err: fmt.Errorf("internal error: %v", err)}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function got a call with a piece of data that is coming from a place it has no idea, and then it also got an error that it has no idea about, because it has not inspected it, from a different function. How does it know it's an internal error?

Comment thread internal/cache/cache.go
var file *os.File
if digest == "" {
file, err = os.CreateTemp(c.filePath(""), "tmp.*")
file, err = os.CreateTemp(filepath.Join(c.Dir, string(algo)), "tmp.*")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the pattern from the existing code not working?

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.

3 participants