mesh-delivery-builder: a build is superseded only by an entry of a newer revision (H-A-557)

The builder's picture lags a step ask whose revision it reads by number:
main.453 asked fp f1b929cd at revision 453 (source 141) while the picture
still held source 140's ee67bdfc as the last entry heard, and supersededBy
judged the newer ask superseded by the older entry. The builder now keeps
the revision beside each entry it heard and supersedes a fingerprint only
by an entry of a newer module graph revision than its own; an older or
equal one is passed over and said once. An older entry heard never
withdraws a newer build either.

Builds: design 47 H2 H-A-557, H-A-555
This commit is contained in:
2026-11-23 12:26:28 +01:00
parent 72bb027767
commit 9c64253b1f
2 changed files with 67 additions and 2 deletions
@@ -147,6 +147,7 @@ type Builder struct {
fillWaits sync.Map
known map[string]meshcatalog.ModulesByModuleValue // by modules key: the first watched branch's
heard map[string]meshcatalog.ModulesByModuleValue // by branch and module (take): what supersedes what
heardAt map[string]Origin // by branch and module (take): the revision the heard entry came from (H-A-557)
origin map[string]Origin // by build key: the catalog revision its entry came from (take)
edges map[string][]meshcatalog.Edge // by build key: the edges of its entry (take), whose parts a package-published names
deps map[string]map[string][]meshbuilds.Dependency // by build key: what each artifact resolved and was built with (keepDependencies)
@@ -182,6 +183,8 @@ type Builder struct {
publishedPins map[string]map[string]string
// supersededSaid are the build keys refused as superseded (H-A-489), so each is said once.
supersededSaid sync.Map
// passedOverSaid are the build keys and heard fingerprints passed over as not newer (H-A-557), so each is said once.
passedOverSaid sync.Map
}
type planned struct {
@@ -206,6 +209,7 @@ func (b *Builder) init() {
b.sem = make(chan struct{}, limit)
b.trunkFP = map[string]bool{}
b.heard, b.known = map[string]meshcatalog.ModulesByModuleValue{}, map[string]meshcatalog.ModulesByModuleValue{}
b.heardAt = map[string]Origin{}
b.origin, b.edges = map[string]Origin{}, map[string][]meshcatalog.Edge{}
b.inflight, b.again, b.plans, b.tried = map[string]bool{}, map[string]meshcatalog.ModulesByModuleValue{}, map[string]planned{}, map[string]bool{}
b.published, b.held, b.waiting = map[string]bool{}, map[string]bool{}, map[string]map[string]chan string{}
@@ -266,6 +270,7 @@ func (b *Builder) EntryGone(branch string, first bool, module string) {
b.init()
b.mu.Lock()
delete(b.heard, branch+"\x00"+module)
delete(b.heardAt, branch+"\x00"+module)
b.mu.Unlock()
b.pictureMoved()
if first {
@@ -294,12 +299,14 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog.
b.mu.Lock()
hk := o.Branch + "\x00" + key
old, had := b.heard[hk]
b.heard[hk] = m
oldAt := b.heardAt[hk]
b.heard[hk], b.heardAt[hk] = m, o
if o.First {
b.known[key] = m
}
var superseded context.CancelCauseFunc
if had && old.Fp2 != "" && old.Fp2 != m.Fp2 {
// Only an entry of a newer module graph revision withdraws the build of the one heard before it (H-A-557).
if newer, known := newerRevision(o, oldAt); had && old.Fp2 != "" && old.Fp2 != m.Fp2 && (newer || !known) {
if ok, err := builds.BuilderBuildKey(key, old.Fp2); err == nil {
superseded = b.builds[ok]
}
@@ -346,9 +353,33 @@ func (b *Builder) supersededBy(module, key, fp string) string {
if !heard || newest.Fp2 == "" || newest.Fp2 == fp {
return ""
}
// The newest entry heard supersedes fp only when it is of a module graph revision newer than fp's own (H-A-557): the
// picture may lag the revision a step ask named (its kept revision read from the catalog), and an entry it heard of an
// older or the same revision is passed over, said once per key.
at := b.heardAt[o.Branch+"\x00"+module]
if newer, known := newerRevision(at, o); known && !newer {
if _, said := b.passedOverSaid.LoadOrStore(key+"\x00"+newest.Fp2, true); !said {
b.logf("%s at %s (revision %d, source %d): the entry heard at %s (revision %d, source %d) is not of a newer revision: not superseded by it (H-A-557)",
module, fp, o.Revision, o.Source, newest.Fp2, at.Revision, at.Source)
}
return ""
}
return newest.Fp2
}
// newerRevision says whether a is of a newer module graph revision than b (H-A-557): by their catalog revision numbers when
// both name one, else by their source revisions when both name one; known is false when neither pair is named, as for an
// entry taken in with no branch.
func newerRevision(a, b Origin) (newer, known bool) {
switch {
case a.Revision > 0 && b.Revision > 0:
return a.Revision > b.Revision, true
case a.Source > 0 && b.Source > 0:
return a.Source > b.Source, true
}
return false, false
}
// saySuperseded says, once per key, that the build of fp is refused as superseded by newer (H-A-489), and gives the words.
func (b *Builder) saySuperseded(module, key, fp, newer string) string {
why := "is not built: superseded by " + newer + ", the newest entry heard on its first branch"
@@ -185,6 +185,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T)
t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision)
t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails)
t.Run("H-A-205: an ask of a revision below the picture's newest is read by number and built", anOlderKeptRevisionIsReadByNumber)
t.Run("H-A-557: an entry the picture heard of an older revision supersedes no ask of a newer one", anOlderHeardEntrySupersedesNoNewerAsk)
t.Run("H-A-162: a revision held that changes no entry wakes the ask", aRevisionHeldWakesTheAsk)
t.Run("H-A-165: a package with no pin waits for its release and is built with it", aPackageWithNoPinWaitsForItsRelease)
t.Run("H-A-165: past its bound a package with no release fails the step", aPackageWithNoReleaseFailsPastItsBound)
@@ -581,6 +582,39 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) {
}
}
// H-A-557 (main.453): the picture lags the runner: it holds source revision 140, its entry of m (fp2) heard at catalog revision
// 452, while main.453's ask names fp1 at revision 453 of source 141, read by number. The older entry heard is passed over:
// the step builds and passes, never superseded by fp2.
func anOlderHeardEntrySupersedesNoNewerAsk(t *testing.T) {
var held atomic.Int64
held.Store(140)
r, res, entry := revisionRig(t, &held, make(chan struct{}, 1))
r.b.RevisionWait = time.Hour
var mu sync.Mutex
var journal []string
r.b.Logf = func(f string, a ...any) { mu.Lock(); journal = append(journal, fmt.Sprintf(f, a...)); mu.Unlock() }
r.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" }
r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) {
return 141, map[string]string{"m": fp1}, nil
}
older := entry
older.Fp = fp2
r.b.Entry(context.Background(), Origin{Branch: "main", Source: 140, Revision: 452, First: true}, older)
r.b.Wait()
run := meshbuilds.StepRun{Pipeline: "main.453.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 453, Source: 141,
Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}
end := r.b.BuildStep(t.Context(), "a1", run)
r.b.Wait()
if end.Outcome != meshbuilds.StepEndedOutcomePassed {
t.Errorf("end = %+v, reserved %+v; want passed: the entry heard at revision 452 supersedes no ask of revision 453", end, res.sources)
}
mu.Lock()
defer mu.Unlock()
if !slices.ContainsFunc(journal, func(l string) bool { return strings.Contains(l, "is not of a newer revision: not superseded by it (H-A-557)") }) {
t.Errorf("the passed-over entry is not said: %v", journal)
}
}
func aStepAskPastItsRevisionBoundFails(t *testing.T) {
var held atomic.Int64
held.Store(40)