P3/P5 one head, Q-a: the head is the newest revision the view holds, its pipeline read by its key, for the carry and for start; start of a module whose own step failed in an older pipeline reopens that pipeline

Builds: design 47 H2 H-A-594 (1), H-A-759, H-A-643, H-A-607 (2)
This commit is contained in:
2026-11-25 19:20:20 +01:00
parent a28caf25f6
commit b96c3f1bd8
4 changed files with 166 additions and 32 deletions
@@ -8,7 +8,6 @@ import (
runnerclient "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshpipelinerunnerclient"
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"
"git.novox.be/novox/mesh-sdk/go/keys"
)
// AddedFrom says where a mover added to a pipeline came from; exactly one field is set (design 47 H2 H-A-645).
@@ -96,35 +95,43 @@ func (f AddedFrom) describe() string {
return fmt.Sprintf("a take-in of source %d", f.TakeIn)
}
// head is the key of the newest pipeline of branch, by its catalog revision, and the pipeline: the head's pipeline (H-A-594 (1)).
func (s *Starter) head(branch string) (seat.Pipeline, bool) {
pkeys, err := s.Store.Keys(keys.EscapeName(branch) + ".*")
if err != nil {
return seat.Pipeline{}, false
}
var best seat.Pipeline
found := false
for _, k := range pkeys {
p, _, err := s.Store.Get(k)
if err != nil || p.Run != "" || p.Branch != branch {
continue
}
if !found || p.Revision > best.Revision {
best, found = p, true
}
}
return best, found
// headKey is the key of the head's pipeline of branch, whose catalog view holds half: the head's revision is the newest one the runner's catalog
// view holds, one head for the carry and for start alike (design 47 H2 H-A-594 (1), H-A-759).
func headKey(branch string, half Half) string {
return Key(branch, keyRevision(Begin{Revision: half.Revision, Source: half.Source}))
}
// CarryToHead adds the closed group of movers pipeline from left to the head's pipeline of its branch when that waits or runs,
// head reads the head's pipeline of half's branch by its key: held is false when the head's revision has no pipeline (a
// revision whose take-in is not handled yet, or that moved nothing); an older open pipeline of the branch is never the head.
func (s *Starter) head(key string) (p seat.Pipeline, held bool, err error) {
keys, err := s.Store.Keys(key)
if err != nil || len(keys) == 0 {
return seat.Pipeline{}, false, err
}
p, _, err = s.Store.Get(key)
return p, err == nil, err
}
// CarryToHead adds the closed group of movers pipeline from left to the head's pipeline of its branch (view's newest revision) when that waits or runs,
// and takes the movers out of from's movers, so none of its later ends names them (H-A-594 (3), (4), H-A-607 (2)). It
// answers the head's key, false when nothing was added: the head is from itself or has ended.
func (s *Starter) CarryToHead(from seat.Pipeline, group []seat.Mover, entries map[string]catalog.CatalogEntry, view func(branch string) (Half, bool)) (string, bool) {
if s.Store == nil {
return "", false
}
head, ok := s.head(from.Branch)
if !ok || head.Pipeline == from.Pipeline || head.Revision < from.Revision || !openPipeline(head) {
if view == nil {
return "", false
}
half, ok := view(from.Branch)
if !ok {
return "", false
}
head, held, err := s.head(headKey(from.Branch, half))
if err != nil {
s.logf("the head's pipeline of %s is not read, so the movers %v of %s are not carried to it: %v", from.Branch, moduleNames(group), from.Pipeline, err)
return "", false
}
if !held || head.Pipeline == from.Pipeline || head.Revision < from.Revision || !openPipeline(head) {
return "", false
}
if _, err := s.AddMovers(head.Pipeline, group, entries, AddedFrom{From: from.Pipeline}, view); err != nil {
@@ -50,21 +50,45 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error
if len(absent) > 0 {
return seat.StartAnswer{}, fmt.Errorf("the head of %s (revision %d) holds no entry of %s: nothing was started", in.Branch, half.Revision, strings.Join(absent, ", "))
}
key := Key(in.Branch, keyRevision(Begin{Revision: half.Revision, Source: half.Source}))
held, err := s.Store.Keys(key)
key := headKey(in.Branch, half)
// A module whose own step failed in a pipeline older than the head reopens that pipeline as rerun does, never joins the head's
// (design 47 H2 H-A-643, H-A-594 (3)); the call is one hand act.
older, movers, err := v.ownFailedPipelines(in.Branch, key, movers, half.Entries)
if err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is not looked for: nothing was started: %w", key, err)
return seat.StartAnswer{}, err
}
var head seat.Pipeline
if len(held) > 0 {
if head, _, err = s.Store.Get(key); err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is not read: nothing was started: %w", key, err)
if len(older) > 0 {
if err := v.record(seat.VerbStart, fmt.Sprintf("started %s at the head of %s by hand", strings.Join(append(moduleNames(movers), olderModules(older)...), ", "), in.Branch), in.Why); err != nil {
return seat.StartAnswer{}, err
}
for _, o := range older {
if err := v.reopenGroup(caller, o.from, o.group, nil, o.entries, in.Why); err != nil {
return seat.StartAnswer{}, err
}
s.markCarriedKeys(o.from, o.group, o.from.Pipeline)
}
w := v
w.noRecord = true
if len(movers) == 0 {
return seat.StartAnswer{Pipeline: older[0].from.Pipeline}, nil
}
return w.startAtHead(caller, in, half, key, movers)
}
return v.startAtHead(caller, in, half, key, movers)
}
// startAtHead is Start's rule for the modules no older pipeline of its own takes: the head's pipeline `key` joins them while it
// waits or runs, or is started with them, or is reopened once it has ended.
func (v Verbs) startAtHead(caller string, in seat.StartInput, half Half, key string, movers []seat.Mover) (seat.StartAnswer, error) {
s := v.Starter
head, held, err := s.head(key)
if err != nil {
return seat.StartAnswer{}, fmt.Errorf("the pipeline %s is not read: nothing was started: %w", key, err)
}
names := moduleNames(movers)
what := fmt.Sprintf("started %s at the head of %s by hand", strings.Join(names, ", "), in.Branch)
switch {
case len(held) == 0:
case !held:
if err := v.record(seat.VerbStart, what, in.Why); err != nil {
return seat.StartAnswer{}, err
}
@@ -122,6 +146,74 @@ func (v Verbs) Start(caller string, in seat.StartInput) (seat.StartAnswer, error
return seat.StartAnswer{Pipeline: key}, nil
}
// ownPipeline is an older pipeline a started module's own step failed in, and the group its reopening puts.
type ownPipeline struct {
from seat.Pipeline
group []string
entries map[string]catalog.CatalogEntry
}
func olderModules(o []ownPipeline) []string {
var out []string
for _, p := range o {
out = appendNew(out, p.group...)
}
return out
}
// ownFailedPipelines splits movers: those whose own required step failed in the newest pipeline of the branch other than the
// head's `key` that moves them, which ended (design 47 H2 H-A-643), with the closed group each such pipeline reopens for, and the movers left.
func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, headEntries map[string]catalog.CatalogEntry) ([]ownPipeline, []seat.Mover, error) {
s := v.Starter
pkeys, err := branchKeys(s.Store, branch)
if err != nil {
return nil, nil, fmt.Errorf("the pipelines of %s are not listed: nothing was started: %w", branch, err)
}
head, held, err := s.head(key)
if err != nil {
return nil, nil, fmt.Errorf("the pipeline %s is not read: nothing was started: %w", key, err)
}
var out []ownPipeline
var rest []seat.Mover
for _, m := range movers {
var best seat.Pipeline
found := false
if !held || !Moves(head, m.Module) {
for _, k := range pkeys {
if k == key {
continue
}
p, _, err := s.Store.Get(k)
if err != nil || p.Run != "" || p.Branch != branch || !Moves(p, m.Module) || slices.Contains(p.Superseded, m.Module) {
continue
}
if !found || p.Revision > best.Revision {
best, found = p, true
}
}
// Only the newest pipeline that moves the module counts: a newer one that passed it leaves the failure behind.
found = found && best.Ended != nil && len(failedSteps(best, m.Module)) > 0
}
if !found {
rest = append(rest, m)
continue
}
at := slices.IndexFunc(out, func(o ownPipeline) bool { return o.from.Pipeline == best.Pipeline })
if at < 0 {
entries := headEntries
if s.Revision != nil {
if h, err := s.Revision(branch, best.Revision); err == nil && h.Entries != nil {
entries = h.Entries
}
}
out = append(out, ownPipeline{from: best, entries: entries})
at = len(out) - 1
}
out[at].group = appendNew(out[at].group, v.closedGroup(best, m.Module, out[at].entries)...)
}
return out, rest, nil
}
// allPassed says whether module has required steps in p and every one passed, was carried or had nothing to run: the pipeline
// delivered it.
func allPassed(p seat.Pipeline, module string) bool {
@@ -614,10 +614,19 @@ func TestAPublishIsTakenIntoThePipelineOfItsRevision(t *testing.T) {
return nil
}}
st := memUnfinished{}
// design 47 H2 H-A-594 (1), H-A-759 (AC-P5 head): the head is the newest revision the view holds, its pipeline read by its
// key; with revision 7 in the view and no pipeline at main.7, the older open main.6 is never taken as the head and nothing
// is carried.
viewAt := func(rev int64) func(string) (Half, bool) {
return func(string) (Half, bool) { return Half{Revision: rev, Source: 9, Entries: entries}, true }
}
if c, ok := s.CarryToHead(failed, []seat.Mover{{Module: "free", Fingerprint: "f3"}}, entries, viewAt(7)); ok || c != "" || len(out) != 0 {
t.Fatalf("a carry with revision 7 in the view and no pipeline at main.7 = %q %t (said %d), want none: main.6 is not the head", c, ok, len(out))
}
u := &Unfinished{Store: st,
Entries: func(string, int64) (map[string]catalog.CatalogEntry, bool) { return entries, true },
Add: func(from seat.Pipeline, group []seat.Mover) (string, bool) {
return s.CarryToHead(from, group, entries, nil)
return s.CarryToHead(from, group, entries, viewAt(6))
}}
u.Ended(failed)
if len(out) != 1 || out[0].ev.Module != "free" || out[0].ev.From != "main.5" || out[0].ev.Pipeline != "main.6" || !strings.HasSuffix(out[0].subject, ".main.6") {
@@ -576,12 +576,38 @@ func TestStartWithModulesJoinsTheHeadsPipelineOrReopensIt(t *testing.T) {
if got, _, _ := store.Get(pkey); got.Outcome != seat.PipelineOutcomeRunning || got.Ended != nil || len(asks.asks) == asked {
t.Errorf("%s is %s ended %v, %d asks since: want reopened and its failed step asked again", pkey, got.Outcome, got.Ended, len(asks.asks)-asked)
}
// H-A-643 (Q-a): a module whose own step failed in a pipeline older than the head reopens that pipeline and is never added to
// the head: with revision 10 in the view and main.9 no longer moving app, start of app reopens the pipeline whose lint failed
// again, and keys no pipeline at main.10.
nine := store["main.9"]
nine.p.Movers = slices.DeleteFunc(slices.Clone(nine.p.Movers), func(m seat.Mover) bool { return m.Module == "app" })
nine.p.Outcome, nine.p.Ended = seat.PipelineOutcomePassed, &end
store["main.9"] = nine
p5 = store[pkey].p
for i := range p5.Steps {
if p5.Steps[i].Step == seat.StepResultStepLint {
p5.Steps[i].Outcome, p5.Steps[i].Ended = seat.StepResultOutcomeFailed, &end
}
}
p5.Outcome, p5.Ended = seat.PipelineOutcomeFailed, &end
store[pkey] = struct {
p seat.Pipeline
rev uint64
}{p5, 3}
revision = 10
asked = len(asks.asks)
if a, err = v.Start("operator", seat.StartInput{Branch: "main", Modules: []string{"app"}, Why: "its lint failed again"}); err != nil || a.Pipeline != pkey {
t.Fatalf("start of app whose step failed in the older %s = %+v, %v; want %s reopened", pkey, a, err, pkey)
}
if got, _, _ := store.Get(pkey); got.Outcome != seat.PipelineOutcomeRunning || len(asks.asks) == asked || made["main.10"] != nil {
t.Errorf("%s is %s, %d asks since, main.10 written %t: want the older pipeline reopened and nothing keyed at the head", pkey, got.Outcome, len(asks.asks)-asked, made["main.10"] != nil)
}
for k := range made {
if strings.Contains(k, ".again.") {
t.Errorf("a start keyed %s", k)
}
}
if len(*acts) != 5 {
if len(*acts) != 6 {
t.Errorf("hand acts %v, want the five starts that did something recorded", *acts)
}
if !IsStepsKey(StepsKey("main.9.again.1", "app")) {