Ask a held first build again when a delivery of build-agent ends (issue 1173)

ADR 0482 section 5: the build waiting for a build-agent that reads its manifest is asked once the plan delivering it ends.
This commit is contained in:
2026-10-22 16:19:45 +02:00
parent 980d396d40
commit 4538d05732
4 changed files with 172 additions and 0 deletions
+55
View File
@@ -310,3 +310,58 @@ func probeFirstBuilds(ctx context.Context, d *doctor) ([]conditions.Observation,
}
return firstBuildObservations(waiting, time.Now().UTC()), nil
}
// askHeldFirstBuildsAgain asks again the first build of each first merge held for a build-agent that reads its manifest,
// when the plan that ended delivered build-agent (novox/hq issue 1173): once for each end, since the ask answers the merge
// and a refusal that comes again holds it anew. Answers how many merges it asked for.
func askHeldFirstBuildsAgain(ctx context.Context, open *stores, p inventory.Plan) int {
if !deliversBuildAgent(p) {
return 0
}
actingOnMerges.Lock()
defer actingOnMerges.Unlock()
inv := open.inventory
waiting, err := inv.WaitingMerges(ctx)
if err != nil {
fmt.Printf("%s delivered build-agent, and the first merges held for it could not be read: %v\n", p.ID, err)
return 0
}
asked := 0
for _, w := range waiting {
k := announcedOf(w)
if k.Held == nil {
continue
}
entries, err := inv.Catalogued(ctx)
if err != nil {
fmt.Printf("%s delivered build-agent, and the catalogue could not be read: %v\n", p.ID, err)
return asked
}
read, err := readForPlanning(ctx, inv)
if err != nil {
fmt.Printf("%s delivered build-agent, and what the builds read could not be read: %v\n", p.ID, err)
return asked
}
added, why, err := firstBuildsOf(ctx, inv, k.SourceMoved, entries, read)
if err != nil || len(added) == 0 {
fmt.Printf("%s delivered build-agent, and the merge %.8s of %s held for it asks no build now (%v): it stays "+
"waiting\n", p.ID, w.Commit, w.Repository, err)
continue
}
fmt.Printf("%s delivered build-agent: the first build of %s, held for the word %q, is asked again\n", p.ID,
k.Held.Module, k.Held.Word)
if err := askFirstBuilds(ctx, inv, k.SourceMoved, time.Now().UTC(), added, why); err != nil {
fmt.Printf(" and could not be asked: %v\n", err)
continue
}
asked++
}
return asked
}
// deliversBuildAgent says a delivery plan ended delivered with build-agent built in it: the reader a held first build
// waits for is the one now running.
func deliversBuildAgent(p inventory.Plan) bool {
m := p.Modules["build-agent"]
return p.WalkSaid == inventory.WalkEnded && p.Outcome() == inventory.WalkDelivered && m != nil && m.State == "built"
}