From 642564629a55f1a050d6409c9cabb85f77ec74ad Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 26 Nov 2026 02:38:48 +0100 Subject: [PATCH] mesh-delivery-pipeline: a rerun of a test-run step and the held-behind list read the head too (fix-770 round 2, issue 1984) H-A-594 (3) puts every path that reopens an ended pipeline under one rule: a rerun of a step that reads a test run now takes the movers a newer revision moved, other than its own, out of the pipeline's movers and says them, as rerun does, through one helper leaveMovedOn. The finding pipeline-failed's held-behind list read the ties without the head, so it could name a mover as held behind a predecessor a newer revision moved: it now reads the head's revision as the carry does (H-A-594 (2)). Builds: design 47 H2 H-A-594 (2), (3), (4), H-A-761 --- .../cmd/mesh-delivery-pipeline/main.go | 4 +- .../internal/pipeline/carry.go | 8 ++- .../internal/pipeline/failed_test.go | 2 +- .../internal/pipeline/repin_test.go | 62 +++++++++++++++++++ .../internal/pipeline/unfinished.go | 8 ++- .../internal/pipeline/verbs.go | 37 +++++++---- 6 files changed, 105 insertions(+), 16 deletions(-) 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 19f4342d1..75a54ae81 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -166,7 +166,9 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro if err != nil { return nil } - return pipeline.HeldBehind(p, module, half.Entries) + // The head's revision says which movers a newer revision moved: they tie nothing (design 47 H2 H-A-594 (2), H-A-761). + head, _ := rv.Catalog.View(p.Branch) + return pipeline.HeldBehind(p, module, half.Entries, head.Entries) }} // Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state // bounds. A step's ask is put as a kept call within the same bound (design 47 H2 §775). diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/carry.go b/modules/mesh-delivery-pipeline/internal/pipeline/carry.go index 85e0db329..c3b9ce88f 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/carry.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/carry.go @@ -164,8 +164,10 @@ func moduleNames(movers []seat.Mover) []string { } // HeldBehind are the movers of p, sorted, that the failed mover module holds back: those whose own steps held and that await -// it, directly or through others, or sit in the tier group of one that does (H-A-625 (2)). -func HeldBehind(p seat.Pipeline, module string, entries map[string]catalog.CatalogEntry) []string { +// it, directly or through others, or sit in the tier group of one that does (H-A-625 (2)). With head, the head's revision's +// entries, a mover of p a newer revision moved, the head's entry holding another fingerprint, ties nothing and is held behind +// nothing, as the carry reads it (design 47 H2 H-A-594 (2), H-A-761). +func HeldBehind(p seat.Pipeline, module string, entries, head map[string]catalog.CatalogEntry) []string { failed := failedMovers(p) var left []string for _, m := range p.Movers { @@ -173,6 +175,8 @@ func HeldBehind(p seat.Pipeline, module string, entries map[string]catalog.Catal left = append(left, m.Module) } } + moved := movedAmong(p, appendNew(slices.Clone(left), failed...), head) + left, failed = without(left, moved), without(failed, moved) var out []string for m, by := range tiedTo(p, left, failed, entries) { if slices.Contains(by, module) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go index 760e7e857..67efea617 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/failed_test.go @@ -167,7 +167,7 @@ func TestEachFailingMoverIsAFindingAndItsNextPassedPipelineClearsIt(t *testing.T Movers: []seat.Mover{{Module: "engine", Commit: "c1"}, {Module: "gitea"}}, Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed}, {Module: "gitea", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}} - fl := &Failures{Findings: f, Observer: "runner", Behind: func(p seat.Pipeline, m string) []string { return HeldBehind(p, m, entries) }} + fl := &Failures{Findings: f, Observer: "runner", Behind: func(p seat.Pipeline, m string) []string { return HeldBehind(p, m, entries, nil) }} fl.StepEnded(nil, p, p.Steps[0]) got := f.held["delivery.engine.main.pipeline-failed"] if !strings.Contains(got.Explanation, "gitea are held behind it") || !strings.Contains(got.Explanation, "runner_unfinished_place") { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go index c0e707b47..78ec26b90 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/repin_test.go @@ -706,6 +706,68 @@ func testAPredecessorANewerRevisionMovedTiesNothing(t *testing.T) { t.Errorf("at main.5's end added %v, state %v, said %q: want gitea carried, stale not kept, engine and stale said", added, st, said) } }) + // The finding pipeline-failed's held-behind list (H-A-625 (2)) reads the head as the carry does: gitea awaits the failed engine's + // package and mate awaits gitea's; a mover a newer revision moved is held behind nothing and holds nothing behind it. + t.Run("the finding's held-behind list", func(t *testing.T) { + p := seat.Pipeline{Pipeline: "main.5", Branch: "main", Revision: 5, Outcome: seat.PipelineOutcomeRunning, + Movers: []seat.Mover{{Module: "engine", Fingerprint: "f1"}, {Module: "gitea", Fingerprint: "f2"}, {Module: "mate", Fingerprint: "f3"}}, + Steps: []seat.StepResult{{Module: "engine", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed}, + {Module: "gitea", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}, + {Module: "mate", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeNotAsked}}} + ties := maps.Clone(edges) + edgeInto(ties, "mate", "gitea", 1) + at := func(engine, gitea string) map[string]catalog.CatalogEntry { + return map[string]catalog.CatalogEntry{"engine": {Fp: engine}, "gitea": {Fp: gitea}, "mate": {Fp: "f3"}} + } + for _, c := range []struct { + head map[string]catalog.CatalogEntry + want []string + }{{nil, []string{"gitea", "mate"}}, {at("f1", "f2"), []string{"gitea", "mate"}}, {at("f1b", "f2"), nil}, {at("f1", "f2b"), nil}} { + if got := HeldBehind(p, "engine", ties, c.head); !slices.Equal(got, c.want) { + t.Errorf("held behind engine with the head %v = %v, want %v", c.head, got, c.want) + } + } + }) + // A rerun of a step that reads a test run reopens its ended pipeline as rerun does (H-A-594 (3)): lib, failed at src2:bb and + // moved by a newer revision to src2:b2, leaves its movers, said. + t.Run("rerun of a test run", func(t *testing.T) { + f := newRunFixture() + reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Policy: catalog.Policy{Steps: catalog.StepStatuses{Lint: "bypass", Unit: "required", + Integration: "bypass", Composition: "bypass", Review: "bypass", Approval: "bypass", Validate: "bypass"}}} + f.s.Registration = func(string) (catalog.Registration, bool) { return reg, true } + p := f.start(t, 4, 9) + e := f.store[p.Pipeline] + e.p.Steps[0].Outcome = seat.StepResultOutcomePassed // the build + f.store[p.Pipeline] = e + unit := stepNamed(p, "app:program", "unit") + ended := time.Now() + if _, err := f.h.OnStepEnded(stepSeatOf(t, "node-build-go"), "mesh.seat.node-build-go.event.step-ended.ace", StepEnded{ID: unit.Ask, + Pipeline: p.Pipeline, Module: "app", Commit: "c1", Fingerprint: "src2:aa", Step: "unit", Node: "ace", Outcome: "failed", Ended: &ended}); err != nil { + t.Fatal(err) + } + e = f.store[p.Pipeline] + if e.p.Outcome != seat.PipelineOutcomeFailed { + t.Fatalf("the pipeline is %s after the failing run, want failed", e.p.Outcome) + } + e.p.Movers = append(e.p.Movers, seat.Mover{Module: "lib", Commit: "c1", Fingerprint: "src2:bb"}) + e.p.Steps = append(e.p.Steps, seat.StepResult{Module: "lib", Step: seat.StepResultStepUnit, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed, Ended: &ended}) + f.store[p.Pipeline] = e + v := Verbs{Hearer: f.h, Starter: f.s, View: func(string) (Half, bool) { + return Half{Revision: 13, Entries: map[string]catalog.CatalogEntry{ + "app": {Module: "app", Fp: "src2:aa", Path: "modules/app", Artifacts: []catalog.Artifact{{Ref: "app:program", Language: "go"}, {Ref: "app:tools", Language: "go"}}}, + "lib": {Module: "lib", Fp: "src2:b2"}, + "mesh-build-go": {Module: "mesh-build-go", Acts: []catalog.ActingRule{{Seat: "node-build-go", Step: "build", On: "go"}}}}}, true + }, Acts: &actLog{}} + if _, err := v.Rerun("op@shanks", seat.RerunInput{Pipeline: p.Pipeline, Module: "app", Step: "unit", Artifact: "app:tools", Why: "flaky"}); err != nil { + t.Fatal(err) + } + f.mu.Lock() + j := saidOf(f.logged) + f.mu.Unlock() + if q := f.pipeline(p); Moves(q, "lib") || !Moves(q, "app") || !namesBoth(j, "lib", p.Pipeline, "src2:bb", "src2:b2", 13) { + t.Errorf("%s moves %+v and the journal says %q: want lib gone, said with both fingerprints", p.Pipeline, q.Movers, j) + } + }) // The reopens (Verbs): main.10 moves app and lib at revision 10; the head's revision 13 holds lib at src2:b2, which a newer // revision moved, and app's entry there awaits lib's package. reg, entries := placeFixture() diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go b/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go index 95879a3a8..b467ff6e0 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/unfinished.go @@ -128,11 +128,17 @@ type movedMover struct{ At, Head string } // pipeline, so it ties nothing and goes in no group (design 47 H2 H-A-594 (2)), and it goes on only at the fingerprint the head's // entry holds (H-A-761). None when head is nil. func movedOn(p seat.Pipeline, head map[string]catalog.CatalogEntry) map[string]movedMover { + return movedAmong(p, appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...), head) +} + +// movedAmong are the movers of p among names whose entry in head does not hold p's fingerprint of them (movedOn); none when head +// is nil. +func movedAmong(p seat.Pipeline, names []string, head map[string]catalog.CatalogEntry) map[string]movedMover { if head == nil { return nil } out := map[string]movedMover{} - for _, name := range appendNew(slices.Clone(unfinishedOf(p)), failedMovers(p)...) { + for _, name := range names { m, _ := MoverOf(p, name) if e := head[name]; !slices.Contains(p.Superseded, name) && e.Fp != m.Fingerprint { out[name] = movedMover{At: m.Fingerprint, Head: e.Fp} diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go index 9c370ea63..26d7a424e 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/verbs.go @@ -408,17 +408,7 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru return -1, err } } - // A rerun that reopens an ended delivering pipeline takes out of its movers each other mover a newer revision moved, the - // head's entry holding another fingerprint: it counts as carried by that revision's pipeline, so it ties nothing and none of - // the pipeline's later ends names it (design 47 H2 H-A-594 (2), (4), H-A-761). - if p.Ended != nil && p.Run == "" && v.View != nil { - if h, ok := v.View(p.Branch); ok { - if moved, head = movedOn(*p, h.Entries), h.Revision; moved != nil { - delete(moved, in.Module) - } - p.Movers = slices.DeleteFunc(slices.Clone(p.Movers), func(m seat.Mover) bool { _, ok := moved[m.Module]; return ok }) - } - } + moved, head = v.leaveMovedOn(p, in.Module) oldAsk := s.Ask replaced = oldAsk *s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat, @@ -468,6 +458,24 @@ func (v Verbs) rerun(caller string, in seat.RerunInput, reopens bool) (seat.Reru return seat.RerunAnswer{Pipeline: in.Pipeline, Result: &r}, nil } +// leaveMovedOn takes out of p, an ended delivering pipeline a rerun of keep's step reopens, each other mover a newer revision +// moved, the head's entry holding another fingerprint: it counts as carried by that revision's pipeline, so it ties nothing and +// none of the pipeline's later ends names it (design 47 H2 H-A-594 (2), (3), (4), H-A-761). It answers them, read at the head's +// revision head; none when p has not ended or the head is not held. +func (v Verbs) leaveMovedOn(p *seat.Pipeline, keep string) (moved map[string]movedMover, head int64) { + if p.Ended == nil || p.Run != "" || v.View == nil { + return nil, 0 + } + h, ok := v.View(p.Branch) + if !ok { + return nil, 0 + } + moved = movedOn(*p, h.Entries) + delete(moved, keep) + p.Movers = slices.DeleteFunc(slices.Clone(p.Movers), func(m seat.Mover) bool { _, ok := moved[m.Module]; return ok }) + return moved, h.Revision +} + // rerunTest asks a test step of a test run again (design 47 G §727, A-469l): it joins its key's run while that runs, reads one // that started after the step's last end, or else starts a new run under a new ask, replacing the ended key by compare-and-set // and carrying its readers into the new value, so the new run's end moves every former reader that did not pass. @@ -508,9 +516,12 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult, if read { event = seat.EventStepEnded } + var moved map[string]movedMover + var head int64 p, _, err := v.change(in.Pipeline, event, func() error { return v.record(seat.VerbRerun, fmt.Sprintf("asked the %s step of %s again", in.Step, in.Pipeline), in.Why) }, func(p *seat.Pipeline, now time.Time) (int, error) { + moved = nil switch p.Outcome { case seat.PipelineOutcomeCancelled, seat.PipelineOutcomeSuperseded: return -1, fmt.Errorf("the pipeline %s is %s: a step of it is not asked again", p.Pipeline, p.Outcome) @@ -519,6 +530,7 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult, if err != nil { return -1, err } + moved, head = v.leaveMovedOn(p, in.Module) // as rerun does (design 47 H2 H-A-594 (3)) s := &p.Steps[i] *s = seat.StepResult{Step: s.Step, Module: s.Module, Artifact: s.Artifact, Status: s.Status, Fingerprint: s.Fingerprint, Seat: s.Seat, Outcome: seat.StepResultOutcomeRunning, By: caller, Rerun: true, Started: &now} @@ -552,6 +564,9 @@ func (v Verbs) rerunTest(caller string, in seat.RerunInput, st seat.StepResult, if err != nil { return seat.RerunAnswer{}, err } + if v.Starter != nil { + v.Starter.passMovedOn(p, head, moved) + } v.sayReopened(p, reopens) switch { case join || read: