Skip to content

Conversation

@AlekSi
Copy link
Owner

@AlekSi AlekSi commented Nov 18, 2025

Refs #11.

Copilot AI review requested due to automatic review settings November 18, 2025 17:21
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements GOCACHEPROG protocol support for hardcache, enabling it to serve as an external build cache program for the Go toolchain. This allows the Go compiler to delegate cache operations to hardcache instead of using the default filesystem-based cache.

Key changes:

  • Added a new internal/prog package that implements the GOCACHEPROG protocol
  • Added a hidden local use command to main.go that starts the cache program in GOCACHEPROG mode
  • Updated the Makefile to test the new functionality by building Go with hardcache as the cache program

Reviewed Changes

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

Show a summary per file
File Description
main.go Adds the local use command that initializes and runs the GOCACHEPROG server with stdin/stdout
internal/prog/prog.go Implements the GOCACHEPROG protocol, handling get, put, and close commands with JSON message encoding/decoding
internal/prog/prog_test.go Adds basic test infrastructure for the prog package, though with limited coverage and bugs
internal/prog/prog_client_test.go Provides a test client for simulating GOCACHEPROG protocol interactions
Makefile Adds a test build using the new GOCACHEPROG functionality

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

pr, cw := io.Pipe()
cr, pw := io.Pipe()

p = New(cache, l, pr, pw)
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

Undefined variable l used. This should likely be logger(t) to match the logger helper function defined in this file.

Suggested change
p = New(cache, l, pr, pw)
p = New(cache, logger(t), pr, pw)

Copilot uses AI. Check for mistakes.
Comment on lines +57 to +58
<-done
cancel()
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The cleanup order is incorrect. The context is being cancelled after waiting for the goroutine to complete, but the goroutine likely needs the context cancellation to exit cleanly. The cancel() call should come before <-done to properly signal the goroutine to stop.

Suggested change
<-done
cancel()
cancel()
<-done

Copilot uses AI. Check for mistakes.
}

if l := len(b); int(req.BodySize) != l {
return nil, fmt.Errorf("put: expected body size %d, got %d", req.BodySize, l)
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

Inconsistent error message format. This error message is missing the "hardcache:" prefix that is used in other error messages throughout this file. Should be: "hardcache: put: expected body size %d, got %d"

Suggested change
return nil, fmt.Errorf("put: expected body size %d, got %d", req.BodySize, l)
return nil, fmt.Errorf("hardcache: put: expected body size %d, got %d", req.BodySize, l)

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +57
// Run runs the Prog until ctx is canceled, close message is received and handled,
// or an error occurs.
Copy link

Copilot AI Nov 18, 2025

Choose a reason for hiding this comment

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

The documentation states "Run runs the Prog until ctx is canceled" but the context is never checked for cancellation in the main loop. The function only exits on EOF, close command, or errors. Consider either updating the documentation to reflect the actual behavior, or adding context cancellation handling in the main loop (e.g., using a select statement or checking ctx.Err()).

Copilot uses AI. Check for mistakes.
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