From 0fcc614e25b95128880fd96e8ffd0fac7b89f332 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 22:59:31 +0100 Subject: [PATCH] Build an ask of an older kept revision by reading it by number, never waiting (H-A-205) Two pipelines of consecutive revisions ran at once (main.45, 22:5x CET): the picture held source revision 46, whose entries had moved on, so the older pipeline's builds waited for a picture that only moves forward and failed "revision 45 of main not in the builder's picture within 2m0s". An ask of a source revision below the newest the picture holds now reads its catalog revision by number through the catalog seat's verb revision (kept while its pipeline runs, H-A-147) and is built when that revision is of its source and names every entry it asks; only a revision above the newest is waited for (H-A-155). Builds: design 47 H H-A-205, H-A-147, H-A-155 --- .../cmd/mesh-delivery-builder/keptrevision.go | 47 +++++++++++++++++++ .../cmd/mesh-delivery-builder/main.go | 2 + .../internal/build/revisionwait.go | 32 +++++++++++++ .../internal/build/run.go | 4 ++ .../internal/build/step_test.go | 38 ++++++++++++++- 5 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 modules/mesh-delivery-builder/cmd/mesh-delivery-builder/keptrevision.go diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/keptrevision.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/keptrevision.go new file mode 100644 index 00000000..f9d6e55e --- /dev/null +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/keptrevision.go @@ -0,0 +1,47 @@ +package main + +import ( + "context" + "encoding/json" + "fmt" + + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + "git.novox.be/novox/mesh-sdk/go/buscalls" + "git.novox.be/novox/mesh-sdk/go/keys" +) + +// keptRevisionVia reads one kept revision of a branch by its number through the catalog seat's verb revision, page by page +// (design 47 H H-A-205, H-A-147): the source revision it was taken in from and the fingerprint of each module it names. +func keptRevisionVia(call toolCaller) func(context.Context, string, int64) (int64, map[string]string, error) { + return func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) { + fps := map[string]string{} + var source int64 + after := "" + for { + raw, err := call(meshcatalogclient.RevisionVerb, meshcatalog.RevisionInput{Branch: keys.EscapeName(branch), Revision: revision, After: after}) + if err != nil { + return 0, nil, err + } + answer, said, ok := buscalls.Unwrap(raw) + if !ok { + return 0, nil, fmt.Errorf("%s answered: %s", meshcatalogclient.RevisionVerb, said) + } + var a meshcatalog.RevisionAnswer + if err := json.Unmarshal(answer, &a); err != nil { + return 0, nil, fmt.Errorf("%s answered no revision: %w", meshcatalogclient.RevisionVerb, err) + } + if a.NoneYet || a.Revision == nil || a.Revision.Revision != revision { + return 0, nil, fmt.Errorf("%s answered no revision %d of %s", meshcatalogclient.RevisionVerb, revision, branch) + } + source = a.Revision.Source + for _, e := range a.Entries { + fps[e.Module] = e.Fp + } + if a.Next == "" { + return source, fps, nil + } + after = a.Next + } + } +} diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go index a5167640..0faf4eaf 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go @@ -469,6 +469,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro // a holder of the seat that is down holds no other part of it). half.b = b b.Picture = half.picture + // An ask of a revision below the newest the picture holds is read by number from the catalog seat (H-A-205). + b.KeptRevision = keptRevisionVia(calls.Call) branches.Held = func(string, meshcatalog.CatalogRevision) { b.PictureHeld() } // a revision held wakes a step ask's wait (H-A-162) half.ready = func() { if err := b.Sweep(ctx, half.pictured()...); err != nil { diff --git a/modules/mesh-delivery-builder/internal/build/revisionwait.go b/modules/mesh-delivery-builder/internal/build/revisionwait.go index 2a052bbc..2ae3c745 100644 --- a/modules/mesh-delivery-builder/internal/build/revisionwait.go +++ b/modules/mesh-delivery-builder/internal/build/revisionwait.go @@ -20,6 +20,11 @@ import ( // revision its view holds (PictureHeld, H-A-162), never a // timer or a poll, up to RevisionWait (the setting revision-wait-minutes); past it the ask fails, naming the revision and the // branch, and nothing is built. A step ask with no source (a run on request) does not wait. +// +// **The picture holds every kept revision, not only the newest** (design 47 H H-A-205, H-A-147): an ask of a source revision +// below the newest the picture holds, whose entries the picture no longer names, asks the catalog seat's verb revision for +// its catalog revision by number, once, and is built when that kept revision is of its source and names every entry it +// asks; it never waits, since the picture only moves on. Only a revision above the newest is waited for. // DefaultRevisionWait is the bound of a step ask's wait for its revision, its setting revision-wait-minutes' default (H-A-156). const DefaultRevisionWait = 2 * time.Minute @@ -68,12 +73,39 @@ func (b *Builder) holdsRevision(branch string, source int64, entries []meshbuild return true } +// keptRevisionHolds answers no outcome when the catalog keeps the ask's revision (its catalog revision by number, of its +// source revision) and that revision names every entry of the ask; else failed or could not run, with its words. +func (b *Builder) keptRevisionHolds(ctx context.Context, run meshbuilds.StepRun, held int64) (outcome, said string) { + below := fmt.Sprintf("revision %d of %s is below the %d the builder's picture holds", run.Source, run.Branch, held) + if b.KeptRevision == nil || run.Revision <= 0 { + return meshbuilds.StepEndedOutcomeFailed, below + ", and the ask names no catalog revision to read it by" + } + source, fps, err := b.KeptRevision(ctx, run.Branch, run.Revision) + if err != nil { + b.logf("%s: %s, and the catalog's revision %d cannot be read: %v", run.Pipeline, below, run.Revision, err) + return meshbuilds.StepEndedOutcomeCouldNotRun, fmt.Sprintf("%s, and the catalog's revision %d cannot be read: %v", below, run.Revision, err) + } + if source != run.Source { + return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d is of source revision %d", below, run.Revision, source) + } + for _, e := range run.Entries { + if fps[e.Module] != e.Fingerprint { + return meshbuilds.StepEndedOutcomeFailed, fmt.Sprintf("%s, and the catalog's revision %d names %s at %q, not %s", below, run.Revision, e.Module, fps[e.Module], e.Fingerprint) + } + } + b.logf("%s: %s; the catalog keeps revision %d with its entries: the build goes on", run.Pipeline, below, run.Revision) + return "", "" +} + // awaitRevision returns no outcome once the builder's picture of the ask's branch holds its source revision; past the bound the // step's outcome failed, at the builder's stop could not run, each with its words. func (b *Builder) awaitRevision(ctx context.Context, run meshbuilds.StepRun) (outcome, said string) { if b.Picture == nil || run.Source <= 0 || run.Branch == "" { return "", "" } + if held, ok := b.Picture(run.Branch); ok && run.Source < held && !b.holdsRevision(run.Branch, run.Source, run.Entries) { + return b.keptRevisionHolds(ctx, run, held) + } bound := b.revisionWait() notHeld := fmt.Sprintf("revision %d of %s not in the builder's picture", run.Source, run.Branch) wait, stop := context.WithTimeout(ctx, bound) // a context's bound, no timer (ADR 0437 ยง8) diff --git a/modules/mesh-delivery-builder/internal/build/run.go b/modules/mesh-delivery-builder/internal/build/run.go index ba6f3e3c..4bfb6df4 100644 --- a/modules/mesh-delivery-builder/internal/build/run.go +++ b/modules/mesh-delivery-builder/internal/build/run.go @@ -110,6 +110,10 @@ type Builder struct { // Picture answers the source revision the builder's picture of a watched branch holds, false while it holds none (design 47 // H H-A-155, H-A-141): a step ask naming a newer one waits for it. Nil waits for nothing. Picture func(branch string) (source int64, held bool) + // KeptRevision asks the catalog seat's verb revision for one kept revision of a branch by its number (design 47 H + // H-A-205, H-A-147): the source revision it was taken in from and the fingerprint of each module it names. A step ask of + // a source revision below the newest the picture holds is built when that kept revision names its entries. Nil reads none. + KeptRevision func(ctx context.Context, branch string, revision int64) (source int64, fingerprints map[string]string, err error) // RevisionWait bounds a step ask's wait for its revision, its setting revision-wait-minutes (H-A-156); DefaultRevisionWait // when 0. RevisionWait time.Duration diff --git a/modules/mesh-delivery-builder/internal/build/step_test.go b/modules/mesh-delivery-builder/internal/build/step_test.go index 6a777cf2..2bf0847a 100644 --- a/modules/mesh-delivery-builder/internal/build/step_test.go +++ b/modules/mesh-delivery-builder/internal/build/step_test.go @@ -119,6 +119,7 @@ func TestABuildStepPassesAReservingBuildOnlyWithItsReservedVersion(t *testing.T) } t.Run("H-A-155: an ask waits for the picture to take its revision in, then builds with its version reserved", aStepAskWaitsForItsRevision) t.Run("H-A-155: past the bound the ask fails naming its revision, and nothing is built", aStepAskPastItsRevisionBoundFails) + t.Run("H-A-205: an ask of a revision below the picture's newest is read by number and built", anOlderKeptRevisionIsReadByNumber) t.Run("H-A-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) @@ -329,6 +330,11 @@ func aStepAskWaitsForItsRevision(t *testing.T) { held.Store(40) asked := make(chan struct{}, 1) r, res, entry := revisionRig(t, &held, asked) + var keptReads atomic.Int64 // H-A-205: a revision above the newest is waited for, never read by number + r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { + keptReads.Add(1) + return 0, nil, errors.New("not asked") + } ended := make(chan meshbuilds.StepEnded, 1) go func() { ended <- r.b.BuildStep(t.Context(), meshbuilds.StepRun{Pipeline: "main.7.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 7, Source: 41, @@ -353,8 +359,36 @@ func aStepAskWaitsForItsRevision(t *testing.T) { t.Fatal("the ask was not woken by the entry the picture took in") } r.b.Wait() - if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 { - t.Errorf("end = %+v, reserved from %+v; want passed with one version reserved from revision 41", end, res.sources) + if end.Outcome != meshbuilds.StepEndedOutcomePassed || len(res.sources) != 1 || res.sources[0].Revision != 41 || keptReads.Load() != 0 { + t.Errorf("end = %+v, reserved from %+v, kept revisions read %d; want passed with one version reserved from revision 41, none read", end, res.sources, keptReads.Load()) + } +} + +// H-A-205: two pipelines of consecutive revisions run at once; the picture holds source revision 46, whose entry of m moved +// on, while the older pipeline asks the build of revision 45. Its kept catalog revision is read by number and the build runs; +// a kept revision naming another fingerprint fails the step, naming it. +func anOlderKeptRevisionIsReadByNumber(t *testing.T) { + var held atomic.Int64 + held.Store(46) + r, _, _ := revisionRig(t, &held, make(chan struct{}, 1)) + r.b.RevisionWait = time.Nanosecond // a wait would fail at once: the older revision is never waited for + var read []string + r.b.KeptRevision = func(_ context.Context, branch string, revision int64) (int64, map[string]string, error) { + read = append(read, fmt.Sprintf("%s %d", branch, revision)) + return 45, map[string]string{"m": fp1}, nil + } + run := meshbuilds.StepRun{Pipeline: "main.45.m", Step: meshbuilds.StepRunStepBuild, Branch: "main", Revision: 45, Source: 45, + Entries: []meshbuilds.BuildEntry{{Module: "m", Fingerprint: fp1}}} + end := r.b.BuildStep(t.Context(), run) + r.b.Wait() + if end.Outcome != meshbuilds.StepEndedOutcomePassed || !slices.Equal(read, []string{"main 45"}) { + t.Errorf("end = %+v, kept revisions read %v; want passed, revision 45 of main read once", end, read) + } + r.b.KeptRevision = func(context.Context, string, int64) (int64, map[string]string, error) { + return 45, map[string]string{"m": "src2:other"}, nil + } + if end := r.b.BuildStep(t.Context(), run); end.Outcome != meshbuilds.StepEndedOutcomeFailed || !strings.Contains(end.Said, "names m at \"src2:other\"") { + t.Errorf("end = %+v; want failed naming the fingerprint the kept revision names", end) } }