From 5e3d92ae337250abf81dbdd27c6a0131a015d6ac Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 20 Nov 2026 16:29:16 +0100 Subject: [PATCH] assigner: leave a stale assignment out of a machine's composition (H-A-148) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The retired checker's assignment on the control-node made every composition there refuse "nothing provides", so every composition step on that machine ended could not run. A module assigned to a machine that the case's manifests do not hold (no watched branch lists it) is now left out of the case's assignments as well, said in the journal and at the judgement as unlisted, and the machine is judged on what remains: a stale assignment is a fault of the assignments, not of the change judged. Builds: design 47 H H-A-148, H-A-143; ADR 0578 §2 --- .../mesh-delivery-assigner/compositionrun.go | 52 +++++++++++++++++-- .../compositionrun_test.go | 48 +++++++++++++++++ .../cmd/mesh-delivery-assigner/main.go | 2 +- .../cmd/mesh-delivery-assigner/world.go | 6 +++ 4 files changed, 102 insertions(+), 6 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 5b7fa7e8..fe5d5e44 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -13,6 +13,8 @@ import ( "github.com/nats-io/nats.go/jetstream" + mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" + 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" meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" @@ -59,8 +61,10 @@ type compositionRun struct { // them (design 47 H-A-143, G §532). Nil: the step's revision alone. newest func() map[string]mcc.Half watched func(module string) []string - // assigned is the modules the assignments place on a machine (world.assignments), for the modules no watched branch lists. - assigned func(node string) []string + // assigned is the modules the assignments place on a machine (world.assignments), for the modules no watched branch lists; + // assignment is the machine's assignments whole, which the case composes with those modules left out (H-A-148). + assigned func(node string) []string + assignment func(node string) (mma.Assignments, bool) // running is the last `running` heard of a module on a node (world.runningOf), never the node-engine's bucket. running func(node, module string) (ne.Running, bool) // away says the watchman holds machine away (machine-away, not back since): the one presence the assigner keeps (world.awayNow), @@ -254,8 +258,15 @@ func (r *compositionRun) start(ctx context.Context, key string, run meshwants.Co end(node + ": " + err.Error()) return } + cs := composer.Case{Name: changeCase, Manifests: prep.manifests, None: prep.none} + if left, err := r.leftOut(node, prep.manifests); err != nil { + end(node + ": " + err.Error()) + return + } else if left != nil { + cs.Assignments = left + } req := composer.Request{V: composer.Version, Input: in.Body, Depth: composer.DepthCompose, Machines: []string{node}, - Cases: []composer.Case{{Name: changeCase, Manifests: prep.manifests, None: prep.none}}, Seats: prep.seats, + Cases: []composer.Case{cs}, Seats: prep.seats, BlameTries: r.runs.set.blameTries} // the composer's bound of its search for culprits (§721, A-466r) raw, err := json.Marshal(req) if err != nil { @@ -301,8 +312,9 @@ const notTried = "not tried: the search reached its bound" // it, on the node's own account; a verdict with no `blamed` (a composer before §721) is judged as before, with the warning "the // composer names no culprits"; otherwise the machine passes, with a warning for each other module blamed there. // -// unlisted are the modules the machine is assigned that none of their watched branches lists: each is said on every path, in the -// machine's failed or could-not-run words where one is set, else as a warning, never dropped in silence (H-A-143, H-A-144). +// unlisted are the modules the machine is assigned that none of their watched branches lists, left out of its composition: each is +// said on every path, in the machine's failed or could-not-run words where one is set, else as a warning, never the machine's +// failure and never dropped in silence (H-A-143, H-A-144, H-A-148). func judgeRun(module string, run meshwants.CompositionRun, unlisted []string) machineEnd { end := judgeVerdict(module, run) for _, u := range unlisted { @@ -602,6 +614,36 @@ func (r *compositionRun) unlistedOn(node string) []string { return slices.Compact(out) } +// leftOut is the case's assignments of node with each module the case's manifests do not hold (none of its watched branches lists +// it) left out, or nil where none is (the case then composes the input's): a stale assignment is a fault of the assignments, not of +// the change judged, so it is left out of the composition, said in the journal and, at the judgement, as unlisted (design 47 +// H-A-148, H-A-143; ADR 0578 §2). +func (r *compositionRun) leftOut(node string, manifests map[string]composer.Manifest) (map[string]json.RawMessage, error) { + if r.assignment == nil { + return nil, nil + } + a, ok := r.assignment(node) + if !ok { + return nil, nil + } + var unlisted []string + for _, m := range a.Modules { + if _, held := manifests[m.Module]; !held { + unlisted = append(unlisted, m.Module) + } + } + if len(unlisted) == 0 { + return nil, nil + } + a.Modules = slices.DeleteFunc(slices.Clone(a.Modules), func(m mma.PlacedModule) bool { return slices.Contains(unlisted, m.Module) }) + raw, err := mmac.EncodeAssignments(a) + if err != nil { + return nil, fmt.Errorf("its assignments with %s left out cannot be encoded: %w", strings.Join(unlisted, ", "), err) + } + r.logf("%s: the composition leaves out %s, assigned there and listed on no watched branch (H-A-148)", node, strings.Join(unlisted, ", ")) + return map[string]json.RawMessage{node: raw}, nil +} + // nodeEngineEntry is the entry of the module that claims the seat node-engine, or false. func nodeEngineEntry(entries map[string]meshcatalog.CatalogEntry) (meshcatalog.CatalogEntry, bool) { for _, name := range slices.Sorted(mapsKeys(entries)) { 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 96b3404a..b1fe0423 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 @@ -11,6 +11,8 @@ import ( "testing" "time" + mmac "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" + 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" meshcatalog "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" @@ -283,6 +285,52 @@ func TestTheCompositionStepRunsOneAskPerMachine(t *testing.T) { c.Manifests["lidarr"].Raw != nil { t.Errorf("the case across the watched branches holds %v", slices.Sorted(maps.Keys(c.Manifests))) } + if c := across.requests["ace"].Cases[0]; c.Assignments != nil { + t.Errorf("with no assignments held the case composes the input's, it carries %v", c.Assignments) + } + + // A stale assignment is left out of the case's assignments as well, said, and the machine composes; a listed module stays in + // (H-A-148, ADR 0578 §2). + for _, tc := range []struct { + name string + assigned []string + want []string // the case's modules of ace; nil: the input's assignments + }{ + {"a stale assignment left out and said, the machine composes", []string{"m", "f1-circuits", "checker"}, []string{"m", "f1-circuits"}}, + {"listed modules alone: the input's assignments", []string{"m", "f1-circuits"}, nil}, + } { + left := newRunStand(t, "src2:e1", "src2:e1", "d1") + left.r.newest, left.r.watched = across.r.newest, across.r.watched + left.r.assigned = func(string) []string { return tc.assigned } + left.r.assignment = func(node string) (mma.Assignments, bool) { + a := mma.Assignments{Node: node} + for _, m := range tc.assigned { + a.Modules = append(a.Modules, mma.PlacedModule{Module: m}) + } + return a, true + } + left.verdict = func(string) (composer.Machine, bool) { return composer.Machine{Composes: true}, true } + out := left.r.run(context.Background(), "ask-step", step) + said := "ace is assigned checker, which no watched branch lists (H-A-143)" + if out.Outcome != meshwants.StepEndedOutcomePassed || (tc.want != nil) != slices.Contains(out.Warnings, said) { + t.Errorf("%s: the step came to %+v", tc.name, out) + } + raw, ok := left.requests["ace"].Cases[0].Assignments["ace"] + if tc.want == nil { + if ok { + t.Errorf("%s: the case carries assignments %s", tc.name, raw) + } + continue + } + a, err := mmac.DecodeAssignments(raw) + var got []string + for _, m := range a.Modules { + got = append(got, m.Module) + } + if err != nil || !slices.Equal(got, tc.want) { + t.Errorf("%s: the case composes ace with %v (%v), want %v", tc.name, got, err, tc.want) + } + } // At the inputs state's cap the ask is refused, naming the store (§354). full := newRunStand(t, "src2:e1", "src2:e1", "d1") 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 e4fac8b3..06eb445f 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -665,7 +665,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, // The composition step (design 47 G §22, §354): the seat mesh-wants' accepted kind step, run by one run ask per machine. if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil { run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, - trunk: trunkOf(iv, w.trunkName), newest: iv.newestOf(), watched: iv.watchedOf, assigned: w.assignedOn, 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, running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf} steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume, validate: run.validate, resumeValidate: run.resumeValidate, ended: runs.stepEnded, now: time.Now, logf: logger.Printf} move := steps.move(ctx) // the readers a rerun carried (§727, A-470d) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go index bb82e620..024beb5b 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/world.go @@ -562,3 +562,9 @@ func (w *world) assignedOn(node string) []string { } return out } + +// assignmentOf is node's assignments, or false where none is held. +func (w *world) assignmentOf(node string) (mma.Assignments, bool) { + a, ok := w.assignments()[node] + return a, ok +}