From b7b3891a4a823a122ef652f5345532be83faabe7 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 21:55:02 +0100 Subject: [PATCH 1/9] T1 indexer: blank only a mover's entry (issue 1984) The take-in blanked a package's pin in every import-form entry, the node-engine's among them though it was no mover, and nothing filled it: every composition of main.506 could not run. A module that is no mover of the take-in keeps its pins, since no step of that pipeline builds it. Tests: TestMoversOf gains the subcase "an import-form importer that is no mover keeps its pin of a package a mover publishes" (1984/AC7); I12's subcase is kept as 1984/AC8. TestASourceRevisionMovingMeshSDKNamesItAndItsImporters (integration) asserted the old blank for importer at m3's take-in, where the take-in makes importer no mover (its fingerprint does not move, noted on issue 1984 as note 24); its assertion now follows H-A-628 (1): blank where importer is a mover of that take-in, its pin kept where not. Builds: design 47 H2 H-A-628 (1) (hq cea6404c); D1 H-A-532 DMC-1; D2 H-A-547 (2) --- .../packages_integration_test.go | 13 +++++++++---- .../internal/index/movers.go | 12 ++++++++---- .../internal/index/movers_test.go | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/packages_integration_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/packages_integration_test.go index 36e635a1a..f7d3e2f0f 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/packages_integration_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/packages_integration_test.go @@ -400,9 +400,10 @@ func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) { } untilModule(t, ctx, js, "legacy", func(m meshcatalog.ModulesByModuleValue) bool { return m.Packages[sdkGo] == "v0.1.29" }) - // DMC-1, H-A-547 (2): the next take-in moving mesh-sdk (m3 changes buildstep again) names it with no version in the - // import-form importer's entry of that take-in's revision, so the importer's build waits for this pipeline's publish; - // legacy, of the version line, keeps its pin. + // DMC-1, H-A-547 (2), H-A-628 (1): the next take-in moving mesh-sdk (m3 changes buildstep again) names it with no version + // in the import-form importer's entry of that take-in's revision where importer is a mover of it, so the importer's build + // waits for this pipeline's publish, and keeps its pin where it is no mover, since no step of that pipeline builds it + // (1984/AC7, AC8); legacy, of the version line, keeps its pin. heard.acked(t, "main") say(13, false, meshdelivery.SourceMovedEventHeadsItem{Repository: "novox/mesh-sdk", Commit: m3}) taken = heard.next(t, "main", 13) @@ -411,7 +412,11 @@ func TestASourceRevisionMovingMeshSDKNamesItAndItsImporters(t *testing.T) { if err != nil { t.Fatal(err) } - for module, want := range map[string]string{"importer": "", "legacy": "v0.1.29"} { + importerWants := "v0.1.29" + if slices.ContainsFunc(taken.Entries, func(m meshcatalog.TakeInEntry) bool { return m.Module == "importer" }) { + importerWants = "" + } + for module, want := range map[string]string{"importer": importerWants, "legacy": "v0.1.29"} { i := slices.IndexFunc(entries, func(e meshcatalog.CatalogEntry) bool { return e.Module == module }) if i < 0 { t.Fatalf("main.%d holds no entry of %s", taken.Revision, module) diff --git a/modules/mesh-delivery-indexer/internal/index/movers.go b/modules/mesh-delivery-indexer/internal/index/movers.go index 3c89bda16..e9072f398 100644 --- a/modules/mesh-delivery-indexer/internal/index/movers.go +++ b/modules/mesh-delivery-indexer/internal/index/movers.go @@ -64,12 +64,16 @@ func moversOf(before []meshcatalog.CatalogEntry, after map[string]meshcatalog.Ca // unpinnedByMovers are the entries of a take-in with no version named, in an importer's packages, for a package a mover of // the same take-in publishes (design 47 H2 H-A-532 DMC-1, H-A-547 Q5): the version that pipeline publishes is not released // at the take-in, so the importer's build waits for that package's publish and is made against it (H-A-165, H-A-521). Only -// an entry on the import form is touched (its import set reported, H-A-538): a version-line entry's fingerprint takes its -// pins (H-A-167, H-A-530), so it keeps them. A mover's own packages are left as they are. The entries are written anew where -// one changes; the others are the same values. +// the entry of a mover of the take-in is touched (H-A-628 (1)): a module that is no mover keeps its pins, since no step of +// that pipeline builds it, so no build waits for the publish the blank serves. Of a mover, only an entry on the import form +// is touched (its import set reported, H-A-538): a version-line entry's fingerprint takes its pins (H-A-167, H-A-530), so +// it keeps them. A mover's own packages are left as they are. The entries are written anew where one changes; the others +// are the same values. func unpinnedByMovers(entries map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry { published := map[string]string{} // package name to the mover that publishes it + moving := make(map[string]bool, len(movers)) for _, m := range movers { + moving[m.Module] = true for _, a := range entries[m.Module].Artifacts { if a.Package != nil && a.Package.Name != "" { published[a.Package.Name] = m.Module @@ -82,7 +86,7 @@ func unpinnedByMovers(entries map[string]meshcatalog.CatalogEntry, movers []mesh out := make(map[string]meshcatalog.CatalogEntry, len(entries)) for name, e := range entries { out[name] = e - if _, reported := importSetOf(e); !reported { + if _, reported := importSetOf(e); !reported || !moving[name] { continue } var pkgs map[string]string diff --git a/modules/mesh-delivery-indexer/internal/index/movers_test.go b/modules/mesh-delivery-indexer/internal/index/movers_test.go index 1a860e13f..799999ee5 100644 --- a/modules/mesh-delivery-indexer/internal/index/movers_test.go +++ b/modules/mesh-delivery-indexer/internal/index/movers_test.go @@ -74,6 +74,7 @@ func TestMoversOf(t *testing.T) { // I12 (design 47 H2 H-A-532 DMC-1, H-A-547 Q5): an import-form importer of a package a mover of the take-in publishes names // no version for it in the revision's entry, so its build waits for that pipeline's publish; a version-line importer keeps // its pin (its fingerprint takes it), and a take-in that moves no publisher touches nothing. + // 1984/AC8: the import-form importer here is a mover (its fingerprint moved), so its entry is blanked. t.Run("an import-form importer names no version for a package a mover publishes", func(t *testing.T) { after := entries(sdk("2"), importer, reported("a2")) got := unpinnedByMovers(after, moversOf([]meshcatalog.CatalogEntry{sdk("1"), importer, reported("a")}, after, []string{"novox/mesh-sdk"})) @@ -88,4 +89,19 @@ func TestMoversOf(t *testing.T) { t.Errorf("a take-in moving no publisher unpinned %v", got["avahi"].Packages) } }) + // 1984/AC7 (design 47 H2 H-A-628 (1)): an import-form importer that is no mover of the take-in (its fingerprint did not + // move: no package it imports changed) keeps its pin of a package a mover publishes, since no step of that pipeline + // builds it and so no build waits for the publish. + t.Run("an import-form importer that is no mover keeps its pin of a package a mover publishes", func(t *testing.T) { + after := entries(sdk("2"), importer, reported("a")) + movers := moversOf([]meshcatalog.CatalogEntry{sdk("1"), importer, reported("a")}, after, []string{"novox/mesh-sdk"}) + for _, m := range movers { + if m.Module == "avahi" { + t.Fatalf("movers %v hold the importer whose fingerprint did not move", movers) + } + } + if got := unpinnedByMovers(after, movers); got["avahi"].Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.20" { + t.Errorf("the import-form non-mover's packages = %v, want mesh-sdk/go pinned at v0.1.20 as it was", got["avahi"].Packages) + } + }) } -- 2.54.0 From 024c137b949da99e794b6ee4669c577eff38eac7 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 22:00:31 +0100 Subject: [PATCH 2/9] T2 assigner: an empty pin of a run's entry is filled from mesh-builds.published (issue 1984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composer's and the validator's run asks go straight to the Go build seat, never through the builder, and pinsOfEntry dropped a pin the entry names with no version, so the build module refused at once with words that blame the builder. Now each empty pin is filled by asking the seat mesh-builds' verb published of the package's publisher in the step's catalog revision; the version it answers is the pin. No run ask is put with a pin left out: a build not yet published, or a package no build of the revision publishes, ends the run could not run naming the package and the entry (the wait for the publish comes with T3). The assigner requires the meshbuilds contract module and its manifest invokes seat:mesh-builds.published (TestManifest holds it). Tests: TestTheCompositionStepRunsOneAskPerMachine (its stand's revision holds x's publisher; rows "not published" and "no publisher") for 1984/AC9; TestTheValidateStepRefusesAManifestProblemAndACycle, revision 13, for 1984/AC10. Builds: design 47 H2 H-A-628 (2), (5) (hq cea6404c); D4 H-A-192; D5 H-A-204; D7 G §718, A-252, A-451; D8 H §745; D9 H-A-326, H-A-328 --- .../mesh-delivery-assigner/compositionrun.go | 119 ++++++++++++++++-- .../compositionrun_test.go | 52 +++++++- .../mesh-delivery-assigner/validatestep.go | 11 +- .../validatestep_test.go | 20 +++ modules/mesh-delivery-assigner/go.mod | 1 + .../mesh-delivery-assigner/manifest_test.go | 1 + modules/mesh-delivery-assigner/module.json | 1 + 7 files changed, 186 insertions(+), 19 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 2188cd04a..0d9114d14 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -17,6 +17,7 @@ import ( mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -46,6 +47,9 @@ const ( // entryVerbKey and seatDefinitionsKey are the mesh-catalog seat verbs the step reads. entryVerbKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbEntry seatDefinitionsKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbSeatDefinitions + // publishedVerbKey is the build seat's read of whether a package built at a fingerprint is published, what fills a run's + // empty pin (design 47 H-A-328, H2 H-A-628 (2)). + publishedVerbKey = "seat:" + builds.Seat + "." + builds.VerbPublished ) // compositionRun runs a composition step. @@ -221,7 +225,10 @@ type runPrep struct { manifests map[string]composer.Manifest none map[string]string programOf func(node string) (buildstep.RunProgram, string, map[string]string, error) - err error + // publishers are the publishers of each package in the step's catalog revision, what an empty pin is filled from + // (H-A-628 (2)). + publishers map[string]packagePublisher + err error } func (p *runPrep) get(ctx context.Context) error { @@ -231,6 +238,7 @@ func (p *runPrep) get(ctx context.Context) error { p.err = errors.New("the step's catalog revision is not read: " + err.Error()) return } + p.publishers = publishersOf(half.Entries) // the step's own revision, before any branch's entry is laid over it if p.r.newest != nil && p.r.watched != nil { half = acrossBranches(p.step, half, p.r.newest(), p.r.watched) } @@ -283,6 +291,15 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co end(node + ": " + err.Error()) return } + pins, waiting, err := r.filledPins(ctx, "the node-engine's entry "+engineFp, pins, prep.publishers) + if err != nil { + end(node + ": " + err.Error()) + return + } + if len(waiting) > 0 { + end(node + ": " + unpublishedSaid(waiting)) + return + } cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none} if left, err := r.leftOut(node, unlisted); err != nil { end(node + ": " + err.Error()) @@ -322,7 +339,7 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co } a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(), Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the composition of " + node + " by the node-engine at " + program.Commit}, - Packages: pins} // the composer is built against its entry's pins, as every build (H-A-203, H-A-192) + Packages: pins} // the composer is built against its entry's pins, each empty one filled (H-A-203, H-A-192, H-A-628 (2)) if err := r.put(ctx, a); err != nil { end(node + ": its run ask " + ask + " is not put: " + err.Error()) } @@ -737,22 +754,100 @@ func programOfEntry(e meshcatalog.CatalogEntry) (buildstep.RunProgram, error) { return buildstep.RunProgram{Repository: e.Repository, Commit: e.Commit, Dir: dir, Package: composer.Package}, nil } -// pinsOfEntry are the mesh packages' versions an entry pins, the ones it names with a version (H-A-203, H-A-183): the pins -// a run's program is built against, in the form the entry keeps and the builder sends. nil when it pins none. +// pinsOfEntry are the mesh packages' versions an entry names (H-A-203, H-A-183, H-A-204): the pins a run's program is built +// against, in the form the entry keeps and the builder sends, a package it names with no version kept with an empty one, +// never left out, for filledPins to fill (H-A-628 (5)). nil when it names none. func pinsOfEntry(e meshcatalog.CatalogEntry) map[string]string { - var out map[string]string - for path, version := range e.Packages { - if version == "" { - continue + if len(e.Packages) == 0 { + return nil + } + return maps.Clone(e.Packages) +} + +// packagePublisher is the build of a catalog revision that publishes a package: its module, the package's artifact reference +// (:) and the build's fingerprint, what the seat mesh-builds' published is asked of (H-A-328, H-A-628 (2)). +type packagePublisher struct { + module, artifact, fingerprint string +} + +// publishersOf are the publishers of each package the entries of a catalog revision publish, by package name. +func publishersOf(entries map[string]meshcatalog.CatalogEntry) map[string]packagePublisher { + out := map[string]packagePublisher{} + for _, e := range entries { + for _, a := range e.Artifacts { + if a.Package != nil && a.Package.Name != "" && e.Fp != "" { + out[a.Package.Name] = packagePublisher{module: e.Module, artifact: a.Ref, fingerprint: e.Fp} + } } - if out == nil { - out = map[string]string{} - } - out[path] = version } return out } +// unpublished is a package an entry names with no version whose publisher's build in the step's revision is not published. +type unpublished struct { + path string + by packagePublisher +} + +// unpublishedSaid names each package of waiting and the build it waits for. +func unpublishedSaid(waiting []unpublished) string { + var said []string + for _, u := range waiting { + said = append(said, fmt.Sprintf("package %s has no published version: the build of %s at %s (%s) is not published", u.path, u.by.module, u.by.fingerprint, u.by.artifact)) + } + return strings.Join(said, "; ") +} + +// filledPins fills each empty pin of pins, which the entry what names, from the seat mesh-builds' verb published, asked of the +// package's publisher in the step's catalog revision: the version it answers is the pin, never one the assigner computes +// (design 47 H2 H-A-628 (2), H-A-328, H-A-192). It answers the pins with every one it could fill, the packages whose +// publisher's build is not published yet, or an error naming the package, the entry and why it has no version (H-A-628 (5)). +// pins itself is left as it is: one entry's pins serve every machine's run. +func (r *compositionRun) filledPins(ctx context.Context, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, []unpublished, error) { + pins = maps.Clone(pins) + var waiting []unpublished + for _, path := range slices.Sorted(maps.Keys(pins)) { + if pins[path] != "" { + continue + } + by, ok := publishers[path] + if !ok { + return nil, nil, fmt.Errorf("package %s has no version in %s, and no build of the step's catalog revision publishes it", path, what) + } + v, published, err := r.publishedOf(ctx, by) + if err != nil { + return nil, nil, fmt.Errorf("package %s has no version in %s, and whether the build of %s at %s publishes it is not read: %w", path, what, by.module, by.fingerprint, err) + } + if !published { + waiting = append(waiting, unpublished{path: path, by: by}) + continue + } + pins[path] = v + r.logf("package %s, named with no version in %s, is pinned at %s: the build of %s at %s published it (mesh-builds' published, H-A-628)", path, what, v, by.module, by.fingerprint) + } + return pins, waiting, nil +} + +// publishedOf asks the seat mesh-builds' verb published whether by's build is published, answering the pin it is published at +// (vMAJOR.MINOR.PATCH, spec S9) when it is. +func (r *compositionRun) publishedOf(ctx context.Context, by packagePublisher) (string, bool, error) { + body, said, err := r.callRetry(ctx, publishedVerbKey, builds.PublishedInput{Module: by.module, Artifact: by.artifact, Fingerprint: by.fingerprint}) + if err != nil || body == nil { + return "", false, unreadErr(builds.VerbPublished+" did not answer", err, said) + } + a, _, err := builds.DecodePublishedAnswer(body) + if err != nil { + return "", false, fmt.Errorf("%s answered what does not read: %w", builds.VerbPublished, err) + } + if !a.Published { + return "", false, nil + } + if a.Version == "" { + return "", false, fmt.Errorf("%s answered published with no version", builds.VerbPublished) + } + return "v" + a.Version, true, nil +} + // programs answers, per machine, the composer its run builds and the node-engine fingerprint it was chosen from (A-226, A-243, // A-252, §719): where the revision's node-engine entry differs from the trunk's, that build for every machine; else the build the // machine's node-engine runs, as its `running` says, its entry read through mesh-catalog's `entry`; a machine whose node-engine's diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 2d94118fc..a21c45bc0 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -17,6 +17,7 @@ import ( ne "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -48,10 +49,16 @@ type runStand struct { listFault error // verdict, when set, is the composer's verdict of a machine (by node), else the stand's own. verdict func(node string) (composer.Machine, bool) + // publishedAt is the version mesh-builds' published answers for a build fingerprint, none (not published) when absent; + // published are the asks it was given (H-A-628 (2)). + publishedAt map[string]string + published []builds.PublishedInput + // noPublisher: the revision holds no build publishing x/go. + noPublisher bool } func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand { - s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}} + s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}} engine := func(fp, commit string) meshcatalog.CatalogEntry { return meshcatalog.CatalogEntry{Module: "engine", Fp: fp, Repository: "novox/mesh-host", Commit: commit, Path: ".", Serves: []string{ne.Seat + ".composition"}, Manifest: map[string]any{"module": "engine"}, Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.25-" + fp, "git.novox.be/novox/x/go": ""}} @@ -65,7 +72,9 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) * Entries: []meshcatalog.CatalogEntry{engine(revisionEngine, revisionCommit), {Module: "bad", Verdict: mcc.VerdictRefused, Inputs: &meshcatalog.EntryInputs{Problems: []string{"no seat x"}}, Manifest: map[string]any{"module": "bad"}}}, Next: "bad"}, "bad": {Revision: &meshcatalog.CatalogRevision{Revision: 7}, Entries: []meshcatalog.CatalogEntry{{Module: "m", Verdict: mcc.VerdictAccepted, Manifest: map[string]any{"module": "m"}}, - {Module: "lidarr", None: "builders disagree: node", Manifest: map[string]any{"module": "lidarr"}}}}, // no fingerprint (A-470j) + {Module: "lidarr", None: "builders disagree: node", Manifest: map[string]any{"module": "lidarr"}}, // no fingerprint (A-470j) + // x publishes the package the node-engine names with no version (H-A-628 (2)); no manifest, so the case holds none of it. + {Module: "x", Fp: "src2:x1", Artifacts: []meshcatalog.Artifact{{Ref: "x:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/x/go"}}}}}}, } call := func(key string, body any) (json.RawMessage, error) { raw, _ := json.Marshal(body) @@ -77,6 +86,9 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) * return nil, errors.New("asked another revision") } page := pages[in.After] + if s.noPublisher { + page.Entries = slices.DeleteFunc(slices.Clone(page.Entries), func(e meshcatalog.CatalogEntry) bool { return e.Module == "x" }) + } if s.noDefinitions && page.Revision != nil { rev := *page.Revision rev.Definitions = nil @@ -101,6 +113,14 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) * s.mu.Unlock() commit := map[string]string{"src2:e1": commitE1, "src2:e2": commitE2}[in.Fingerprint] return json.Marshal(meshcatalog.EntryAnswer{Entry: engine(in.Fingerprint, commit)}) + case publishedVerbKey: + var in builds.PublishedInput + _ = json.Unmarshal(raw, &in) + s.mu.Lock() + s.published = append(s.published, in) + v, ok := s.publishedAt[in.Fingerprint] + s.mu.Unlock() + return json.Marshal(builds.PublishedAnswer{Published: ok, Version: v}) } return nil, errors.New("no such verb " + key) } @@ -187,11 +207,31 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { if s.asks["g14"].Run.Program.Commit != commitE2 { t.Errorf("g14's composer is built at %s, want the build its node-engine runs", s.asks["g14"].Run.Program.Commit) } - // Each composer is built against the pins of the node-engine entry it is built from, a pin with no version left out - // (H-A-203, H-A-192). + // Each composer is built against the pins of the node-engine entry it is built from (H-A-203, H-A-192); 1984/AC9: the one + // it names with no version is filled from mesh-builds' published of its publisher's build in the step's revision, at the + // version that answers, never left out (H-A-628 (2), (5)). for node, fp := range map[string]string{"ace": "src2:e1", "g14": "src2:e2"} { - if got := s.asks[node].Packages; len(got) != 1 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.25-"+fp { - t.Errorf("%s's composer is built against the pins %v; want its entry's", node, got) + if got := s.asks[node].Packages; len(got) != 2 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.25-"+fp || got["git.novox.be/novox/x/go"] != "v0.1.9" { + t.Errorf("%s's composer is built against the pins %v; want its entry's, x/go at v0.1.9 from published", node, got) + } + } + if len(s.published) == 0 || s.published[0] != (builds.PublishedInput{Module: "x", Artifact: "x:go", Fingerprint: "src2:x1"}) { + t.Errorf("published was asked %+v, want x's build of x:go at src2:x1 in the step's revision", s.published) + } + // 1984/AC9: no run ask is put with a pin left out: x's build not published, or no build of the revision publishing x/go, + // ends the run could not run naming the package and the entry, never the builder (H-A-628 (5)). + for name, c := range map[string]struct { + stand func(*runStand) + said string + }{ + "not published": {func(s *runStand) { s.publishedAt = nil }, "package git.novox.be/novox/x/go has no published version: the build of x at src2:x1 (x:go) is not published"}, + "no publisher": {func(s *runStand) { s.publishedAt = nil; s.noPublisher = true }, "package git.novox.be/novox/x/go has no version in the node-engine's entry src2:e1, and no build of the step's catalog revision publishes it"}, + } { + u := newRunStand(t, "src2:e1", "src2:e1", "d1") + c.stand(u) + if out := u.r.run(context.Background(), "ask-step", step); out.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(out.Said, c.said) || + strings.Contains(out.Said, "the builder pins or waits") || len(u.asks) != 0 { + t.Errorf("%s: the step came to %+v with %d run asks put, want could not run saying %q and none put", name, out, len(u.asks), c.said) } } if req.Depth != composer.DepthCompose || req.BlameTries != 20 || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase || diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index c513565f1..54a609a12 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -288,6 +288,15 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh return } program.Package = validatorPackage + pins, waiting, err := r.filledPins(ctx, "the manifest validator's entry "+entry.Fp, pinsOfEntry(entry), publishersOf(half.Entries)) + if err != nil { + couldNot(err.Error()) + return + } + if len(waiting) > 0 { + couldNot(unpublishedSaid(waiting)) + return + } seats, list, err := r.validateSeats(ctx, ask, half.Revision.Definitions) if err != nil { couldNot(err.Error()) @@ -334,7 +343,7 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh } a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(), Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the manifest validator of " + step.Pipeline + " at " + program.Commit}, - Packages: pinsOfEntry(entry)} // the validator is built against its entry's pins at the step's revision (H-A-203, H-A-192, H-A-205) + Packages: pins} // the validator is built against its entry's pins at the step's revision, each empty one filled (H-A-203, H-A-192, H-A-205, H-A-628 (2)) if err := r.put(ctx, a); err != nil { couldNot("its run ask " + ask + " is not put: " + err.Error()) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go index cbe180e69..867f60cbb 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go @@ -12,6 +12,7 @@ import ( "time" mcc "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + builds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -32,6 +33,8 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { indexer := meshcatalog.CatalogEntry{Module: "indexer", Repository: "novox/mesh-delivery", Commit: commitE3, Path: "modules/mesh-delivery-indexer", Fp: "src2:ix", Serves: []string{"seat:" + meshcatalog.Seat + ".revision"}, Manifest: map[string]any{"module": "indexer"}, ManifestDigest: "d-ix", Packages: map[string]string{"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient": "v0.1.4"}} + unpinned := indexer + unpinned.Packages = map[string]string{"git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient": "v0.1.4", "git.novox.be/novox/mesh-sdk/go": ""} entry := func(module, digest string, edges ...meshcatalog.Edge) meshcatalog.CatalogEntry { return meshcatalog.CatalogEntry{Module: module, Manifest: map[string]any{"module": module, "d": digest}, ManifestDigest: digest, Edges: edges} } @@ -41,6 +44,9 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { 9: {indexer, entry("a", "d-a", meshcatalog.Edge{From: "a:x", To: "b:y", Kind: 3}, meshcatalog.Edge{From: "b:y", To: "a:x", Kind: 3}), entry("b", "d-b")}, 3: {indexer}, 12: {indexer, entry("web", "d-web-2"), entry("db", "d-db")}, + // 1984/AC10: the validator's entry names mesh-sdk/go with no version, and mesh-sdk's build in the revision publishes it. + 13: {unpinned, entry("web", "d-web-2"), entry("db", "d-db"), {Module: "mesh-sdk", Fp: "src2:sdk1", + Artifacts: []meshcatalog.Artifact{{Ref: "mesh-sdk:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}}, } // base is the newest kept revision below n, as the take-in names it; none below the first. Revision 12 names 7 with 8 to 11 // never kept, so a case before read as the number minus one could not run (H-A-154). @@ -74,6 +80,13 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { Definitions: defs}, Entries: entries}) case seatDefinitionsKey: return json.Marshal(meshcatalog.SeatDefinitionsAnswer{Found: true, Entry: &meshcatalog.SeatDefinitionsAnswerEntry{Seat: "s1", Digest: "sd", Definition: map[string]any{"seat": "s1"}}}) + case publishedVerbKey: + var in builds.PublishedInput + _ = json.Unmarshal(raw, &in) + if in != (builds.PublishedInput{Module: "mesh-sdk", Artifact: "mesh-sdk:go", Fingerprint: "src2:sdk1"}) { + return nil, errors.New("published asked of another build") + } + return json.Marshal(builds.PublishedAnswer{Published: true, Version: "0.1.36"}) } return nil, errors.New("no such verb " + key) } @@ -217,4 +230,11 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { } else if web := requests[2].Cases[1].Manifests["web"]; len(requests[2].Cases[1].Manifests) != 3 || !strings.Contains(string(web.Raw), "d-web-2") { t.Errorf("the case before of revision 12 is %+v, want base 7's manifests", requests[2].Cases[1].Manifests) } + // 1984/AC10 (H-A-628 (2), (5)): the validator's pin with no version is filled from mesh-builds' published of its publisher's + // build in the step's revision, never left out. + if o := r.validate(ctx, "ask-unpinned", step("web", 13)); o.Outcome != meshwants.StepEndedOutcomeFailed || len(asks) != 4 { + t.Errorf("a validator entry with an empty pin ended %+v (%d validator asks), want it judged", o, len(asks)) + } else if got := asks[3].Packages; len(got) != 2 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" || got["git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"] != "v0.1.4" { + t.Errorf("the validator is built against the pins %v; want mesh-sdk/go at v0.1.36 from published beside its entry's", got) + } } diff --git a/modules/mesh-delivery-assigner/go.mod b/modules/mesh-delivery-assigner/go.mod index f28e78db2..135a432f3 100644 --- a/modules/mesh-delivery-assigner/go.mod +++ b/modules/mesh-delivery-assigner/go.mod @@ -8,6 +8,7 @@ require ( git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshhandacts v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-contracts/provisioning/go/clients/meshprovisionerclient v0.0.0-00010101000000-000000000000 + git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants v0.0.0-00010101000000-000000000000 git.novox.be/novox/mesh-sdk/go v0.0.0-00010101000000-000000000000 github.com/nats-io/nats-server/v2 v2.11.17 diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index c119e8b37..bf784b1f1 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -158,6 +158,7 @@ func TestManifest(t *testing.T) { } if want := []string{"mesh-delivery-indexer.manifests", "mesh-delivery-indexer.modules", buckets.TellerModule + "." + buckets.AnswersReadTool, // A-175, A-178: the teller's answers' first view + "seat:mesh-builds.published", // design 47 H2 H-A-628 (2), H-A-328: a run's empty pin filled from its publisher's build (1984/AC9, AC10) "seat:mesh-catalog.entry", "seat:mesh-catalog.registrations", "seat:mesh-catalog.revision", "seat:mesh-catalog.seat-definitions", // ADR 0636 §4: the seat list "seat:mesh-catalog.seat-list", // design 47 H2 H-A-443: the validate step's trunk seat list, in chunks "seat:mesh-conditions.conditions", // design 47 G §706: the conditions read at each judging of an outside wait diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index 1bd9bbdfe..b5974c67e 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -69,6 +69,7 @@ "mesh-delivery-indexer.manifests", "mesh-delivery-indexer.modules", "mesh-delivery-teller.teller_read_answers", + "seat:mesh-builds.published", "seat:mesh-catalog.entry", "seat:mesh-catalog.registrations", {"verb": "seat:mesh-catalog.revision", "fields": ["none-yet"]}, -- 2.54.0 From 4bcc12d7b15296e3528d348ec6107b417505e9d8 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 22:35:43 +0100 Subject: [PATCH 3/9] T3 assigner: a run waits for its package's publish, bounded, then could not run naming it (issue 1984) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit T2 ended a composition or validate run at once when its entry named a package whose publisher's build in the step's revision was not published yet. Now the run waits: it reads mesh-builds' published first and again at each package-published heard (and at each bind of the consumer); the run's value names the package and the time its wait began in `waits`; its bound bound. is armed for what is left of the new setting package-wait-minutes (1 to 120, default 10). Past the bound the run ends could not run, "package has no published version within (package-wait-minutes)", never the builder's words. `waits` and the bound go when the run ask is put (an ask in the queue has no clock) or the run ends. Every step reading the run says the phase fetch while it holds `waits`, its journal naming the package, and run once none does. At the assigner's start a run holding `waits` and no program ends past its bound, or has its bound armed again for what is left and its whole start run again. A run with no publisher still ends at once (principle 3). The seat mesh-wants' CompositionRun gains `waits` {package, since}, its form raised to 3 as a field added (§780, H-A-352 (3)); the Go and TypeScript contracts regenerated by seatgen. The assigner consumes mesh-builds.package-published. Tests: TestTheCompositionStepRunsOneAskPerMachine (rows: the wait, its `waits` and bound, the phase fetch then run, the pin after the publish with `waits` and the bound gone at the put, past the bound) for 1984/AC9; TestACompositionRunIsOneKeyPerCandidateAndMachine/settings; TestManifest; TestTheCompositionStepComposesEachMachineThroughTheBuildSeat extended (the wait and the publish event, a restart during the wait, a run past its bound at the restart and one past it while running) for 1984/AC11. Builds: design 47 H2 H-A-628 (3), (4), (5) (hq 8aa70271); H-A-629 (1), (2), (3) (hq 8aa70271); D4 H-A-192; D9 H-A-326, H-A-328; G §719, §720; H2 §780 with H-A-352 (3) --- .../compositionbounds.go | 22 +++ .../mesh-delivery-assigner/compositionrun.go | 166 +++++++++++++++-- .../compositionrun_test.go | 140 ++++++++++++++- .../mesh-delivery-assigner/compositionruns.go | 89 +++++++++- .../compositionruns_test.go | 6 +- .../compositionstep_integration_test.go | 168 ++++++++++++++++-- .../cmd/mesh-delivery-assigner/main.go | 13 +- .../mesh-delivery-assigner/validatestep.go | 16 +- .../mesh-delivery-assigner/manifest_test.go | 11 +- modules/mesh-delivery-assigner/module.json | 20 ++- .../go/seats/meshwants/contract.go | 16 +- .../seats/mesh-wants/seat.json | 21 ++- .../ts/seats/meshwants/index.d.ts | 10 ++ 13 files changed, 649 insertions(+), 49 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go index 1fb929de0..a8e2ce7ac 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go @@ -193,6 +193,10 @@ func (r *compositionRuns) expired(boundKey string) { if err != nil || !ok || run.Ended != nil { return } + if setting == "composition-step-bound" && run.Waits != nil { // the bound a wait for a package's publish armed (H-A-628 (4)) + r.waitExpired(boundKey, key, run) + return + } // The marker of an expiry holds no value (A-470o): the run ends only while its bound is still absent when read again, and // the run is taken for bound., untaken for untaken., so an expiry heard after a bound was armed again, or of a run replaced // since, ends nothing. @@ -229,6 +233,24 @@ func (r *compositionRuns) expired(boundKey string) { } } +// waitExpired ends a run whose wait for a package's publish passed its bound, the expiry of the bound key bound. the +// wait armed (design 47 H2 H-A-628 (3), (4)): could not run naming the package, read from the run's value (H-A-629 (1)). Its run +// ask is not put yet, so none is dropped; a bound armed again since (the marker holds no value, A-470o) ends nothing. +func (r *compositionRuns) waitExpired(boundKey, key string, run meshwants.CompositionRun) { + _, _, armed, err := r.boundOf(boundKey) + if err != nil { + r.logf("the bound %s is not read again, so its expiry ends nothing: %v", boundKey, err) + return + } + if armed { + r.logf("the expiry of %s ends nothing: the bound is armed again (A-470o)", boundKey) + return + } + if _, err := r.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) + } +} + // endRun ends a run (end) and clears its bounds: the untaken key's readers said superseded, both bound keys deleted. func (r *compositionRuns) endRun(key, ask, outcome, said string, verdict map[string]any) (bool, error) { return r.endRunOf(key, ask, outcome, said, verdict, r.untaken(key, ask)) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 0d9114d14..75debacea 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -142,11 +142,10 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step } // read waits for the end of each run of keys and judges the step of module from them, naming in its progress and its end the -// runs it reads and their asks (§723, §729). +// runs it reads and their asks (§723, §729); while a run it reads waits for a package's publish its phase is fetch (H-A-629 (2)). func (r *compositionRun) read(ctx context.Context, module string, keys []string, ends []machineEnd) stepOutcome { setShared(ctx, r.runs.sharedOf(keys, nil)) - setPhase(ctx, meshwants.StepProgressEventPhaseRun) - runs := r.runs.await(ctx, keys) + runs := r.runs.awaitEach(ctx, keys, r.sayingWaits(ctx, "the composition step of "+module)) setPhase(ctx, meshwants.StepProgressEventPhaseReport) for _, key := range keys { ends = append(ends, judgeRun(module, runs[key])) @@ -291,13 +290,11 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co end(node + ": " + err.Error()) return } - pins, waiting, err := r.filledPins(ctx, "the node-engine's entry "+engineFp, pins, prep.publishers) - if err != nil { - end(node + ": " + err.Error()) - return - } - if len(waiting) > 0 { - end(node + ": " + unpublishedSaid(waiting)) + pins, said, ok := r.awaitPins(ctx, key, ask, "the node-engine's entry "+engineFp, pins, prep.publishers) + if !ok { + if said != "" { // else the run ended or was replaced while it waited, or the step's wait ended + end(node + ": " + said) + } return } cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none} @@ -332,6 +329,7 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: engineFp} c.Input = digest + c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) return true }); err != nil { end(node + ": the run's program and input are not written: " + err.Error()) @@ -828,6 +826,154 @@ func (r *compositionRun) filledPins(ctx context.Context, what string, pins map[s return pins, waiting, nil } +// awaitPins fills the empty pins of the entry what names for the run of ask under key (filledPins) and, while a package's +// publisher's build is not published, waits for it (design 47 H2 H-A-628 (3), (4); H-A-629 (1), (3)): the run's value names the +// package in `waits`, the time its wait began kept across a start taken up again; the run's bound key bound. is armed +// for what is left of package-wait-minutes from that time, never in full again; published is read first and again at each +// package-published heard (H-A-326), and the run's end is heard through its own state, its bound's expiry among them. It answers +// the pins, every one filled, the bound key deleted again (an ask in the queue has no clock, §720), and true; else false and why the +// run could not run, or no words when the run ended or was replaced meanwhile, or ctx ended. +func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, string, bool) { + armed, said := false, "" + for { + published := r.runs.publishWake() // taken before the read, so a publish heard meanwhile wakes the next one + filled, waiting, err := r.filledPins(ctx, what, pins, publishers) + if err != nil { + return nil, err.Error(), false + } + if len(waiting) == 0 { + if armed { + if err := r.runs.clearBounds(key, ask, runBoundPrefix); err != nil { + r.logf("the bound of the composition run %s's wait is not deleted: %v", key, err) + } + r.logf("the composition run %s waits no more: every package %s names is published", key, what) + } + return filled, "", true + } + path := waiting[0].path + since, held, err := r.runs.waitFor(key, ask, path) + if err != nil { + return nil, "its wait for package " + path + " is not written: " + err.Error(), false + } + if !held { + return nil, "", false + } + left := since.Add(r.runs.set.packageWait).Sub(r.now()) + if left <= 0 { + return nil, r.runs.pastWaitSaid("", path), false + } + if !armed { + stands, err := r.runs.armBound(runBoundPrefix, key, ask, wholeSeconds(left)) + if err != nil { + return nil, "the bound of its wait for package " + path + " is not armed: " + err.Error(), false + } + if !stands { + return nil, "", false + } + armed = true + } + if path != said { + said = path + r.logf("the composition run %s waits for package %s, named with no version in %s: %s; %s ends its wait at %s", key, path, what, + unpublishedSaid(waiting), packageWaitSetting, since.Add(r.runs.set.packageWait).Format(time.RFC3339)) + } + for woke := false; !woke; { + changed := r.runs.wake() + run, _, ok, err := r.runs.read(key) + if err == nil && (!ok || run.Ended != nil || run.Ask != ask) { + return nil, "", false + } + select { + case <-ctx.Done(): + return nil, "", false + case <-published: + woke = true + case <-changed: + } + } + } +} + +// wholeSeconds is d rounded up to a whole second, the bus's least step of a key's time to live: what is left of a wait's bound +// is never refused as a time to live below a second. +func wholeSeconds(d time.Duration) time.Duration { + if w := d.Truncate(time.Second); w < d { + return w + time.Second + } + return d +} + +// sayingWaits is what a step reading runs says of them at each read (design 47 H2 H-A-629 (2)): the phase fetch while a run it +// reads holds `waits`, its journal naming the package, and run once none does. +func (r *compositionRun) sayingWaits(ctx context.Context, what string) func(map[string]meshwants.CompositionRun) { + said := "" + return func(runs map[string]meshwants.CompositionRun) { + waits, of := "", "" + for _, key := range slices.Sorted(maps.Keys(runs)) { + if run := runs[key]; run.Ended == nil && run.Waits != nil { + waits, of = run.Waits.Package, key + break + } + } + if waits == "" { + setPhase(ctx, meshwants.StepProgressEventPhaseRun) + } else { + setPhase(ctx, meshwants.StepProgressEventPhaseFetch) + } + if waits != said { + if waits != "" { + r.logf("%s says fetch: the composition run %s waits for package %s", what, of, waits) + } else { + r.logf("%s says run: no composition run it reads waits for a package", what) + } + said = waits + } + } +} + +// takeUpWaits takes up, at the assigner's start, each run still waiting for a package's publish, its value holding `waits` and +// no program (design 47 H2 H-A-629 (3)): past the time its wait began plus package-wait-minutes it ends could not run naming the +// package; before it, its bound key is armed again for what is left and its whole start runs again, a compose-candidate ask of the +// node and its kept request, which reads published first, as its first reader's step. +func (r *compositionRun) takeUpWaits(ctx context.Context) { + all, err := r.runs.keys() + if err != nil { + r.logf("composition-runs: the runs standing at the start are not read, so no run waiting for a package is taken up: %v", err) + return + } + for _, key := range all { + if !isRunKey(key) { + continue + } + run, _, ok, err := r.runs.read(key) + if err != nil || !ok || run.Ended != nil || run.Waits == nil || run.Program != nil { + continue + } + left := run.Waits.Since.Add(r.runs.set.packageWait).Sub(r.now()) + if left <= 0 { + if _, err := r.runs.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.runs.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) + } + continue + } + if _, err := r.runs.armBound(runBoundPrefix, key, run.Ask, wholeSeconds(left)); err != nil { + r.logf("the bound of the composition run %s's wait is not armed again: %v", key, err) + } + if len(run.Readers) == 0 { + r.logf("the composition run %s waiting for package %s has no reader, so its start does not run again; its bound ends it", key, run.Waits.Package) + continue + } + first := run.Readers[0] + r.logf("the composition run %s, waiting for package %s since %s, is taken up again: its start runs again (H-A-629 (3))", key, run.Waits.Package, + run.Waits.Since.Format(time.RFC3339)) + if isValidateRun(run) { + go r.startValidate(ctx, key, run, stepRunOf(first)) + } else { + go r.start(ctx, key, run, &runPrep{r: r, step: stepRunOf(first)}, first.ID) + } + } +} + // publishedOf asks the seat mesh-builds' verb published whether by's build is published, answering the pin it is published at // (vMAJOR.MINOR.PATCH, spec S9) when it is. func (r *compositionRun) publishedOf(ctx context.Context, by packagePublisher) (string, bool, error) { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index a21c45bc0..2a907854d 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "git.novox.be/novox/mesh-sdk/go/process" "maps" "slices" @@ -57,6 +58,48 @@ type runStand struct { noPublisher bool } +// logLines is a journal a test awaits lines of: each write wakes the waiter, no sleep stands in for it. +type logLines struct { + mu sync.Mutex + text []string + grew chan struct{} +} + +func newLogLines() *logLines { return &logLines{grew: make(chan struct{})} } + +func (l *logLines) logf(format string, a ...any) { + l.mu.Lock() + defer l.mu.Unlock() + l.text = append(l.text, fmt.Sprintf(format, a...)) + close(l.grew) + l.grew = make(chan struct{}) +} + +// await returns once n lines hold words, and fails the test when they did not come within 10 s. +func (l *logLines) await(t *testing.T, words string, n int) { + t.Helper() + deadline := time.After(10 * time.Second) + for { + l.mu.Lock() + count, grew := 0, l.grew + for _, line := range l.text { + if strings.Contains(line, words) { + count++ + } + } + text := strings.Join(l.text, "\n") + l.mu.Unlock() + if count >= n { + return + } + select { + case <-grew: + case <-deadline: + t.Fatalf("no %d lines %q in the journal within 10 s:\n%s", n, words, text) + } + } +} + func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand { s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}} engine := func(fp, commit string) meshcatalog.CatalogEntry { @@ -218,14 +261,13 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { if len(s.published) == 0 || s.published[0] != (builds.PublishedInput{Module: "x", Artifact: "x:go", Fingerprint: "src2:x1"}) { t.Errorf("published was asked %+v, want x's build of x:go at src2:x1 in the step's revision", s.published) } - // 1984/AC9: no run ask is put with a pin left out: x's build not published, or no build of the revision publishing x/go, - // ends the run could not run naming the package and the entry, never the builder (H-A-628 (5)). + // 1984/AC9: no run ask is put with a pin left out: no build of the revision publishing x/go ends the run could not run at once, + // naming the package and the entry, never the builder (H-A-628 (5)). for name, c := range map[string]struct { stand func(*runStand) said string }{ - "not published": {func(s *runStand) { s.publishedAt = nil }, "package git.novox.be/novox/x/go has no published version: the build of x at src2:x1 (x:go) is not published"}, - "no publisher": {func(s *runStand) { s.publishedAt = nil; s.noPublisher = true }, "package git.novox.be/novox/x/go has no version in the node-engine's entry src2:e1, and no build of the step's catalog revision publishes it"}, + "no publisher": {func(s *runStand) { s.publishedAt = nil; s.noPublisher = true }, "package git.novox.be/novox/x/go has no version in the node-engine's entry src2:e1, and no build of the step's catalog revision publishes it"}, } { u := newRunStand(t, "src2:e1", "src2:e1", "d1") c.stand(u) @@ -234,6 +276,96 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { t.Errorf("%s: the step came to %+v with %d run asks put, want could not run saying %q and none put", name, out, len(u.asks), c.said) } } + // 1984/AC9; H-A-628 (3), (4); H-A-629 (1), (2): x's build not published yet: each run waits, its value naming x/go in `waits` + // with the time its wait began, its bound bound. armed for package-wait-minutes, the step saying fetch naming the + // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the + // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. + for _, publish := range []bool{true, false} { + u := newRunStand(t, "src2:e1", "src2:e1", "d1") + u.publishedAt = nil + journal := newLogLines() + u.r.logf = journal.logf + atPut := map[string]string{} // by run key: what stood of its wait as its run ask was put + put := u.r.put + u.r.put = func(ctx context.Context, a buildstep.StepAsk) error { + key, run, _ := u.runs.keyOfAsk(a.ID) + bound, _, _ := u.runs.kv.get(runBoundPrefix + key) + u.mu.Lock() + atPut[key] = fmt.Sprintf("waits %v, bound %s", run.Waits, bound) + u.mu.Unlock() + return put(ctx, a) + } + phase := &stepPhase{} + done := make(chan stepOutcome, 1) + go func() { done <- u.r.run(context.WithValue(context.Background(), phaseKey{}, phase), "ask-step", step) }() + journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) + journal.await(t, "the composition step of m says fetch: the composition run", 1) + if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch { + t.Errorf("waiting, the step says the phase %q, want fetch", got) + } + kv := u.runs.kv.(*runsMem) + var keys []string + all, _ := u.runs.keys() + for _, key := range all { + if isRunKey(key) { + keys = append(keys, key) + } + } + for _, key := range keys { + run, _, _, _ := u.runs.read(key) + kv.mu.Lock() + ttl := kv.ttl[runBoundPrefix+key] + kv.mu.Unlock() + if len(keys) != 2 || run.Waits == nil || run.Waits.Package != "git.novox.be/novox/x/go" || run.Waits.Since.IsZero() || ttl <= 9*time.Minute || ttl > 10*time.Minute { + t.Errorf("the waiting run %s of %v holds %+v, its bound %s; want x/go in waits and package-wait-minutes' bound", key, keys, run.Waits, ttl) + } + } + if !publish { + for _, key := range keys { + kv.expire(runBoundPrefix + key) + u.runs.expired(runBoundPrefix + key) + } + } else { + u.mu.Lock() + u.publishedAt = map[string]string{"src2:x1": "0.1.9"} + u.mu.Unlock() + u.runs.heardPublished() + } + var out stepOutcome + select { + case out = <-done: + case <-time.After(10 * time.Second): + t.Fatalf("publish %v: the waiting step said no end", publish) + } + journal.await(t, "the composition step of m says run", 1) + if !publish { + for _, key := range keys { + if run, _, _, _ := u.runs.read(key); run.Ended == nil || run.Waits != nil { + t.Errorf("past its bound the run %s holds ended %v, waits %+v; want it ended and its wait gone", key, run.Ended, run.Waits) + } + } + for _, node := range []string{"ace", "g14"} { + if want := node + ": package git.novox.be/novox/x/go has no published version within 10m0s (package-wait-minutes)"; out.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + !strings.Contains(out.Said, want) || strings.Contains(out.Said, "the builder pins or waits") || len(u.asks) != 0 { + t.Errorf("past its bound the step came to %+v with %d run asks put, want could not run saying %q", out, len(u.asks), want) + } + } + continue + } + if out.Outcome != meshwants.StepEndedOutcomeFailed || !strings.Contains(out.Said, "g14 does not compose") || len(u.asks) != 2 { + t.Errorf("after the publish the step came to %+v with %d run asks", out, len(u.asks)) + } + for node, a := range u.asks { + if a.Packages["git.novox.be/novox/x/go"] != "v0.1.9" { + t.Errorf("after the publish %s's composer is built against %v, want x/go at v0.1.9", node, a.Packages) + } + } + for _, key := range keys { + if got := atPut[key]; got != "waits , bound " { + t.Errorf("as the run ask of %s was put its wait stood: %s; want waits and the bound gone (§720: an ask in the queue has no clock)", key, got) + } + } + } if req.Depth != composer.DepthCompose || req.BlameTries != 20 || len(req.Machines) != 1 || req.Machines[0] != "ace" || len(req.Cases) != 1 || req.Cases[0].Name != changeCase || string(req.Input) != `{"node":"ace"}` || len(req.Seats) != 1 || string(req.Seats[0]) != `{"seat":"s1"}` { t.Errorf("the request of ace %+v", req) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index 22d713664..9aab4f502 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -60,16 +60,35 @@ type runSettings struct { kept, stepBound, untaken time.Duration // blameTries is blame-tries, carried in each run's request (§721). blameTries int + // packageWait is package-wait-minutes: how long a run waits for the publish of a package its entry names with no version + // before it ends could not run naming the package, counted from the time its wait began (design 47 H2 H-A-628 (3), H-A-629 (3)). + packageWait time.Duration } // defaultRunSettings are the settings' defaults, as the manifest gives them. -var defaultRunSettings = runSettings{capBytes: 16 << 20, kept: 24 * time.Hour, stepBound: 30 * time.Minute, untaken: 24 * time.Hour, blameTries: 20} +var defaultRunSettings = runSettings{capBytes: 16 << 20, kept: 24 * time.Hour, stepBound: 30 * time.Minute, untaken: 24 * time.Hour, blameTries: 20, + packageWait: 10 * time.Minute} + +// packageWaitUnit is the unit of the setting package-wait-minutes, a minute; the whole test sets a shorter one, so a run's wait +// passes its bound within the test (as tierBoundUnit). +var packageWaitUnit = time.Minute + +// packageWaitSetting names the setting package-wait-minutes in a run's words. +const packageWaitSetting = "package-wait-minutes" // runSettingsOf reads the settings composition-runs-cap-mib, composition-runs-kept, composition-step-bound, -// run-untaken-bound and blame-tries from the files the environment names (A-469x, as outsideSettings): a missing or empty -// file is its default; a content that is no positive whole number or Go duration is an error naming the file. +// run-untaken-bound, blame-tries and package-wait-minutes from the files the environment names (A-469x, as outsideSettings): a +// missing or empty file is its default; a content that is no positive whole number or Go duration is an error naming the file. func runSettingsOf(getenv func(string) string) (runSettings, error) { s := defaultRunSettings + s.packageWait = 10 * packageWaitUnit + minutes, err := settingFile(getenv("MESH_ASSIGNER_PACKAGE_WAIT_FILE")) + if err != nil { + return s, err + } + if minutes > 0 { + s.packageWait = time.Duration(minutes) * packageWaitUnit + } mib, err := settingFile(getenv("MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE")) if err != nil { return s, err @@ -255,6 +274,9 @@ type compositionRuns struct { mu sync.Mutex // changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again. changed chan struct{} + // published is closed and replaced at each package-published of the seat mesh-builds heard (heardPublished): a run waiting for + // a package's publish asks published again (design 47 H2 H-A-628 (3), H-A-326). + published chan struct{} // seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is // being written at that moment, so every lookup takes these beside it (keys). seen map[string]bool @@ -268,7 +290,57 @@ type compositionRuns struct { } func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns { - return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{})} + return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: make(chan struct{})} +} + +// heardPublished wakes every run waiting for a package's publish, at the seat mesh-builds' package-published heard and at each +// bind of the assigner's consumer (an event said before it was made is not delivered): each reads published again, the event +// only its second path (design 47 H2 H-A-628 (3); H-A-326, H-A-328). +func (r *compositionRuns) heardPublished() { + r.mu.Lock() + close(r.published) + r.published = make(chan struct{}) + r.mu.Unlock() +} + +// publishWake is closed at the next package-published heard. +func (r *compositionRuns) publishWake() <-chan struct{} { + r.mu.Lock() + defer r.mu.Unlock() + return r.published +} + +// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time +// its wait began is kept where the run holds one already (a start taken up again, H-A-629 (3)), else it is now. It answers that +// time, and false when the key holds another run, or the run ended or has its program. +func (r *compositionRuns) waitFor(key, ask, path string) (time.Time, bool, error) { + var since time.Time + held := false + _, _, err := r.change(key, func(c *meshwants.CompositionRun) bool { + if held = c.Ask == ask && c.Ended == nil && c.Program == nil; !held { + return false + } + since = r.now().UTC() + if c.Waits != nil { + since = c.Waits.Since + if c.Waits.Package == path { + return false + } + } + c.Waits = &meshwants.CompositionRunWaits{Package: path, Since: since} + return true + }) + return since, held, err +} + +// pastWaitSaid is the end of a run of machine whose wait for the publish of the package path passed package-wait-minutes (design +// 47 H2 H-A-628 (3)). +func (r *compositionRuns) pastWaitSaid(machine, path string) string { + said := fmt.Sprintf("package %s has no published version within %s (%s)", path, r.set.packageWait, packageWaitSetting) + if machine != "" { + said = machine + ": " + said + } + return said } // heard takes a change of the state from its watch (a module watches its own state, principle 1). @@ -642,6 +714,7 @@ func (r *compositionRuns) end(key, ask, outcome, said string, verdict map[string } at := r.now().UTC() c.Ended, c.Outcome, c.Said, c.Verdict = &at, outcome, said, verdict + c.Waits = nil // a run's wait ends with it (H-A-629 (1)) ended = true return true }) @@ -702,6 +775,11 @@ func (r *compositionRuns) heardEnd(e buildstep.StepEnded, read func(buildstep.St // await waits until each run of keys has ended, through the state's changes heard, or ctx ends: it answers each run as it // stands then; a key gone could not run. func (r *compositionRuns) await(ctx context.Context, keys []string) map[string]meshwants.CompositionRun { + return r.awaitEach(ctx, keys, nil) +} + +// awaitEach is await, handing each read of the runs, as they stand, to each before it waits again; nil hands none. +func (r *compositionRuns) awaitEach(ctx context.Context, keys []string, each func(map[string]meshwants.CompositionRun)) map[string]meshwants.CompositionRun { out := map[string]meshwants.CompositionRun{} for { wake := r.wake() @@ -722,6 +800,9 @@ func (r *compositionRuns) await(ctx context.Context, keys []string) map[string]m } out[key] = run } + if each != nil { + each(out) + } if !open { return out } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go index 7a0ccf151..61dbef4fa 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns_test.go @@ -324,7 +324,8 @@ func TestACompositionRunIsOneKeyPerCandidateAndMachine(t *testing.T) { t.Run("settings", func(t *testing.T) { dir := t.TempDir() files := map[string]string{"MESH_ASSIGNER_COMPOSITION_RUNS_CAP_MIB_FILE": "8", "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "2h", - "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "", "MESH_ASSIGNER_BLAME_TRIES_FILE": "5"} + "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "2s", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "", "MESH_ASSIGNER_BLAME_TRIES_FILE": "5", + "MESH_ASSIGNER_PACKAGE_WAIT_FILE": "3"} // package-wait-minutes in minutes (design 47 H2 H-A-628 (3)) env := map[string]string{} for name, content := range files { p := filepath.Join(dir, name) @@ -334,7 +335,8 @@ func TestACompositionRunIsOneKeyPerCandidateAndMachine(t *testing.T) { env[name] = p } s, err := runSettingsOf(func(k string) string { return env[k] }) - if err != nil || s.capBytes != 8<<20 || s.kept != 2*time.Hour || s.stepBound != 2*time.Second || s.untaken != 24*time.Hour || s.blameTries != 5 { + if err != nil || s.capBytes != 8<<20 || s.kept != 2*time.Hour || s.stepBound != 2*time.Second || s.untaken != 24*time.Hour || s.blameTries != 5 || + s.packageWait != 3*time.Minute { t.Errorf("settings %+v %v", s, err) } _ = os.WriteFile(env["MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE"], []byte("30"), 0o600) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go index 51528de73..c89da0004 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "strings" + "sync/atomic" "testing" "time" @@ -16,6 +17,7 @@ import ( "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads" "git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs" + meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" @@ -31,8 +33,25 @@ import ( // machine on the Go build seat's check queue under its name, its program the node-engine build each machine runs; the stand-in // build seat reads each request by the seat mesh-wants' verb input in chunks and says its step-ended with the composer's verdict; // the step's step-ended fails naming the machine that does not compose, warns of the machine away, and no input stays kept. +// 1984/AC11 (design 47 H2 H-A-628 (2) to (5), H-A-629): the node-engine's entry names the package x/go with no version, and x's +// build in the step's revision publishes it: each run waits while the seat mesh-builds' published answers not published, and +// puts its run ask with x/go at the version published once the package-published is heard; a restart during the wait takes the +// runs up, the one past package-wait-minutes ending could not run naming the package, the other's start run again composing +// after a publish heard while the assigner was down; a run whose wait passes its bound ends could not run naming the package +// and the bound, never "no pin … the builder pins or waits", with no run ask put. func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) { b := startBed(t, "") + t.Cleanup(func() { + if t.Failed() { + b.journal.mu.Lock() + t.Log(b.journal.text.String()) + b.journal.mu.Unlock() + } + }) + packageWaitUnit = time.Second // package-wait-minutes in seconds at the test's unit + t.Cleanup(func() { packageWaitUnit = time.Minute }) + b.settings = map[string]string{"MESH_ASSIGNER_PACKAGE_WAIT_FILE": "30"} + const pkg = "git.novox.be/novox/x/go" nc, err := nats.Connect(b.srv.ClientURL()) if err != nil { t.Fatal(err) @@ -43,7 +62,7 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) // machine-back, as the grants part derives them from its consumes; what each node runs it hears on its kept stream (the bed's). if _, err := b.js.CreateOrUpdateConsumer(b.ctx, "EVENTS", jetstream.ConsumerConfig{Durable: "n1_mesh-delivery-assigner", FilterSubjects: []string{enginereads.SubjectPrefix + "*", "mesh.mod." + buckets.IndexerModule + ".event.views.>", meshcatalog.SubjectCatalogRevisionAll, - nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil { + nodebuildgo.SubjectStepEndedAll, meshwatchdogs.SubjectMachineAwayAll, meshwatchdogs.SubjectMachineBackAll, meshbuilds.SubjectPackagePublished}, AckPolicy: jetstream.AckExplicitPolicy}); err != nil { t.Fatal(err) } for _, node := range []string{"n1", "n2"} { @@ -59,10 +78,12 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } // The trunk's catalog half holds the module and the node-engine, the module claiming the seat node-engine. engine := meshcatalog.CatalogEntry{Module: "engine", Fp: "src2:e1", Repository: "novox/mesh-host", Commit: engineCommit, Path: ".", - Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}} + Serves: []string{nodeengine.Seat + ".composition"}, Manifest: map[string]any{"module": "engine", "version": "0.1"}, Packages: map[string]string{pkg: ""}} b.cat.mu.Lock() b.cat.entries[trunkBranch] = map[string]meshcatalog.CatalogEntry{"engine": engine, - "m": {Module: "m", Fp: "src2:m1", Repository: "novox/m", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "m", "version": "0.1"}}} + "m": {Module: "m", Fp: "src2:m1", Repository: "novox/m", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "m", "version": "0.1"}}, + "x": {Module: "x", Fp: "src2:x1", Repository: "novox/x", Commit: engineCommit, Path: ".", Manifest: map[string]any{"module": "x", "version": "0.1"}, + Artifacts: []meshcatalog.Artifact{{Ref: "x:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: pkg}}}}} b.cat.rev[trunkBranch] = 3 b.cat.mu.Unlock() for _, node := range []string{"n1", "n2", "n3"} { @@ -72,7 +93,10 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) asked := make(chan string, 8) engines, err := nc.Subscribe("mesh.seat.node-engine.call.compose-candidate.*.*", func(m *nats.Msg) { node := strings.Split(m.Subject, ".")[5] - asked <- node + select { // the first step's asks are read; a later step's runs ask again + case asked <- node: + default: + } raw, _ := json.Marshal(map[string]any{"result": map[string]any{"candidate": "main.3", "node": node, "verdict": "composed", "input": map[string]any{"node": node}, "modules": []any{}, "own": map[string]any{}, "took": 1, "v": 1}, "node": node}) _ = m.Respond(raw) @@ -90,9 +114,23 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) t.Fatal(err) } t.Cleanup(func() { _ = entries.Unsubscribe() }) + // The seat mesh-builds' published answers x's build published at 0.1.9 once pub is set (H-A-328). + var pub atomic.Bool + publishedAsks, err := nc.Subscribe("mesh.seat.mesh-builds.call.published.*", func(m *nats.Msg) { + a := meshbuilds.PublishedAnswer{} + if pub.Load() { + a = meshbuilds.PublishedAnswer{Published: true, Version: "0.1.9"} + } + raw, _ := json.Marshal(map[string]any{"result": a, "node": "n0"}) + _ = m.Respond(raw) + }) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = publishedAsks.Unsubscribe() }) subscribed(t, nc) // The runner hears the step's end. - ended := make(chan meshwants.StepEnded, 1) + ended := make(chan meshwants.StepEnded, 8) ends, err := nc.Subscribe("mesh.seat.mesh-wants.event.step-ended.n1", func(m *nats.Msg) { var e meshwants.StepEnded _ = json.Unmarshal(m.Data, &e) @@ -105,7 +143,7 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) subscribed(t, nc) from := b.journal.mark() - b.start(t) + _, stop := b.startStoppable(t) b.journal.await(t, from, "the composition step is pulled from", "the composition step served", 30*time.Second) b.journal.await(t, from, "n3 is away (machine-away)", "the machine-away of n3 heard", 30*time.Second) @@ -116,6 +154,16 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } putStep(b.ctx, t, b.js, "step-ask-1", meshwants.StepRun{Pipeline: "main.3.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, Revision: 3, Commit: engineCommit, Fingerprint: "src2:m1"}) + // Each machine's run waits for x/go's publish, the step saying fetch; the publish heard, each puts its run ask (1984/AC11). + for _, node := range []string{"n1", "n2"} { + b.journal.await(t, from, "the composition run main=2e3."+node+" waits for package "+pkg, "the run of "+node+" waits", 30*time.Second) + } + b.journal.await(t, from, "the composition step of m says fetch", "the step says fetch", 30*time.Second) + pub.Store(true) + published, _ := json.Marshal(meshbuilds.PackagePublished{V: 1, Module: "x", Artifact: "x:go", Version: "0.1.9", Digest: "sha256:x", Branch: trunkBranch, Source: 3}) + if _, err := b.js.Publish(b.ctx, meshbuilds.SubjectPackagePublished, published); err != nil { + t.Fatal(err) + } // The stand-in Go build seat takes the run asks put under the assigner's name, reads each request by the verb input and says // its end with the composer's verdict: n1 composes, n2 does not. @@ -146,6 +194,9 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } node := req.Machines[0] programs[node] = a.Run.Program.Commit + if a.Packages[pkg] != "v0.1.9" { + t.Errorf("the composer of %s is built against %v, want x/go at v0.1.9 from published", node, a.Packages) + } m := composer.Machine{Composes: true} if node == "n2" { m = composer.Machine{Reason: "two modules own one path", Problems: []string{"/etc/x"}} @@ -170,10 +221,14 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) if programs["n1"] != engineCommit || programs["n2"] != engineCommit { t.Errorf("the composers were built at %v, want the node-engine build each machine runs", programs) } - close(asked) - for node := range asked { - if node == "n3" { - t.Error("the machine away was asked for its input") + for drained := false; !drained; { + select { + case node := <-asked: + if node == "n3" { + t.Error("the machine away was asked for its input") + } + default: + drained = true } } // The run's end comes before the input's delete (A-470o, A-470p): the inputs go after the step's end, heard by their watch. @@ -196,6 +251,99 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) } } queueEmpty(b.ctx, t, b.js) // the step's ask acknowledged at its end (design 47 H2 §777) + + // A restart during the wait (H-A-629 (3)): the runs of the next revision wait, the assigner stops, n2's wait is aged past + // package-wait-minutes as if the assigner were down that long, and x/go is published with no event heard. The start takes + // both up: n2's ends could not run naming the package; n1's start runs again, reads published first and composes. + revision := func(n int64) { + b.cat.mu.Lock() + b.cat.rev[trunkBranch] = n + b.cat.mu.Unlock() + } + stepEnd := func(id string) meshwants.StepEnded { + t.Helper() + for { + select { + case e := <-ended: + if e.ID == id { + return e + } + case <-time.After(30 * time.Second): + t.Fatalf("the step %s said no end within 30 s", id) + } + } + } + pub.Store(false) + revision(4) + from = b.journal.mark() + putStep(b.ctx, t, b.js, "step-ask-2", meshwants.StepRun{Pipeline: "main.4.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, + Revision: 4, Commit: engineCommit, Fingerprint: "src2:m1"}) + for _, node := range []string{"n1", "n2"} { + b.journal.await(t, from, "the composition run main=2e4."+node+" waits for package "+pkg, "the run of "+node+" waits", 30*time.Second) + } + stop() + runs := b.buckets[buckets.CompositionRuns()] + e2, err := runs.Get(b.ctx, "main=2e4.n2") + if err != nil { + t.Fatal(err) + } + var waiting meshwants.CompositionRun + if err := json.Unmarshal(e2.Value(), &waiting); err != nil || waiting.Waits == nil || waiting.Waits.Package != pkg || waiting.Program != nil { + t.Fatalf("the waiting run of n2 holds %s (%v), want waits naming x/go and no program", e2.Value(), err) + } + waiting.Waits.Since = waiting.Waits.Since.Add(-time.Hour) + aged, _ := json.Marshal(waiting) + if _, err := runs.Update(b.ctx, "main=2e4.n2", aged, e2.Revision()); err != nil { + t.Fatal(err) + } + pub.Store(true) + from = b.journal.mark() + _, stop = b.startStoppable(t) + b.journal.await(t, from, "the composition run main=2e4.n1, waiting for package "+pkg, "the run of n1 taken up", 30*time.Second) + got, err := worker.Next(jetstream.FetchMaxWait(30 * time.Second)) + if err != nil { + t.Fatalf("no run ask is put after the restart: %v", err) + } + _ = got.Ack() + a, err := buildstep.DecodeStepAsk(got.Data()) + if err != nil || a.Run == nil || a.Packages[pkg] != "v0.1.9" { + t.Fatalf("the run ask after the restart %+v (%v), want x/go at v0.1.9", a, err) + } + if req, err := composer.Decode(readInput(t, nc, a.Run.Input)); err != nil || len(req.Machines) != 1 || req.Machines[0] != "n1" { + t.Fatalf("the run ask after the restart composes %+v (%v), want n1", req.Machines, err) + } + v, _ := json.Marshal(composer.Verdict{V: composer.Version, Cases: []composer.CaseVerdict{{Name: changeCase, Machines: map[string]composer.Machine{"n1": {Composes: true}}}}}) + end, _ := json.Marshal(buildstep.StepEnded{V: 1, ID: a.ID, Ask: a.ID, Asker: runAsker, Node: "b1", Outcome: buildstep.OutcomePassed, Output: string(v), At: time.Now().UTC()}) + if _, err := b.js.Publish(b.ctx, nodebuildgo.SubjectStepEnded("b1"), end); err != nil { + t.Fatal(err) + } + if e := stepEnd("step-ask-2"); e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || strings.Contains(e.Said, "the builder pins or waits") || + !strings.Contains(e.Said, "n2: package "+pkg+" has no published version within 30s (package-wait-minutes)") || strings.Contains(e.Said, "n1") { + t.Fatalf("the step taken up ended %+v, want could not run naming n2's package past its bound alone", e) + } + + // Past the bound while running (H-A-628 (3), (4)): with package-wait-minutes at one, nothing is published, the bound's expiry + // ends each run could not run naming the package and the bound, and no run ask is put. + stop() + b.settings["MESH_ASSIGNER_PACKAGE_WAIT_FILE"] = "1" + pub.Store(false) + revision(5) + from = b.journal.mark() + _, stop = b.startStoppable(t) + b.journal.await(t, from, "the composition step is pulled from", "the composition step served again", 30*time.Second) + putStep(b.ctx, t, b.js, "step-ask-3", meshwants.StepRun{Pipeline: "main.5.m", Step: meshwants.StepRunStepComposition, Module: "m", Branch: trunkBranch, + Revision: 5, Commit: engineCommit, Fingerprint: "src2:m1"}) + e3 := stepEnd("step-ask-3") + for _, node := range []string{"n1", "n2"} { + if want := node + ": package " + pkg + " has no published version within 1s (package-wait-minutes)"; e3.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + !strings.Contains(e3.Said, want) || strings.Contains(e3.Said, "the builder pins or waits") { + t.Fatalf("the step past its bound ended %+v, want could not run saying %q", e3, want) + } + } + if info, err := worker.Info(b.ctx); err != nil || info.NumPending != 0 || info.NumAckPending != 0 { + t.Errorf("run asks were put past the bound: %+v %v", info, err) + } + stop() } // readInput reads a run's input as a build seat does: the seat mesh-wants' verb input answers its digest and chunk count, then its diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 22e4783ac..d291c641e 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -10,6 +10,7 @@ import ( "context" "fmt" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -516,6 +517,15 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, if err := hearRunBounds(hub, runs, logger.Printf); err != nil { logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err) } + // The seat mesh-builds' package-published wakes a run waiting for a package's publish, which reads published again; so does + // each bind of the consumer, which hears no event said before it was made (design 47 H2 H-A-628 (3); H-A-326, H-A-328). + if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { + runs.heardPublished() + _ = m.Ack() + }); err != nil { + logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err) + } + hub.OnBound(func(time.Time) { runs.heardPublished() }) } if inputs != nil { var runEnded func(buildstep.StepEnded) error @@ -699,7 +709,8 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, runs.moved.Store(&move) // The state's watch wakes the steps waiting on a run and hears a bound's expiry; the runs standing at the start are taken up // once the values that stand are read (§719, §720). - if err := watchRuns(ctx, kvs[buckets.CompositionRuns()], runs, runs.expired, func() { steps.takeUp(ctx, runs) }); err != nil { + // A run still waiting for a package's publish has its start run again (H-A-629 (3)). + if err := watchRuns(ctx, kvs[buckets.CompositionRuns()], runs, runs.expired, func() { steps.takeUp(ctx, runs); run.takeUpWaits(ctx) }); err != nil { return fmt.Errorf("the state %s is not watched: %w", buckets.CompositionRunsState, err) } // The runs' read and drop, the seat mesh-wants' verbs compositions and compositions-drop (§728, A-469f), answered here diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index 54a609a12..6ebc5eb41 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -92,8 +92,7 @@ func (r *compositionRun) resumeValidate(ctx context.Context, _ string, step mesh // readValidate waits for the end of the validate run of key and judges the step from it. func (r *compositionRun) readValidate(ctx context.Context, key string, step meshwants.StepRun) stepOutcome { setShared(ctx, r.runs.sharedOf([]string{key}, nil)) - setPhase(ctx, meshwants.StepProgressEventPhaseRun) - run := r.runs.await(ctx, []string{key})[key] + run := r.runs.awaitEach(ctx, []string{key}, r.sayingWaits(ctx, "the validate step of "+step.Module))[key] setPhase(ctx, meshwants.StepProgressEventPhaseReport) out := r.judgeValidate(ctx, step, run) out.Shared = r.runs.sharedOf([]string{key}, map[string]meshwants.CompositionRun{key: run}) @@ -288,13 +287,11 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh return } program.Package = validatorPackage - pins, waiting, err := r.filledPins(ctx, "the manifest validator's entry "+entry.Fp, pinsOfEntry(entry), publishersOf(half.Entries)) - if err != nil { - couldNot(err.Error()) - return - } - if len(waiting) > 0 { - couldNot(unpublishedSaid(waiting)) + pins, said, ok := r.awaitPins(ctx, key, ask, "the manifest validator's entry "+entry.Fp, pinsOfEntry(entry), publishersOf(half.Entries)) + if !ok { + if said != "" { // else the run ended or was replaced while it waited, or the step's wait ended + couldNot(said) + } return } seats, list, err := r.validateSeats(ctx, ask, half.Revision.Definitions) @@ -336,6 +333,7 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: entry.Fp} c.Input = digest + c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) return true }); err != nil { couldNot("the run's program and input are not written: " + err.Error()) diff --git a/modules/mesh-delivery-assigner/manifest_test.go b/modules/mesh-delivery-assigner/manifest_test.go index bf784b1f1..4d6b406f2 100644 --- a/modules/mesh-delivery-assigner/manifest_test.go +++ b/modules/mesh-delivery-assigner/manifest_test.go @@ -153,7 +153,7 @@ func TestManifest(t *testing.T) { // issue 1966 note 151: and the teller's ask-ended, its subject the one the assigner hears; §389: the watchman's machine-away // and machine-back, read whole at its start. A1/AC1 (design 47 H §750, §764): no version-delivered, delivery-waits, // delivered-again or assigner_delivered_again: a want waits on no dependency's delivery. - if !slices.Equal(m.Consumes, []string{"mesh-conditions.findings-asked", "mesh-conditions.condition-raised", "mesh-conditions.condition-changed", "mesh-conditions.condition-cleared", "mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "mesh-catalog.version-released", "mesh-watchdogs.machine-away", "mesh-watchdogs.machine-back", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", builds.BuilderModule + "." + builds.BuildsStreamEvents, buckets.TellerModule + "." + tellerevents.AskEnded, buckets.TellerModule + ".views." + buckets.AnswersState, "mesh-pipeline-runner.pipeline-ended", "node-build-go.step-ended", "node-build-go.ask-taken", "node-build-go.step-progress", "node-engine.manifest-reads-changed", "node-engine.running"}) { + if !slices.Equal(m.Consumes, []string{"mesh-conditions.findings-asked", "mesh-conditions.condition-raised", "mesh-conditions.condition-changed", "mesh-conditions.condition-cleared", "mesh-catalog.catalog-revision", "mesh-catalog.registration-changed", "mesh-delivery.source-moved", "mesh-catalog.version-released", "mesh-watchdogs.machine-away", "mesh-watchdogs.machine-back", "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", builds.BuilderModule + "." + builds.BuildsStreamEvents, "mesh-builds.package-published", buckets.TellerModule + "." + tellerevents.AskEnded, buckets.TellerModule + ".views." + buckets.AnswersState, "mesh-pipeline-runner.pipeline-ended", "node-build-go.step-ended", "node-build-go.ask-taken", "node-build-go.step-progress", "node-engine.manifest-reads-changed", "node-engine.running"}) { t.Errorf("consumes = %v, want the catalog half's revisions (design 47 G §195), the teller's ask-ended, the engines' reads changed and what they run", m.Consumes) } if want := []string{"mesh-delivery-indexer.manifests", "mesh-delivery-indexer.modules", @@ -185,9 +185,11 @@ func TestManifest(t *testing.T) { } file, _ := os.ReadFile("module.json") if err := json.Unmarshal(file, &raw); err != nil || raw.Config["outside-wait-minutes"].Default != float64(30) || raw.Config["outside-settle-seconds"].Default != float64(90) || - raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 15 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || + raw.Config["ask-operator-for"].Default != "take-off,remove-node,stops" || len(raw.Config) != 16 || raw.Config["tier-bound"].Default != float64(30) || raw.Config["entry-asks"].Default != float64(5) || raw.Config["composition-runs-cap-mib"].Default != float64(16) || raw.Config["composition-runs-kept"].Default != "24h" || raw.Config["composition-step-bound"].Default != "30m" || raw.Config["run-untaken-bound"].Default != "24h" || raw.Config["blame-tries"].Default != float64(20) || + // design 47 H2 H-A-628 (3): the bound of a run's wait for a package's publish, the builder's default + raw.Config["package-wait-minutes"].Default != float64(10) || // design 47 H2 §775, H-A-381 (2): the taken key's bound and the kept-call pace, runtime settings raw.Config["ask-taken-bound"].Default != "10m" || raw.Config["kept-call-pace-first"].Default != "1s" || raw.Config["kept-call-pace-max"].Default != "30s" || raw.Config["compose-ask-bound"].Default != "10s" || raw.Config["keeping-retry"].Default != "30s" { t.Errorf("config = %+v (%v), want outside-wait-minutes of 30, outside-settle-seconds of 90 and ask-operator-for of take-off,remove-node,stops (A-425a)", raw.Config, err) @@ -202,8 +204,9 @@ func TestManifest(t *testing.T) { {"MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE", "${dir:state}/composition-step-bound", "composition-step-bound"}, {"MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE", "${dir:state}/run-untaken-bound", "run-untaken-bound"}, {"MESH_ASSIGNER_BLAME_TRIES_FILE", "${dir:state}/blame-tries", "blame-tries"}, - {"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751 - {"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60 + {"MESH_ASSIGNER_PACKAGE_WAIT_FILE", "${dir:state}/package-wait-minutes", "package-wait-minutes"}, // design 47 H2 H-A-628 (3) + {"MESH_ASSIGNER_TIER_BOUND_FILE", "${dir:state}/tier-bound", "tier-bound"}, // design 47 H §751 + {"MESH_ASSIGNER_ENTRY_ASKS_FILE", "${dir:state}/entry-asks", "entry-asks"}, // design 47 H H-A-60 } { if !strings.Contains(string(file), `"`+f.env+`": "`+f.path+`"`) || !strings.Contains(string(file), `"path": "`+f.path+`"`) || !strings.Contains(string(file), `"content": "${config:`+f.key+`}"`) { diff --git a/modules/mesh-delivery-assigner/module.json b/modules/mesh-delivery-assigner/module.json index b5974c67e..d2266001d 100644 --- a/modules/mesh-delivery-assigner/module.json +++ b/modules/mesh-delivery-assigner/module.json @@ -56,6 +56,7 @@ "mesh-catalog.seat-definition-changed", "mesh-catalog.seat-definition-removed", "mesh-delivery-builder.build.ended.**", + "mesh-builds.package-published", "mesh-delivery-teller.ask-ended", "mesh-delivery-teller.views.answers", "mesh-pipeline-runner.pipeline-ended", @@ -230,6 +231,14 @@ "trusted": false, "default": "24h" }, + "package-wait-minutes": { + "type": "number", + "description": "minutes a composition or validate run waits for the publish of a mesh package its entry names with no version, counted from the time its wait began, before it ends could not run naming the package (design 47 H2 H-A-628 (3), H-A-629 (3)); the builder's range and default.", + "minimum": 1, + "maximum": 120, + "trusted": false, + "default": 10 + }, "blame-tries": { "type": "number", "description": "the most compositions a machine's composer makes to find the modules it blames, carried in the run's request as blame_tries (design 47 G section 721, A-466r).", @@ -369,6 +378,14 @@ "mode": "0600", "content": "${config:run-untaken-bound}" }, + { + "id": "package-wait-minutes", + "type": "file", + "path": "${dir:state}/package-wait-minutes", + "owner": "mesh-delivery-assigner", + "mode": "0600", + "content": "${config:package-wait-minutes}" + }, { "id": "blame-tries", "type": "file", @@ -396,7 +413,8 @@ "MESH_ASSIGNER_COMPOSITION_RUNS_KEPT_FILE": "${dir:state}/composition-runs-kept", "MESH_ASSIGNER_COMPOSITION_STEP_BOUND_FILE": "${dir:state}/composition-step-bound", "MESH_ASSIGNER_RUN_UNTAKEN_BOUND_FILE": "${dir:state}/run-untaken-bound", - "MESH_ASSIGNER_BLAME_TRIES_FILE": "${dir:state}/blame-tries" + "MESH_ASSIGNER_BLAME_TRIES_FILE": "${dir:state}/blame-tries", + "MESH_ASSIGNER_PACKAGE_WAIT_FILE": "${dir:state}/package-wait-minutes" }, "user": "mesh-delivery-assigner", "health": { diff --git a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go index 8f93ec1c9..5c93d9967 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go @@ -14,13 +14,13 @@ const Seat = "mesh-wants" // 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 = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=a64bc503c99a CompositionRunProgram=5a1202df3497 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" + generatedForms = "3" + generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=92d1d2424265 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" ) const ( @@ -856,6 +856,14 @@ type CompositionRunProgram struct { Repository string `json:"repository,omitempty"` } +// CompositionRunWaits is the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)). +type CompositionRunWaits struct { + // the package's path + Package string `json:"package"` + // the time its wait began, which the bound package-wait-minutes counts from + Since time.Time `json:"since"` +} + // CompositionRun is one composition run of a candidate and a machine, a key of the assigner's state composition-runs (design 47 G §719, §728; A-469u). type CompositionRun struct { // the id of the build seat's run ask @@ -880,6 +888,8 @@ type CompositionRun struct { Unlisted []string `json:"unlisted,omitempty"` // that machine's composer verdict (design 47 G §721) Verdict map[string]any `json:"verdict,omitempty"` + // the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) + Waits *CompositionRunWaits `json:"waits,omitempty"` } // The values of CompositionRun's outcome. diff --git a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json index f9d926694..2ba3f893d 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json @@ -1807,6 +1807,25 @@ "type": "string" }, "description": "the module names of the assignments left out of the machine's composition, those no watched branch's newest revision lists, written when the run starts and read by every step's judgement and by the resume (design 47 H-A-152, H-A-153)" + }, + "waits": { + "type": "object", + "description": "the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1))", + "properties": { + "package": { + "type": "string", + "description": "the package's path" + }, + "since": { + "type": "string", + "format": "date-time", + "description": "the time its wait began, which the bound package-wait-minutes counts from" + } + }, + "required": [ + "package", + "since" + ] } }, "required": [ @@ -1886,5 +1905,5 @@ "on": "every" } ], - "form": 2 + "form": 3 } diff --git a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts index dd3efa85d..0990e6b10 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts @@ -312,6 +312,14 @@ export interface CompositionRunProgram { "repository"?: string; } +/** the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) */ +export interface CompositionRunWaits { + /** the package's path */ + "package": string; + /** the time its wait began, which the bound package-wait-minutes counts from */ + "since": string; +} + /** one composition run of a candidate and a machine, a key of the assigner's state composition-runs (design 47 G §719, §728; A-469u) */ export interface CompositionRun { /** the id of the build seat's run ask */ @@ -336,6 +344,8 @@ export interface CompositionRun { "unlisted"?: string[]; /** that machine's composer verdict (design 47 G §721) */ "verdict"?: Record; + /** the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) */ + "waits"?: CompositionRunWaits; } export interface DifferenceRefusedItem { -- 2.54.0 From 8a1605d2832f7565c7761ab35d0670322067ca18 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:05:51 +0100 Subject: [PATCH 4/9] assigner: a package-published wakes only the runs waiting for its artifact's package (issue 1984, review round 1) Every package-published heard woke every run waiting for any package, each asking mesh-builds' published again. Now the wake is kept per the artifact of a package's publisher: the assigner's consumer reads the heard event's artifact (hearPublished) and wakes only the runs whose `waits` names the package that artifact publishes, as the runner's hearPublished matches by artifact; a publish of another package wakes none and asks no published. An event that does not read is journaled and wakes none. Each bind of the consumer still wakes every waiting run (heardBind). Test: TestTheCompositionStepRunsOneAskPerMachine, the wait's row: a package-published of y:go, handed to the consumer's handler while the runs wait for x/go, leaves their wake standing and asks no published; x:go's own then wakes them (failed first with the wake ignoring the artifact). Builds: design 47 H2 H-A-630 (1) (hq 1cdfa6ff); H-A-628 (3) (hq cea6404c); H-A-326 --- .../mesh-delivery-assigner/compositionrun.go | 10 ++- .../compositionrun_test.go | 43 ++++++++++- .../mesh-delivery-assigner/compositionruns.go | 72 ++++++++++++++----- .../cmd/mesh-delivery-assigner/main.go | 13 ++-- 4 files changed, 111 insertions(+), 27 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 75debacea..4e7827fc9 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -836,7 +836,14 @@ func (r *compositionRun) filledPins(ctx context.Context, what string, pins map[s func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, pins map[string]string, publishers map[string]packagePublisher) (map[string]string, string, bool) { armed, said := false, "" for { - published := r.runs.publishWake() // taken before the read, so a publish heard meanwhile wakes the next one + // The wake of each empty pin's publisher, taken before the read, so a publish heard meanwhile wakes the next one; the run + // waits on the one of the package its `waits` names alone (H-A-630 (1)). + wakes := map[string]<-chan struct{}{} + for path, v := range pins { + if by, ok := publishers[path]; ok && v == "" { + wakes[path] = r.runs.publishWake(by.artifact) + } + } filled, waiting, err := r.filledPins(ctx, what, pins, publishers) if err != nil { return nil, err.Error(), false @@ -851,6 +858,7 @@ func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, p return filled, "", true } path := waiting[0].path + published := wakes[path] since, held, err := r.runs.waitFor(key, ask, path) if err != nil { return nil, "its wait for package " + path + " is not written: " + err.Error(), false diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 2a907854d..41a5a5170 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "git.novox.be/novox/mesh-sdk/go/process" + "github.com/nats-io/nats.go/jetstream" "maps" "slices" "strings" @@ -100,6 +101,29 @@ func (l *logLines) await(t *testing.T, words string, n int) { } } +// eventsOf is the assigner's hub as a test hands it events: each handler by its subject, each bind's hearer. +type eventsOf struct { + handle map[string]func(jetstream.Msg) + bound []func(time.Time) +} + +func (h *eventsOf) Handle(subject string, f func(jetstream.Msg)) error { + h.handle[subject] = f + return nil +} +func (h *eventsOf) OnBound(f func(time.Time)) { h.bound = append(h.bound, f) } + +// say hands the handler of subject the event ev, and fails the test when it is not acknowledged. +func (h *eventsOf) say(t *testing.T, subject string, ev any) { + t.Helper() + raw, _ := json.Marshal(ev) + m := &heardMsg{data: raw, subject: subject} + h.handle[subject](m) + if !m.acked { + t.Errorf("the event %s on %s is not acknowledged", raw, subject) + } +} + func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) *runStand { s := &runStand{asks: map[string]buildstep.StepAsk{}, requests: map[string]composer.Request{}, publishedAt: map[string]string{"src2:x1": "0.1.9"}} engine := func(fp, commit string) meshcatalog.CatalogEntry { @@ -326,10 +350,27 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { u.runs.expired(runBoundPrefix + key) } } else { + // H-A-630 (1): a package-published of another package wakes no run waiting for x/go, so it asks no published; x's own + // wakes each. + hub := &eventsOf{handle: map[string]func(jetstream.Msg){}} + if err := hearPublished(hub, u.runs, t.Logf); err != nil { + t.Fatal(err) + } u.mu.Lock() + asked := len(u.published) + u.mu.Unlock() + hub.say(t, builds.SubjectPackagePublished, builds.PackagePublished{Module: "y", Artifact: "y:go", Branch: "main", Source: 7, Version: "0.2.0", V: 1}) + u.runs.mu.Lock() + _, open := u.runs.published["x:go"] + u.runs.mu.Unlock() + u.mu.Lock() + after := len(u.published) u.publishedAt = map[string]string{"src2:x1": "0.1.9"} u.mu.Unlock() - u.runs.heardPublished() + if !open || after != asked { + t.Errorf("a publish of y:go woke the runs waiting for x/go (their wake standing %v) or asked published %d times more", open, after-asked) + } + hub.say(t, builds.SubjectPackagePublished, builds.PackagePublished{Module: "x", Artifact: "x:go", Branch: "main", Source: 7, Version: "0.1.9", V: 1}) } var out stepOutcome select { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index 9aab4f502..24ac30c72 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -15,6 +15,7 @@ import ( "github.com/nats-io/nats.go/jetstream" + meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" meshwants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" "git.novox.be/novox/mesh-sdk/go/keys" @@ -274,9 +275,10 @@ type compositionRuns struct { mu sync.Mutex // changed is closed and replaced at each change of the state heard (heard): a step waiting on a run reads its key again. changed chan struct{} - // published is closed and replaced at each package-published of the seat mesh-builds heard (heardPublished): a run waiting for - // a package's publish asks published again (design 47 H2 H-A-628 (3), H-A-326). - published chan struct{} + // published holds, by the artifact of a package's publisher (:), what is closed and deleted at the seat + // mesh-builds' package-published of that artifact heard (heardPublished), and at each bind of the consumer: a run waiting for + // the package that artifact publishes asks published again (design 47 H2 H-A-628 (3), H-A-630 (1); H-A-326). + published map[string]chan struct{} // seen are the keys the state's watch handed and has not seen deleted: a listing of the bucket misses a key that is // being written at that moment, so every lookup takes these beside it (keys). seen map[string]bool @@ -290,24 +292,60 @@ type compositionRuns struct { } func newCompositionRuns(kv runsKV, set runSettings, now func() time.Time, logf func(string, ...any)) *compositionRuns { - return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: make(chan struct{})} + return &compositionRuns{kv: kv, set: set, now: now, logf: logf, changed: make(chan struct{}), published: map[string]chan struct{}{}} } -// heardPublished wakes every run waiting for a package's publish, at the seat mesh-builds' package-published heard and at each -// bind of the assigner's consumer (an event said before it was made is not delivered): each reads published again, the event -// only its second path (design 47 H2 H-A-628 (3); H-A-326, H-A-328). -func (r *compositionRuns) heardPublished() { - r.mu.Lock() - close(r.published) - r.published = make(chan struct{}) - r.mu.Unlock() -} - -// publishWake is closed at the next package-published heard. -func (r *compositionRuns) publishWake() <-chan struct{} { +// heardPublished wakes the runs waiting for the package artifact publishes, at the seat mesh-builds' package-published of that +// artifact heard: each reads published again, the event only its second path; a publish of another package wakes none, so it asks +// no published (design 47 H2 H-A-628 (3), H-A-630 (1); H-A-326, H-A-328). +func (r *compositionRuns) heardPublished(artifact string) { r.mu.Lock() defer r.mu.Unlock() - return r.published + if w, ok := r.published[artifact]; ok { + close(w) + delete(r.published, artifact) + } +} + +// heardBind wakes every run waiting for a package's publish, at each bind of the assigner's consumer of package-published, which +// hears no event said before it was made: each reads published again. +func (r *compositionRuns) heardBind() { + r.mu.Lock() + defer r.mu.Unlock() + for artifact, w := range r.published { + close(w) + delete(r.published, artifact) + } +} + +// publishWake is closed at the next package-published of artifact heard, or the consumer's next bind. +func (r *compositionRuns) publishWake(artifact string) <-chan struct{} { + r.mu.Lock() + defer r.mu.Unlock() + w, ok := r.published[artifact] + if !ok { + w = make(chan struct{}) + r.published[artifact] = w + } + return w +} + +// hearPublished hears the seat mesh-builds' package-published on the assigner's durable consumer: the runs waiting for the +// package its artifact publishes are woken (heardPublished, design 47 H2 H-A-630 (1)); one that does not read wakes none and is +// journaled. +func hearPublished(hub interface { + Handle(string, func(jetstream.Msg)) error +}, r *compositionRuns, logf func(string, ...any)) error { + return hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { + ev, _, err := meshbuilds.DecodePackagePublishedEvent(m.Data()) + if err != nil || ev.Artifact == "" { + logf("%s holds what is no package-published naming its artifact, so it wakes no composition run: %v", m.Subject(), err) + _ = m.Ack() + return + } + r.heardPublished(ev.Artifact) + _ = m.Ack() + }) } // waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index d291c641e..d656ec854 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -10,7 +10,6 @@ import ( "context" "fmt" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" - meshbuilds "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep" @@ -517,15 +516,13 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, if err := hearRunBounds(hub, runs, logger.Printf); err != nil { logger.Printf("the build seats' ask-taken and step-progress are not heard, so a composition run is ended by no bound: %v", err) } - // The seat mesh-builds' package-published wakes a run waiting for a package's publish, which reads published again; so does - // each bind of the consumer, which hears no event said before it was made (design 47 H2 H-A-628 (3); H-A-326, H-A-328). - if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { - runs.heardPublished() - _ = m.Ack() - }); err != nil { + // The seat mesh-builds' package-published wakes the runs waiting for the package its artifact publishes, which read published + // again; each bind of the consumer, which hears no event said before it was made, wakes every waiting run (design 47 H2 + // H-A-628 (3), H-A-630 (1); H-A-326, H-A-328). + if err := hearPublished(hub, runs, logger.Printf); err != nil { logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err) } - hub.OnBound(func(time.Time) { runs.heardPublished() }) + hub.OnBound(func(time.Time) { runs.heardBind() }) } if inputs != nil { var runEnded func(buildstep.StepEnded) error -- 2.54.0 From 051e104f1bf31629008fc957e5185b2e192c30ff Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:06:56 +0100 Subject: [PATCH 5/9] assigner: each bind of the package-published consumer wakes every waiting run (issue 1984, review round 1) The bind wake stood in main.go untested. It now sits beside the consumer's handler in hearPublished, which registers both: each bind of the assigner's consumer of package-published wakes every run waiting for a package's publish to read published again, since an event said while the consumer was not bound is never heard. Test: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows gain "bind": x/go published with no event heard, a bind of the consumer wakes each waiting run, which reads it published and puts its run ask with the pin (failed first, no end within 10 s, with the bind's hearer removed). Builds: design 47 H2 H-A-630 (2) (hq 1cdfa6ff); H-A-628 (3) (hq cea6404c) --- .../compositionrun_test.go | 24 +++++++++++++++---- .../mesh-delivery-assigner/compositionruns.go | 5 +++- .../cmd/mesh-delivery-assigner/main.go | 5 ++-- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 41a5a5170..169dcc0c1 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -303,8 +303,10 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { // 1984/AC9; H-A-628 (3), (4); H-A-629 (1), (2): x's build not published yet: each run waits, its value naming x/go in `waits` // with the time its wait began, its bound bound. armed for package-wait-minutes, the step saying fetch naming the // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the - // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. - for _, publish := range []bool{true, false} { + // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. H-A-630 (2): a + // bind of the consumer, the publish said while it was not bound, wakes each to read it published. + for _, how := range []string{"published", "bind", "past its bound"} { + publish := how != "past its bound" u := newRunStand(t, "src2:e1", "src2:e1", "d1") u.publishedAt = nil journal := newLogLines() @@ -344,12 +346,24 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { t.Errorf("the waiting run %s of %v holds %+v, its bound %s; want x/go in waits and package-wait-minutes' bound", key, keys, run.Waits, ttl) } } - if !publish { + switch how { + case "past its bound": for _, key := range keys { kv.expire(runBoundPrefix + key) u.runs.expired(runBoundPrefix + key) } - } else { + case "bind": + hub := &eventsOf{handle: map[string]func(jetstream.Msg){}} + if err := hearPublished(hub, u.runs, t.Logf); err != nil { + t.Fatal(err) + } + u.mu.Lock() + u.publishedAt = map[string]string{"src2:x1": "0.1.9"} + u.mu.Unlock() + for _, bound := range hub.bound { + bound(time.Now()) + } + default: // H-A-630 (1): a package-published of another package wakes no run waiting for x/go, so it asks no published; x's own // wakes each. hub := &eventsOf{handle: map[string]func(jetstream.Msg){}} @@ -376,7 +390,7 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { select { case out = <-done: case <-time.After(10 * time.Second): - t.Fatalf("publish %v: the waiting step said no end", publish) + t.Fatalf("%s: the waiting step said no end", how) } journal.await(t, "the composition step of m says run", 1) if !publish { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index 24ac30c72..2e6038923 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -332,10 +332,13 @@ func (r *compositionRuns) publishWake(artifact string) <-chan struct{} { // hearPublished hears the seat mesh-builds' package-published on the assigner's durable consumer: the runs waiting for the // package its artifact publishes are woken (heardPublished, design 47 H2 H-A-630 (1)); one that does not read wakes none and is -// journaled. +// journaled. Each bind of the consumer wakes every waiting run (heardBind, H-A-630 (2)): an event said while it was not bound is +// never heard, so no run waits until its bound alone ends it while its package stands published. func hearPublished(hub interface { Handle(string, func(jetstream.Msg)) error + OnBound(func(time.Time)) }, r *compositionRuns, logf func(string, ...any)) error { + hub.OnBound(func(time.Time) { r.heardBind() }) return hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { ev, _, err := meshbuilds.DecodePackagePublishedEvent(m.Data()) if err != nil || ev.Artifact == "" { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index d656ec854..4a68a428d 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -518,11 +518,10 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, } // The seat mesh-builds' package-published wakes the runs waiting for the package its artifact publishes, which read published // again; each bind of the consumer, which hears no event said before it was made, wakes every waiting run (design 47 H2 - // H-A-628 (3), H-A-630 (1); H-A-326, H-A-328). + // H-A-628 (3), H-A-630 (1), (2); H-A-326, H-A-328). if err := hearPublished(hub, runs, logger.Printf); err != nil { - logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start: %v", err) + logger.Printf("the seat mesh-builds' package-published is not heard, so a composition run waiting for a package reads published only at its start and at each bind: %v", err) } - hub.OnBound(func(time.Time) { runs.heardBind() }) } if inputs != nil { var runEnded func(buildstep.StepEnded) error -- 2.54.0 From dc2ddb871a85521bb74c1e804a8dc8a1c4710030 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:11:32 +0100 Subject: [PATCH 6/9] assigner: a run's start and its wait run on the assigner's own context (issue 1984, review round 1) The composition and validate runs were started on the context of the step that started them, so a supersede or a drop of that step ended the wait for a package's publish silently, while other steps share the run: it then waited, woken by nothing, until its bound ended it "no published version" though the package stood published. The start, its wait and its run ask now run on the assigner's own context (compositionRun.own), as the take-up's do. Tests: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows gain "superseded": a second step joins the waiting runs, the starting step's context ends, the runs stay waiting with both readers, and at the publish the second step reads them composed with the pin; TestTheValidateStepRefusesAManifestProblemAndACycle, revision 14: the validate run waiting for mesh-sdk's publish outlives its starting step and ends passed after the publish. Both failed first (no end within 10 s) with the start on the step's context. Builds: design 47 H2 H-A-630 (3) (hq 1cdfa6ff); H-A-628 (3) (hq cea6404c); H-A-629 (3) (hq 8aa70271) --- .../mesh-delivery-assigner/compositionrun.go | 5 ++- .../compositionrun_test.go | 29 ++++++++++++--- .../cmd/mesh-delivery-assigner/main.go | 2 +- .../mesh-delivery-assigner/validatestep.go | 2 +- .../validatestep_test.go | 36 ++++++++++++++++++- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 4e7827fc9..961b187b5 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -84,6 +84,9 @@ type compositionRun struct { away func(machine string) bool // put puts a run ask on the build seat's check queue under the assigner's name. put func(ctx context.Context, a buildstep.StepAsk) error + // own is the assigner's own context: a run's start, and its wait for a package's publish, run on it as the take-up's do, never + // on the starting step's, which a supersede or a drop ends while other steps share the run (design 47 H2 H-A-630 (3)). + own context.Context // reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer). reads *compositionReads sleep func(ctx context.Context, d time.Duration) error @@ -134,7 +137,7 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step continue } if j.started { - go r.start(ctx, j.key, j.run, prep, id) + go r.start(r.own, j.key, j.run, prep, id) // on the assigner's own context (H-A-630 (3)) } keys = append(keys, j.key) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 169dcc0c1..40bd04ec8 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -201,7 +201,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) * s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) s.r = &compositionRun{runs: s.runs, inputs: &compositionInputs{machines: func(string, string) []string { return []string{"ace", "g14", "shanks"} }, callFile: engines, bound: time.Second}, - keeper: keeper, reads: &compositionReads{}, call: call, away: away, now: time.Now, logf: t.Logf, + keeper: keeper, reads: &compositionReads{}, call: call, away: away, own: context.Background(), now: time.Now, logf: t.Logf, trunk: func() (mcc.Half, bool) { return mcc.Half{Entries: map[string]meshcatalog.CatalogEntry{"engine": engine(trunkEngine, commitE1)}}, true }, @@ -304,8 +304,9 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { // with the time its wait began, its bound bound. armed for package-wait-minutes, the step saying fetch naming the // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. H-A-630 (2): a - // bind of the consumer, the publish said while it was not bound, wakes each to read it published. - for _, how := range []string{"published", "bind", "past its bound"} { + // bind of the consumer, the publish said while it was not bound, wakes each to read it published. H-A-630 (3): the starting + // step superseded leaves the runs another step shares waiting, and that step reads them composed after the publish. + for _, how := range []string{"published", "bind", "superseded", "past its bound"} { publish := how != "past its bound" u := newRunStand(t, "src2:e1", "src2:e1", "d1") u.publishedAt = nil @@ -323,7 +324,9 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { } phase := &stepPhase{} done := make(chan stepOutcome, 1) - go func() { done <- u.r.run(context.WithValue(context.Background(), phaseKey{}, phase), "ask-step", step) }() + first, supersede := context.WithCancel(context.WithValue(context.Background(), phaseKey{}, phase)) + defer supersede() + go func() { done <- u.r.run(first, "ask-step", step) }() journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) journal.await(t, "the composition step of m says fetch: the composition run", 1) if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch { @@ -352,6 +355,24 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { kv.expire(runBoundPrefix + key) u.runs.expired(runBoundPrefix + key) } + case "superseded": + second := make(chan stepOutcome, 1) + go func() { + second <- u.r.run(context.WithValue(context.Background(), phaseKey{}, &stepPhase{}), "ask-step-2", step) + }() + journal.await(t, "the composition step of m says fetch: the composition run", 2) // the second step reads the waiting runs + supersede() + <-done + for _, key := range keys { + if run, _, _, _ := u.runs.read(key); run.Ended != nil || run.Waits == nil || len(run.Readers) != 2 { + t.Errorf("the starting step superseded, the run %s holds ended %v, waits %+v, readers %d; want it waiting for its two readers", key, run.Ended, run.Waits, len(run.Readers)) + } + } + done = second + u.mu.Lock() + u.publishedAt = map[string]string{"src2:x1": "0.1.9"} + u.mu.Unlock() + u.runs.heardPublished("x:go") case "bind": hub := &eventsOf{handle: map[string]func(jetstream.Msg){}} if err := hearPublished(hub, u.runs, t.Logf); err != nil { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 4a68a428d..a99dfb49f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -687,7 +687,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, return err } run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFileKept, bound: askBound}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, callFile: bus.CallFileKept, - trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf} + trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, assignment: w.assignmentOf, findings: findings, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), own: ctx, ask: bus.CallFile, now: time.Now, logf: logger.Printf} // The seat's work queue (design 47 H2 §777): pulled through its one worker, each ask taken once in the state taken. takenBound, err := askTakenBound() if err != nil { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index 6ebc5eb41..7b4332588 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -75,7 +75,7 @@ func (r *compositionRun) validate(ctx context.Context, id string, step meshwants return couldNotRun("the validate run " + key + " is not joined: " + err.Error()) } if j.started { - go r.startValidate(ctx, key, j.run, step) + go r.startValidate(r.own, key, j.run, step) // on the assigner's own context (H-A-630 (3)) } return r.readValidate(ctx, key, step) } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go index 867f60cbb..b18a6531c 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go @@ -48,6 +48,9 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { 13: {unpinned, entry("web", "d-web-2"), entry("db", "d-db"), {Module: "mesh-sdk", Fp: "src2:sdk1", Artifacts: []meshcatalog.Artifact{{Ref: "mesh-sdk:go", Language: "go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}}}}}, } + revisions[14] = revisions[13] // H-A-630 (3): its validate run waits for mesh-sdk's publish + var sdkMu sync.Mutex + sdkUnpublished := false // base is the newest kept revision below n, as the take-in names it; none below the first. Revision 12 names 7 with 8 to 11 // never kept, so a case before read as the number minus one could not run (H-A-154). base := func(n int64) (b int64) { @@ -86,6 +89,11 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { if in != (builds.PublishedInput{Module: "mesh-sdk", Artifact: "mesh-sdk:go", Fingerprint: "src2:sdk1"}) { return nil, errors.New("published asked of another build") } + sdkMu.Lock() + defer sdkMu.Unlock() + if sdkUnpublished { + return json.Marshal(builds.PublishedAnswer{}) + } return json.Marshal(builds.PublishedAnswer{Published: true, Version: "0.1.36"}) } return nil, errors.New("no such verb " + key) @@ -111,7 +119,7 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { var requests []composer.Request keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now) runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) - r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, now: time.Now, logf: t.Logf, + r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf, put: func(_ context.Context, a buildstep.StepAsk) error { body, err := keeper.body(a.Run.Input.Digest) if err != nil { @@ -237,4 +245,30 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { } else if got := asks[3].Packages; len(got) != 2 || got["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" || got["git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient"] != "v0.1.4" { t.Errorf("the validator is built against the pins %v; want mesh-sdk/go at v0.1.36 from published beside its entry's", got) } + // H-A-630 (3): the validate run waits for mesh-sdk's publish on the assigner's own context, so the step that started it, ended + // meanwhile, leaves it waiting: at the publish it is put and ends passed for the movers that read it. + sdkMu.Lock() + sdkUnpublished = true + sdkMu.Unlock() + journal := newLogLines() + r.logf = journal.logf + starting, stop := context.WithCancel(ctx) + left := make(chan stepOutcome, 1) + go func() { left <- r.validate(starting, "ask-left", step("web", 14)) }() + journal.await(t, "waits for package git.novox.be/novox/mesh-sdk/go", 1) + stop() + if o := <-left; o.Outcome != meshwants.StepEndedOutcomeCouldNotRun { + t.Errorf("the starting step stopped ended %+v", o) + } + sdkMu.Lock() + sdkUnpublished = false + sdkMu.Unlock() + runs.heardPublished("mesh-sdk:go") + key, _ := validateKeyOf(step("web", 14)) + run := runs.awaitEach(ctx, []string{key}, nil)[key] + mu.Lock() + defer mu.Unlock() + if run.Ended == nil || run.Outcome != meshwants.CompositionRunOutcomePassed || len(asks) != 5 || asks[4].Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" { + t.Errorf("the validate run its starting step left ended %v %s %q with %d validator asks, want it put after the publish and passed", run.Ended, run.Outcome, run.Said, len(asks)) + } } -- 2.54.0 From a46f14ba239a0c10526aa2b72033cea30426c0fb Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:14:57 +0100 Subject: [PATCH 7/9] assigner: the words past a wait's bound name the package, the entry and the bound (issue 1984, review round 1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A run past its wait's bound ended "package has no published version within ", naming no entry, and two of its three paths (the bound's expiry and the take-up at a start) read only the run's value. The seat mesh-wants' CompositionRunWaits gains `entry`, the words of the import-form entry the run is built from (such as "the node-engine's entry src2:e1"), written with the package when the wait begins; the waiting start's end, the expiry and the take-up all say "package has no published version within (package-wait-minutes), named with no version in " from it. The definition's form stays 3, raised by this fix; the Go and TypeScript contracts regenerated by seatgen (seatgen -check passes). Tests: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows: the waiting run's `waits` holds its entry; "past its bound" (the expiry) and a new "past its bound at a take-up" (takeUpWaits) end saying package, entry and bound (both failed first with no entry written); TestTheCompositionStepComposesEachMachineThroughTheBuildSeat (whole, embedded bus): the waiting run's entry, and the take-up's and the expiry's words with it. Builds: design 47 H2 H-A-630 (4) (hq 1cdfa6ff); H-A-631 (hq ee89b857); H-A-628 (3), (5) (hq cea6404c); H-A-629 (1) (hq 8aa70271); H2 §780 --- .../compositionbounds.go | 7 ++--- .../mesh-delivery-assigner/compositionrun.go | 6 ++--- .../compositionrun_test.go | 27 ++++++++++++------- .../mesh-delivery-assigner/compositionruns.go | 22 ++++++++------- .../compositionstep_integration_test.go | 12 +++++---- .../go/seats/meshwants/contract.go | 4 ++- .../seats/mesh-wants/seat.json | 5 ++++ .../ts/seats/meshwants/index.d.ts | 2 ++ 8 files changed, 54 insertions(+), 31 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go index a8e2ce7ac..ea44f2bee 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go @@ -234,8 +234,9 @@ func (r *compositionRuns) expired(boundKey string) { } // waitExpired ends a run whose wait for a package's publish passed its bound, the expiry of the bound key bound. the -// wait armed (design 47 H2 H-A-628 (3), (4)): could not run naming the package, read from the run's value (H-A-629 (1)). Its run -// ask is not put yet, so none is dropped; a bound armed again since (the marker holds no value, A-470o) ends nothing. +// wait armed (design 47 H2 H-A-628 (3), (4)): could not run naming the package, the entry and the bound, read from the run's value +// (H-A-629 (1), H-A-631). Its run ask is not put yet, so none is dropped; a bound armed again since (the marker holds no value, +// A-470o) ends nothing. func (r *compositionRuns) waitExpired(boundKey, key string, run meshwants.CompositionRun) { _, _, armed, err := r.boundOf(boundKey) if err != nil { @@ -246,7 +247,7 @@ func (r *compositionRuns) waitExpired(boundKey, key string, run meshwants.Compos r.logf("the expiry of %s ends nothing: the bound is armed again (A-470o)", boundKey) return } - if _, err := r.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + if _, err := r.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.pastWaitSaid(run.Machine, *run.Waits), nil); err != nil { r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) } } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 961b187b5..01d8aaf23 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -862,7 +862,7 @@ func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, p } path := waiting[0].path published := wakes[path] - since, held, err := r.runs.waitFor(key, ask, path) + since, held, err := r.runs.waitFor(key, ask, path, what) if err != nil { return nil, "its wait for package " + path + " is not written: " + err.Error(), false } @@ -871,7 +871,7 @@ func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, p } left := since.Add(r.runs.set.packageWait).Sub(r.now()) if left <= 0 { - return nil, r.runs.pastWaitSaid("", path), false + return nil, r.runs.pastWaitSaid("", meshwants.CompositionRunWaits{Package: path, Entry: what}), false } if !armed { stands, err := r.runs.armBound(runBoundPrefix, key, ask, wholeSeconds(left)) @@ -962,7 +962,7 @@ func (r *compositionRun) takeUpWaits(ctx context.Context) { } left := run.Waits.Since.Add(r.runs.set.packageWait).Sub(r.now()) if left <= 0 { - if _, err := r.runs.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.runs.pastWaitSaid(run.Machine, run.Waits.Package), nil); err != nil { + if _, err := r.runs.endRun(key, run.Ask, meshwants.CompositionRunOutcomeCouldNotRun, r.runs.pastWaitSaid(run.Machine, *run.Waits), nil); err != nil { r.logf("the composition run %s past its wait for package %s is not ended: %v", key, run.Waits.Package, err) } continue diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 40bd04ec8..19a2504a6 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -305,9 +305,10 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { // package; at the publish heard each reads published again and puts its run ask with the pin, `waits` and the bound gone, the // step saying run; past the bound each ends could not run naming the package and the bound, no run ask put. H-A-630 (2): a // bind of the consumer, the publish said while it was not bound, wakes each to read it published. H-A-630 (3): the starting - // step superseded leaves the runs another step shares waiting, and that step reads them composed after the publish. - for _, how := range []string{"published", "bind", "superseded", "past its bound"} { - publish := how != "past its bound" + // step superseded leaves the runs another step shares waiting, and that step reads them composed after the publish. H-A-630 (4), + // H-A-631: past the bound, by the bound's expiry or at a take-up, the words name the package, the entry and the bound. + for _, how := range []string{"published", "bind", "superseded", "past its bound", "past its bound at a take-up"} { + publish := !strings.HasPrefix(how, "past its bound") u := newRunStand(t, "src2:e1", "src2:e1", "d1") u.publishedAt = nil journal := newLogLines() @@ -345,8 +346,9 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { kv.mu.Lock() ttl := kv.ttl[runBoundPrefix+key] kv.mu.Unlock() - if len(keys) != 2 || run.Waits == nil || run.Waits.Package != "git.novox.be/novox/x/go" || run.Waits.Since.IsZero() || ttl <= 9*time.Minute || ttl > 10*time.Minute { - t.Errorf("the waiting run %s of %v holds %+v, its bound %s; want x/go in waits and package-wait-minutes' bound", key, keys, run.Waits, ttl) + if len(keys) != 2 || run.Waits == nil || run.Waits.Package != "git.novox.be/novox/x/go" || !strings.HasPrefix(run.Waits.Entry, "the node-engine's entry src2:e") || + run.Waits.Since.IsZero() || ttl <= 9*time.Minute || ttl > 10*time.Minute { + t.Errorf("the waiting run %s of %v holds %+v, its bound %s; want x/go and its entry in waits and package-wait-minutes' bound", key, keys, run.Waits, ttl) } } switch how { @@ -355,6 +357,13 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { kv.expire(runBoundPrefix + key) u.runs.expired(runBoundPrefix + key) } + case "past its bound at a take-up": // the wait began longer ago than package-wait-minutes, as if the assigner were down + for _, key := range keys { + if _, _, err := u.runs.change(key, func(c *meshwants.CompositionRun) bool { c.Waits.Since = c.Waits.Since.Add(-time.Hour); return true }); err != nil { + t.Fatal(err) + } + } + u.r.takeUpWaits(context.Background()) case "superseded": second := make(chan stepOutcome, 1) go func() { @@ -417,13 +426,13 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { if !publish { for _, key := range keys { if run, _, _, _ := u.runs.read(key); run.Ended == nil || run.Waits != nil { - t.Errorf("past its bound the run %s holds ended %v, waits %+v; want it ended and its wait gone", key, run.Ended, run.Waits) + t.Errorf("%s: the run %s holds ended %v, waits %+v; want it ended and its wait gone", how, key, run.Ended, run.Waits) } } - for _, node := range []string{"ace", "g14"} { - if want := node + ": package git.novox.be/novox/x/go has no published version within 10m0s (package-wait-minutes)"; out.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + for node, fp := range map[string]string{"ace": "src2:e1", "g14": "src2:e2"} { + if want := node + ": package git.novox.be/novox/x/go has no published version within 10m0s (package-wait-minutes), named with no version in the node-engine's entry " + fp; out.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(out.Said, want) || strings.Contains(out.Said, "the builder pins or waits") || len(u.asks) != 0 { - t.Errorf("past its bound the step came to %+v with %d run asks put, want could not run saying %q", out, len(u.asks), want) + t.Errorf("%s: the step came to %+v with %d run asks put, want could not run saying %q", how, out, len(u.asks), want) } } continue diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go index 2e6038923..82a50ebd9 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionruns.go @@ -351,10 +351,11 @@ func hearPublished(hub interface { }) } -// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), by compare-and-set: the time -// its wait began is kept where the run holds one already (a start taken up again, H-A-629 (3)), else it is now. It answers that -// time, and false when the key holds another run, or the run ended or has its program. -func (r *compositionRuns) waitFor(key, ask, path string) (time.Time, bool, error) { +// waitFor writes on the run of ask the package it waits for, `waits` (design 47 H2 H-A-629 (1)), with the words of the entry +// that names it with no version (H-A-631), by compare-and-set: the time its wait began is kept where the run holds one already (a +// start taken up again, H-A-629 (3)), else it is now. It answers that time, and false when the key holds another run, or the run +// ended or has its program. +func (r *compositionRuns) waitFor(key, ask, path, entry string) (time.Time, bool, error) { var since time.Time held := false _, _, err := r.change(key, func(c *meshwants.CompositionRun) bool { @@ -364,20 +365,21 @@ func (r *compositionRuns) waitFor(key, ask, path string) (time.Time, bool, error since = r.now().UTC() if c.Waits != nil { since = c.Waits.Since - if c.Waits.Package == path { + if c.Waits.Package == path && c.Waits.Entry == entry { return false } } - c.Waits = &meshwants.CompositionRunWaits{Package: path, Since: since} + c.Waits = &meshwants.CompositionRunWaits{Package: path, Entry: entry, Since: since} return true }) return since, held, err } -// pastWaitSaid is the end of a run of machine whose wait for the publish of the package path passed package-wait-minutes (design -// 47 H2 H-A-628 (3)). -func (r *compositionRuns) pastWaitSaid(machine, path string) string { - said := fmt.Sprintf("package %s has no published version within %s (%s)", path, r.set.packageWait, packageWaitSetting) +// pastWaitSaid is the end of a run of machine whose wait for the publish of the package path, which the entry names with no +// version, passed package-wait-minutes: it names the package, the entry and the bound on every path that ends it, the waiting +// start's, the bound's expiry and the take-up's, each from `waits` (design 47 H2 H-A-628 (3), (5); H-A-630 (4); H-A-631). +func (r *compositionRuns) pastWaitSaid(machine string, w meshwants.CompositionRunWaits) string { + said := fmt.Sprintf("package %s has no published version within %s (%s), named with no version in %s", w.Package, r.set.packageWait, packageWaitSetting, w.Entry) if machine != "" { said = machine + ": " + said } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go index c89da0004..09a0cac1c 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionstep_integration_test.go @@ -288,8 +288,9 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) t.Fatal(err) } var waiting meshwants.CompositionRun - if err := json.Unmarshal(e2.Value(), &waiting); err != nil || waiting.Waits == nil || waiting.Waits.Package != pkg || waiting.Program != nil { - t.Fatalf("the waiting run of n2 holds %s (%v), want waits naming x/go and no program", e2.Value(), err) + if err := json.Unmarshal(e2.Value(), &waiting); err != nil || waiting.Waits == nil || waiting.Waits.Package != pkg || + waiting.Waits.Entry != "the node-engine's entry src2:e1" || waiting.Program != nil { + t.Fatalf("the waiting run of n2 holds %s (%v), want waits naming x/go and its entry, and no program", e2.Value(), err) } waiting.Waits.Since = waiting.Waits.Since.Add(-time.Hour) aged, _ := json.Marshal(waiting) @@ -318,12 +319,13 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) t.Fatal(err) } if e := stepEnd("step-ask-2"); e.Outcome != meshwants.StepEndedOutcomeCouldNotRun || strings.Contains(e.Said, "the builder pins or waits") || - !strings.Contains(e.Said, "n2: package "+pkg+" has no published version within 30s (package-wait-minutes)") || strings.Contains(e.Said, "n1") { + !strings.Contains(e.Said, "n2: package "+pkg+" has no published version within 30s (package-wait-minutes), named with no version in the node-engine's entry src2:e1") || + strings.Contains(e.Said, "n1") { t.Fatalf("the step taken up ended %+v, want could not run naming n2's package past its bound alone", e) } // Past the bound while running (H-A-628 (3), (4)): with package-wait-minutes at one, nothing is published, the bound's expiry - // ends each run could not run naming the package and the bound, and no run ask is put. + // ends each run could not run naming the package, the entry and the bound (H-A-630 (4), H-A-631), and no run ask is put. stop() b.settings["MESH_ASSIGNER_PACKAGE_WAIT_FILE"] = "1" pub.Store(false) @@ -335,7 +337,7 @@ func TestTheCompositionStepComposesEachMachineThroughTheBuildSeat(t *testing.T) Revision: 5, Commit: engineCommit, Fingerprint: "src2:m1"}) e3 := stepEnd("step-ask-3") for _, node := range []string{"n1", "n2"} { - if want := node + ": package " + pkg + " has no published version within 1s (package-wait-minutes)"; e3.Outcome != meshwants.StepEndedOutcomeCouldNotRun || + if want := node + ": package " + pkg + " has no published version within 1s (package-wait-minutes), named with no version in the node-engine's entry src2:e1"; e3.Outcome != meshwants.StepEndedOutcomeCouldNotRun || !strings.Contains(e3.Said, want) || strings.Contains(e3.Said, "the builder pins or waits") { t.Fatalf("the step past its bound ended %+v, want could not run saying %q", e3, want) } diff --git a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go index 5c93d9967..4e95b05e3 100644 --- a/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go +++ b/modules/mesh-delivery-contracts/go/seats/meshwants/contract.go @@ -20,7 +20,7 @@ const Form = 3 // whose fields changed while its forms did not (design 47 H2 §780). const ( generatedForms = "3" - generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=92d1d2424265 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" + generatedFieldsDigest = "Ask=6cb8b82e2fbe AskTakenEvent=6d5d3da7ac39 AsksByAssignmentsProposalValue=0bb5682c7b3b AsksByBackupNodeModuleFingerprintValue=0bb5682c7b3b AsksByHoldModuleFingerprintValue=0bb5682c7b3b AsksByOutsideNodeModuleFingerprintValue=0bb5682c7b3b AsksByRecordNodeModuleDigestValue=0bb5682c7b3b AsksByRestoreNodeModuleFingerprintValue=0bb5682c7b3b AsksByRevertNodeModuleFingerprintValue=0bb5682c7b3b AssignmentEntry=7d2549782eb2 AssignmentRevision=72c8701f7314 AssignmentRevisionCapabilitiesItem=0c89b0717762 AssignmentRevisionEvent=7faff968ce44 AssignmentRevisionsByCandidateGroupHeadsValue=8553b390118d AssignmentRevisionsByEntryDigestValue=4e5ee7a23e5b AssignmentRevisionsByTrunkRevisionValue=8553b390118d BusAnswer=7538f2f5e68e CatalogOf=7a4646fdbea7 Change=28d1f3c5cd32 ChangeAfterItem=30d718c21581 CompositionReader=5a943c1f8ef1 CompositionRun=2a08fc65e2d0 CompositionRunProgram=5a1202df3497 CompositionRunWaits=9cd147ddfc06 CompositionsAnswer=f8bca93c7f9c CompositionsByGroupHeadsValue=9428965fab8f CompositionsDropAnswer=52803700282a Difference=4011cff516b1 DifferenceAnswer=629237aa39f0 DifferenceEvent=49066d0dff6d DifferenceRefusedItem=0e9caa83ace7 DifferencesByNodeModuleValue=a22487ffadfd DropAnswer=7538f2f5e68e Edge=a71709025a08 EntryAnswer=05adebad70d6 Fill=80f442916429 FillingEvent=5bd4df78ed84 FullEvent=5bd4df78ed84 Held=15abbd6a1a33 HeldCandidate=04872f6afbfa InputAnswer=cd41ee65565d KeepNowAnswer=9962ab9fc051 NodeEntryRef=3888ae847653 NotRunning=279b628db0ec PipelineWanted=e1e379c21e59 PipelineWantedEvent=59946b31ab7d PolicyChangedEvent=7538f2f5e68e RevisionAnswer=39002c770cbd RoomEvent=5bd4df78ed84 Shared=c981cf6aa860 SharedAskedBy=c9b30cc4d0d0 StepAccept=18efeefb6c34 StepEnded=edd08ab1a18b StepEndedEvent=207787118dac StepProgressEvent=8215e490ea8d StepRun=b975f402601a UpgradeAnswer=7538f2f5e68e Wait=951500be820c WaitEndedEvent=2bf6d38041c0 WaitHeldEvent=2bf6d38041c0 WantedEvent=58cf7a9f646b WantsByHeldModuleFingerprintValue=ff14aa998a5d WantsByWantNodeModuleValue=ab7c6799fd5d WantsByWantNodeNodeValue=a737a2108d53" ) const ( @@ -858,6 +858,8 @@ type CompositionRunProgram struct { // CompositionRunWaits is the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)). type CompositionRunWaits struct { + // the words of the import-form entry the run is built from, which names the package with no version (such as the node-engine's entry of a fingerprint), written with the package, so every end of the run past its bound names it (design 47 H2 H-A-630 (4), H-A-631) + Entry string `json:"entry"` // the package's path Package string `json:"package"` // the time its wait began, which the bound package-wait-minutes counts from diff --git a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json index 2ba3f893d..a2245fc2f 100644 --- a/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json +++ b/modules/mesh-delivery-contracts/seats/mesh-wants/seat.json @@ -1816,6 +1816,10 @@ "type": "string", "description": "the package's path" }, + "entry": { + "type": "string", + "description": "the words of the import-form entry the run is built from, which names the package with no version (such as the node-engine's entry of a fingerprint), written with the package, so every end of the run past its bound names it (design 47 H2 H-A-630 (4), H-A-631)" + }, "since": { "type": "string", "format": "date-time", @@ -1824,6 +1828,7 @@ }, "required": [ "package", + "entry", "since" ] } diff --git a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts index 0990e6b10..357099d37 100644 --- a/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts +++ b/modules/mesh-delivery-contracts/ts/seats/meshwants/index.d.ts @@ -314,6 +314,8 @@ export interface CompositionRunProgram { /** the package the run waits for before its run ask is put, its publisher's build not yet published: written when the wait begins, deleted when the run ask is put or the run ends; absent while the run waits for nothing (design 47 H2 H-A-628 (3), H-A-629 (1)) */ export interface CompositionRunWaits { + /** the words of the import-form entry the run is built from, which names the package with no version (such as the node-engine's entry of a fingerprint), written with the package, so every end of the run past its bound names it (design 47 H2 H-A-630 (4), H-A-631) */ + "entry": string; /** the package's path */ "package": string; /** the time its wait began, which the bound package-wait-minutes counts from */ -- 2.54.0 From 5884f8ed7bcb60ac3f0b922cdd10db6db210307a Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:17:41 +0100 Subject: [PATCH 8/9] assigner: while a run waits for a package's publish its readers' wait-held names that package (issue 1984, review round 1) A run waiting for a package's publish left its readers said waiting for a build node (`on: build node`), though no ask was put. While the run's value holds `waits`, waitOf now says the step waits for the publish of that package (`on: publish of package `, since the wait began), naming the package and the entry, never a build node; the readers are said so when the wait begins, under their held id with the package's path added, so the bus's duplicate window keeps it apart from the first, and a reader joining a waiting run is said so at its join. Test: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows: each reader's wait-held names the publish of x/go and the node-engine's entry (failed first, no such wait-held within 10 s, with waitOf ignoring `waits`). Builds: design 47 H2 H-A-630 (5) (hq 1cdfa6ff); H-A-631 (hq ee89b857); A-469y --- .../mesh-delivery-assigner/compositionbounds.go | 15 ++++++++++++++- .../cmd/mesh-delivery-assigner/compositionrun.go | 4 ++++ .../mesh-delivery-assigner/compositionrun_test.go | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go index ea44f2bee..5fb6f5fc1 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go @@ -44,7 +44,12 @@ func dropOver(call func(key string, body any) (json.RawMessage, error)) func(ask } } -// waitOf is a reader's wait for a build node to take its run's ask (A-469y). +// waitOnPublish begins what a composition run's waiting reader waits on while the run waits for a package's publish, the +// package's path after it (design 47 H2 H-A-630 (5)). +const waitOnPublish = "publish of package " + +// waitOf is a reader's wait for a build node to take its run's ask (A-469y); while the run's value holds `waits`, its wait for +// that package's publish before the ask is put, naming the package and the entry, never a build node (H-A-630 (5)). func waitOf(run meshwants.CompositionRun, reader meshwants.CompositionReader) meshwants.Wait { w := meshwants.Wait{Step: "pipeline", Owner: meshwants.Seat, Module: reader.Module, Node: run.Machine, On: waitOnBuildNode, Fp: reader.Fingerprint, Words: fmt.Sprintf("the composition step of %s waits for a build node to take the composition run %s of %s (ask %s)", reader.Pipeline, @@ -52,6 +57,11 @@ func waitOf(run meshwants.CompositionRun, reader meshwants.CompositionReader) me if run.Started != nil { w.Since = *run.Started } + if run.Waits != nil { + w.On, w.Since = waitOnPublish+run.Waits.Package, run.Waits.Since + w.Words = fmt.Sprintf("the composition step of %s waits for the publish of package %s, named with no version in %s, before the composition run %s of %s is asked (ask %s)", + reader.Pipeline, run.Waits.Package, run.Waits.Entry, runKeyOf(run.Candidate, run.Machine), run.Machine, run.Ask) + } return w } @@ -63,6 +73,9 @@ func (r *compositionRuns) sayWaits(run meshwants.CompositionRun, readers []meshw for _, c := range readers { w := waitOf(run, c) event, id := meshwants.EventWaitHeld, "composition."+runKeyOf(run.Candidate, run.Machine)+"."+run.Ask+"."+c.ID+".held" + if run.Waits != nil && how == "" { // a wait-held of its own, so the bus's duplicate window does not take it for the first one's + id += "." + run.Waits.Package + } if how != "" { w.How, event, id = how, meshwants.EventWaitEnded, strings.TrimSuffix(id, ".held")+".ended" } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 01d8aaf23..d4734d163 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -887,6 +887,10 @@ func (r *compositionRun) awaitPins(ctx context.Context, key, ask, what string, p said = path r.logf("the composition run %s waits for package %s, named with no version in %s: %s; %s ends its wait at %s", key, path, what, unpublishedSaid(waiting), packageWaitSetting, since.Add(r.runs.set.packageWait).Format(time.RFC3339)) + // Its readers are said waiting for that package's publish, naming it, no longer for a build node (H-A-630 (5)). + if run, _, ok, err := r.runs.read(key); err == nil && ok && run.Ended == nil && run.Ask == ask && run.Waits != nil { + r.runs.sayWaits(run, run.Readers, "") + } } for woke := false; !woke; { changed := r.runs.wake() diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 19a2504a6..741d0d4d6 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -323,6 +323,11 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { u.mu.Unlock() return put(ctx, a) } + u.runs.say = func(event string, body any, id string) error { + w := body.(meshwants.Wait) + journal.logf("said %s on %s: %s (%s)", event, w.On, w.Words, id) + return nil + } phase := &stepPhase{} done := make(chan stepOutcome, 1) first, supersede := context.WithCancel(context.WithValue(context.Background(), phaseKey{}, phase)) @@ -330,6 +335,8 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { go func() { done <- u.r.run(first, "ask-step", step) }() journal.await(t, "waits for package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) journal.await(t, "the composition step of m says fetch: the composition run", 1) + // H-A-630 (5): each reader's wait-held says it waits for x/go's publish, naming the package and the entry. + journal.await(t, "said wait-held on "+waitOnPublish+"git.novox.be/novox/x/go: the composition step of waits for the publish of package git.novox.be/novox/x/go, named with no version in the node-engine's entry src2:e", 2) if got := phase.get(); got != meshwants.StepProgressEventPhaseFetch { t.Errorf("waiting, the step says the phase %q, want fetch", got) } -- 2.54.0 From 773ba91222200d97422193cdff9ebaa9a81465fc Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 23:19:56 +0100 Subject: [PATCH 9/9] assigner: at the put of a run that waited for a package its readers wait for a build node again (issue 1984, review round 1) Once a run's wait for a package's publish ended and its run ask was put, `waits` was deleted but its readers' newest wait-held still said they waited for the package's publish, until ask-taken's wait-ended. Now the start that deletes `waits` as it writes the run's program says its readers' wait-held for a build node again, under their held id with .put added, so the bus's duplicate window keeps it apart from the first; the composition and the validate run alike. Tests: TestTheCompositionStepRunsOneAskPerMachine, the wait's rows: after the put each machine's newest wait-held is for a build node under its held id with .put; TestTheValidateStepRefusesAManifestProblemAndACycle, revision 14: the reader is said waiting for mesh-sdk's publish, then for a build node again at the put. Both failed first without the say at the put. Builds: design 47 H2 H-A-632 (hq c7f31726, f9be4ef0); H-A-630 (5) (hq 1cdfa6ff); H-A-629 (1), (2) (hq 8aa70271) --- .../mesh-delivery-assigner/compositionbounds.go | 13 +++++++++++++ .../cmd/mesh-delivery-assigner/compositionrun.go | 12 +++++++++--- .../mesh-delivery-assigner/compositionrun_test.go | 15 +++++++++++++++ .../cmd/mesh-delivery-assigner/validatestep.go | 12 +++++++++--- .../mesh-delivery-assigner/validatestep_test.go | 13 +++++++++++++ 5 files changed, 59 insertions(+), 6 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go index 5fb6f5fc1..83ea8bce3 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionbounds.go @@ -67,6 +67,18 @@ func waitOf(run meshwants.CompositionRun, reader meshwants.CompositionReader) me // sayWaits says, for each reader, its wait held or ended (how: ran, superseded); a wait that cannot be said is journaled. func (r *compositionRuns) sayWaits(run meshwants.CompositionRun, readers []meshwants.CompositionReader, how string) { + r.sayWaitsOf(run, readers, how, "") +} + +// sayWaitsAtPut says, at the put of the run ask of a run whose wait for a package's publish ended, its readers' wait-held for a +// build node again, under their held id with .put added, so the bus's duplicate window does not take it for the first one's +// (design 47 H2 H-A-632). +func (r *compositionRuns) sayWaitsAtPut(run meshwants.CompositionRun) { + r.sayWaitsOf(run, run.Readers, "", ".put") +} + +// sayWaitsOf is sayWaits, each held id with after added. +func (r *compositionRuns) sayWaitsOf(run meshwants.CompositionRun, readers []meshwants.CompositionReader, how, after string) { if r.say == nil { return } @@ -76,6 +88,7 @@ func (r *compositionRuns) sayWaits(run meshwants.CompositionRun, readers []meshw if run.Waits != nil && how == "" { // a wait-held of its own, so the bus's duplicate window does not take it for the first one's id += "." + run.Waits.Package } + id += after if how != "" { w.How, event, id = how, meshwants.EventWaitEnded, strings.TrimSuffix(id, ".held")+".ended" } diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index d4734d163..f81b50b8f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -326,18 +326,24 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co end(node + ": " + err.Error()) return } - if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool { + waited := false + written, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool { + waited = false if c.Ask != ask || c.Ended != nil { return false } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: engineFp} c.Input = digest - c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) + waited, c.Waits = c.Waits != nil, nil // its wait ends as its run ask is put (H-A-629 (1)) return true - }); err != nil { + }) + if err != nil { end(node + ": the run's program and input are not written: " + err.Error()) return } + if waited { // its readers wait for a build node again, no longer for the package's publish (H-A-632) + r.runs.sayWaitsAtPut(written) + } a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(), Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the composition of " + node + " by the node-engine at " + program.Commit}, Packages: pins} // the composer is built against its entry's pins, each empty one filled (H-A-203, H-A-192, H-A-628 (2)) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index 741d0d4d6..6d4c08a76 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -323,9 +323,15 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { u.mu.Unlock() return put(ctx, a) } + lastHeld := map[string]string{} // by machine: what its newest wait-held waits on, and its id u.runs.say = func(event string, body any, id string) error { w := body.(meshwants.Wait) journal.logf("said %s on %s: %s (%s)", event, w.On, w.Words, id) + if event == meshwants.EventWaitHeld { + u.mu.Lock() + lastHeld[w.Node] = w.On + " (" + id + ")" + u.mu.Unlock() + } return nil } phase := &stepPhase{} @@ -452,6 +458,15 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { t.Errorf("after the publish %s's composer is built against %v, want x/go at v0.1.9", node, a.Packages) } } + // H-A-632: at the put each reader's newest wait-held is for a build node again, under its held id with .put added. + for _, node := range []string{"ace", "g14"} { + u.mu.Lock() + got := lastHeld[node] + u.mu.Unlock() + if !strings.HasPrefix(got, waitOnBuildNode+" (") || !strings.HasSuffix(got, ".held.put)") { + t.Errorf("%s: after the put the newest wait-held of %s waits on %s, want a build node under its held id with .put", how, node, got) + } + } for _, key := range keys { if got := atPut[key]; got != "waits , bound " { t.Errorf("as the run ask of %s was put its wait stood: %s; want waits and the bound gone (§720: an ask in the queue has no clock)", key, got) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go index 7b4332588..95166e21a 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep.go @@ -327,18 +327,24 @@ func (r *compositionRun) startValidate(ctx context.Context, key string, run mesh couldNot(err.Error()) return } - if _, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool { + waited := false + written, _, err := r.runs.change(key, func(c *meshwants.CompositionRun) bool { + waited = false if c.Ask != ask || c.Ended != nil { return false } c.Program = &meshwants.CompositionRunProgram{Repository: program.Repository, Commit: program.Commit, Directory: program.Dir, Fingerprint: entry.Fp} c.Input = digest - c.Waits = nil // its wait ends as its run ask is put (H-A-629 (1)) + waited, c.Waits = c.Waits != nil, nil // its wait ends as its run ask is put (H-A-629 (1)) return true - }); err != nil { + }) + if err != nil { couldNot("the run's program and input are not written: " + err.Error()) return } + if waited { // its readers wait for a build node again, no longer for the package's publish (H-A-632) + r.runs.sayWaitsAtPut(written) + } a := buildstep.StepAsk{ID: ask, Kind: buildstep.AskCheck, Language: buildstep.AskGo, Asker: runAsker, At: r.now().UTC(), Run: &buildstep.RunJob{Program: program, Heads: []buildstep.RunHead{}, Input: ref, Reader: "the manifest validator of " + step.Pipeline + " at " + program.Commit}, Packages: pins} // the validator is built against its entry's pins at the step's revision, each empty one filled (H-A-203, H-A-192, H-A-205, H-A-628 (2)) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go index b18a6531c..5deaaae2f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/validatestep_test.go @@ -119,6 +119,15 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { var requests []composer.Request keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now) runs := newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) + var held []string // the wait-helds of the reader ask-left said, what each waits on and its id (H-A-630 (5), H-A-632) + runs.say = func(event string, body any, id string) error { + if w := body.(meshwants.Wait); event == meshwants.EventWaitHeld && strings.Contains(id, ".ask-left.") { + mu.Lock() + held = append(held, w.On+" ("+id+")") + mu.Unlock() + } + return nil + } r := &compositionRun{runs: runs, keeper: keeper, reads: &compositionReads{}, call: call, callFile: callFile, own: context.Background(), now: time.Now, logf: t.Logf, put: func(_ context.Context, a buildstep.StepAsk) error { body, err := keeper.body(a.Run.Input.Digest) @@ -271,4 +280,8 @@ func TestTheValidateStepRefusesAManifestProblemAndACycle(t *testing.T) { if run.Ended == nil || run.Outcome != meshwants.CompositionRunOutcomePassed || len(asks) != 5 || asks[4].Packages["git.novox.be/novox/mesh-sdk/go"] != "v0.1.36" { t.Errorf("the validate run its starting step left ended %v %s %q with %d validator asks, want it put after the publish and passed", run.Ended, run.Outcome, run.Said, len(asks)) } + if len(held) < 2 || !strings.HasPrefix(held[len(held)-2], waitOnPublish+"git.novox.be/novox/mesh-sdk/go (") || + !strings.HasPrefix(held[len(held)-1], waitOnBuildNode+" (") || !strings.HasSuffix(held[len(held)-1], ".held.put)") { + t.Errorf("the validate run's reader was said waiting %v; want mesh-sdk's publish, then a build node again at the put (H-A-632)", held) + } } -- 2.54.0