diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index 5242f95ce..71569ba45 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -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,19 @@ 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 - if o.First { - b.known[key] = m + oldAt := b.heardAt[hk] + // An entry of an older module graph revision than the one heard before it neither replaces it as the branch's newest nor + // withdraws its build (H-A-557): it is still built for the older revision's pipeline. + before, known := newerRevision(oldAt, o) + older := had && known && before + if !older { + 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 { + if had && !older && old.Fp2 != "" && old.Fp2 != m.Fp2 { if ok, err := builds.BuilderBuildKey(key, old.Fp2); err == nil { superseded = b.builds[ok] } @@ -311,6 +323,10 @@ func (b *Builder) take(ctx context.Context, o Origin, key string, m meshcatalog. b.edges[bk] = e } b.mu.Unlock() + if older { + b.logf("%s at %s (revision %d, source %d): older than the entry heard at %s (revision %d, source %d): it stays the newest (H-A-557)", + key, m.Fp2, o.Revision, o.Source, old.Fp2, oldAt.Revision, oldAt.Source) + } b.pictureMoved() if superseded != nil { // A newer fingerprint of the module: the build of the older one in flight is taken out, and its asks are withdrawn @@ -346,9 +362,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" diff --git a/modules/mesh-delivery-builder/internal/build/step.go b/modules/mesh-delivery-builder/internal/build/step.go index 25e57df5f..ad2bf357b 100644 --- a/modules/mesh-delivery-builder/internal/build/step.go +++ b/modules/mesh-delivery-builder/internal/build/step.go @@ -34,6 +34,9 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step } at := b.now() end.Ended, end.Outcome, end.Said = &at, outcome, said + if outcome != meshbuilds.StepEndedOutcomeSuperseded { + end.Revision = 0 + } movers := make([]string, 0, len(run.Entries)) for _, e := range run.Entries { movers = append(movers, e.Module) @@ -56,6 +59,8 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step } // The version is reserved before the build (H-A-155): the ask waits for the builder's picture to hold its revision. if outcome, said := b.awaitRevision(ctx, run); outcome != "" { + // Superseded here, the catalog's revision the ask named names the superseding fingerprint (H-A-561). + end.Revision = run.Revision return finish(outcome, said) } b.askedRevision(run) @@ -80,6 +85,8 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step failed = append(failed, said) case meshbuilds.StepEndedOutcomeSuperseded: superseded = append(superseded, said) + // The end names the module graph revision of the entry that superseded it, the newest of its entries' (H-A-561). + end.Revision = max(end.Revision, b.supersedingRevision(e.Module, e.Fingerprint)) } } if len(failed) > 0 { @@ -91,6 +98,22 @@ func (b *Builder) BuildStep(ctx context.Context, ask string, run meshbuilds.Step return finish(meshbuilds.StepEndedOutcomePassed, "") } +// supersedingRevision is the module graph revision of the entry heard newest on the branch of module's fingerprint fp, the +// one that supersedes it (H-A-561); 0 when the picture names none. +func (b *Builder) supersedingRevision(module, fp string) int64 { + key, err := builds.BuilderBuildKey(module, fp) + if err != nil { + return 0 + } + b.mu.Lock() + defer b.mu.Unlock() + o, ok := b.origin[key] + if !ok { + o = Origin{First: true} + } + return b.heardAt[o.Branch+"\x00"+module].Revision +} + // askedRevision records on the origin of each entry of run the catalog revision the ask names (design 47 H H-A-218), where // the origin is of the ask's branch and source revision: the version reserved for its build names it, and so does its // package-published, so the runner finds the publishing pipeline by branch and revision. diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index ba470fd87..9a62217c5 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -185,6 +185,8 @@ 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-557: an entry heard of an older revision withdraws no running build of a newer one", anOlderHeardEntryWithdrawsNoNewerBuild) 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) @@ -526,7 +528,8 @@ func anOlderKeptRevisionIsReadByNumber(t *testing.T) { } // H-A-508 second addendum: below the picture, a kept revision naming another fingerprint of the module superseded the // ask's: the step ends superseded naming it, never failed with the "below" words. - if end := r2.b.BuildStep(t.Context(), "a1", run); end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || end.Said != stepSuperseded("m", fp1, "src2:other") { + // H-A-561: the end names the catalog's revision that names the superseding fingerprint, the ask's own. + if end := r2.b.BuildStep(t.Context(), "a1", run); end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || end.Said != stepSuperseded("m", fp1, "src2:other") || end.Revision != 47 { t.Errorf("end = %+v; want superseded naming the fingerprint the kept revision names", end) } // H-A-222: an ask of the very source the picture holds, whose entries the picture no longer names (a re-pin kept revision 48 @@ -581,6 +584,80 @@ 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) + } +} + +// H-A-557 (review round 1): the entry of m at revision 453 (fp1) is heard and its build runs; an entry of revision 452 (fp2) +// heard after it is older and withdraws nothing; one of revision 454 withdraws it, naming the newer fingerprint. +func anOlderHeardEntryWithdrawsNoNewerBuild(t *testing.T) { + var held atomic.Int64 + held.Store(141) + r, _, entry := revisionRig(t, &held, make(chan struct{}, 1)) + r.b.FirstBranch = func(branch, module string) bool { return branch == "main" && module == "m" } + r.b.Entry(context.Background(), Origin{Branch: "main", Source: 141, Revision: 453, First: true}, entry) + r.b.Wait() + var withdrawn []error + r.b.mu.Lock() + r.b.builds[r.key] = func(cause error) { withdrawn = append(withdrawn, cause) } // fp1's build runs + r.b.mu.Unlock() + older := entry + older.Fp = fp2 + r.b.Entry(context.Background(), Origin{Branch: "main", Source: 140, Revision: 452, First: true}, older) + r.b.Wait() + if len(withdrawn) != 0 { + t.Fatalf("an entry of revision 452 withdrew the build of revision 453's fingerprint: %v", withdrawn) + } + newer := entry + newer.Fp = "src2:" + hex64('e') + r.b.Entry(context.Background(), Origin{Branch: "main", Source: 142, Revision: 454, First: true}, newer) + r.b.Wait() + if len(withdrawn) != 1 || !strings.Contains(withdrawn[0].Error(), newer.Fp) { + t.Errorf("after revision 454's entry: withdrawn %v; want fp1's build withdrawn once, naming %s", withdrawn, newer.Fp) + } + // H-A-561: a step of fp1 at revision 453 now ends superseded, naming revision 454, the superseding entry's. + r.b.mu.Lock() + delete(r.b.builds, r.key) + r.b.mu.Unlock() + r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { return 141, map[string]string{"m": fp1}, nil } + held.Store(142) + end := r.b.BuildStep(t.Context(), "a1", meshbuilds.StepRun{Pipeline: "main.453.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 453, Source: 141, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}}) + r.b.Wait() + if end.Outcome != meshbuilds.StepEndedOutcomeSuperseded || end.Revision != 454 || !strings.Contains(end.Said, newer.Fp) { + t.Errorf("fp1's step after revision 454's entry: end = %+v; want superseded by %s, naming revision 454", end, newer.Fp) + } +} + func aStepAskPastItsRevisionBoundFails(t *testing.T) { var held atomic.Int64 held.Store(40) diff --git a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go index 7393b6ff0..002593838 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract.go @@ -13,13 +13,13 @@ const Seat = "mesh-builds" // Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780): // a reader of a value of another form says "form N, this reader knows M". -const Form = 2 +const Form = 3 // The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition // whose fields changed while its forms did not (design 47 H2 §780). const ( - generatedForms = "2" - generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=40a0090f7cb5 StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07" + generatedForms = "3" + generatedFieldsDigest = "AskTakenEvent=6d5d3da7ac39 BuildEntry=3c829a0a3d58 Dependency=90a32b07c563 DropAnswer=7538f2f5e68e PackagePublished=34dd069a6aab PackagePublishedEvent=8e12888c1559 PublishQueueAnswer=0f1326e35e17 PublishQueueAnswerCountsItem=b770db2f0920 PublishQueueAnswerQueueItem=b1eebc09f41e PublishedAnswer=69a801982819 ReservedAnswer=2272a4d6f0f4 ReservedAnswerArtifactsItem=d74eb6e00abb Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=be571d4ff16f StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=dc5893aef7e5 ToolchainAgreed=f3d9ce993734 ToolchainAgreedDigestsItem=1d42893a96b9 ToolchainAgreedEvent=e3502d6f194d VersionReservedEvent=984547d6ad07" ) const ( @@ -198,6 +198,8 @@ type StepEnded struct { Packages map[string]string `json:"packages,omitempty"` Pipeline string `json:"pipeline"` Rerun bool `json:"rerun,omitempty"` + // for a step ended superseded, the module graph revision of the entry that superseded it, 0 when the builder knows none; the runner moves the mover out only for a revision newer than its pipeline's that its view holds (design 47 H2 H-A-561) + Revision int64 `json:"revision,omitempty"` // why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint Said string `json:"said,omitempty"` Started *time.Time `json:"started,omitempty"` diff --git a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract_test.go b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract_test.go index 4d81e2183..f1bf4660f 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract_test.go +++ b/modules/mesh-delivery-contracts/go/seats/meshbuilds/contract_test.go @@ -27,6 +27,8 @@ func TestFixtures(t *testing.T) { decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")}, {name: "the build step ended superseded: a newer entry of its branch superseded its fingerprint (H-A-508)", subject: "mesh.seat.mesh-builds.event.step-ended.laptop", given: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":2,\"id\":\"m2kx9a1b3c4d6c\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", wire: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":2,\"id\":\"m2kx9a1b3c4d6c\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")}, + {name: "the build step ended superseded, naming the revision of the entry that superseded it (H-A-561)", subject: "mesh.seat.mesh-builds.event.step-ended.laptop", given: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":3,\"id\":\"m2kx9a1b3c4d6e\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"revision\":14,\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", wire: "{\"entries\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\"}],\"form\":3,\"id\":\"m2kx9a1b3c4d6e\",\"node\":\"laptop\",\"outcome\":\"superseded\",\"pipeline\":\"main.12.nats\",\"revision\":14,\"said\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\",\"step\":\"build\",\"v\":1}", + decode: func(b []byte) (any, error) { var v StepEndedEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.step-ended\\.[^.*> ]+$")}, {name: "an ask taken at the pull", subject: "mesh.seat.mesh-builds.event.ask-taken.main-3589-mesh-sdk-unit", given: "{\"ask\":\"main-3589-mesh-sdk-unit\",\"at\":\"2026-11-21T22:00:00Z\",\"node\":\"anchor\"}", wire: "{\"ask\":\"main-3589-mesh-sdk-unit\",\"at\":\"2026-11-21T22:00:00Z\",\"node\":\"anchor\"}", decode: func(b []byte) (any, error) { var v AskTakenEvent; err := json.Unmarshal(b, &v); return v, err }, subjectIs: regexp.MustCompile("^mesh\\.seat\\.mesh-builds\\.event\\.ask-taken\\.[^.*> ]+$")}, {name: "a version reserved at a fingerprint", subject: "mesh.seat.mesh-builds.event.version-reserved", given: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}", wire: "{\"artifact\":\"mesh-sdk:go\",\"fingerprint\":\"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\",\"form\":1,\"module\":\"mesh-sdk\",\"path\":\"git.novox.be/novox/mesh-sdk/go\",\"revision\":\"412\",\"version\":\"0.1.21\"}", diff --git a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract.go b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract.go index 5543cbcfe..22a9a5c7a 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract.go @@ -14,13 +14,13 @@ const Seat = "mesh-pipeline-runner" // Form is the form of the seat's values, events and answers this contract was generated at (design 47 H2 §780): // a reader of a value of another form says "form N, this reader knows M". -const Form = 11 +const Form = 12 // The forms and the digest of the fields this contract was generated from: the generator's compare fails a definition // whose fields changed while its forms did not (design 47 H2 §780). const ( - generatedForms = "11" - generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=e3f4c58f93c8 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=397a8219a855 PipelineStarted=582f8ff3b28d PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=0dac0e15d017 StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466" + generatedForms = "12" + generatedFieldsDigest = "AcceptAnswer=224df0394653 Accepted=d2b011e5090f AskAgainAnswer=224df0394653 CancelAnswer=a0dcc32b3f57 EndAgainAnswer=a0dcc32b3f57 FailedStep=cd7184342136 Fill=7a76c9ceb157 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 KeptAnswer=dfe0d48bc169 KeptByLevelDigestValue=f06c90f7da7f KeptResult=af5f81f189b7 ListAnswer=284210b3c054 LogEntry=b059967b2ae4 Member=8a103baec01f Mover=5db376275bcf MoverEnded=4b35095f6829 MoverRow=b61f41d131a3 Pipeline=2663792125bf PipelineEnded=e3f4c58f93c8 PipelineEndedEvent=cb44007f7173 PipelineEndedPhases=9d1c33ce4cc4 PipelineEndedPhasesBuild=a08d49692a09 PipelineEndedPhasesComposition=a08d49692a09 PipelineEndedPhasesIntegration=a08d49692a09 PipelineEndedPhasesLint=a08d49692a09 PipelineEndedPhasesUnit=a08d49692a09 PipelineEndedPhasesValidate=a08d49692a09 PipelineRow=397a8219a855 PipelineStarted=582f8ff3b28d PipelineStartedEvent=eaa401af4117 PipelinesByBranchRevisionAgainNValue=693580eed498 PipelinesByBranchRevisionUnfinishedModuleValue=693580eed498 PipelinesByBranchRevisionValue=693580eed498 PipelinesByBranchRunRunValue=693580eed498 PipelinesByBranchSourcePublishedPackageVersionValue=693580eed498 PipelinesByStepsPipelineMoverValue=94de99db7816 PlaceAnswer=a0dcc32b3f57 PlaceUnfinishedAnswer=ed94ced4513a Published=d9af3024dacc QueueByQueueNextValue=765a2918a728 QueueByRunningPipelineValue=ed94ced4513a QueueByWaitingSequenceValue=99605298ae13 RePinnedEvent=92fd04bfa6d3 RerunAnswer=9b7efd0df344 ReviewAnswer=f397b8965179 RoomEvent=5bd4df78ed84 RunAnswer=96bd45aa2e62 RunStarted=b280617410c3 RunStartedEvent=0767a9358fa3 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 ShowAnswer=48b8cecc529a StandsAnswer=0afa3693bf3b StartAnswer=ed94ced4513a StepEndedEvent=799020642c19 StepEvent=64f18c40ed5d StepLogByPipelineValue=ffdde090a101 StepResult=bdaa8bbfbcab StepStartedEvent=799020642c19 TestCounts=9c1332427159 TestRun=ca5a87f3b6b8 TestRunPackage=a7d30558470d TestRunReader=c9b30cc4d0d0 TestRunsAnswer=7ab81a45ca33 TestRunsDropAnswer=8ee70b35469d ToolchainUsed=43b6d42376fb Wait=21e4ee7a3ef1 WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 Waiting=ed94ced4513a WhyCarriedAnswer=8e2fcea6479f Widening=e2790a307466" ) const ( @@ -1070,6 +1070,8 @@ type StepResult struct { Outcome string `json:"outcome"` // the step was asked again by the runner's rerun Rerun bool `json:"rerun,omitempty"` + // for a step waiting on the revision view, the module graph revision it waits for: a build ended superseded by an entry of a revision the runner's view does not hold yet (design 47 H2 H-A-561, H-A-562) + Revision int64 `json:"revision,omitempty"` // the seat that serves the step, whose holder alone may end it (ADR 0666 section 21) Seat string `json:"seat,omitempty"` // the run the step read or asked for every step that reads it: a composition step's per machine, as mesh-wants' step-ended names them; a test step's one, with asked-by when another step asked it (design 47 G §726, §729; A-468d, A-468e, A-469t) diff --git a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go index d1394d8e1..7a21c876b 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go +++ b/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner/contract_test.go @@ -57,6 +57,12 @@ func TestFixtures(t *testing.T) { err := json.Unmarshal(b, &v) return v, err }, subjectIs: nil}, + {name: "a running pipeline whose build waits on the revision view for the revision that superseded it (H-A-561, H-A-562)", subject: "", given: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"form\":12,\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":13,\"source\":3590,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"on\":\"revision view\",\"outcome\":\"waiting\",\"revision\":14,\"seat\":\"mesh-builds\",\"status\":\"required\",\"step\":\"build\",\"why\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\"}],\"v\":1}", wire: "{\"branch\":\"main\",\"call\":\"0123456789abcdef\",\"form\":12,\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1}],\"outcome\":\"running\",\"pipeline\":\"main.3590\",\"revision\":13,\"source\":3590,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"on\":\"revision view\",\"outcome\":\"waiting\",\"revision\":14,\"seat\":\"mesh-builds\",\"status\":\"required\",\"step\":\"build\",\"why\":\"nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch\"}],\"v\":1}", + decode: func(b []byte) (any, error) { + var v PipelinesByBranchRevisionValue + err := json.Unmarshal(b, &v) + return v, err + }, subjectIs: nil}, {name: "a pipeline a publish started, its mover the package's dependent, with the version released for it", subject: "", given: "{\"branch\":\"main\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"pipeline\":\"main.3589.published.mesh-sdk.0.1.21\",\"published\":{\"artifact\":\"mesh-sdk\",\"version\":\"0.1.21\"},\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"v\":1}", wire: "{\"branch\":\"main\",\"end-count\":1,\"ended\":\"2026-11-10T10:20:00Z\",\"movers\":[{\"commit\":\"0123456789abcdef0123456789abcdef01234567\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"repository\":\"mesh-networking\",\"tier\":1,\"version\":\"0.1.15\"}],\"outcome\":\"passed\",\"pipeline\":\"main.3589.published.mesh-sdk.0.1.21\",\"published\":{\"artifact\":\"mesh-sdk\",\"version\":\"0.1.21\"},\"revision\":12,\"source\":3589,\"started\":\"2026-11-10T10:00:00Z\",\"steps\":[{\"artifact\":\"nats:program\",\"ask\":\"m2kx9a1b3c4d5e\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"anchor\",\"outcome\":\"passed\",\"seat\":\"node-build-go\",\"status\":\"required\",\"step\":\"lint\"},{\"artifact\":\"nats:program\",\"carried-from\":\"main.3588\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"outcome\":\"carried\",\"status\":\"required\",\"step\":\"unit\",\"tests\":{\"unit\":42}},{\"artifact\":\"nats:program\",\"fingerprint\":\"fp-0123\",\"module\":\"nats\",\"node\":\"home-server\",\"outcome\":\"failed\",\"seat\":\"node-build-go\",\"status\":\"optional\",\"step\":\"integration\",\"tests\":{\"integration\":3},\"why\":\"TestTheBusWhole failed\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"seat\":\"mesh-wants\",\"status\":\"required\",\"step\":\"composition\"},{\"module\":\"nats\",\"outcome\":\"bypassed\",\"status\":\"bypass\",\"step\":\"review\"},{\"module\":\"nats\",\"outcome\":\"passed\",\"status\":\"required\",\"step\":\"approval\"}],\"v\":1}", decode: func(b []byte) (any, error) { var v PipelinesByBranchSourcePublishedPackageVersionValue diff --git a/modules/mesh-delivery-contracts/seats/mesh-builds/fixtures/events.json b/modules/mesh-delivery-contracts/seats/mesh-builds/fixtures/events.json index 755c765d9..c9d557847 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-builds/fixtures/events.json +++ b/modules/mesh-delivery-contracts/seats/mesh-builds/fixtures/events.json @@ -117,6 +117,28 @@ "said": "nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch" } }, + { + "name": "the build step ended superseded, naming the revision of the entry that superseded it (H-A-561)", + "of": "event:step-ended", + "subject": "mesh.seat.mesh-builds.event.step-ended.laptop", + "given": { + "v": 1, + "form": 3, + "id": "m2kx9a1b3c4d6e", + "pipeline": "main.12.nats", + "step": "build", + "node": "laptop", + "outcome": "superseded", + "entries": [ + { + "module": "nats", + "fingerprint": "fp-0123" + } + ], + "said": "nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch", + "revision": 14 + } + }, { "name": "an ask taken at the pull", "of": "event:ask-taken", diff --git a/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json b/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json index 7d7872486..ce1bca641 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-builds/seat.json @@ -687,6 +687,10 @@ "type": "string", "description": "why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint" }, + "revision": { + "type": "integer", + "description": "for a step ended superseded, the module graph revision of the entry that superseded it, 0 when the builder knows none; the runner moves the mover out only for a revision newer than its pipeline's that its view holds (design 47 H2 H-A-561)" + }, "rerun": { "type": "boolean" }, @@ -787,5 +791,5 @@ ] } }, - "form": 2 + "form": 3 } diff --git a/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/fixtures/states.json b/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/fixtures/states.json index 9229229fb..1e21b7505 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/fixtures/states.json +++ b/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/fixtures/states.json @@ -82,6 +82,43 @@ ] } }, + { + "name": "a running pipeline whose build waits on the revision view for the revision that superseded it (H-A-561, H-A-562)", + "of": "state:pipelines/.", + "given": { + "pipeline": "main.3590", + "branch": "main", + "revision": 13, + "source": 3590, + "v": 1, + "form": 12, + "outcome": "running", + "steps": [ + { + "step": "build", + "status": "required", + "outcome": "waiting", + "on": "revision view", + "revision": 14, + "why": "nats at fp-0123 is superseded by fp-0456, the newest entry heard on its first branch", + "fingerprint": "fp-0123", + "seat": "mesh-builds", + "module": "nats" + } + ], + "started": "2026-11-10T10:00:00Z", + "call": "0123456789abcdef", + "movers": [ + { + "module": "nats", + "commit": "0123456789abcdef0123456789abcdef01234567", + "fingerprint": "fp-0123", + "repository": "mesh-networking", + "tier": 1 + } + ] + } + }, { "name": "a pipeline a publish started, its mover the package's dependent, with the version released for it", "of": "state:pipelines/..published..", diff --git a/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json b/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json index 9da66533b..5e4447060 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-pipeline-runner/seat.json @@ -1198,6 +1198,10 @@ "type": "string", "description": "for a waiting step, who or what it waits on: a person, a build node, the revision view" }, + "revision": { + "type": "integer", + "description": "for a step waiting on the revision view, the module graph revision it waits for: a build ended superseded by an entry of a revision the runner's view does not hold yet (design 47 H2 H-A-561, H-A-562)" + }, "fingerprint": { "type": "string", "description": "the artifact's build-input fingerprint the step ran at" @@ -2382,5 +2386,5 @@ ] } }, - "form": 11 + "form": 12 } diff --git a/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts index 3ad14d117..f0ab476e4 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshbuilds/index.d.ts @@ -135,6 +135,8 @@ export interface StepEnded { "packages"?: Record; "pipeline": string; "rerun"?: boolean; + /** for a step ended superseded, the module graph revision of the entry that superseded it, 0 when the builder knows none; the runner moves the mover out only for a revision newer than its pipeline's that its view holds (design 47 H2 H-A-561) */ + "revision"?: number; /** why it failed, could not run or was superseded: the entry not built, the part not heard, the superseding fingerprint */ "said"?: string; "started"?: string; diff --git a/modules/mesh-delivery-contracts/ts/seats/meshpipelinerunner/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshpipelinerunner/index.d.ts index 56cd74691..c526c7b30 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshpipelinerunner/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshpipelinerunner/index.d.ts @@ -568,6 +568,8 @@ export interface StepResult { "outcome": "running" | "waiting" | "passed" | "failed" | "nothing to run" | "bypassed" | "carried" | "could not run" | "waiting for a build node" | "did not build" | "accepted" | "not asked" | "declined" | "superseded" | "cancelled"; /** the step was asked again by the runner's rerun */ "rerun"?: boolean; + /** for a step waiting on the revision view, the module graph revision it waits for: a build ended superseded by an entry of a revision the runner's view does not hold yet (design 47 H2 H-A-561, H-A-562) */ + "revision"?: number; /** the seat that serves the step, whose holder alone may end it (ADR 0666 section 21) */ "seat"?: string; /** the run the step read or asked for every step that reads it: a composition step's per machine, as mesh-wants' step-ended names them; a test step's one, with asked-by when another step asked it (design 47 G §726, §729; A-468d, A-468e, A-469t) */ diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index 33105faee..c09058a4e 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -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 @@ -365,6 +371,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro verbs.Runs = pipeline.RunsRead{Runs: runsKept{ctx: ctx, kv: runsKV}, Object: runObjs.Get, Fill: starter.TestRunsFill} // A declined step is put again on a node that has its need (design 47 H2 H-A-375, H-A-445). hearer.NeedNodes, hearer.AskDeclined, hearer.PutAgain = rv.Holders.Nodes, verbs.DeclinedAsk, starter.PutAgain + hearer.View = rv.Catalog.View // a build ended superseded moves its mover out only for a newer revision (H-A-555) dropExpired := boundExpired(dropUnanswered(ctx, rv.Findings, cred.Module, time.Now), logger.Printf) askExpired := askBoundExpired(verbs.AskUnanswered, logger.Printf) expired := func(key string) { diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/steps.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/steps.go index 75d3797e8..847e0650d 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/steps.go @@ -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) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/endopen_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/endopen_test.go index 3694f842c..1c07f6844 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/endopen_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/endopen_test.go @@ -10,6 +10,7 @@ import ( "git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants" builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" + catalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" seat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshpipelinerunner" ) @@ -73,6 +74,7 @@ func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) { if p, _, _ := h.Store.Get("main.117"); p.Steps[2].Outcome != seat.StepResultOutcomeRunning { t.Errorf("the refused end moved the lint step: %+v", p.Steps[2]) } + h.View = newerView // the runner's view holds revision 120, naming a at src2:a2 (H-A-555) bs := stepSeatOf(t, builds.Seat) end := 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"} @@ -167,7 +169,8 @@ func TestAPipelineWithNothingOpenEndsAtOnce(t *testing.T) { e.p.Steps[0].Why = notBuiltWhy("a") store["main.117"] = e var released []string - h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 }, Release: func(key string) { released = append(released, key) }} + h := &Hearer{Store: store, Say: func(string, any) error { return nil }, Now: func() time.Time { return t0 }, Release: func(key string) { released = append(released, key) }, + View: newerView} bs := stepSeatOf(t, builds.Seat) got, 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"}) @@ -179,4 +182,104 @@ 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-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 + superseding int64 + view int64 + want string // left, again or held + }{ + {"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, the builder's kept revision (H-A-563)", 117, 117, "left"}, + {"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-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 + var waits []string // the waits said, by event and what they wait on (H-A-563) + view := r.view + say := func(subject string, body any) error { + if w, ok := body.(seat.Wait); ok { + ev := seat.EventWaitHeld + if strings.Contains(subject, seat.EventWaitEnded) { + ev = seat.EventWaitEnded + } + waits = append(waits, ev+" "+w.Step+" "+w.On+" "+w.Module) + } + return nil + } + h := &Hearer{Store: store, Say: say, Now: func() time.Time { return t0 }, + 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.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") + 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) + } + 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) + } + if want := []string{seat.EventWaitHeld + " build revision view a"}; !slices.Equal(waits, want) { + t.Errorf("waits said %q, want %q", waits, want) + } + // 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) + } + if want := []string{seat.EventWaitHeld + " build revision view a", seat.EventWaitEnded + " build revision view a"}; !slices.Equal(waits, want) { + t.Errorf("waits said %q, want %q", waits, want) + } + } + }) + } +} + +// newerView is the runner's view of main at revision 120, naming a at src2:a2: newer than main.117 (H-A-555). +func newerView(string) (Half, bool) { + return Half{Revision: 120, Source: 120, Entries: map[string]catalog.CatalogEntry{"a": {Module: "a", Fp: "src2:a2"}}}, true } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index b0cba09ac..a78936d96 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -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). @@ -194,6 +208,10 @@ type Hearer struct { // queue (Starter.PutAgain); with either nil a declined step ends could not run. 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 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 // never held by a seat that answers a kept call only at its bound (H-A-506); nil runs it in place. @@ -248,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) @@ -321,6 +345,51 @@ func (h *Hearer) OnStepEndedPinned(bs StepSeat, subject string, ev StepEnded, sh } ev.Outcome, ev.Said = nodebuildgo.StepEndedOutcomeCouldNotRun, why } + // 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 older than the pipeline's own is asked again at once; one of its own revision (the builder's + // kept-revision path) moves the mover out (H-A-563); one newer that the runner's view does not hold yet holds the step + // waiting on the revision view, said as a wait held (H-A-562, H-A-563); 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 older than the pipeline's %d", superseding, own) + old := s.Ask + a, why := h.supersededAgain(&p, i, ev, passed, now) + if a != nil { + 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), 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-561)", ev.Pipeline, s.Module, ev.Said, passed, why) + ev.Outcome, ev.Said = nodebuildgo.StepEndedOutcomeCouldNotRun, why + case superseding > own && !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) + if err := h.say(seat.EventWaitHeld, p, s); err != nil { + return p, fmt.Errorf("pipeline %s's %s waits on the revision view but %s is not said: %w", ev.Pipeline, s.Module, seat.EventWaitHeld, err) + } + 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 if len(shared) > 0 { s.Shared = shared @@ -670,6 +739,9 @@ func (h *Hearer) say(event string, p seat.Pipeline, step *seat.StepResult) error if step != nil { m, _ := MoverOf(p, step.Module) w.Module, w.Commit, w.Fingerprint, w.Step, w.Ask = m.Module, m.Commit, m.Fingerprint, step.Step, step.Ask + if step.On == seat.WaitOnRevisionView { // a build waiting for the revision that superseded it (H-A-563) + w.On = step.On + } } return h.Say(runnerclient.RevisionSubject(event, p.Branch, subjectRevision(p)), w) } @@ -797,6 +869,31 @@ func phasesOf(p seat.Pipeline) *seat.PipelineEndedPhases { return ph } +// 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 false + } + 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), +// again under a new id, written into the step (its ask, asked-at; taken-at and node cleared) (H-A-557); nil and the why of +// its could-not-run end when it cannot be asked. +func (h *Hearer) supersededAgain(p *seat.Pipeline, i int, ev StepEnded, passed string, now time.Time) (*Asked, string) { + s := &p.Steps[i] + if h.AskDeclined == nil || h.PutAgain == nil { + return nil, fmt.Sprintf("its build ended superseded (%s), though %s, and the runner cannot ask it again", ev.Said, passed) + } + a, err := h.AskDeclined(*p, *s, now) + if err != nil { + return nil, fmt.Sprintf("its build ended superseded (%s), though %s, and it cannot be asked again: %v", ev.Said, passed, err) + } + s.Ask, s.AskedAt, s.TakenAt, s.Node = a.ID, &now, nil, "" + return a, "" +} + // supersededBuild says whether o is the outcome superseded of a build step of the seat mesh-builds, the one seat whose end // names it (H-A-508): another seat's end naming it is refused as any outcome the runner does not know. func supersededBuild(st seat.StepResult, o string) bool { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go index 284b478c8..f2c7858e9 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/supersede.go @@ -343,3 +343,105 @@ 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, waited []seat.StepResult + for i := range p.Steps { + st := &p.Steps[i] + if !slices.Contains(moved, st.Module) || (!open(*st) && st.Outcome != seat.StepResultOutcomeWaiting) { + continue + } + if waitsOnRevision(*st, held) { + waited = append(waited, *st) // its wait-ended is said as it was held (H-A-563) + } + 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 waited { + if err := h.say(seat.EventWaitEnded, p, &waited[i]); err != nil { + h.logf("wait-ended of %s's %s %s on the revision view is not said: %v", key, waited[i].Module, waited[i].Step, err) + } + } + 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 + } +}