mesh-delivery-pipeline: judge a superseded build by the revision its end names (H-A-561, H-A-562)

A build ended superseded is judged by the module graph revision its end
names of the entry that superseded it, never by the order entries were
heard in: none (a builder before H-A-561) moves the mover out as before;
one not newer than the pipeline's own is asked again at once; one newer
the runner's view does not hold yet keeps the step waiting on the
revision view, its revision in the pipeline's value, and each move of
the view judges such steps again, moving the mover out once it holds
the revision; one newer and held moves the mover out at once. No re-ask
can loop: the builder names the revision it judged by.

Builds: design 47 H2 H-A-555, H-A-561, H-A-562
This commit is contained in:
2026-11-23 12:44:19 +01:00
parent f9e2bbe193
commit fb3f186aed
5 changed files with 212 additions and 59 deletions
@@ -224,6 +224,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if n, err := starter.Waiting(store, branch, rv.Catalog.View); err != nil || n > 0 {
logger.Printf("the pipelines of %s that waited on its half for their steps: %d placed (%v)", branch, n, err)
}
if moved := hearer.RevisionHeld(branch); len(moved) > 0 { // a step waiting on the revision view the half now holds (H-A-562)
logger.Printf("the pipelines of %s whose builds waited on the revision view: %s judged again", branch, strings.Join(moved, ", "))
}
n, err := starter.Resume(store, branch, half)
if err != nil {
logger.Printf("the steps placed on %s and not yet asked: %d asked, then %v", branch, n, err)
@@ -238,6 +241,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
if n, err := starter.Waiting(store, branch, rv.Catalog.View); err != nil || n > 0 {
logger.Printf("the pipelines of %s that waited for a newer revision of its half: %d placed (%v)", branch, n, err)
}
if moved := hearer.RevisionHeld(branch); len(moved) > 0 { // a step waiting on the revision view the half now holds (H-A-562)
logger.Printf("the pipelines of %s whose builds waited on the revision view: %s judged again", branch, strings.Join(moved, ", "))
}
}
advancer.Store(&advance)
// A registration-changed places the steps of its module's pipelines started before it, from it (A-327), and binds the
@@ -124,7 +124,11 @@ func hearStepEnded(hub handlers, h *pipeline.Hearer, logf func(string, ...any))
if bs.Pins != nil {
pins = bs.Pins(m.Data())
}
_, err = h.OnStepEndedPinned(bs, m.Subject(), ev, shared, pins)
var superseding int64
if bs.Superseding != nil {
superseding = bs.Superseding(m.Data())
}
_, err = h.OnStepEndedRevised(bs, m.Subject(), ev, shared, pins, superseding)
switch {
case errors.Is(err, pipeline.ErrRefused):
logf("%v", err)
@@ -182,50 +182,81 @@ func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) {
t.Errorf("pipeline %s superseded %v steps %+v released %v; want running, a left, b taken out to be placed again", got.Outcome, got.Superseded, got.Steps, released)
}
})
// H-A-555, H-A-557 (main.453): a build ended superseded moves its mover out only when the runner's view holds a revision
// newer than the pipeline's own naming another fingerprint of it; an entry of an older or the same revision (the builder's
// picture lagging), or a newer one naming the mover's own fingerprint, is passed over and said, and the build is asked
// again at once under a new ask; nothing leaves and the pipeline runs on.
// H-A-555, H-A-561, H-A-562 (main.453): a build ended superseded is judged by the revision its end names of the entry that
// superseded it: none (a builder before H-A-561) moves the mover out as before; one not newer than the pipeline's own is
// passed over, said, and asked again at once; one newer the runner's view does not hold yet holds the step waiting on the
// revision view, kept in the pipeline's value, until the view's move judges it again and the mover moves out; one newer and
// held moves the mover out at once.
// The revision is read from the seat mesh-builds' end, and only from one ended superseded.
if got, passed := buildSuperseding([]byte(`{"outcome":"superseded","revision":120}`)), buildSuperseding([]byte(`{"outcome":"passed","revision":120}`)); got != 120 || passed != 0 {
t.Errorf("the superseding revision read = %d, of a passed end %d; want 120 and 0", got, passed)
}
for _, r := range []struct {
name string
view Half
left bool
name string
superseding int64
view int64
want string // left, again or held
}{
{"an older revision's entry", Half{Revision: 116, Source: 116, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a2"}}}, false},
{"the same revision", Half{Revision: 117, Source: 117, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a2"}}}, false},
{"a newer revision naming the mover's own fingerprint", Half{Revision: 120, Source: 120, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a1"}}}, false},
{"a newer revision naming another fingerprint", Half{Revision: 120, Source: 120, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a2"}}}, true},
{"an end naming no revision (H-A-508 as before)", 0, 116, "left"},
{"an older revision's entry", 116, 117, "again"},
{"the same revision's entry", 117, 117, "again"},
{"a newer revision's entry the view does not hold yet", 120, 118, "held"},
{"a newer revision's entry the view holds", 120, 120, "left"},
} {
t.Run("H-A-555: a build superseded by "+r.name, func(t *testing.T) {
t.Run("H-A-561: a build superseded by "+r.name, func(t *testing.T) {
store := memStore{"main.117": {p: seat.Pipeline{V: 1, Pipeline: "main.117", Branch: "main", Source: 117, Revision: 117, Outcome: seat.PipelineOutcomeRunning,
Movers: slices.Clone(movers[:2]), Steps: []seat.StepResult{step("a", seat.StepResultOutcomeRunning, "x1"), step("b", seat.StepResultOutcomeRunning, "x2")}}, rev: 1}}
var put []Asked
var journal []string
view := r.view
h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 },
View: func(string) (Half, bool) { return r.view, true },
View: func(string) (Half, bool) {
return Half{Revision: view, Source: view, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a2"}}}, true
},
AskDeclined: func(_ seat.Pipeline, s seat.StepResult, _ time.Time) (*Asked, error) {
return &Asked{Seat: s.Seat, ID: s.Ask + "again"}, nil
},
PutAgain: func(_ string, a Asked) error { put = append(put, a); return nil },
Logf: func(f string, a ...any) { journal = append(journal, fmt.Sprintf(f, a...)) }}
bs := stepSeatOf(t, builds.Seat)
if _, err := h.OnStepEnded(bs, bs.Prefix+"n1", StepEnded{ID: "x1", Node: "n1", Pipeline: "main.117", Module: "a", Commit: "c1", Fingerprint: "src2:a1",
Step: "build", Outcome: builds.StepEndedOutcomeSuperseded, Said: "a at src2:a1 is superseded by src2:a2, the newest entry heard on its first branch"}); err != nil {
if _, err := h.OnStepEndedRevised(bs, bs.Prefix+"n1", StepEnded{ID: "x1", Node: "n1", Pipeline: "main.117", Module: "a", Commit: "c1", Fingerprint: "src2:a1",
Step: "build", Outcome: builds.StepEndedOutcomeSuperseded, Said: "a at src2:a1 is superseded by src2:a2, the newest entry heard on its first branch"}, nil, nil, r.superseding); err != nil {
t.Fatal(err)
}
p, _, _ := store.Get("main.117")
if r.left {
if !slices.Equal(p.Superseded, []string{"a"}) || p.Steps[0].Outcome != seat.StepResultOutcomeSuperseded || len(put) != 0 {
left := func(p seat.Pipeline) bool {
return slices.Equal(p.Superseded, []string{"a"}) && p.Steps[0].Outcome == seat.StepResultOutcomeSuperseded && len(put) == 0
}
switch r.want {
case "left":
if !left(p) {
t.Errorf("superseded %v, a's build %+v, put %+v; want a left, its build superseded, nothing asked again", p.Superseded, p.Steps[0], put)
}
return
}
if len(p.Superseded) != 0 || p.Steps[0].Outcome != seat.StepResultOutcomeRunning || p.Steps[0].Ask != "x1again" || p.Steps[0].Ended != nil ||
len(put) != 1 || put[0].ID != "x1again" || p.Outcome != seat.PipelineOutcomeRunning {
t.Errorf("superseded %v, a's build %+v, put %+v, pipeline %s; want nothing left, the build asked again as x1again, the pipeline running", p.Superseded, p.Steps[0], put, p.Outcome)
}
if !slices.ContainsFunc(journal, func(l string) bool { return strings.Contains(l, "passed over") }) {
t.Errorf("the passed-over end is not said: %q", journal)
case "again":
if len(p.Superseded) != 0 || p.Steps[0].Outcome != seat.StepResultOutcomeRunning || p.Steps[0].Ask != "x1again" || p.Steps[0].Ended != nil ||
len(put) != 1 || put[0].ID != "x1again" || p.Outcome != seat.PipelineOutcomeRunning {
t.Errorf("superseded %v, a's build %+v, put %+v, pipeline %s; want nothing left, the build asked again as x1again", p.Superseded, p.Steps[0], put, p.Outcome)
}
if !slices.ContainsFunc(journal, func(l string) bool { return strings.Contains(l, "passed over") }) {
t.Errorf("the passed-over end is not said: %q", journal)
}
case "held":
if s := p.Steps[0]; len(p.Superseded) != 0 || s.Outcome != seat.StepResultOutcomeWaiting || s.On != seat.WaitOnRevisionView || s.Revision != 120 ||
len(put) != 0 || p.Outcome != seat.PipelineOutcomeRunning {
t.Fatalf("superseded %v, a's build %+v, put %+v; want the build waiting on the revision view for revision 120, nothing asked", p.Superseded, s, put)
}
// The view's move to 119 holds it still; at 120 it is judged again and the mover moves out (H-A-562).
view = 119
if moved := h.RevisionHeld("main"); len(moved) != 0 {
t.Errorf("at revision 119 the view moved %v, want none", moved)
}
view = 120
if moved := h.RevisionHeld("main"); !slices.Equal(moved, []string{"main.117"}) {
t.Errorf("at revision 120 the view moved %v, want main.117", moved)
}
if p, _, _ := store.Get("main.117"); !left(p) || p.Steps[0].On != "" || p.Outcome != seat.PipelineOutcomeRunning {
t.Errorf("after the view held 120: superseded %v, a's build %+v, pipeline %s; want a left, b still running", p.Superseded, p.Steps[0], p.Outcome)
}
}
})
}
@@ -34,6 +34,9 @@ type StepSeat struct {
Shared func([]byte) []seat.Shared
// Pins reads the pins a build's end names it was built with (H-A-207); nil for a seat whose ends name none.
Pins func([]byte) map[string]string
// Superseding reads the module graph revision a build's end ended superseded names of the entry that superseded it
// (H-A-561); nil for a seat whose ends name none.
Superseding func([]byte) int64
}
// StepSeats are the three build seats, from their contracts.
@@ -42,7 +45,8 @@ var StepSeats = []StepSeat{
{Seat: nodebuildnode.Seat, Prefix: strings.TrimSuffix(nodebuildnode.SubjectStepEndedAll, "*")},
{Seat: nodebuildimage.Seat, Prefix: strings.TrimSuffix(nodebuildimage.SubjectStepEndedAll, "*")},
// The seat mesh-builds answers the build step of a candidate, one entry named by its fingerprint (A-97, A-99).
{Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Decode: decodeBuildEnded, Pins: buildPins},
{Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Decode: decodeBuildEnded, Pins: buildPins,
Superseding: buildSuperseding},
// The seat mesh-wants answers the composition step (§22, §24).
{Seat: wants.Seat, Prefix: strings.TrimSuffix(wants.SubjectStepEndedAll, "*"), Decode: decodeWantsEnded, Shared: wantsShared},
}
@@ -89,6 +93,16 @@ func buildPins(raw []byte) map[string]string {
return b.Packages
}
// buildSuperseding is the module graph revision a build step's end of the seat mesh-builds names of the entry that superseded
// it (H-A-561); 0 when it names none.
func buildSuperseding(raw []byte) int64 {
var b builds.StepEnded
if json.Unmarshal(raw, &b) != nil || b.Outcome != builds.StepEndedOutcomeSuperseded {
return 0
}
return b.Revision
}
// decodeBuildEnded reads the build step's end of the seat mesh-builds as the form the hearer holds each end to: its one
// entry names the module, the commit and the fingerprint the step was asked at; an end naming another number of entries is
// refused (A-99).
@@ -195,8 +209,8 @@ type Hearer struct {
AskDeclined func(p seat.Pipeline, s seat.StepResult, now time.Time) (*Asked, error)
PutAgain func(key string, a Asked) error
// View is the runner's view of a branch's catalog half (its newest module graph revision and entries), and whether it is
// read: a build ended superseded moves its mover out only when that revision is newer than the pipeline's own and names
// another fingerprint of it (H-A-555); otherwise the build is asked again (H-A-557). Nil reads none, so none moves out.
// read: a build ended superseded by an entry of a newer revision moves its mover out only once the view holds that revision
// (H-A-561); nil holds none, so such a step waits on the revision view.
View func(branch string) (Half, bool)
// Aside runs do beside the caller's path: the drops of an ended pipeline's open asks, each asked side by side, so an end is
@@ -252,6 +266,12 @@ func (h *Hearer) OnStepEndedShared(bs StepSeat, subject string, ev StepEnded, sh
// OnStepEndedPinned is OnStepEndedShared of a build's end naming the pins it was built with (H-A-207): a passed build's
// mover's steps that waited for its entry's pins are asked with them.
func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, shared []seat.Shared, pins map[string]string) (seat.Pipeline, error) {
return h.OnStepEndedRevised(bs, subject, ev, shared, pins, 0)
}
// OnStepEndedRevised is OnStepEndedPinned of a build's end ended superseded naming superseding, the module graph revision of
// the entry that superseded it (H-A-561); 0 names none.
func (h *Hearer) OnStepEndedRevised(bs StepSeat, subject string, ev StepEnded, shared []seat.Shared, pins map[string]string, superseding int64) (seat.Pipeline, error) {
node := strings.TrimPrefix(subject, bs.Prefix)
if node == subject || node == "" || strings.Contains(node, ".") {
return seat.Pipeline{}, fmt.Errorf("%w: %s is not a subject of %s's step-ended", ErrRefused, subject, bs.Seat)
@@ -325,10 +345,15 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
}
ev.Outcome, ev.Said = nodebuildgo.StepEndedOutcomeCouldNotRun, why
}
if supersededBuild(*s, ev.Outcome) {
// A build superseded only by an entry of a revision no newer than the pipeline's own is passed over and asked
// again at once (H-A-555, H-A-557): the builder's picture lagged, its revision wait holds the new ask.
if passed := h.notNewer(p, s.Module); passed != "" {
// A build ended superseded is judged by the module graph revision of the entry that superseded it, never by the order
// the builder heard entries in (H-A-555, H-A-561): one naming no revision (a builder before H-A-561) moves its mover out
// as before (H-A-508); one not newer than the pipeline's own is asked again at once; one newer that the runner's view
// does not hold yet holds the step waiting on the revision view (H-A-562); one newer and held moves the mover out.
if supersededBuild(*s, ev.Outcome) && superseding > 0 {
own := keyRevision(Begin{Revision: p.Revision, Source: p.Source})
switch {
case superseding <= own:
passed := fmt.Sprintf("the superseding entry's revision %d is not newer than the pipeline's %d", superseding, own)
old := s.Ask
a, why := h.supersededAgain(&p, i, ev, passed, now)
if a != nil {
@@ -338,15 +363,27 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh
return p, fmt.Errorf("pipeline %s cannot be written: %w", ev.Pipeline, err)
}
unmarkAsk(h.Clock, old, h.logf)
h.logf("%s: %s's build ended superseded (%s), passed over: %s; asked again as %s (H-A-555, H-A-557)", ev.Pipeline,
h.logf("%s: %s's build ended superseded (%s), passed over: %s; asked again as %s (H-A-555, H-A-561)", ev.Pipeline,
s.Module, ev.Said, passed, a.ID)
if err := h.PutAgain(ev.Pipeline, *a); err != nil {
h.logf("%s: the build of %s asked again as %s is written and not put, put again at the next start: %v", ev.Pipeline, s.Module, a.ID, err)
}
return p, nil
}
h.logf("%s: %s's build ended superseded (%s), passed over: %s; %s (H-A-555, H-A-557)", ev.Pipeline, s.Module, ev.Said, passed, why)
h.logf("%s: %s's build ended superseded (%s), passed over: %s; %s (H-A-555, H-A-561)", ev.Pipeline, s.Module, ev.Said, passed, why)
ev.Outcome, ev.Said = nodebuildgo.StepEndedOutcomeCouldNotRun, why
case !h.viewHolds(p.Branch, superseding):
old := s.Ask
s.Outcome, s.On, s.Revision, s.Node, s.Why = seat.StepResultOutcomeWaiting, seat.WaitOnRevisionView, superseding, node, ev.Said
if _, err := h.Store.Update(ev.Pipeline, p, rev); errors.Is(err, ErrChanged) {
continue
} else if err != nil {
return p, fmt.Errorf("pipeline %s cannot be written: %w", ev.Pipeline, err)
}
unmarkAsk(h.Clock, old, h.logf)
h.logf("%s: %s's build ended superseded (%s) by an entry of revision %d, which the runner's view of %s does not hold yet: the step waits on the revision view (H-A-561, H-A-562)",
ev.Pipeline, s.Module, ev.Said, superseding, p.Branch)
return p, nil
}
}
s.Outcome, s.Node, s.Why, s.Rerun, s.By, s.Ended = ev.Outcome, node, ev.Said, ev.Rerun, ev.By, &now
@@ -825,32 +862,13 @@ func phasesOf(p seat.Pipeline) *seat.PipelineEndedPhases {
return ph
}
// notNewer is why a build of module in p ended superseded is passed over (H-A-555): "" when the runner's view of p's branch
// holds a module graph revision newer than p's own (by its source where p names no revision) whose entry names another
// fingerprint of module than p moves; else the words of what the view holds.
func (h *Hearer) notNewer(p seat.Pipeline, module string) string {
m, _ := MoverOf(p, module)
// viewHolds says whether the runner's view of branch holds the module graph revision revision or a newer one (H-A-561).
func (h *Hearer) viewHolds(branch string, revision int64) bool {
if h.View == nil {
return "the runner reads no view of " + p.Branch + "'s catalog half"
return false
}
half, ok := h.View(p.Branch)
if !ok {
return "the runner's view of " + p.Branch + "'s catalog half is not read yet"
}
newer := half.Revision > p.Revision
if p.Revision <= 0 {
newer = half.Source > p.Source
}
e, named := half.Entries[module]
switch {
case !newer:
return fmt.Sprintf("the newest revision of %s is %d (source %d), not newer than the pipeline's %d (source %d)", p.Branch,
half.Revision, half.Source, p.Revision, p.Source)
case !named || e.Fp == "" || e.Fp == m.Fingerprint:
return fmt.Sprintf("the newer revision %d of %s names %s at %q, the pipeline's own fingerprint %s or none", half.Revision, p.Branch,
module, e.Fp, m.Fingerprint)
}
return ""
half, ok := h.View(branch)
return ok && half.Revision >= revision
}
// supersededAgain is the ask that puts the build step i of p, ended superseded by an entry no newer than p's (passed),
@@ -343,3 +343,97 @@ func supersededWhy(p seat.Pipeline, module string, entries map[string]catalog.Ca
}
}
}
// RevisionHeld judges again, once the runner's view of branch moved, every step of its running pipelines waiting on the
// revision view (H-A-562): a build ended superseded by an entry of a revision the view now holds moves its mover out, as a
// build ended superseded does (H-A-508, H-A-561): its open and waiting steps end superseded, it is kept in the pipeline's
// superseded, and the pipeline is judged by its other movers alone. It answers the pipelines it touched.
func (h *Hearer) RevisionHeld(branch string) []string {
if h.View == nil {
return nil
}
half, ok := h.View(branch)
if !ok {
return nil
}
pkeys, err := branchKeys(h.Store, branch)
if err != nil {
h.logf("the running pipelines of %s are not listed, so no step waiting on the revision view is judged again at revision %d: %v", branch, half.Revision, err)
return nil
}
var touched []string
for _, key := range pkeys {
if h.revisionHeldOne(key, half.Revision) {
touched = append(touched, key)
}
}
return touched
}
// waitsOnRevision says whether st is a build step waiting on the revision view for a revision held holds (H-A-562).
func waitsOnRevision(st seat.StepResult, held int64) bool {
return st.Outcome == seat.StepResultOutcomeWaiting && st.On == seat.WaitOnRevisionView && st.Revision > 0 && st.Revision <= held
}
func (h *Hearer) revisionHeldOne(key string, held int64) bool {
wr := h.widensReads() // made before the compare-and-set, kept for its retries (H-A-289)
for {
p, rev, err := h.Store.Get(key)
if err != nil || p.Outcome != seat.PipelineOutcomeRunning {
return false
}
var moved []string
whys := map[string]string{}
for _, st := range p.Steps {
if waitsOnRevision(st, held) && !slices.Contains(p.Superseded, st.Module) && !slices.Contains(moved, st.Module) {
moved = append(moved, st.Module)
whys[st.Module] = st.Why
}
}
if len(moved) == 0 {
return false
}
now := h.now()
var ended []int
var leave, drop []seat.StepResult
for i := range p.Steps {
st := &p.Steps[i]
if !slices.Contains(moved, st.Module) || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) {
continue
}
why := fmt.Sprintf("superseded: its build was superseded and its mover left for the newer revision's pipeline, revision %d now held (H-A-508, H-A-562): %s", held, whys[st.Module])
st.On, st.Revision = "", 0
l, d := supersedeStep(&p, st, why, now)
leave, drop = append(leave, l...), append(drop, d...)
ended = append(ended, i)
}
p.Superseded = append(p.Superseded, moved...)
again := takeOutNotAsked(&p)
done := h.endPipeline(&p, now, wr)
if _, err := h.Store.Update(key, p, rev); errors.Is(err, ErrChanged) {
continue
} else if err != nil {
h.logf("the running pipeline %s is not written, so its movers waiting on the revision view stay: %v", key, err)
return false
}
h.logf("%s: the runner's view holds revision %d: %s, whose builds an entry of it superseded, leave for the newer revision's pipeline, %d of their steps ended superseded (H-A-562)",
key, held, strings.Join(moved, ", "), len(ended))
if len(again) > 0 {
h.logf("%s: %s, not asked on a dependency that left, placed again (H-A-361)", key, strings.Join(again, ", "))
}
for _, i := range ended {
if err := h.say(seat.EventStepEnded, p, &p.Steps[i]); err != nil {
h.logf("step-ended of %s's %s %s, superseded, is not said: %v", key, p.Steps[i].Module, p.Steps[i].Step, err)
}
}
h.leaveSteps(key, leave, drop, "the mover %s left "+key+" for the newer revision's pipeline", "superseded: its build was superseded (H-A-508)")
if err := h.said(p, nil, done); err != nil {
h.logf("%v", err)
}
h.appendUnlogged(key)
if !done && h.Release != nil {
h.Release(key)
}
return true
}
}