Skip to content

Commit 1eae92f

Browse files
leodidoona-agent
andcommitted
fix: correct build summary counts for packages built after verification failure
Packages that failed SLSA verification and were rebuilt locally were incorrectly counted as 'downloaded' instead of 'built_locally' in the build summary. Root cause: In rare edge cases, packages built locally after verification failure are not tracked in newlyBuiltMap, causing them to fall through to the wrong category in the else-if chain. Fix: Add defensive check before the PackageDownloaded check to catch packages that were supposed to be downloaded but weren't, yet are now in cache. These must have been built locally. Additionally, add comprehensive debug logging to help diagnose the root cause and any future edge cases: - Log all packages in newlyBuiltMap with their versions - Log categorization decision for each package (inNewlyBuilt, inPkgsToDownload, status) - Log when defensive fix is applied This defensive fix handles the edge case gracefully while the logging will help identify the underlying cause in production. Evidence: https://github.com/gitpod-io/gitpod-next/actions/runs/19638569673/job/56247504536 Co-authored-by: Ona <no-reply@ona.com>
1 parent 73bc825 commit 1eae92f

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

pkg/leeway/build.go

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,10 @@ func printBuildSummary(ctx *buildContext, targetPkg *Package, allpkg []*Package,
780780
newlyBuiltMap := make(map[string]bool)
781781
for _, p := range newlyBuilt {
782782
newlyBuiltMap[p.FullName()] = true
783+
log.WithFields(log.Fields{
784+
"package": p.FullName(),
785+
"version": p.versionCache,
786+
}).Debug("Package in newlyBuiltMap")
783787
}
784788

785789
// Track packages that were supposed to be downloaded but weren't
@@ -802,19 +806,40 @@ func printBuildSummary(ctx *buildContext, targetPkg *Package, allpkg []*Package,
802806
total++
803807

804808
// Determine what happened to this package
805-
if newlyBuiltMap[p.FullName()] {
809+
inNewlyBuilt := newlyBuiltMap[p.FullName()]
810+
inPkgsToDownload := pkgsToDownloadMap[p.FullName()]
811+
status := statusAfterDownload[p]
812+
813+
log.WithFields(log.Fields{
814+
"package": p.FullName(),
815+
"inNewlyBuilt": inNewlyBuilt,
816+
"inPkgsToDownload": inPkgsToDownload,
817+
"status": status,
818+
}).Debug("Categorizing package for build summary")
819+
820+
if inNewlyBuilt {
806821
// Package was built during this build
807822
builtLocally++
808823

809824
// Check if this was supposed to be downloaded but wasn't
810825
// This indicates verification or download failure
811-
if pkgsToDownloadMap[p.FullName()] && statusAfterDownload[p] != PackageDownloaded {
826+
if inPkgsToDownload && status != PackageDownloaded {
812827
failedDownloads = append(failedDownloads, p)
813828
}
814-
} else if statusAfterDownload[p] == PackageDownloaded {
829+
} else if inPkgsToDownload && status != PackageDownloaded {
830+
// Package was supposed to be downloaded but wasn't, yet it's now in cache
831+
// This means it was built locally after download/verification failure
832+
// but wasn't tracked in newlyBuiltMap (edge case - defensive fix applied)
833+
log.WithFields(log.Fields{
834+
"package": p.FullName(),
835+
"status": status,
836+
}).Debug("Package built locally after download/verification failure (defensive fix applied)")
837+
builtLocally++
838+
failedDownloads = append(failedDownloads, p)
839+
} else if status == PackageDownloaded {
815840
// Package was downloaded
816841
downloaded++
817-
} else if statusAfterDownload[p] == PackageBuilt {
842+
} else if status == PackageBuilt {
818843
// Package was already cached
819844
alreadyCached++
820845
} else {

0 commit comments

Comments
 (0)