From e3d994fde182e708162c13aa14103140e10e31c2 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:03:18 +0100 Subject: [PATCH 01/18] composer: a module that fetches from an artifact store no node reaches waits alone, never the node Typed resolution.NoStoreError from artifactsInto (image, source, tools bundle, runtime program, templates archive), laid on its module by composeWithoutStoreFetchers with A-452's "nothing provides" words and composed again, instead of a whole-node refusal. Replaces storeHeld and modulesNeedingTheStore, whose shape list missed bundles and held stand-ins. Builds: design 47 G-22 A-452, A-461, A-461b, A-459b --- internal/compose/node.go | 26 +++++++++++++++- internal/compose/render.go | 10 ------- internal/compose/rendering.go | 27 ----------------- internal/compose/rendering_test.go | 38 +++++++++++++++++++----- internal/compose/resolution/artifacts.go | 15 ++++++++-- 5 files changed, 68 insertions(+), 48 deletions(-) diff --git a/internal/compose/node.go b/internal/compose/node.go index 1d52253f..c9be3575 100644 --- a/internal/compose/node.go +++ b/internal/compose/node.go @@ -2,6 +2,7 @@ package compose import ( "encoding/json" + "errors" "fmt" "sort" "strings" @@ -171,6 +172,29 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) { return d, validate.Declaration(body), nil } +// composeWithoutStoreFetchers is resolution.Compose where a module that fetches from the artifact store while the node reaches +// none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates +// archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it +// (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read. +func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, error) { + for { + composed, err := resolution.Compose(plan, with) + var none *resolution.NoStoreError + if !errors.As(err, &none) { + return composed, with, err + } + if _, already := with.NotPlaced[none.Module]; already { + return catalogue.Composed{}, with, err + } + left := make(map[string]string, len(with.NotPlaced)+1) + for m, why := range with.NotPlaced { + left[m] = why + } + left[none.Module] = none.Error() + with.NotPlaced = left + } +} + // declaration is the controller's declarationWith over the plain Input. func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { resolved, err := c.planFor(nodeName) @@ -188,7 +212,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { with := rendered.Rendering with.Generators = gens plan := resolved.Plan - composed, err := resolution.Compose(plan, with) + composed, with, err := composeWithoutStoreFetchers(plan, with) if err != nil { return Declared{}, err } diff --git a/internal/compose/render.go b/internal/compose/render.go index 194c3da2..09d9b7be 100644 --- a/internal/compose/render.go +++ b/internal/compose/render.go @@ -125,16 +125,6 @@ func (c *composer) render(nodeName string, mode Mode) (Rendered, error) { } } - // A module that fetches from an artifact store with no known address waits for it; the machine composes the rest (A-461). - for module, why := range placed.storeHeld { - if r.NotPlaced == nil { - r.NotPlaced = map[string]string{} - } - if _, said := r.NotPlaced[module]; !said { - r.NotPlaced[module] = why - } - } - // And a certificate for this machine's name inside the mesh, when anything on it asks. for _, m := range plan.Modules { if m.Certificate == nil { diff --git a/internal/compose/rendering.go b/internal/compose/rendering.go index 4dfb2ed6..d7750d0f 100644 --- a/internal/compose/rendering.go +++ b/internal/compose/rendering.go @@ -10,7 +10,6 @@ import ( "git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay" "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/compose/resolution" - "github.com/novox/mesh-host/internal/registryforms" ) // The contracts of the node-engine's statement that gate what a machine is sent, as the controller's link package names them @@ -42,8 +41,6 @@ type Placed struct { // manifest's own number as the Reading mode composes them, and never invented. The controller's adapter allocates and // composes again. ForeseenPorts []string - // storeHeld are the modules left out of the declaration because the artifact store has no known address, and why (A-461). - storeHeld map[string]string } // Places composes the place half of the rendering for a node (the controller's renderingFor in the Reading and Foreseeing modes, @@ -101,7 +98,6 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) { var noAddress *storeListenError if errors.As(err, &noAddress) { // Only the store holder's listen refusal holds its fetchers; any other error still refuses the node (A-461b). - out.storeHeld = modulesNeedingTheStore(plan.Modules, err) store, err = "", nil } if err != nil { @@ -338,29 +334,6 @@ func (c *composer) namesInTheMesh() map[string]string { return out } -// modulesNeedingTheStore are the modules with a resource whose image or source is a kept reference into the artifact store, each -// with why it waits: nothing provides the store's address (A-461). -func modulesNeedingTheStore(modules []catalogue.Manifest, why error) map[string]string { - out := map[string]string{} - for _, m := range modules { - for _, res := range m.Resources { - needs := false - for _, key := range []string{"image", "source"} { - if written, ok := res[key].(string); ok { - if _, kept := registryforms.Forms.InArtifactStore(written); kept { - needs = true - } - } - } - if needs { - out[m.Module] = fmt.Sprintf("nothing provides %q, wanted by %s: %v", "the artifact store's address", m.Module, why) - break - } - } - } - return out -} - // StoreSeat is the seat whose holder is the artifact store (novox/hq ADR 0632 §1): the store's address is that holder's // listen open to the mesh, on the machine assignment puts it on. The provision artifact-store it was found by before is // retired; no module serves it. diff --git a/internal/compose/rendering_test.go b/internal/compose/rendering_test.go index e7bc84e0..698021a5 100644 --- a/internal/compose/rendering_test.go +++ b/internal/compose/rendering_test.go @@ -2,6 +2,7 @@ package compose import ( "errors" + "slices" "strings" "testing" @@ -351,23 +352,44 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) { m := in.Catalogue["registry"] m.Listens = append(m.Listens, catalogue.Listening{Name: "other", Port: 5300, From: catalogue.FromMesh}) in.Catalogue["registry"] = m - // A-461: a store with no known address (two listens open to the mesh, so none is a guess) costs the modules that fetch from - // it, not the node: those wait with the words of an unanswered requirement, and the node composes the rest. + // A-461, A-452: a node that reaches no store address (a holder opening two listens to the mesh, so none is a guess, or a holder + // laid name-only, found by nobody) costs the modules that fetch from it, whatever the shape of the fetch (an image, a tools + // bundle of the runtime), and never the node: they wait with the words of an unanswered requirement, and the rest composes. + dg := "sha256:" + strings.Repeat("a", 64) in.Catalogue["app"] = catalogue.Manifest{Module: "app", Version: "1", - Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@sha256:" + strings.Repeat("a", 64)}}} - in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1"} + Resources: []map[string]any{{"id": "c", "type": "container", "name": "app", "image": "artifact-store://app/c@" + dg}}} + in.Catalogue["node-tools"] = catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true, + OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/node-tools/broker"}}, + Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg, + Digest: dg, Language: "go", Binary: "node-tools"}}} + in.Catalogue["plain"] = catalogue.Manifest{Module: "plain", Version: "1", + Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/plain", "mode": "0700"}}} laptop := nodeOf(t, &in, "laptop") - laptop.Assigned = append(laptop.Assigned, "app", "plain") + laptop.Assigned = append(laptop.Assigned, "app", "node-tools", "plain") + laptop.SealingKey = keyOf(t, "laptop") + in.BusMinted = []string{"laptop.node-tools"} got, err := Render(in, "laptop", Reading) if err != nil { t.Fatalf("a holder opening two listens to the mesh refuses the whole node: %v", err) } - if why := got.Rendering.NotPlaced["app"]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "opens registry (5000), other (5300) to the mesh") { - t.Errorf("the module that fetches from the store waits with %q", why) + if got.Rendering.ArtifactStore != "" { + t.Errorf("the store has an address: %q", got.Rendering.ArtifactStore) } - if why, held := got.Rendering.NotPlaced["plain"]; held { + d, _, err := Compose(in, "laptop") + if err != nil { + t.Fatalf("a node that reaches no store address is refused whole: %v", err) + } + for _, m := range []string{"app", "node-tools"} { + if why := d.LeftOutWhy[m]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "no artifact store") { + t.Errorf("%s, which fetches from the store, waits with %q", m, why) + } + } + if why, held := d.LeftOutWhy["plain"]; held { t.Errorf("a module that fetches nothing from the store waits: %q", why) } + if !slices.ContainsFunc(d.Resources, func(r map[string]any) bool { return r["id"] == "plain.state" }) { + t.Errorf("the rest of the node was not composed: %v", d.Resources) + } // A-461b: only the listen refusal holds the store's fetchers; any other fault of finding the store (here the holder's machine is // on the network as first read but unknown when its assignment is read) still refuses the node. broken := newComposer(in) diff --git a/internal/compose/resolution/artifacts.go b/internal/compose/resolution/artifacts.go index dab2f869..71613ea4 100644 --- a/internal/compose/resolution/artifacts.go +++ b/internal/compose/resolution/artifacts.go @@ -8,6 +8,17 @@ import ( "github.com/novox/mesh-host/internal/registryforms" ) +// NoStoreError is a module that fetches from the artifact store while this node reaches none: it costs that module, never the +// node. The caller leaves the module out of the declaration, with these words (design 47 G A-461, A-452; ADR 0163 rule 6). +type NoStoreError struct { + Module string + said string +} + +func (e *NoStoreError) Error() string { + return fmt.Sprintf("nothing provides %q, wanted by %s: %s", "the artifact store's address", e.Module, e.said) +} + // artifactsInto composes the artifact store's address into a resource's `image` and `source`. // // **Composed here, at the last moment before a machine, and stored nowhere.** A kept reference is @@ -35,11 +46,11 @@ func artifactsInto(resource map[string]any, module string, with mcat.Rendering) } if _, kept := registryforms.Forms.InArtifactStore(written); kept { if with.ArtifactStore == "" { - return fmt.Errorf( + return &NoStoreError{Module: module, said: fmt.Sprintf( "%s's %v names %s, which is in the mesh's artifact store, and this mesh has no "+ "artifact store on its network to fetch it from — nothing assigned holds the seat "+ "container-image-registry, or the machine holding it is not on the private network", - module, resource["id"], written) + module, resource["id"], written)} } resource[key] = registryforms.Forms.Routed(written, with.ArtifactStore) imageSeatInto(resource, key, written, with) -- 2.54.0 From 43c812e98eb07df76717446d037dd41458a6ed20 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:06:01 +0100 Subject: [PATCH 02/18] selfcompose: a module placed on another node and not heard running is laid from its placed or trunk build Being heard running is no condition: such a module counts as one whose running build has no entry (wantedBuilds, askTrunkBuilds, layModules, lacksEntry), so the store holder is found from the build its placement names or its trunk build. Builds: design 47 G-22 A-461d, A-461b --- internal/selfcompose/entries.go | 62 +++++++++++++++++++++------- internal/selfcompose/entries_test.go | 17 +++++--- 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index c5eb2705..9b003c16 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -274,15 +274,20 @@ func (c *Composer) wantedBuilds() map[string]bool { } } } - for node, mods := range c.heard { - for module, run := range mods { + for _, mods := range c.heard { + for _, run := range mods { if !run.stopped && strings.HasPrefix(run.fingerprint, meshcatalogclient.SourcePrefix2) { if _, named := out[run.fingerprint]; !named { out[run.fingerprint] = false } } - // The build the assignment places for another node's module stands for its want where the running build has no entry (A-461). - if built := c.placedBuild(node, module); c.lacksEntry(node, module, run) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { + } + } + // The build the assignment places for another node's module stands for its want where the running build has no entry, or + // none is heard (A-461, A-461d). + for node, p := range c.assignments { + for _, pm := range p.Modules { + if built := c.placedBuild(node, pm.Module); c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { if _, named := out[built]; !named { out[built] = false } @@ -416,6 +421,26 @@ func (c *Composer) layModules() { } } } + // A module placed on another node and not heard running is one whose running build has no entry (A-461d): laid from the build + // its placement names, or its trunk build (A-461b). + placedOn := make([]string, 0, len(c.assignments)) + for node := range c.assignments { + placedOn = append(placedOn, node) + } + sort.Strings(placedOn) + for _, node := range placedOn { + if node == c.env.Node { + continue + } + for _, pm := range c.assignments[node].Modules { + if _, heard := c.heard[node][pm.Module]; heard { + continue + } + if built := c.placedBuild(node, pm.Module); built != "" { + lay(pm.Module, built) + } + } + } for module, w := range c.wants { if module == agent.NodeModule || w.Fp == "" { continue @@ -471,12 +496,19 @@ func (c *Composer) placedBuild(node, module string) string { return "" } -// lacksEntry says whether the build another node's module runs has no entry held (c.mu held): the only case the placed build stands -// in (A-461b). It is never so for this node's own modules. -func (c *Composer) lacksEntry(node, module string, run heardRun) bool { - if node == c.env.Node || run.stopped || run.fingerprint == "" { +// lacksEntry says whether the build another node's module runs has no entry held, or none is heard (c.mu held): the only cases the +// placed build stands in (A-461b, A-461d). It is never so for this node's own modules. +func (c *Composer) lacksEntry(node, module string) bool { + if node == c.env.Node { return false } + run, heard := c.heard[node][module] + if heard && run.stopped { + return false + } + if !heard || run.fingerprint == "" { + return true // placed there, and not heard running (A-461d) + } k, ok := c.keptEnt[run.fingerprint] return !ok || k.entry.Module == "" } @@ -487,15 +519,15 @@ func (c *Composer) askTrunkBuilds() { type ask struct{ node, module, running string } var asks []ask c.mu.Lock() - for node, mods := range c.heard { - for module, run := range mods { - if !c.lacksEntry(node, module, run) { + for node, p := range c.assignments { + for _, pm := range p.Modules { + module := pm.Module + if pm.Build != "" || !c.lacksEntry(node, module) { continue } - for _, pm := range c.assignments[node].Modules { - if pm.Module == module && pm.Build == "" && c.trunkBuilds[module].running != run.fingerprint { - asks = append(asks, ask{node, module, run.fingerprint}) - } + running := c.heard[node][module].fingerprint + if had, asked := c.trunkBuilds[module]; !asked || had.running != running { + asks = append(asks, ask{node, module, running}) } } } diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 30e89a7c..dbc82d67 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -351,12 +351,16 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { node string build, trunk string holds, laid bool + notHeard bool // A-461d: nothing of what the node runs is heard }{ - {"placed build has an entry", "n2", placedFp, "", true, true}, - {"neither build has an entry", "n2", placedFp, "", false, false}, - {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true}, - {"placement names no build, trunk names none", "n2", "", "", false, false}, - {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false}, + {"placed build has an entry", "n2", placedFp, "", true, true, false}, + {"neither build has an entry", "n2", placedFp, "", false, false, false}, + {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true, false}, + {"placement names no build, trunk names none", "n2", "", "", false, false, false}, + {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false, false}, + {"placed, not heard, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, true}, + {"placed, not heard, placed build has an entry (A-461d)", "n2", placedFp, "", true, true, true}, + {"placed, not heard, trunk names none (A-461d)", "n2", "", "", false, false, true}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -371,6 +375,9 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { c.mu.Lock() c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}} c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}} + if tc.notHeard { + c.heard = map[string]map[string]heardRun{} + } c.mu.Unlock() if tc.holds { c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`) -- 2.54.0 From d57e2325f6f439dc2b58ebd39d439be825e39f4f Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:11:59 +0100 Subject: [PATCH 03/18] composer: a store fetcher left out is held with its words, so its handed composition stays Declared.Held carries the modules composeWithoutStoreFetchers leaves out (A-452: each stays on the build it runs). The store-address comment and code say A-461e: no address read without error holds only the fetchers, a fault reading the inputs still refuses the node. Builds: design 47 G-22 A-452, A-461, A-461e --- internal/compose/node.go | 31 ++++++++++++++++++++++++------ internal/compose/rendering.go | 7 ++++--- internal/compose/rendering_test.go | 7 +++++++ 3 files changed, 36 insertions(+), 9 deletions(-) diff --git a/internal/compose/node.go b/internal/compose/node.go index c9be3575..30f05154 100644 --- a/internal/compose/node.go +++ b/internal/compose/node.go @@ -172,19 +172,20 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) { return d, validate.Declaration(body), nil } -// composeWithoutStoreFetchers is resolution.Compose where a module that fetches from the artifact store while the node reaches +// composeWithoutStoreFetchers (it answers the modules it left out, and why) is resolution.Compose where a module that fetches from the artifact store while the node reaches // none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates // archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it // (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read. -func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, error) { +func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, map[string]string, error) { + var held map[string]string for { composed, err := resolution.Compose(plan, with) var none *resolution.NoStoreError if !errors.As(err, &none) { - return composed, with, err + return composed, with, held, err } if _, already := with.NotPlaced[none.Module]; already { - return catalogue.Composed{}, with, err + return catalogue.Composed{}, with, nil, err } left := make(map[string]string, len(with.NotPlaced)+1) for m, why := range with.NotPlaced { @@ -192,6 +193,10 @@ func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rende } left[none.Module] = none.Error() with.NotPlaced = left + if held == nil { + held = map[string]string{} + } + held[none.Module] = none.Error() } } @@ -212,7 +217,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { with := rendered.Rendering with.Generators = gens plan := resolved.Plan - composed, with, err := composeWithoutStoreFetchers(plan, with) + composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with) if err != nil { return Declared{}, err } @@ -226,7 +231,21 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) { if err != nil { return Declared{}, err } - out := Declared{Held: resolved.Held, Resources: composed.Resources, Adoption: adoptionFor(plan, node, composed), + // A module that fetches from a store no node reaches is held with its words, as a module whose claim cannot be held is: it + // stays on the build it runs, its composition kept (A-452, A-461). + held := resolved.Held + if len(storeHeld) > 0 { + held = make(map[string]string, len(resolved.Held)+len(storeHeld)) + for m, why := range resolved.Held { + held[m] = why + } + for m, why := range storeHeld { + if _, said := held[m]; !said { + held[m] = why + } + } + } + out := Declared{Held: held, Resources: composed.Resources, Adoption: adoptionFor(plan, node, composed), Received: composed.Received, Mesh: with.Mesh, BusUsers: with.BusUsers, LeftOut: sortedKeysOf(composed.LeftOut), LeftOutWhy: composed.LeftOut, Withheld: rendered.Withheld, Unbound: rendered.Unbound, diff --git a/internal/compose/rendering.go b/internal/compose/rendering.go index d7750d0f..6382bab2 100644 --- a/internal/compose/rendering.go +++ b/internal/compose/rendering.go @@ -92,12 +92,13 @@ func (c *composer) places(nodeName string, resolved Resolved) (Placed, error) { r.MeshRange = c.overlayRange() // The artifact store as this node reaches it now, with what the mesh has built. - // Where no address is known (the holder opens no listen to the mesh, or two), only the modules that fetch from the store - // wait, with the words of an unanswered requirement; the node composes the rest (design 47 G A-461, A-452). + // No address for any reason read without error (no holder, a holder laid by its name alone, a holder not on the private + // network, a holder opening no listen to the mesh, or two) holds only the modules that fetch from the store: they wait, + // with the words of an unanswered requirement, and the node composes the rest (design 47 G A-461, A-461e, A-452). A fault + // reading the inputs still refuses the node (A-461b). store, err := c.artifactStoreAddress(nodeName) var noAddress *storeListenError if errors.As(err, &noAddress) { - // Only the store holder's listen refusal holds its fetchers; any other error still refuses the node (A-461b). store, err = "", nil } if err != nil { diff --git a/internal/compose/rendering_test.go b/internal/compose/rendering_test.go index 698021a5..8777d324 100644 --- a/internal/compose/rendering_test.go +++ b/internal/compose/rendering_test.go @@ -383,6 +383,13 @@ func TestTheStoreIsFoundByTheImageSeatsHolderAndItsListen(t *testing.T) { if why := d.LeftOutWhy[m]; !strings.Contains(why, "nothing provides") || !strings.Contains(why, "no artifact store") { t.Errorf("%s, which fetches from the store, waits with %q", m, why) } + // Held, not only left out: it stays on the build it runs and its handed composition is kept (A-452). + if why := d.Held[m]; !strings.Contains(why, "nothing provides") { + t.Errorf("%s, which fetches from the store, is held with %q", m, why) + } + } + if _, held := d.Held["plain"]; held { + t.Errorf("a module that fetches nothing from the store is held") } if why, held := d.LeftOutWhy["plain"]; held { t.Errorf("a module that fetches nothing from the store waits: %q", why) -- 2.54.0 From 07ea73bd64f69a16c7596f27a7900ba5997b6c65 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:12:51 +0100 Subject: [PATCH 04/18] selfcompose: a stopped or build-less placed module is laid from its placement; an unobtained trunk build is asked again lacksEntry holds for a stopped run and for one naming no build, and the loop for another node's placed modules lays every one not yet laid where it holds. A trunk build askTrunkBuilds could not get is said with its reason and asked again on the next pass. Builds: design 47 G-22 A-461d, A-461e --- internal/selfcompose/entries.go | 20 +++++++++-------- internal/selfcompose/entries_test.go | 33 +++++++++++++++++++--------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 9b003c16..f5801ffe 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -421,8 +421,8 @@ func (c *Composer) layModules() { } } } - // A module placed on another node and not heard running is one whose running build has no entry (A-461d): laid from the build - // its placement names, or its trunk build (A-461b). + // A module placed on another node and not heard running (or stopped, or running no build it names) is one whose running build has + // no entry (A-461d): laid, where not laid yet, from the build its placement names, or its trunk build (A-461b). placedOn := make([]string, 0, len(c.assignments)) for node := range c.assignments { placedOn = append(placedOn, node) @@ -433,7 +433,7 @@ func (c *Composer) layModules() { continue } for _, pm := range c.assignments[node].Modules { - if _, heard := c.heard[node][pm.Module]; heard { + if _, laid := modules[pm.Module]; laid || !c.lacksEntry(node, pm.Module) { continue } if built := c.placedBuild(node, pm.Module); built != "" { @@ -503,11 +503,8 @@ func (c *Composer) lacksEntry(node, module string) bool { return false } run, heard := c.heard[node][module] - if heard && run.stopped { - return false - } - if !heard || run.fingerprint == "" { - return true // placed there, and not heard running (A-461d) + if !heard || run.stopped || run.fingerprint == "" { + return true // placed there, and not heard running (A-461d), stopped or running no build it names } k, ok := c.keptEnt[run.fingerprint] return !ok || k.entry.Module == "" @@ -533,7 +530,12 @@ func (c *Composer) askTrunkBuilds() { } c.mu.Unlock() for _, a := range asks { - fp, _ := c.trunkFp(a.module) + fp, why := c.trunkFp(a.module) + if fp == "" { + // Said with its reason, and asked again on the next pass: nothing is kept of an answer that was none (A-461e). + c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again: %s", a.module, a.node, why)) + continue + } c.mu.Lock() if c.trunkBuilds == nil { c.trunkBuilds = map[string]trunkBuild{} diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index dbc82d67..6bb5f7b3 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -351,16 +351,18 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { node string build, trunk string holds, laid bool - notHeard bool // A-461d: nothing of what the node runs is heard + heard string // A-461d: what is heard of it: "" its running build, "none", "stopped", "no-build" }{ - {"placed build has an entry", "n2", placedFp, "", true, true, false}, - {"neither build has an entry", "n2", placedFp, "", false, false, false}, - {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true, false}, - {"placement names no build, trunk names none", "n2", "", "", false, false, false}, - {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false, false}, - {"placed, not heard, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, true}, - {"placed, not heard, placed build has an entry (A-461d)", "n2", placedFp, "", true, true, true}, - {"placed, not heard, trunk names none (A-461d)", "n2", "", "", false, false, true}, + {"placed build has an entry", "n2", placedFp, "", true, true, ""}, + {"neither build has an entry", "n2", placedFp, "", false, false, ""}, + {"placement names no build, trunk build has an entry", "n2", "", placedFp, true, true, ""}, + {"placement names no build, trunk names none", "n2", "", "", false, false, ""}, + {"this node's own module is not laid from a placement", "n1", placedFp, "", true, false, ""}, + {"placed, not heard, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "none"}, + {"placed, not heard, placed build has an entry (A-461d)", "n2", placedFp, "", true, true, "none"}, + {"placed, stopped there, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "stopped"}, + {"placed, heard with no build, placement names no build, trunk build has an entry (A-461d)", "n2", "", placedFp, true, true, "no-build"}, + {"placed, not heard, trunk names none (A-461d)", "n2", "", "", false, false, "none"}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -375,14 +377,25 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { c.mu.Lock() c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}} c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}} - if tc.notHeard { + switch tc.heard { + case "none": c.heard = map[string]map[string]heardRun{} + case "stopped": + c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old, stopped: true}}} + case "no-build": + c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {}}} } c.mu.Unlock() if tc.holds { c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`) } c.askTrunkBuilds() + c.mu.Lock() + _, kept := c.trunkBuilds["distribution"] + c.mu.Unlock() + if tc.node == "n2" && tc.build == "" && tc.trunk == "" && kept { + t.Error("a trunk build that could not be had was kept, so it is asked once per process (A-461e)") + } if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) { t.Errorf("the placed build asked = %v", asked) } -- 2.54.0 From 9172eccbc47da0716b3ffc9a03f5c07a61f748e2 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 16:52:28 +0100 Subject: [PATCH 05/18] selfcompose: only what the node needs of another node's placement is asked, beside the pass The trunk build is asked, and a placed module laid, only for the store's holder (a store seat's holding on that node) and the providers this node's modules are bound to; never every module placed elsewhere. The asks run beside the pass, three at a time, and an answer asks a pass; a module that waits is only the one needing that address. Builds: design 47 G-22 A-461, A-461d, A-461e --- internal/selfcompose/entries.go | 80 ++++++++++++++++++++++------ internal/selfcompose/entries_test.go | 40 +++++++++++++- internal/selfcompose/selfcompose.go | 2 + 3 files changed, 103 insertions(+), 19 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index f5801ffe..18015852 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -12,6 +12,7 @@ import ( "slices" "sort" "strings" + "sync" "time" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" @@ -21,6 +22,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/agent" + "github.com/novox/mesh-host/internal/compose/resolution" engcomp "github.com/novox/mesh-host/internal/compositions" ) @@ -287,7 +289,7 @@ func (c *Composer) wantedBuilds() map[string]bool { // none is heard (A-461, A-461d). for node, p := range c.assignments { for _, pm := range p.Modules { - if built := c.placedBuild(node, pm.Module); c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { + if built := c.placedBuild(node, pm.Module); c.needsAddressOf(node, pm.Module) && c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { if _, named := out[built]; !named { out[built] = false } @@ -433,7 +435,7 @@ func (c *Composer) layModules() { continue } for _, pm := range c.assignments[node].Modules { - if _, laid := modules[pm.Module]; laid || !c.lacksEntry(node, pm.Module) { + if _, laid := modules[pm.Module]; laid || !c.needsAddressOf(node, pm.Module) || !c.lacksEntry(node, pm.Module) { continue } if built := c.placedBuild(node, pm.Module); built != "" { @@ -510,39 +512,83 @@ func (c *Composer) lacksEntry(node, module string) bool { return !ok || k.entry.Module == "" } +// needsAddressOf says whether this node needs the address of module on node (c.mu held): it holds a store seat there (the image +// seats' holders), or a module placed here is bound to it as the provider of a requirement (A-461). +func (c *Composer) needsAddressOf(node, module string) bool { + for _, h := range c.assignments[node].Holds { + if h.Module == module && slices.Contains(resolution.StoreSeats, h.Claim) { + return true + } + } + for _, pm := range c.assignments[c.env.Node].Modules { + for _, b := range pm.Bindings { + if b.Module == module && b.Node == node { + return true + } + } + } + return false +} + // askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk // build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call. -func (c *Composer) askTrunkBuilds() { +func (c *Composer) askTrunkBuilds() (wait func()) { type ask struct{ node, module, running string } var asks []ask c.mu.Lock() for node, p := range c.assignments { for _, pm := range p.Modules { module := pm.Module - if pm.Build != "" || !c.lacksEntry(node, module) { + // Only a module this node needs the address of (A-461): the store's holder, the provider of a requirement. + if pm.Build != "" || !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) || c.trunkAsking[module] { continue } running := c.heard[node][module].fingerprint if had, asked := c.trunkBuilds[module]; !asked || had.running != running { asks = append(asks, ask{node, module, running}) + if c.trunkAsking == nil { + c.trunkAsking = map[string]bool{} + } + c.trunkAsking[module] = true } } } c.mu.Unlock() - for _, a := range asks { - fp, why := c.trunkFp(a.module) - if fp == "" { - // Said with its reason, and asked again on the next pass: nothing is kept of an answer that was none (A-461e). - c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again: %s", a.module, a.node, why)) - continue - } - c.mu.Lock() - if c.trunkBuilds == nil { - c.trunkBuilds = map[string]trunkBuild{} - } - c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp} - c.mu.Unlock() + // Asked beside the pass, a few at a time: no pass waits on the catalog half's answer, and a module that waits for it is only + // the one needing that address (A-461e). An answer asks a pass. + var all sync.WaitGroup + work := make(chan ask) + for i := 0; i < 3 && i < len(asks); i++ { + all.Add(1) + go func() { + defer all.Done() + for a := range work { + fp, why := c.trunkFp(a.module) + c.mu.Lock() + delete(c.trunkAsking, a.module) + if fp != "" { + if c.trunkBuilds == nil { + c.trunkBuilds = map[string]trunkBuild{} + } + c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp} + } + c.mu.Unlock() + if fp == "" { + // Said with its reason, and asked again on the next pass: nothing is kept of an answer that was none (A-461e). + c.env.Say(fmt.Sprintf("the trunk build of %s, placed on %s, could not be had, and is asked again: %s", a.module, a.node, why)) + continue + } + c.askRehand() + } + }() } + go func() { + for _, a := range asks { + work <- a + } + close(work) + }() + return all.Wait } // entryManifest is an entry's manifest as a reader takes it, with its digest: the one the indexer set at take-in, or, where it set diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 6bb5f7b3..5d857781 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -375,7 +375,8 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { }) c := New(env) c.mu.Lock() - c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}} + c.assignments[tc.node] = meshmoduleassigner.Assignments{Node: tc.node, Modules: []meshmoduleassigner.PlacedModule{{Module: "distribution", Build: tc.build}}, + Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}} c.heard = map[string]map[string]heardRun{tc.node: {"distribution": {fingerprint: old}}} switch tc.heard { case "none": @@ -389,7 +390,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { if tc.holds { c.holdEntry(t, "distribution", placedFp, `{"module":"distribution","version":"2"}`) } - c.askTrunkBuilds() + c.askTrunkBuilds()() c.mu.Lock() _, kept := c.trunkBuilds["distribution"] c.mu.Unlock() @@ -410,3 +411,38 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { }) } } + +// A-461, A-461e: a node asks the trunk build only of what it needs of another node's placement (the store's holder, the provider +// it is bound to), never of every module placed there, and beside the pass. +func TestOnlyWhatTheNodeNeedsOfAnotherNodesPlacementIsAsked(t *testing.T) { + env := newFakeBus().env() + env.Node = "n1" + var mu sync.Mutex + asked := map[string]int{} + env.Entry = EntryCall(func(_ context.Context, _, verb string, in any) (json.RawMessage, error) { + if verb == meshcatalog.VerbModule { + mu.Lock() + asked[in.(meshcatalog.ModuleInput).Module]++ + mu.Unlock() + } + return nil, errors.New("not held") + }) + c := New(env) + var unrelated []meshmoduleassigner.PlacedModule + for i := 0; i < 40; i++ { + unrelated = append(unrelated, meshmoduleassigner.PlacedModule{Module: fmt.Sprintf("unrelated%d", i)}) + } + c.mu.Lock() + c.assignments["n2"] = meshmoduleassigner.Assignments{Node: "n2", + Modules: append(unrelated, meshmoduleassigner.PlacedModule{Module: "distribution"}, meshmoduleassigner.PlacedModule{Module: "provider"}), + Holds: []meshmoduleassigner.Holding{{Claim: "container-image-registry", Module: "distribution", Scope: "mesh"}}} + c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{ + {Module: "app", Bindings: map[string]meshmoduleassigner.Provider{"postgres-database": {Module: "provider", Node: "n2"}}}}} + c.mu.Unlock() + c.askTrunkBuilds()() + mu.Lock() + defer mu.Unlock() + if len(asked) != 2 || asked["distribution"] != 1 || asked["provider"] != 1 { + t.Errorf("the trunk builds asked are %v, want the store's holder and the bound provider alone", asked) + } +} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index 994205c4..cf5e4408 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -212,6 +212,8 @@ type Composer struct { heard map[string]map[string]heardRun // trunkBuilds is, by module, the trunk build asked for another node's module whose placement names none, with the running build it was asked for (A-461b). trunkBuilds map[string]trunkBuild + // trunkAsking is, by module, a trunk build being asked beside the pass (askTrunkBuilds), under mu. + trunkAsking map[string]bool heardRead bool // ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that // ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293). -- 2.54.0 From baeb87d19582a426f0fe98933209d7693a31941b Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 22:58:11 +0100 Subject: [PATCH 06/18] frombus: a held module still provides what its running build provides (A-480) A module the node holds keeps running what it runs, so a module that requires what it provides is no longer held for "nothing provides": the held offer's provisions are the running composition's build's manifest, else the manifest the module's running event names. Builds: design 47 G A-480 (G-22-lead-answers-2.md) --- internal/compose/frombus/answer.go | 23 +++++++++++ internal/compose/frombus/held_rows_test.go | 46 ++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/internal/compose/frombus/answer.go b/internal/compose/frombus/answer.go index cf2ca2b0..27b8f5aa 100644 --- a/internal/compose/frombus/answer.go +++ b/internal/compose/frombus/answer.go @@ -358,11 +358,21 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b if !ok { return } + running, known := catalogue.Manifest{}, false if ran != nil { if was, ok := ran(m); ok { man.Contributes, man.ContributesMany, man.Listens = was.Contributes, was.ContributesMany, was.Listens + running, known = was, true } } + if !known { + running, known = heardManifest(in, node, m) + } + if known { + // A held module keeps running what it runs, so it keeps providing what that build provides, whatever its version and + // whether the catalog lists the build: the module that requires it is no "nothing provides" (A-480). + man.Provides = running.Provides + } src[m] = man } if leave != "" { @@ -512,6 +522,19 @@ func manifestOn(in compose.Input, node, module string) (catalogue.Manifest, bool return man, ok } +// heardManifest is the manifest of the build node said it runs of module (its `running` event's manifest, read by the event's digest, +// Node.Heard): false where nothing runs of it, it is stopped or the digest could not be read. +func heardManifest(in compose.Input, node, module string) (catalogue.Manifest, bool) { + for _, n := range in.Nodes { + if n.Name == node { + if h, ok := n.Heard[module]; ok && h.Read && !h.Stopped { + return h.Manifest, true + } + } + } + return catalogue.Manifest{}, false +} + // culprit is the module placed on node whose composition the error is of, and what of its offer to leave out: the // first, in assignment order, whose stub (compose.Stub) makes the composition in mode succeed or fail otherwise (leave // ""); else the first whose stub without what it contributes to one provision does (leave that provision: de-spiegel's diff --git a/internal/compose/frombus/held_rows_test.go b/internal/compose/frombus/held_rows_test.go index 05588031..71077f7c 100644 --- a/internal/compose/frombus/held_rows_test.go +++ b/internal/compose/frombus/held_rows_test.go @@ -338,3 +338,49 @@ func TestASecondClaimantOfASeatIsHeldAndTheNodeComposesTheRest(t *testing.T) { } } } + +// A-480 (design 47 G): a module the node holds keeps running what it runs, and so keeps providing what its running build provides, +// whatever its catalogue entry: the module that requires it is not held for "nothing provides" (live, 2026-11-17 22:52: feh on g14 +// held for "x11-display" while xorg runs there, held only for want of an entry of its wanted build). The offer is the running +// composition's build's manifest (the builder's done key), else the manifest the module's `running` event names; a module +// neither running nor composable still gives "nothing provides". +func TestAHeldModuleStillProvidesWhatItsRunningBuildProvides(t *testing.T) { + const xorgRunning = `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` + feh := `{"module":"feh","version":"1","requires":["x11-display"]}` + nameOnly := `{"module":"xorg","version":"0"}` + for _, row := range []struct { + name string + scope func(fps map[string]string, b *bus) Scope + provided bool + }{ + {"it runs a build its running event names", func(fps map[string]string, b *bus) Scope { + digest := meshcatalogclient.ManifestDigest([]byte(xorgRunning)) + b.manifests[digest] = []byte(xorgRunning) + return Scope{Heard: map[string]map[string]Heard{"n1": {"xorg": {Fingerprint: "src2:" + strings.Repeat("r", 64), Manifest: digest}}}} + }, true}, + {"its composition runs a build the builder holds done", func(fps map[string]string, b *bus) Scope { + fp := "src2:" + strings.Repeat("r", 64) + digest := meshcatalogclient.ManifestDigest([]byte(xorgRunning)) + b.manifests[digest] = []byte(xorgRunning) + b.builds["xorg "+fp] = &builds.BuilderBuild{State: builds.BuildDone, Manifest: digest} + return Scope{Running: []engcomp.Composed{{Node: "n1", Module: "xorg", FP: fp}}} + }, true}, + {"nothing of it runs", func(map[string]string, *bus) Scope { return Scope{} }, false}, + } { + b, fps := aNode(t, nameOnly, feh) + scope := row.scope(fps, b) + scope.Node = "n1" + scope.Held = map[string]string{"xorg": "entry-missing: the catalog half holds no entry of the build"} + _, _, held, err := Compose(context.Background(), b, Mesh{}, scope, fps) + why, fehHeld := held["feh"] + if row.provided && (err != nil || fehHeld) { + t.Errorf("%s: err %v, feh held %q; want feh composed with xorg held as what runs", row.name, err, why) + } + if !row.provided && !(fehHeld && strings.Contains(why, `nothing provides "x11-display"`)) && (err == nil || !strings.Contains(err.Error(), "nothing provides")) { + t.Errorf("%s: err %v, held %v; want nothing provides", row.name, err, held) + } + if !strings.Contains(held["xorg"], "entry-missing") { + t.Errorf("%s: xorg's own hold is %q, want it said", row.name, held["xorg"]) + } + } +} -- 2.54.0 From e7803f8943055bd9b0bd7360cf7ecf8edecee2df Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:01:09 +0100 Subject: [PATCH 07/18] frombus: the A-480 rows join the held-rows test, no new test function Builds: design 47 G A-480 (G-22-lead-answers-2.md) --- internal/compose/frombus/held_rows_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/compose/frombus/held_rows_test.go b/internal/compose/frombus/held_rows_test.go index 71077f7c..4d8d8367 100644 --- a/internal/compose/frombus/held_rows_test.go +++ b/internal/compose/frombus/held_rows_test.go @@ -337,14 +337,13 @@ func TestASecondClaimantOfASeatIsHeldAndTheNodeComposesTheRest(t *testing.T) { t.Errorf("running %v: the answer is %+v, want beta refused with the claim's words", running, ans) } } -} -// A-480 (design 47 G): a module the node holds keeps running what it runs, and so keeps providing what its running build provides, -// whatever its catalogue entry: the module that requires it is not held for "nothing provides" (live, 2026-11-17 22:52: feh on g14 -// held for "x11-display" while xorg runs there, held only for want of an entry of its wanted build). The offer is the running -// composition's build's manifest (the builder's done key), else the manifest the module's `running` event names; a module -// neither running nor composable still gives "nothing provides". -func TestAHeldModuleStillProvidesWhatItsRunningBuildProvides(t *testing.T) { + // A-480 rows, in this test to keep the module's count: + // A-480 (design 47 G): a module the node holds keeps running what it runs, and so keeps providing what its running build provides, + // whatever its catalogue entry: the module that requires it is not held for "nothing provides" (live, 2026-11-17 22:52: feh on g14 + // held for "x11-display" while xorg runs there, held only for want of an entry of its wanted build). The offer is the running + // composition's build's manifest (the builder's done key), else the manifest the module's `running` event names; a module + // neither running nor composable still gives "nothing provides". const xorgRunning = `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` feh := `{"module":"feh","version":"1","requires":["x11-display"]}` nameOnly := `{"module":"xorg","version":"0"}` -- 2.54.0 From 7bfeb466bfc0cd601ed25fdcb42702f2e7df4b57 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:09:15 +0100 Subject: [PATCH 08/18] selfcompose: a module that runs with no entry of its wanted or running build counts what its trunk build provides (A-480a) Builds: design 47 G A-480a (G-22-lead-answers-2.md) --- internal/selfcompose/entries.go | 51 ++++++++++++++++++++++++++++ internal/selfcompose/entries_test.go | 22 +++++++++--- 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 18015852..922142c6 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -296,6 +296,14 @@ func (c *Composer) wantedBuilds() map[string]bool { } } } + // The trunk build of a module this node runs without an entry of its wanted or running build is asked too (A-480a). + for module, tb := range c.trunkBuilds { + if tb.fp != "" && c.runsWithoutEntry(module) { + if _, named := out[tb.fp]; !named { + out[tb.fp] = false + } + } + } // The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held // for the judgement of a move's data forms though the catalog half dropped it and no event of the stream names it. for _, r := range running { @@ -463,6 +471,17 @@ func (c *Composer) layModules() { } continue } + // Running here with no entry of its wanted or running build and none of the newest: it stands, for resolution alone, as its + // trunk build, so the module that requires what it provides is no "nothing provides" (A-480a); its want stays held. + if _, laid := modules[module]; !laid && c.runsWithoutEntry(module) { + if tb := c.trunkBuilds[module]; tb.fp != "" && lay(module, tb.fp) { + m := modules[module] + m.Fp2 = w.Fp + modules[module] = m + said = append(said, fmt.Sprintf("%s runs a build whose manifest the node does not hold, so it counts what the trunk build %s of %s provides; its want stays held", module, tb.fp, module)) + continue + } + } lay(module, w.Fp) } // A module an assignment places whose entry is not held (not wanted here, not heard running, or its entry asked and not @@ -530,6 +549,22 @@ func (c *Composer) needsAddressOf(node, module string) bool { return false } +// runsWithoutEntry says this node runs module (heard, not stopped) and holds no entry of its wanted build nor of its running build +// (c.mu held): the case where its provisions are read from its trunk build (A-480a). +func (c *Composer) runsWithoutEntry(module string) bool { + run, ok := c.heard[c.env.Node][module] + w, wanted := c.wants[module] + if !ok || run.stopped || !wanted || w.Fp == "" { + return false + } + for _, fp := range []string{w.Fp, run.fingerprint} { + if k, held := c.keptEnt[fp]; held && k.entry.Module != "" { + return false + } + } + return true +} + // askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk // build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call. func (c *Composer) askTrunkBuilds() (wait func()) { @@ -553,6 +588,22 @@ func (c *Composer) askTrunkBuilds() (wait func()) { } } } + // A module this node runs whose wanted build and running build have no entry stands as its trunk build, for resolution alone + // (A-480a): asked once per running build, as another node's is. + for _, pm := range c.assignments[c.env.Node].Modules { + module := pm.Module + if !c.runsWithoutEntry(module) || c.trunkAsking[module] { + continue + } + running := c.heard[c.env.Node][module].fingerprint + if had, asked := c.trunkBuilds[module]; !asked || had.running != running { + asks = append(asks, ask{c.env.Node, module, running}) + if c.trunkAsking == nil { + c.trunkAsking = map[string]bool{} + } + c.trunkAsking[module] = true + } + } c.mu.Unlock() // Asked beside the pass, a few at a time: no pass waits on the catalog half's answer, and a module that waits for it is only // the one needing that address (A-461e). An answer asks a pass. diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 5d857781..c3298890 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -274,15 +274,25 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { holds bool laid bool wantFp string + trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) }{ - {"runs, newest entry held", true, newest, true, true, old}, - {"not running here", false, newest, true, false, old}, - {"names no newer build", true, "", false, false, old}, - {"newest entry not held", true, newest, false, false, old}, + {"runs, newest entry held", true, newest, true, true, old, false}, + {"not running here", false, newest, true, false, old, false}, + {"names no newer build", true, "", false, false, old, false}, + {"newest entry not held", true, newest, false, false, old, false}, + {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, true}, + {"not running here, trunk entry held (A-480a)", false, "", false, false, old, true}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() env.Node = "n1" + trunkFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("4", 64) + env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) { + if verb == meshcatalog.VerbModule && tc.trunk { + return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp}}) + } + return nil, errors.New("not held") + }) c := New(env) c.mu.Lock() c.wants["postgres"] = meshwants.WantsByWantNodeModuleValue{Fp: old, Newest: tc.newest} @@ -294,6 +304,10 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { if tc.holds { c.holdEntry(t, "postgres", newest, body) } + if tc.trunk { + c.holdEntry(t, "postgres", trunkFp, body) + } + c.askTrunkBuilds()() if got := c.wantedBuilds()[newest]; tc.newest != "" && got { t.Errorf("the newest build is named by a want, want only asked") } -- 2.54.0 From 179a4a64023100380be626931bf068206105e931 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:16:33 +0100 Subject: [PATCH 09/18] selfcompose: a module built by hand, with no running event, is held as running; its trunk build is asked (A-480a) Builds: design 47 G A-480a (G-22-lead-answers-2.md) --- internal/selfcompose/entries.go | 9 +++---- internal/selfcompose/entries_test.go | 36 +++++++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 922142c6..14ccf1e3 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -549,12 +549,13 @@ func (c *Composer) needsAddressOf(node, module string) bool { return false } -// runsWithoutEntry says this node runs module (heard, not stopped) and holds no entry of its wanted build nor of its running build -// (c.mu held): the case where its provisions are read from its trunk build (A-480a). +// runsWithoutEntry says this node holds module on, as it runs it, and holds no entry of its wanted build nor of its running build +// (c.mu held): the case where its provisions are read from its trunk build (A-480a). A module built by hand before G says no running +// event (the engine says one only of a build whose manifest it knows), so it is held as running unless it was heard stopped. func (c *Composer) runsWithoutEntry(module string) bool { - run, ok := c.heard[c.env.Node][module] + run := c.heard[c.env.Node][module] w, wanted := c.wants[module] - if !ok || run.stopped || !wanted || w.Fp == "" { + if run.stopped || !wanted || w.Fp == "" { return false } for _, fp := range []string{w.Fp, run.fingerprint} { diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index c3298890..b506ba2e 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -44,7 +44,10 @@ func composeFromEntries(t *testing.T) { var mu sync.Mutex var asked []string ask := func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) { - in := args.(meshcatalog.EntryInput) + in, isEntry := args.(meshcatalog.EntryInput) + if !isEntry { + return nil, errors.New("the catalog half holds no trunk build here") // A-480a: the module verb, asked of a ghost + } mu.Lock() asked = append(asked, in.Fingerprint) mu.Unlock() @@ -268,20 +271,22 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { newest := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64) body := `{"module":"postgres","version":"2"}` for _, tc := range []struct { - name string - runs bool - newest string - holds bool - laid bool - wantFp string - trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) + name string + runs bool + newest string + holds bool + laid bool + wantFp string + stopped bool // A-480a: heard stopped + trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) }{ - {"runs, newest entry held", true, newest, true, true, old, false}, - {"not running here", false, newest, true, false, old, false}, - {"names no newer build", true, "", false, false, old, false}, - {"newest entry not held", true, newest, false, false, old, false}, - {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, true}, - {"not running here, trunk entry held (A-480a)", false, "", false, false, old, true}, + {"runs, newest entry held", true, newest, true, true, old, false, false}, + {"not running here", false, newest, true, false, old, false, false}, + {"names no newer build", true, "", false, false, old, false, false}, + {"newest entry not held", true, newest, false, false, old, false, false}, + {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true}, + {"heard no running event (built by hand), trunk entry held (A-480a)", false, "", false, true, old, false, true}, + {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -300,6 +305,9 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { if tc.runs { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}} } + if tc.stopped { + c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, stopped: true}}} + } c.mu.Unlock() if tc.holds { c.holdEntry(t, "postgres", newest, body) -- 2.54.0 From 87cfae48b23a4fb8c0a9ec4352c5e53d3aec25d7 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:44:15 +0100 Subject: [PATCH 10/18] agent: the parts check counts the templates archives a composition was rendered from as fetched (A-481, A-481a) compose fills Composed.Templates from the resolved manifest's TemplatesDigest; partsDifference adds them to the digests fetched. Builds: design 47 G A-481, A-481a --- internal/agent/agent.go | 2 +- internal/agent/agent_test.go | 25 ++++++++++++++++------- internal/agent/parts.go | 7 ++++++- internal/compose/composed.go | 4 ++++ internal/compose/composed_test.go | 10 +++++++++ internal/compositions/composed.go | 6 ++++-- internal/compositions/composed_compare.go | 2 ++ 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index a83ace65..72262646 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -1631,7 +1631,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo // A want with parts is applied only when they and the digests its composition fetches agree (design 47 G §524): the // module keeps running what it has, and the have says which digest differs. - if words := partsDifference(w.Want.Parts, comp.C.Resources); words != "" { + if words := partsDifference(w.Want.Parts, comp.C.Resources, comp.C.Templates); words != "" { a.mu.Lock() prev, runs := a.running[module] a.attempt[module] = attempt{FP: fp, Composed: dig, WantRev: w.Rev, CompRev: comp.Rev, Held: true, AnsweredRev: w.Rev} diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 8ea01aa6..4a4989a2 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -364,33 +364,44 @@ func TestAWantAndItsCompositionApplyTheModuleAndTheHaveNamesBoth(t *testing.T) { } // A container's digest is the one after its image's @. container := json.RawMessage(`{"id":"web.c","type":"container","name":"web-c","image":"store/web@` + d3 + `","image-seat":"mesh-artifact-store","image-holder":"n1","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, nil); got != "" { t.Fatalf("a container whose digest is in the parts differs: %q", got) } // A-454: an image the manifest pins from outside, by its digest, is no part of the want's parts, and a mesh-built one still is. upstream := json.RawMessage(`{"id":"web.u","type":"container","name":"web-u","image":"registry@` + d2 + `","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, upstream}, nil); got != "" { t.Fatalf("an upstream image pinned by its digest is a part: %q", got) } // And neither is the registry seat's copy of an upstream image, though it is routed through the seat. mirrored := json.RawMessage(`{"id":"web.m","type":"container","name":"web-m","image":"store:5000/upstream/docker.io/library/registry@` + d1 + `","image-seat":"container-image-registry","image-holder":"n1","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, mirrored}, nil); got != "" { t.Fatalf("an upstream copy served through the registry seat is a part: %q", got) } - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{upstream}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d3) || strings.Contains(got, d2) { t.Fatalf("with only an upstream image the mesh-built one is not missing, or the upstream one is named: %q", got) } // A-454a: a mesh-built image whose seat holder is not on record carries no image-seat; its digest is in the parts, so it is fetched. noSeat := json.RawMessage(`{"id":"web.n","type":"container","name":"web-n","image":"store/web@` + d3 + `","module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat}, nil); got != "" { t.Fatalf("a mesh-built image with no image-seat, named by the parts, is not fetched: %q", got) } - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{noSeat, upstream}, nil); got != "" { t.Fatalf("an upstream image beside it is a part: %q", got) } + // A-481: a templates archive the composition was rendered from is fetched, one the want's parts do not name is a part + // the composition lacks, and the want's digest nothing read stays not fetched. + if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, []string{d1}); got != "" { + t.Fatalf("a templates archive named by the parts and rendered from is fetched: %q", got) + } + if got := partsDifference(map[string]string{"web:c": d3, "web:files": d1}, []json.RawMessage{container}, nil); !strings.Contains(got, "in the want's parts and not fetched: "+d1) { + t.Fatalf("a templates archive nothing read stays not fetched: %q", got) + } + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container}, []string{d1}); !strings.Contains(got, "fetched and not in the want's parts: "+d1) { + t.Fatalf("a templates archive outside the parts differs: %q", got) + } // A-432: a runtime of its own runs the tool runner's program, which the module's parts do not name. ownRuntime := json.RawMessage(`{"id":"web.own-runtime","type":"process","name":"web-runtime","source":"store/node-tools","digest":"` + d1 + `","run":["./node-tools"],"module":"web"}`) - if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}); got != "" { + if got := partsDifference(map[string]string{"web:c": d3}, []json.RawMessage{container, ownRuntime}, nil); got != "" { t.Fatalf("a runtime of its own differs from the module's parts: %q", got) } } diff --git a/internal/agent/parts.go b/internal/agent/parts.go index 5d19152b..bcd9c0eb 100644 --- a/internal/agent/parts.go +++ b/internal/agent/parts.go @@ -60,7 +60,7 @@ func upstreamCopy(image string) bool { // assigner of before G, or a node whose record does not state `want-parts`) is applied as today: it returns "". With // `parts`, the want is applied only when the digest of every resource fetched is among the values of `parts` and every // value of `parts` is the digest of a resource fetched; otherwise it returns the detail naming each digest. -func partsDifference(parts map[string]string, resources []json.RawMessage) string { +func partsDifference(parts map[string]string, resources []json.RawMessage, templates []string) string { if len(parts) == 0 { return "" } @@ -69,6 +69,11 @@ func partsDifference(parts map[string]string, resources []json.RawMessage) strin inParts[d] = true } fetched := map[string]bool{} + // A templates archive the composition was rendered from was read from the artifact store and checked by its digest: + // a part fetched (design 47 G A-481, A-481a). + for _, d := range templates { + fetched[d] = true + } for _, raw := range resources { r, err := declaration.ParseResource(raw) if err != nil { diff --git a/internal/compose/composed.go b/internal/compose/composed.go index eff389e5..6866fa9a 100644 --- a/internal/compose/composed.go +++ b/internal/compose/composed.go @@ -297,6 +297,10 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli } if m, ok := in.Catalogue[c.Module]; ok && c.Module != "" { c.Data = len(m.DataItems()) > 0 + // The archive its files were rendered from, which the parts check counts as fetched (design 47 G A-481a). + if m.TemplatesDigest != "" { + c.Templates = []string{m.TemplatesDigest} + } out[key] = c } } diff --git a/internal/compose/composed_test.go b/internal/compose/composed_test.go index 11732c84..71eaf9b0 100644 --- a/internal/compose/composed_test.go +++ b/internal/compose/composed_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" engcomp "github.com/novox/mesh-host/internal/compositions" + "slices" "sort" "strings" "testing" @@ -32,10 +33,19 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { sort.Strings(want) fps := map[string]string{"mesh-wireguard": fpFor('a'), "files": fpFor('b')} + // A-481a: the composition names the digest of the templates archive its module was rendered from. + templated := in.Catalogue["files"] + templated.TemplatesDigest = "sha256:" + strings.Repeat("e", 64) + in.Catalogue["files"] = templated out, skipped, err := Compositions(in, "laptop", fps, Foreseeing) if err != nil || len(skipped) != 0 { t.Fatalf("Compositions = %v, skipped %v", err, skipped) } + for _, c := range out { + if want := map[string][]string{"files": {templated.TemplatesDigest}}[c.Module]; !slices.Equal(c.Templates, want) { + t.Errorf("%s names the templates %v, want %v", c.Module, c.Templates, want) + } + } var got []string for key, c := range out { node, module, fp, isNode, err := engcomp.ParseKey(key) diff --git a/internal/compositions/composed.go b/internal/compositions/composed.go index 6549e389..5d1d730b 100644 --- a/internal/compositions/composed.go +++ b/internal/compositions/composed.go @@ -40,6 +40,8 @@ type Composed struct { Own NodeOwn Plan *catalogue.Plan Refused string + // Templates are the digests of the templates archives the module's files were rendered from, sorted (A-481a). + Templates []string } // Bucket constants of a node's compositions (the state composed is one bucket per node). @@ -65,7 +67,7 @@ func BucketFor(node string) (string, error) { func toClient(c Composed) (nodeengineclient.Composition, error) { out := nodeengineclient.Composition{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, - Resources: c.Resources, Filled: c.Filled, Refused: c.Refused} + Resources: c.Resources, Filled: c.Filled, Refused: c.Refused, Templates: c.Templates} raw, err := json.Marshal(c.Own) if err != nil { return out, err @@ -83,7 +85,7 @@ func toClient(c Composed) (nodeengineclient.Composition, error) { func fromClient(c nodeengineclient.Composition) (Composed, error) { out := Composed{V: c.V, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, Resources: c.Resources, - Filled: c.Filled, Refused: c.Refused} + Filled: c.Filled, Refused: c.Refused, Templates: c.Templates} raw, err := json.Marshal(c.Own) if err != nil { return out, err diff --git a/internal/compositions/composed_compare.go b/internal/compositions/composed_compare.go index ec3606ed..827a40be 100644 --- a/internal/compositions/composed_compare.go +++ b/internal/compositions/composed_compare.go @@ -150,6 +150,8 @@ func compareOne(module string, composed, running Composed, sameValue func(a, b s switch { case !jsonEqual(a.Filled, b.Filled): return differs("", "the files the provisioner fills differ") + case !jsonEqual(a.Templates, b.Templates): + return differs("", "the templates archives it was rendered from differ") case a.Data != b.Data: return differs("", "whether it declares data differs") case !jsonEqual(a.Own, b.Own): -- 2.54.0 From ba9d4787f94c41daf498e6fd838d9b032e38a875 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:46:03 +0100 Subject: [PATCH 11/18] selfcompose: a module counts as running here only when heard, run by the agent or its have says running or held; the trunk build stands only where no manifest is named (A-482, A-480a) Both review findings of 7bfeb466 and 179a4a64 sit in runsWithoutEntry and are one change. Builds: design 47 G A-482, A-480a --- internal/selfcompose/entries.go | 15 ++++++++++--- internal/selfcompose/entries_test.go | 32 +++++++++++++++++++--------- internal/selfcompose/selfcompose.go | 18 ++++++++++++---- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 14ccf1e3..d07b7bf9 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -550,14 +550,23 @@ func (c *Composer) needsAddressOf(node, module string) bool { } // runsWithoutEntry says this node holds module on, as it runs it, and holds no entry of its wanted build nor of its running build -// (c.mu held): the case where its provisions are read from its trunk build (A-480a). A module built by hand before G says no running -// event (the engine says one only of a build whose manifest it knows), so it is held as running unless it was heard stopped. +// (c.mu held), and that neither its running event nor a composition it runs names the manifest of that build: the case where its +// provisions are read from its trunk build (A-480a). A module built by hand before G says no running event (the engine says one only +// of a build whose manifest it knows), so it counts as running when its have names a build in the phase running or held (A-482); one +// wanted here that is heard running nowhere, runs nothing here and has no such have does not count. func (c *Composer) runsWithoutEntry(module string) bool { run := c.heard[c.env.Node][module] w, wanted := c.wants[module] - if run.stopped || !wanted || w.Fp == "" { + if run.stopped || !wanted || w.Fp == "" || run.manifest != "" || !(c.runsHere(module) || c.haveRuns[module]) { return false } + if c.env.Running != nil { + for _, r := range c.env.Running() { + if r.Module == module && r.FP != "" { + return false // its running composition says the build it runs: its manifest is read there, or its own words say it is not + } + } + } for _, fp := range []string{w.Fp, run.fingerprint} { if k, held := c.keptEnt[fp]; held && k.entry.Module != "" { return false diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index b506ba2e..b0ae1ab5 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -46,7 +46,8 @@ func composeFromEntries(t *testing.T) { ask := func(_ context.Context, seat, verb string, args any) (json.RawMessage, error) { in, isEntry := args.(meshcatalog.EntryInput) if !isEntry { - return nil, errors.New("the catalog half holds no trunk build here") // A-480a: the module verb, asked of a ghost + t.Errorf("the trunk build is asked (%s %v) of a module nothing says runs here (A-482)", verb, args) + return nil, errors.New("the catalog half holds no trunk build here") } mu.Lock() asked = append(asked, in.Fingerprint) @@ -277,16 +278,21 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { holds bool laid bool wantFp string - stopped bool // A-480a: heard stopped - trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) + stopped bool // A-480a: heard stopped + trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) + have string // A-482: the phase its have says, naming the build it runs ("" for none) + named bool // A-480a: its running event names a manifest }{ - {"runs, newest entry held", true, newest, true, true, old, false, false}, - {"not running here", false, newest, true, false, old, false, false}, - {"names no newer build", true, "", false, false, old, false, false}, - {"newest entry not held", true, newest, false, false, old, false, false}, - {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true}, - {"heard no running event (built by hand), trunk entry held (A-480a)", false, "", false, true, old, false, true}, - {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true}, + {"runs, newest entry held", true, newest, true, true, old, false, false, "", false}, + {"not running here", false, newest, true, false, old, false, false, "", false}, + {"names no newer build", true, "", false, false, old, false, false, "", false}, + {"newest entry not held", true, newest, false, false, old, false, false, "", false}, + {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true, "", false}, + {"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", false}, + {"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", false}, + {"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", false}, + {"its running event names a manifest (A-480a)", true, "", false, false, old, false, true, "", true}, + {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", false}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -305,6 +311,12 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { if tc.runs { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}} } + if tc.named { + c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, manifest: "sha256:" + strings.Repeat("9", 64)}}} + } + if tc.have != "" { + c.haveRuns["postgres"] = true + } if tc.stopped { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, stopped: true}}} } diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index cf5e4408..f2f463a4 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -179,7 +179,10 @@ type Composer struct { records map[string]nodeengine.NodeRecord // inOwn is, by module, whether this node's have of it names no fingerprint of the new form (mesh-wireguard, a module // at a build of the old form): the node runs it inside its own composition, and composes it there again (issue 1126). - inOwn map[string]bool + inOwn map[string]bool + // haveRuns is, by module, whether this node's have of it names a build in the phase running or held: a module that + // keeps running what it runs, though no running event says it (design 47 G A-482). + haveRuns map[string]bool modules map[string]meshcatalog.ModulesByModuleValue told map[string]bool // lines said once each (sayOnceEach) values map[string]map[string]any // by module, this node's @@ -423,7 +426,7 @@ func New(env Env) *Composer { func newComposer(env Env) *Composer { return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, assignments: map[string]meshmoduleassigner.Assignments{}, assignmentKeys: meshmoduleassignerclient.NewKeys(), - records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{}, + records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, haveRuns: map[string]bool{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{}, manifests: map[string][]byte{}, archives: map[string][]byte{}, handed: map[string]string{}, notTaken: map[string]string{}, unmadeSaid: map[string]string{}, rehand: make(chan struct{}, 1), sealedOwn: map[string]ownSealed{}, pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)} } @@ -862,9 +865,10 @@ func (c *Composer) takeModuleHave(u agent.Update) bool { if err != nil || isNode || node != c.env.Node { return false } - in := false + in, runs := false, false if !u.Deleted { if h, err := nodeengineclient.DecodeHave(u.Value); err == nil { + runs = (h.Phase == nodeengineclient.PhaseRunning || h.Phase == nodeengineclient.PhaseHeld) && h.Fp != "" // A have that names nothing it runs, failed (the node could not compose a module it never ran: NotComposed), is // no module run inside the node's own composition: taken as one, it was composed from its manifest past its // build (issue 1126, review round 1 of the builds). @@ -879,8 +883,14 @@ func (c *Composer) takeModuleHave(u agent.Update) bool { } c.mu.Lock() defer c.mu.Unlock() + changed := c.haveRuns[module] != runs + if runs { + c.haveRuns[module] = true + } else { + delete(c.haveRuns, module) + } if c.inOwn[module] == in { - return false + return changed } if in { c.inOwn[module] = true -- 2.54.0 From 121a8090b3cfa91348485db08ea5ef360a8c2443 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:57:16 +0100 Subject: [PATCH 12/18] composer: a take-in's templates digest is no difference between two manifests (A-481a) Builds: design 47 G A-481a --- internal/composer/composer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 5013e4e8..60372efa 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -743,6 +743,7 @@ func manifestOf(how *compose.ComposedHow, module string) string { func sameContract(built, carried catalogue.Manifest) bool { contract := func(m catalogue.Manifest) string { m.Handed, m.Build, m.Templates, m.Resources, m.Bundles, m.Items = nil, nil, "", nil, nil, nil + m.TemplatesDigest = "" // written by a take-in (A-481a) raw, err := json.Marshal(m) if err != nil { return "" -- 2.54.0 From cdd8bd3cba384458e00d41fdcdc1c7487929bdd4 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:58:13 +0100 Subject: [PATCH 13/18] selfcompose: what is read decides the trunk build's stand: the running event's manifest held, a running composition's build read as ranOf reads it (A-480a, A-482) Builds: design 47 G A-480a, A-482 --- internal/selfcompose/entries.go | 15 +++++----- internal/selfcompose/entries_test.go | 37 +++++++++++++++--------- internal/selfcompose/selfcompose_test.go | 19 +++++++----- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index d07b7bf9..ca6abd86 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -550,22 +550,21 @@ func (c *Composer) needsAddressOf(node, module string) bool { } // runsWithoutEntry says this node holds module on, as it runs it, and holds no entry of its wanted build nor of its running build -// (c.mu held), and that neither its running event nor a composition it runs names the manifest of that build: the case where its +// (c.mu held), and whose running event's manifest is not held (A-480a): the case where its // provisions are read from its trunk build (A-480a). A module built by hand before G says no running event (the engine says one only // of a build whose manifest it knows), so it counts as running when its have names a build in the phase running or held (A-482); one // wanted here that is heard running nowhere, runs nothing here and has no such have does not count. func (c *Composer) runsWithoutEntry(module string) bool { run := c.heard[c.env.Node][module] w, wanted := c.wants[module] - if run.stopped || !wanted || w.Fp == "" || run.manifest != "" || !(c.runsHere(module) || c.haveRuns[module]) { + if run.stopped || !wanted || w.Fp == "" || !(c.runsHere(module) || c.haveRuns[module]) { return false } - if c.env.Running != nil { - for _, r := range c.env.Running() { - if r.Module == module && r.FP != "" { - return false // its running composition says the build it runs: its manifest is read there, or its own words say it is not - } - } + // What is read decides (A-480a: "can be read from neither"): the manifest its running event names, where that digest is held; + // a running composition's build is read as frombus ranOf reads it, only through the entry of the wanted fingerprint (the + // loop below), so a composition at another build reads nothing. + if _, read := c.manifests[run.manifest]; run.manifest != "" && read { + return false } for _, fp := range []string{w.Fp, run.fingerprint} { if k, held := c.keptEnt[fp]; held && k.entry.Module != "" { diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index b0ae1ab5..5650de53 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -281,18 +281,20 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { stopped bool // A-480a: heard stopped trunk bool // A-480a: the catalog half's trunk build of the module has an entry (the newest build has none) have string // A-482: the phase its have says, naming the build it runs ("" for none) - named bool // A-480a: its running event names a manifest + named string // A-480a: the manifest its running event names ("held": one this node holds, "unread": one it does not) }{ - {"runs, newest entry held", true, newest, true, true, old, false, false, "", false}, - {"not running here", false, newest, true, false, old, false, false, "", false}, - {"names no newer build", true, "", false, false, old, false, false, "", false}, - {"newest entry not held", true, newest, false, false, old, false, false, "", false}, - {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true, "", false}, - {"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", false}, - {"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", false}, - {"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", false}, - {"its running event names a manifest (A-480a)", true, "", false, false, old, false, true, "", true}, - {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", false}, + {"runs, newest entry held", true, newest, true, true, old, false, false, "", ""}, + {"not running here", false, newest, true, false, old, false, false, "", ""}, + {"names no newer build", true, "", false, false, old, false, false, "", ""}, + {"newest entry not held", true, newest, false, false, old, false, false, "", ""}, + {"runs, no newest build, trunk entry held (A-480a)", true, "", false, true, old, false, true, "", ""}, + {"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", ""}, + {"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", ""}, + {"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", ""}, + {"its running event names a manifest this node holds (A-480a)", true, "", false, false, old, false, true, "", "held"}, + {"its running event names a manifest this node cannot read (A-480a)", true, "", false, true, old, false, true, "", "unread"}, + {"runs a composition at another build, no manifest read (A-480a)", true, "", false, true, old, false, true, "other", ""}, + {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", ""}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -311,12 +313,21 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { if tc.runs { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}} } - if tc.named { - c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, manifest: "sha256:" + strings.Repeat("9", 64)}}} + if tc.named != "" { + digest := "sha256:" + strings.Repeat("9", 64) + c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, manifest: digest}}} + if tc.named == "held" { + c.manifests[digest] = []byte(body) + } } if tc.have != "" { c.haveRuns["postgres"] = true } + if tc.have == "other" { + c.env.Running = func() []compositions.Composed { + return []compositions.Composed{{Node: "n1", Module: "postgres", FP: meshcatalogclient.SourcePrefix2 + strings.Repeat("5", 64)}} + } + } if tc.stopped { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old, stopped: true}}} } diff --git a/internal/selfcompose/selfcompose_test.go b/internal/selfcompose/selfcompose_test.go index 3b7209fb..e97dab75 100644 --- a/internal/selfcompose/selfcompose_test.go +++ b/internal/selfcompose/selfcompose_test.go @@ -1828,22 +1828,24 @@ func TestAHaveSaysWhetherItsModuleRunsInsideTheNodesOwn(t *testing.T) { in bool // heldToday says the shadow counts the module held today (issue 1126: a seed holding it too holds it as today). heldToday bool + // runs says the have names a build in the phase running or held: it keeps running what it runs (A-482). + runs bool }{ {"failed, naming nothing it runs", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseFailed, Health: nodeengineclient.HealthFailed, - Detail: "the node cannot compose it, and keeps running what it ran: no build"}, false, true}, + Detail: "the node cannot compose it, and keeps running what it ran: no build"}, false, true, false}, {"failed at a build fingerprint", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseFailed, - Health: nodeengineclient.HealthFailed, Detail: "the node cannot compose it, and keeps running what it ran: no build"}, true, true}, + Health: nodeengineclient.HealthFailed, Detail: "the node cannot compose it, and keeps running what it ran: no build"}, true, true, false}, // The live have of novox's de-spiegel (2026-10-28): a build of the old form, named by `build`, and no `fp`. - {"running a build of the old form", nodeengine.HaveByNodeModuleValue{Build: "build-1790368817085312877", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, true}, + {"running a build of the old form", nodeengine.HaveByNodeModuleValue{Build: "build-1790368817085312877", Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, true, false}, {"running a build of the new form", nodeengine.HaveByNodeModuleValue{Fp: meshcatalogclient.SourcePrefix2 + strings.Repeat("a", 64), Composed: "sha256:" + strings.Repeat("c", 64), - Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, false, false}, - {"running with no fingerprint (mesh-wireguard)", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, false}, + Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, false, false, true}, + {"running with no fingerprint (mesh-wireguard)", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK}, true, false, false}, {"held today", nodeengine.HaveByNodeModuleValue{Fp: "build-0123abcd", Composed: "sha256:" + strings.Repeat("c", 64), Phase: nodeengineclient.PhaseHeld, - Health: nodeengineclient.HealthWaits, Detail: "held: a required config value is unset"}, true, true}, + Health: nodeengineclient.HealthWaits, Detail: "held: a required config value is unset"}, true, true, true}, // novox's postgres (2026-10-31), its have written before mesh-host #189: held by a backup the node agent's stop // interrupted and naming nothing; counted in, it was composed from its manifest and refused for its secret reader. {"held by an interrupted backup, naming nothing", nodeengine.HaveByNodeModuleValue{Phase: nodeengineclient.PhaseHeld, Health: nodeengineclient.HealthWaits, - Detail: agent.BackupInterrupted}, false, true}, + Detail: agent.BackupInterrupted}, false, true, false}, } { t.Run(row.name, func(t *testing.T) { c := New(Env{Node: "n1"}) @@ -1859,6 +1861,9 @@ func TestAHaveSaysWhetherItsModuleRunsInsideTheNodesOwn(t *testing.T) { if c.inOwn["web"] != row.in { t.Errorf("web counted inside the node's own composition: %v, want %v", c.inOwn["web"], row.in) } + if c.haveRuns["web"] != row.runs { + t.Errorf("web counted as running by its have: %v, want %v", c.haveRuns["web"], row.runs) + } s := &Shadow{c: c, ran: map[string]string{}} s.takeRan(agent.Update{Key: key, Value: value}) if _, got := s.heldToday(nil)["web"]; got != row.heldToday { -- 2.54.0 From d1768241dc5a53dbbca328fbd3474a78880f87c2 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 00:23:46 +0100 Subject: [PATCH 14/18] selfcompose: a running build with no entry keeps what its running composition keeps; with no data on either side the move goes on (A-483) Builds: design 47 G A-483 --- internal/selfcompose/entries.go | 14 ++++++++++ internal/selfcompose/entries_test.go | 39 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index ca6abd86..74d01903 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -825,6 +825,20 @@ func (c *Composer) FormChanges(_ context.Context, module, runningFp, appliedFp s } running, err := read(runningFp) if err != nil { + // A running build with no entry (one from before G): what it keeps on the bus is read from the composition it runs on this + // node, as what it provides is (A-480). Where neither that composition nor the wanted build's manifest keeps data, no form + // can change; where either does, the module still waits for the entry (A-113, A-483). + wanted, werr := read(appliedFp) + if werr != nil { + return nil, fmt.Errorf("%s's wanted manifest: %w", module, werr) + } + if c.env.Running != nil && len(wanted.DataItems()) == 0 { + for _, r := range c.env.Running() { + if r.Module == module && r.FP != "" && !r.Data { + return nil, nil + } + } + } return nil, fmt.Errorf("%s's running manifest: %w", module, err) } applied, err := read(appliedFp) diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 5650de53..beafd92b 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -387,6 +387,45 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { t.Error("an entry of the running build was answered, and the composition was not handed again") } + // A-483: a running build with no entry is read from the composition it runs here: where neither it nor the wanted build's manifest + // keeps data on the bus no form can change and the move goes on; where either does, or no composition is run, it still waits. + for _, tc := range []struct { + name string + runs, data bool // a composition of the module runs here, keeping data + wantedData bool + wantedHeld bool + moves bool + }{ + {"no entry of the running build, its composition and the wanted build keep no data", true, false, false, true, true}, + {"no entry, its composition keeps data", true, true, false, true, false}, + {"no entry, the wanted build keeps data", true, false, true, true, false}, + {"no entry, no composition of it runs here", false, false, false, true, false}, + {"no entry, the wanted build's entry is not held either", true, false, false, false, false}, + } { + t.Run(tc.name, func(t *testing.T) { + env := newFakeBus().env() + env.Node = "n1" + env.Running = func() []compositions.Composed { + if !tc.runs { + return nil + } + return []compositions.Composed{{Node: "n1", Module: "feh", FP: old, Data: tc.data}} + } + c := New(env) + if tc.wantedHeld { + body := `{"module":"feh","version":"2"}` + if tc.wantedData { + body = `{"module":"feh","version":"2","data":{"own":[{"id":"state","kind":"state"}]}}` + } + c.holdEntry(t, "feh", next, body) + } + changes, err := c.FormChanges(context.Background(), "feh", old, next) + if (err == nil) != tc.moves || len(changes) != 0 { + t.Errorf("FormChanges = %v, %v; the move goes on: %v", changes, err, tc.moves) + } + }) + } + // A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment // places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name // alone, and this node's own module is never laid from a placement. -- 2.54.0 From 0cc1728a049e74ec570808e15c23f10c81eba8cf Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 00:34:36 +0100 Subject: [PATCH 15/18] =?UTF-8?q?agent:=20a=20held=20have=20is=20judged=20?= =?UTF-8?q?again=20at=20a=20start=20from=20its=20wait's=20reason,=20not=20?= =?UTF-8?q?from=20its=20detail's=20opening=20words=20(A-453,=20=C2=A7541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G A-453, §541, A-484 --- internal/agent/agent.go | 4 ++-- internal/agent/agent_test.go | 27 +++++++++++++++++++-------- internal/agent/parts.go | 20 ++++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 72262646..a3a7437c 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -1539,7 +1539,7 @@ func (a *Agent) baseline(ctx context.Context, module string, w wantNow, comp com a.mu.Unlock() return false } - if h.Phase == string(nodeengineclient.PhaseHeld) && !judgedAgain(h.Detail) { + if h.Phase == string(nodeengineclient.PhaseHeld) && !judgedAgain(h) { // Held for a failed backup, and the operator's answer is still to come: the hold is kept, nothing is // backed up again or applied, and the next revision of the want is the answer (ADR 0568 §4). Said, so // why it holds is read from the journal and not guessed (issue 1585: this branch was silent). @@ -1643,7 +1643,7 @@ func (a *Agent) apply(ctx context.Context, module string, w wantNow, comp compNo } a.env.Say(fmt.Sprintf("%s is held: %s", module, words)) a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld), - Detail: words, Wait: a.composeWait("parts-differ", words)}) + Detail: words, Wait: a.composeWait(strings.TrimSuffix(PartsDiffer, ":"), words)}) return } diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index 4a4989a2..d70664b3 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -859,20 +859,28 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) { detail, backup string backups, applied int phase string - namesNothing bool // the have names no fp and no composition + namesNothing bool // the have names no fp and no composition + reason string // the reason of the wait the have carries; empty: it carries none }{ - {BackupInterrupted, meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false}, + {BackupInterrupted, meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false, ""}, // novox's postgres: its held have, written before mesh-host #189, names nothing it runs. - {BackupInterrupted, "", 1, 1, nodeengineclient.PhaseRunning, true}, + {BackupInterrupted, "", 1, 1, nodeengineclient.PhaseRunning, true, ""}, // A backup that failed, and the want carries the operator's answer, written before this start (nats on novox, // 2026-11-04, issue 1585): again backs it up and applies, skip applies without one; no answer keeps the hold. - {"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false}, - {"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, 1, nodeengineclient.PhaseRunning, false}, - {"restic: the repository is locked", "", 0, 0, nodeengineclient.PhaseHeld, false}, + {"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupAgain, 1, 1, nodeengineclient.PhaseRunning, false, ""}, + {"restic: the repository is locked", meshwants.WantsByWantNodeModuleValueBackupSkip, 0, 1, nodeengineclient.PhaseRunning, false, ""}, + {"restic: the repository is locked", "", 0, 0, nodeengineclient.PhaseHeld, false, ""}, // A hold the node-engine judges again (novox's indexer, 2026-11-16): its parts differed or its entry was not // held, which no answer of the operator's releases; at a start it is judged again, here backed up and applied. - {PartsDiffer + " fetched and not in the want's parts: sha256:a03131c6", "", 1, 1, nodeengineclient.PhaseRunning, false}, - {EntryMissing + " the catalog half holds no entry of the build", "", 1, 1, nodeengineclient.PhaseRunning, false}, + {PartsDiffer + " fetched and not in the want's parts: sha256:a03131c6", "", 1, 1, nodeengineclient.PhaseRunning, false, "parts-differ"}, + {EntryMissing + " the catalog half holds no entry of the build", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-missing"}, + // g14's feh, 2026-11-18: the kept step's hold opens "whether ..." and says its reason in its wait; the words decide nothing. + {"whether feh's kept data changes form is not known", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-missing"}, + {EntryAsked + " the entry is asked", "", 1, 1, nodeengineclient.PhaseRunning, false, "entry-asked"}, + // Opening words alone are no reason: a failed backup's detail that opens with them waits for the answer. + {PartsDiffer + " as the words of a failed backup", "", 0, 0, nodeengineclient.PhaseHeld, false, ""}, + // A restore point not taken waits for the answer, its reason being its words. + {"the restore point of db's data was not taken", "", 0, 0, nodeengineclient.PhaseHeld, false, "the restore point of db's data was not taken"}, } { r := newBed(t) r.comps.before(ck1, craw1) @@ -880,6 +888,9 @@ func TestADataModuleIsBackedUpFirstAndHeldWhenItFails(t *testing.T) { wk, wraw := wantFor(t, "db", fp2, dig2, row.backup) r.wants.before(wk, wraw) held := Have{Module: "db", FP: fp1, Composed: dig1, Phase: string(nodeengineclient.PhaseHeld), Detail: row.detail} + if row.reason != "" { + held.Wait = &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: row.reason, Words: row.detail} + } if row.namesNothing { held.FP, held.Composed = "", "" } diff --git a/internal/agent/parts.go b/internal/agent/parts.go index bcd9c0eb..19e47efb 100644 --- a/internal/agent/parts.go +++ b/internal/agent/parts.go @@ -23,12 +23,20 @@ const ( EntryMissing = "entry-missing:" ) -// judgedAgain says a held have's detail is a hold the node-engine judges again at a start, not one that waits for the -// operator's answer: its want's parts differ from its composition (§524) or its entry is not held (§421). Only a failed -// backup or restore point waits for an answer (ADR 0568 §4); novox, 2026-11-16: the indexer held "parts-differ" was kept -// at a start as "held for a failed backup", waiting for an answer nobody was asked. -func judgedAgain(why string) bool { - return strings.HasPrefix(why, PartsDiffer) || heldForEntry(why) +// judgedAgain says a held have is a hold the node-engine judges again at a start, not one that waits for the operator's answer: +// its wait's reason (the structured field the have carries) is that its want's parts differ from its composition (§524) or its +// entry is not held (§421), whatever words its detail opens with. Only a failed backup or restore point waits for an answer (ADR +// 0568 §4); novox, 2026-11-16: the indexer held "parts-differ" was kept at a start as "held for a failed backup"; g14, 2026-11-18: +// feh held "whether ..." with the reason entry-missing was kept the same way. +func judgedAgain(h Have) bool { + if h.Wait == nil { + return false + } + switch h.Wait.Reason { + case strings.TrimSuffix(PartsDiffer, ":"), strings.TrimSuffix(EntryAsked, ":"), strings.TrimSuffix(EntryMissing, ":"): + return true + } + return false } // heldReason is the opening of a detail held for an entry: EntryAsked or EntryMissing. -- 2.54.0 From 7b6468e2bb59f5272321183fd3448e2739eb5b60 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 00:46:49 +0100 Subject: [PATCH 16/18] selfcompose: the manifest of the build a module runs here is answered in one place; every step reads it there (A-484) Entry of the running build, else the composition this node runs of it, else the module's trunk manifest through the seat mesh-catalog's verb module; said once per module and source; words naming the three where none answers. Read there: a held module's offer (frombus Scope.RunningManifest), FormChanges (A-483), the store holder and the stand of a running module without an entry (A-461d, A-480a), and the tool composition. Builds: design 47 G A-484, A-480, A-480a, A-483, A-461d, A-482 --- cmd/mesh-host/nodeagent.go | 2 +- internal/agent/agent.go | 4 + internal/agent/agent_test.go | 9 + internal/agent/composition.go | 26 ++- internal/compose/frombus/answer.go | 29 +-- internal/compose/frombus/answer_rows_test.go | 5 +- internal/compose/frombus/frombus.go | 34 +-- internal/compose/frombus/held_rows_test.go | 22 +- internal/selfcompose/candidate.go | 2 +- internal/selfcompose/entries.go | 196 ++++++++-------- internal/selfcompose/entries_test.go | 35 ++- internal/selfcompose/running.go | 227 +++++++++++++++++++ internal/selfcompose/running_test.go | 76 +++++++ internal/selfcompose/selfcompose.go | 16 +- internal/selfcompose/shadow.go | 2 +- 15 files changed, 510 insertions(+), 175 deletions(-) create mode 100644 internal/selfcompose/running.go create mode 100644 internal/selfcompose/running_test.go diff --git a/cmd/mesh-host/nodeagent.go b/cmd/mesh-host/nodeagent.go index 7476a3f8..ebb39e01 100644 --- a/cmd/mesh-host/nodeagent.go +++ b/cmd/mesh-host/nodeagent.go @@ -699,7 +699,7 @@ func nodeAgent(ctx context.Context, opts options, signer ed25519.PublicKey, trus apply.UseEngineModule(composer.EngineModule) // the guard of the engine's own trees fixes no name (§527) env.Composed, env.SelfComposed, env.Policy, env.ComposedToday = composer, true, composer.Policy, composer.ComposedToday env.Recovery = recoveryEnv(session, composer) - env.WhyUnmade, env.Waiting = composer.WhyUnmade, composer.Waiting + env.WhyUnmade, env.Waiting, env.RunningManifest = composer.WhyUnmade, composer.Waiting, composer.RunningManifest keptFetchFn := keptArtifactFetch(composer.KeptBuildOf, session.AskSeatOn, session.KeptObject) keptFetch.Store(&keptFetchFn) env.HoldsData = composer.HoldsData // what runs from the kept declaration says Data as its manifest does diff --git a/internal/agent/agent.go b/internal/agent/agent.go index a3a7437c..2ae0a6d9 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -132,6 +132,10 @@ type Env struct { // a fingerprint it holds none of, so a composer that believes it handed it hands it again. Nil tells nobody. WhyUnmade func(module string) string Waiting func(module, fp string) + // RunningManifest is the one place that answers the manifest of the build a module runs here (design 47 G A-484): the source + // that answered with its build, or, where none did, the words naming the three it tried. The tool composition says it. Nil + // says nothing. + RunningManifest func(module string) (source, fp, words string) // Apply applies one module's composition (scope NodeModule for the node's own), given the compositions the node's // other modules run so a path, unit or group they hold is not removed or taken. It is called with one module at a // time. diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index d70664b3..f4f8e4c2 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -1718,6 +1718,15 @@ func TestTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes( if _, err := b.ag.Composition(context.Background(), "ghost", "", false); err == nil || !strings.Contains(err.Error(), "waits for the composer: no manifest in the composer's picture") { t.Errorf("the composition read of ghost says %v, want why the composer made none", err) } + // Where the one place says what runs of it (A-484), the tool answers it though the want's build has no composition. + b.ag.env.RunningManifest = func(string) (string, string, string) { + return "the module's trunk manifest in the catalog", "src2:t", "the manifest of the build ghost runs here is read from the module's trunk manifest in the catalog" + } + if view, err := b.ag.Composition(context.Background(), "ghost", "", false); err != nil || view.RunsManifest == nil || + view.RunsManifest.Source != "the module's trunk manifest in the catalog" || !strings.Contains(view.Composition.Refused, "waits for the composer") { + t.Errorf("the composition read of ghost says %+v, %v, want what runs of it and why the composer made none", view.RunsManifest, err) + } + b.ag.env.RunningManifest = nil toldMu.Lock() if n := slices.Index(told, "ghost@"+fpOf("9")); saidCount() != 1 || n < 0 || slices.Contains(told[n+1:], "ghost@"+fpOf("9")) { t.Errorf("said %d times, told %q; want once and ghost told once", saidCount(), told) diff --git a/internal/agent/composition.go b/internal/agent/composition.go index 9539952c..b570f5f7 100644 --- a/internal/agent/composition.go +++ b/internal/agent/composition.go @@ -37,6 +37,9 @@ type CompositionView struct { Revisions []RevisionView `json:"revisions,omitempty"` // Runs is what runs of the module, and where that is known from; nil when nothing of it runs. Runs *RunsView `json:"runs,omitempty"` + // RunsManifest is the manifest of the build that runs of the module, as the one place reads it (design 47 G A-484): which + // source answered, or the words naming the three it tried. Said also where the want's build has no composition. + RunsManifest *RunsManifestView `json:"runs-manifest,omitempty"` // Judged is the move from what runs to the composition read, as the agent judges it before an apply. Judged JudgedView `json:"judged"` // Diff is every resource that differs from what runs, when asked. @@ -136,6 +139,14 @@ type RunsView struct { Resources int `json:"resources"` } +// RunsManifestView is what the one place answers of the build a module runs here. +type RunsManifestView struct { + // Source is the source that answered; empty when none did. + Source string `json:"source,omitempty"` + FP string `json:"fp,omitempty"` + Words string `json:"words"` +} + // JudgedView is a move's judgement. type JudgedView struct { Judgement string `json:"judgement"` @@ -178,6 +189,10 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo Held: att.Held, AnsweredRevision: att.AnsweredRev, Transient: att.Transient} } view.Started = a.checked[module] + if a.env.RunningManifest != nil && module != NodeModule { + src, rfp, words := a.env.RunningManifest(module) + view.RunsManifest = &RunsManifestView{Source: src, FP: rfp, Words: words} + } latest, haveLatest := a.compositionFor(module, fp) r, ran := a.running[module] from, known := a.runningComposition(module) @@ -220,12 +235,19 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo case digest != "" && read == nil: return view, fmt.Errorf("no revision of %s the bucket keeps has the digest %s; revisions lists those it keeps", key, digest) case read == nil && !haveLatest: + // What runs of the module is still said, through the one place (A-484): the composition read is the want's build, and a + // module held at another build has none of it. + words := fmt.Sprintf("the bucket holds no composition of %s at %s", module, fp) if a.env.SelfComposed && a.env.WhyUnmade != nil && module != NodeModule { if why := a.env.WhyUnmade(module); why != "" { - return view, fmt.Errorf("the bucket holds no composition of %s at %s; the agent waits for the composer: %s", module, fp, why) + words = fmt.Sprintf("the bucket holds no composition of %s at %s; the agent waits for the composer: %s", module, fp, why) } } - return view, fmt.Errorf("the bucket holds no composition of %s at %s", module, fp) + if view.RunsManifest == nil { + return view, errors.New(words) + } + view.Composition = RevisionView{Key: key, Refused: words} + return view, nil case read == nil: read = &latest } diff --git a/internal/compose/frombus/answer.go b/internal/compose/frombus/answer.go index 27b8f5aa..3ee74415 100644 --- a/internal/compose/frombus/answer.go +++ b/internal/compose/frombus/answer.go @@ -75,7 +75,7 @@ func Answer(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]st return refuse(fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err)) } } - composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), true) + composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, s.RunningManifest, true) if err != nil { // Not one module's: the node's own (a value served elsewhere, the mesh's network), said once as the node's. if len(failed) == 0 { @@ -358,21 +358,13 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b if !ok { return } - running, known := catalogue.Manifest{}, false if ran != nil { if was, ok := ran(m); ok { - man.Contributes, man.ContributesMany, man.Listens = was.Contributes, was.ContributesMany, was.Listens - running, known = was, true + // A held module keeps running what it runs, so it keeps offering what that build offers, whatever its version and + // whether the catalog lists the build: the module that requires it is no "nothing provides" (A-480, A-484). + man.Contributes, man.ContributesMany, man.Listens, man.Provides = was.Contributes, was.ContributesMany, was.Listens, was.Provides } } - if !known { - running, known = heardManifest(in, node, m) - } - if known { - // A held module keeps running what it runs, so it keeps providing what that build provides, whatever its version and - // whether the catalog lists the build: the module that requires it is no "nothing provides" (A-480). - man.Provides = running.Provides - } src[m] = man } if leave != "" { @@ -522,19 +514,6 @@ func manifestOn(in compose.Input, node, module string) (catalogue.Manifest, bool return man, ok } -// heardManifest is the manifest of the build node said it runs of module (its `running` event's manifest, read by the event's digest, -// Node.Heard): false where nothing runs of it, it is stopped or the digest could not be read. -func heardManifest(in compose.Input, node, module string) (catalogue.Manifest, bool) { - for _, n := range in.Nodes { - if n.Name == node { - if h, ok := n.Heard[module]; ok && h.Read && !h.Stopped { - return h.Manifest, true - } - } - } - return catalogue.Manifest{}, false -} - // culprit is the module placed on node whose composition the error is of, and what of its offer to leave out: the // first, in assignment order, whose stub (compose.Stub) makes the composition in mode succeed or fail otherwise (leave // ""); else the first whose stub without what it contributes to one provision does (leave that provision: de-spiegel's diff --git a/internal/compose/frombus/answer_rows_test.go b/internal/compose/frombus/answer_rows_test.go index 5ea57583..d15ef72a 100644 --- a/internal/compose/frombus/answer_rows_test.go +++ b/internal/compose/frombus/answer_rows_test.go @@ -638,7 +638,10 @@ func answerNamesEveryRefusalAndLeavesAnOldBuildToTheNode(t *testing.T) { siteRuns.FP = fp("7") b.manifests[meshcatalogclient.ManifestDigest(site)] = site b.builds["site "+fp("7")] = &builds.BuilderBuild{State: builds.BuildDone, Manifest: meshcatalogclient.ManifestDigest(site)} - got, _, held, err = Compose(ctx, b, Mesh{}, Scope{Node: "n1", Running: []engcomp.Composed{siteRuns}}, fps) + // The manifest of the build that runs is read in the one place (A-484), here the manifest of the build 7. + ranSite, _ := catalogue.Decode(site) + got, _, held, err = Compose(ctx, b, Mesh{}, Scope{Node: "n1", Running: []engcomp.Composed{siteRuns}, + RunningManifest: func(module string) (catalogue.Manifest, bool) { return ranSite, module == "site" }}, fps) if err != nil || held["site"] == "" || held["nft"] != "" { t.Errorf("site moved to 9090 in its new manifest: %v, held %v; want site held alone", err, held) } diff --git a/internal/compose/frombus/frombus.go b/internal/compose/frombus/frombus.go index 991efd3b..2f9866ef 100644 --- a/internal/compose/frombus/frombus.go +++ b/internal/compose/frombus/frombus.go @@ -197,6 +197,11 @@ type Scope struct { // the seat list, novox/hq ADR 0636 §1): each is held as it runs, as a module refused alone is, so no take-in or // artifact reference of it can refuse the node (issue 1966). Nil holds none. Held map[string]string + // RunningManifest answers the manifest of the build a module runs on the composing node, from the one place that reads it + // (design 47 G A-484: its entry, else the composition the node runs of it, else the trunk's manifest): what a held module + // keeps offering the others (what it provides, contributes and listens on), since it keeps running what it runs. False + // where nothing is read; the manifest it is composed from is its offer then. Nil: none is read. + RunningManifest func(module string) (catalogue.Manifest, bool) } // InOwn is, of the modules p places on its node, those whose resources the node's own composition it runs @@ -703,7 +708,7 @@ func Compose(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[string]s return nil, nil, held, fmt.Errorf("frombus: the credentials of %s: %w", s.Node, err) } } - out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), true) + out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, s.RunningManifest, true) return out, skipped, held, err } @@ -991,33 +996,6 @@ func parser(Mesh) func([]byte) (catalogue.Manifest, error) { return catalogue.Decode } -// ranOf is what a module last offered the others, read when it is held (composeEach, issue 1960): its manifest at the -// build its own composition runs at (running), where that is another build than the one it is composed at (fps) and -// the builder holds it done. False where nothing is known of it (it runs no composition of its own, it runs the build -// it is composed at, or its build is unread): the manifest it is composed from is its offer then. Only what it says to -// others is taken of it, which needs no take-in of its artifacts. -func ranOf(ctx context.Context, r Reader, mesh Mesh, running []engcomp.Composed, fps map[string]string) func(string) (catalogue.Manifest, bool) { - parse := parser(mesh) - return func(module string) (catalogue.Manifest, bool) { - for _, c := range running { - if c.Module != module || c.FP == "" || c.FP == fps[module] { - continue - } - b, err := r.Build(ctx, module, c.FP) - if err != nil || b == nil || b.State != builds.BuildDone || b.Manifest == "" { - return catalogue.Manifest{}, false - } - raw, err := r.Manifest(ctx, b.Manifest) - if err != nil { - return catalogue.Manifest{}, false - } - man, err := parse(raw) - return man, err == nil - } - return catalogue.Manifest{}, false - } -} - // fromBuilds puts in the built manifest of each module placed on the composing node, at the trunk's FP2, and of each // module it keeps at another build (Scope.KeptAt, into its node's Kept), read from the builder's done key and resolved // by the one take-in rule (takein.Manifest), a templates archive read in the artifact store as the node reaches it diff --git a/internal/compose/frombus/held_rows_test.go b/internal/compose/frombus/held_rows_test.go index 4d8d8367..628d617e 100644 --- a/internal/compose/frombus/held_rows_test.go +++ b/internal/compose/frombus/held_rows_test.go @@ -10,6 +10,7 @@ import ( "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" + "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/compose" "github.com/novox/mesh-host/internal/compose/resolution" engcomp "github.com/novox/mesh-host/internal/compositions" @@ -342,8 +343,8 @@ func TestASecondClaimantOfASeatIsHeldAndTheNodeComposesTheRest(t *testing.T) { // A-480 (design 47 G): a module the node holds keeps running what it runs, and so keeps providing what its running build provides, // whatever its catalogue entry: the module that requires it is not held for "nothing provides" (live, 2026-11-17 22:52: feh on g14 // held for "x11-display" while xorg runs there, held only for want of an entry of its wanted build). The offer is the running - // composition's build's manifest (the builder's done key), else the manifest the module's `running` event names; a module - // neither running nor composable still gives "nothing provides". + // manifest of the build it runs, from the one place that reads it (A-484); a module neither running nor composable still gives + // "nothing provides". const xorgRunning = `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` feh := `{"module":"feh","version":"1","requires":["x11-display"]}` nameOnly := `{"module":"xorg","version":"0"}` @@ -352,18 +353,13 @@ func TestASecondClaimantOfASeatIsHeldAndTheNodeComposesTheRest(t *testing.T) { scope func(fps map[string]string, b *bus) Scope provided bool }{ - {"it runs a build its running event names", func(fps map[string]string, b *bus) Scope { - digest := meshcatalogclient.ManifestDigest([]byte(xorgRunning)) - b.manifests[digest] = []byte(xorgRunning) - return Scope{Heard: map[string]map[string]Heard{"n1": {"xorg": {Fingerprint: "src2:" + strings.Repeat("r", 64), Manifest: digest}}}} - }, true}, - {"its composition runs a build the builder holds done", func(fps map[string]string, b *bus) Scope { - fp := "src2:" + strings.Repeat("r", 64) - digest := meshcatalogclient.ManifestDigest([]byte(xorgRunning)) - b.manifests[digest] = []byte(xorgRunning) - b.builds["xorg "+fp] = &builds.BuilderBuild{State: builds.BuildDone, Manifest: digest} - return Scope{Running: []engcomp.Composed{{Node: "n1", Module: "xorg", FP: fp}}} + {"the one place answers the manifest of the build it runs (A-484)", func(fps map[string]string, b *bus) Scope { + man, _ := catalogue.Decode([]byte(xorgRunning)) + return Scope{RunningManifest: func(module string) (catalogue.Manifest, bool) { return man, module == "xorg" }} }, true}, + {"the one place reads none", func(map[string]string, *bus) Scope { + return Scope{RunningManifest: func(string) (catalogue.Manifest, bool) { return catalogue.Manifest{}, false }} + }, false}, {"nothing of it runs", func(map[string]string, *bus) Scope { return Scope{} }, false}, } { b, fps := aNode(t, nameOnly, feh) diff --git a/internal/selfcompose/candidate.go b/internal/selfcompose/candidate.go index 42edf498..e6ec25cf 100644 --- a/internal/selfcompose/candidate.go +++ b/internal/selfcompose/candidate.go @@ -490,7 +490,7 @@ func (c *Composer) composeShadow(ctx context.Context, running []engcomp.Composed c.mu.Lock() c.wants = wants c.mu.Unlock() - scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow()} + scope := frombus.Scope{Node: node, KeptAt: kept, InOwn: inOwn, Running: running, SameValue: c.sameValue, Heard: c.heardNow(), RunningManifest: c.runningFor(node)} if input != nil { input(scope, fps) } diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 74d01903..99f878a1 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -296,14 +296,6 @@ func (c *Composer) wantedBuilds() map[string]bool { } } } - // The trunk build of a module this node runs without an entry of its wanted or running build is asked too (A-480a). - for module, tb := range c.trunkBuilds { - if tb.fp != "" && c.runsWithoutEntry(module) { - if _, named := out[tb.fp]; !named { - out[tb.fp] = false - } - } - } // The build each module runs here, as the node's own record of it says: its entry, kept in the composition state, stays held // for the judgement of a move's data forms though the catalog half dropped it and no event of the stream names it. for _, r := range running { @@ -391,6 +383,11 @@ func (c *Composer) layModules() { c.sayOnceEach(line) } }() + // Read before the lock: what the node runs is the agent's, and a read of it may wait. + var running []engcomp.Composed + if c.env.Running != nil { + running = c.env.Running() + } c.mu.Lock() defer c.mu.Unlock() modules := map[string]meshcatalog.ModulesByModuleValue{} @@ -413,6 +410,19 @@ func (c *Composer) layModules() { c.manifests[digest] = raw return true } + // layAnswer lays a module from the manifest the one place read of the build it runs (A-484): the entry's own fields, or the + // trunk's answer, which holds none of an entry's checks. + layAnswer := func(module string, a runningAnswer) bool { + switch { + case !a.Known: + return false + case a.Source == SourceTrunk: + modules[module] = meshcatalog.ModulesByModuleValue{Fp2: a.FP, Manifest: a.Digest, Repository: a.Repository, Commit: a.Commit, Path: a.Path} + c.manifests[a.Digest] = a.Raw + return true + } + return lay(module, a.FP) + } nodes := make([]string, 0, len(c.heard)) for node := range c.heard { nodes = append(nodes, node) @@ -424,9 +434,7 @@ func (c *Composer) layModules() { // Where the running build has no entry, the module is laid from the entry of the build the assignment places // for that node, the mesh's truth of what it runs there (A-461); with neither it stays name-only below. if !lay(module, run.fingerprint) && node != c.env.Node { - if built := c.placedBuild(node, module); built != "" && built != run.fingerprint { - lay(module, built) - } + layAnswer(module, c.runningLocked(running, node, module, "")) } } } @@ -446,9 +454,7 @@ func (c *Composer) layModules() { if _, laid := modules[pm.Module]; laid || !c.needsAddressOf(node, pm.Module) || !c.lacksEntry(node, pm.Module) { continue } - if built := c.placedBuild(node, pm.Module); built != "" { - lay(pm.Module, built) - } + layAnswer(pm.Module, c.runningLocked(running, node, pm.Module, "")) } } for module, w := range c.wants { @@ -471,14 +477,19 @@ func (c *Composer) layModules() { } continue } - // Running here with no entry of its wanted or running build and none of the newest: it stands, for resolution alone, as its - // trunk build, so the module that requires what it provides is no "nothing provides" (A-480a); its want stays held. - if _, laid := modules[module]; !laid && c.runsWithoutEntry(module) { - if tb := c.trunkBuilds[module]; tb.fp != "" && lay(module, tb.fp) { + // Running here with no entry of its wanted build and none of the newest: it stands, for resolution alone, as the manifest of + // the build it runs, from the one place (A-484), so the module that requires what it provides is no "nothing provides"; + // its want stays held. A running build whose entry is held is laid where it is heard (above) and is read by a held module's offer + // through the one place alone, so it is not laid again here. + if _, laid := modules[module]; !laid && c.countsAsRunning(module) { + if a := c.runningLocked(running, c.env.Node, module, ""); a.Source != SourceEntry && layAnswer(module, a) { m := modules[module] m.Fp2 = w.Fp modules[module] = m - said = append(said, fmt.Sprintf("%s runs a build whose manifest the node does not hold, so it counts what the trunk build %s of %s provides; its want stays held", module, tb.fp, module)) + said = append(said, fmt.Sprintf("%s runs a build whose entry the node does not hold, so it counts the manifest read from %s; its want stays held", module, a.Source)) + if a.Said != "" { + said = append(said, a.Said) + } continue } } @@ -503,15 +514,12 @@ func (c *Composer) layModules() { c.modules = modules } -// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; where the -// placement names none, the module's trunk build as syncEntries asked it (A-461b). Empty where neither is known. +// placedBuild is the build the assignment places for module on node (c.mu held), the mesh's truth of what it runs there; empty +// where the placement names none (the one place then asks the trunk's manifest, A-484). func (c *Composer) placedBuild(node, module string) string { for _, pm := range c.assignments[node].Modules { if pm.Module == module { - if pm.Build != "" { - return pm.Build - } - return c.trunkBuilds[module].fp + return pm.Build } } return "" @@ -549,68 +557,40 @@ func (c *Composer) needsAddressOf(node, module string) bool { return false } -// runsWithoutEntry says this node holds module on, as it runs it, and holds no entry of its wanted build nor of its running build -// (c.mu held), and whose running event's manifest is not held (A-480a): the case where its -// provisions are read from its trunk build (A-480a). A module built by hand before G says no running event (the engine says one only -// of a build whose manifest it knows), so it counts as running when its have names a build in the phase running or held (A-482); one -// wanted here that is heard running nowhere, runs nothing here and has no such have does not count. -func (c *Composer) runsWithoutEntry(module string) bool { - run := c.heard[c.env.Node][module] - w, wanted := c.wants[module] - if run.stopped || !wanted || w.Fp == "" || !(c.runsHere(module) || c.haveRuns[module]) { - return false - } - // What is read decides (A-480a: "can be read from neither"): the manifest its running event names, where that digest is held; - // a running composition's build is read as frombus ranOf reads it, only through the entry of the wanted fingerprint (the - // loop below), so a composition at another build reads nothing. - if _, read := c.manifests[run.manifest]; run.manifest != "" && read { - return false - } - for _, fp := range []string{w.Fp, run.fingerprint} { - if k, held := c.keptEnt[fp]; held && k.entry.Module != "" { - return false - } - } - return true -} - // askTrunkBuilds asks, for each module another node runs at a build with no entry and whose placement names no build, the trunk // build by the seat's verb `module`, once per running build (A-461b). Called before the lock is taken: the verb is a call. func (c *Composer) askTrunkBuilds() (wait func()) { type ask struct{ node, module, running string } var asks []ask + var running []engcomp.Composed + if c.env.Running != nil { + running = c.env.Running() + } c.mu.Lock() + // The module whose running build's manifest the one place reads from the trunk, where neither its entry nor its composition + // answers (A-484): the modules this node runs, and another node's module this node needs the address of (A-461, A-461d). for node, p := range c.assignments { for _, pm := range p.Modules { module := pm.Module - // Only a module this node needs the address of (A-461): the store's holder, the provider of a requirement. - if pm.Build != "" || !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) || c.trunkAsking[module] { + if c.trunkAsking[module] { continue } - running := c.heard[node][module].fingerprint - if had, asked := c.trunkBuilds[module]; !asked || had.running != running { - asks = append(asks, ask{node, module, running}) - if c.trunkAsking == nil { - c.trunkAsking = map[string]bool{} + if node == c.env.Node { + if !c.countsAsRunning(module) { + continue } - c.trunkAsking[module] = true + } else if !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) { + continue } - } - } - // A module this node runs whose wanted build and running build have no entry stands as its trunk build, for resolution alone - // (A-480a): asked once per running build, as another node's is. - for _, pm := range c.assignments[c.env.Node].Modules { - module := pm.Module - if !c.runsWithoutEntry(module) || c.trunkAsking[module] { - continue - } - running := c.heard[c.env.Node][module].fingerprint - if had, asked := c.trunkBuilds[module]; !asked || had.running != running { - asks = append(asks, ask{c.env.Node, module, running}) - if c.trunkAsking == nil { - c.trunkAsking = map[string]bool{} + if a := c.runningLocked(running, node, module, ""); a.NeedTrunk { + if had, asked := c.trunkBuilds[module]; !asked || had.running != a.RunFP { + asks = append(asks, ask{node, module, a.RunFP}) + if c.trunkAsking == nil { + c.trunkAsking = map[string]bool{} + } + c.trunkAsking[module] = true + } } - c.trunkAsking[module] = true } } c.mu.Unlock() @@ -623,14 +603,22 @@ func (c *Composer) askTrunkBuilds() (wait func()) { go func() { defer all.Done() for a := range work { - fp, why := c.trunkFp(a.module) + t, why := c.trunkOf(a.module) + fp := t.fp c.mu.Lock() delete(c.trunkAsking, a.module) if fp != "" { if c.trunkBuilds == nil { c.trunkBuilds = map[string]trunkBuild{} } - c.trunkBuilds[a.module] = trunkBuild{running: a.running, fp: fp} + t.running = a.running + c.trunkBuilds[a.module] = t + delete(c.trunkWhy, a.module) + } else { + if c.trunkWhy == nil { + c.trunkWhy = map[string]string{} + } + c.trunkWhy[a.module] = why } c.mu.Unlock() if fp == "" { @@ -823,23 +811,34 @@ func (c *Composer) FormChanges(_ context.Context, module, runningFp, appliedFp s } return catalogue.Decode(raw) } - running, err := read(runningFp) - if err != nil { - // A running build with no entry (one from before G): what it keeps on the bus is read from the composition it runs on this - // node, as what it provides is (A-480). Where neither that composition nor the wanted build's manifest keeps data, no form - // can change; where either does, the module still waits for the entry (A-113, A-483). + // The manifest of the build the module runs is read in the one place (A-484): its entry, else the composition this node runs of + // it, else the trunk's manifest. Where it reads no manifest, the composition says whether the running build keeps data: with + // none on either side no form can change and the move goes on; where either keeps data, the move waits (A-113, A-483), with + // the words naming the three sources tried. + // The entry of the running build is asked of the catalog half (once), and kept when answered, as every entry the composer reads. + if e, state := c.entryOf(runningFp); state == meshcatalogclient.EntryAnswered && e.Module != "" { + c.mu.Lock() + if _, kept := c.keptEnt[runningFp]; !kept { + c.keptEnt[runningFp] = keptEntry{entry: e, since: c.now()} + } + c.mu.Unlock() + } + ra := c.runningManifest(c.env.Node, module, runningFp) + var running catalogue.Manifest + if ra.Known { + var err error + if running, err = catalogue.Decode(ra.Raw); err != nil { + return nil, fmt.Errorf("%s's running manifest: %w", module, err) + } + } else { wanted, werr := read(appliedFp) if werr != nil { return nil, fmt.Errorf("%s's wanted manifest: %w", module, werr) } - if c.env.Running != nil && len(wanted.DataItems()) == 0 { - for _, r := range c.env.Running() { - if r.Module == module && r.FP != "" && !r.Data { - return nil, nil - } - } + if ra.Source == SourceComposition && !ra.Data && len(wanted.DataItems()) == 0 { + return nil, nil } - return nil, fmt.Errorf("%s's running manifest: %w", module, err) + return nil, fmt.Errorf("%s's running manifest: %s", module, ra.Why) } applied, err := read(appliedFp) if err != nil { @@ -873,27 +872,34 @@ func (c *Composer) syncShadowEntries(ctx context.Context) (pending bool) { // moduleVerb is the seat mesh-catalog's verb `module`: one module's trunk fingerprint and manifest by name. const moduleVerb = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbModule -// trunkFp is the fingerprint of a module's trunk build, by the seat's verb `module`; empty with why where the catalog half gives none. -func (c *Composer) trunkFp(module string) (fp, why string) { +// trunkOf is a module's trunk build, by the seat's verb `module`: its fingerprint, manifest and where it is built from; empty with +// why where the catalog half gives none. +func (c *Composer) trunkOf(module string) (t trunkBuild, why string) { if c.env.Entry == nil { - return "", "this node reads no module of the catalog half" + return t, "this node reads no module of the catalog half" } raw, err := c.env.Entry(moduleVerb, meshcatalog.ModuleInput{Module: module}) if err != nil { - return "", fmt.Sprintf("the catalog half's answer for %s: %v", module, err) + return t, fmt.Sprintf("the catalog half's answer for %s: %v", module, err) } answer, said, ok := buscalls.Unwrap(raw) if !ok { - return "", fmt.Sprintf("the catalog half holds no module %s: %s", module, said) + return t, fmt.Sprintf("the catalog half holds no module %s: %s", module, said) } var a meshcatalog.ModuleAnswer if err := json.Unmarshal(answer, &a); err != nil { - return "", fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err) + return t, fmt.Sprintf("the catalog half's answer for %s cannot be read: %v", module, err) } if a.Module.Fp == "" { - return "", fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None) + return t, fmt.Sprintf("the catalog half gives %s no fingerprint: %s", module, a.Module.None) } - return a.Module.Fp, "" + return trunkBuild{fp: a.Module.Fp, manifest: a.Module.Manifest, repository: a.Module.Repository, commit: a.Module.Commit, path: a.Module.Path}, "" +} + +// trunkFp is the fingerprint of a module's trunk build (trunkOf); empty with why where the catalog half gives none. +func (c *Composer) trunkFp(module string) (fp, why string) { + t, why := c.trunkOf(module) + return t.fp, why } // addedModule is the trunk's build of a module an assignment candidate adds to this node when no want here names it yet: the diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index beafd92b..64fae4ba 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -291,7 +291,7 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { {"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", ""}, {"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", ""}, {"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", ""}, - {"its running event names a manifest this node holds (A-480a)", true, "", false, false, old, false, true, "", "held"}, + {"its running event names a manifest this node holds: no source of the one place (A-484)", true, "", false, true, old, false, true, "", "held"}, {"its running event names a manifest this node cannot read (A-480a)", true, "", false, true, old, false, true, "", "unread"}, {"runs a composition at another build, no manifest read (A-480a)", true, "", false, true, old, false, true, "other", ""}, {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", ""}, @@ -302,7 +302,9 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { trunkFp := meshcatalogclient.SourcePrefix2 + strings.Repeat("4", 64) env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) { if verb == meshcatalog.VerbModule && tc.trunk { - return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp}}) + var man map[string]any + _ = json.Unmarshal([]byte(body), &man) + return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: trunkFp, Manifest: man}}) } return nil, errors.New("not held") }) @@ -426,6 +428,27 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { }) } + // A-484: where neither the entry nor a composition answers, the trunk's manifest is the running build's: a form change is judged + // against it, and its words name the three sources where the trunk answered none either. + for _, trunk := range []bool{true, false} { + env := newFakeBus().env() + env.Node = "n1" + c := New(env) + c.holdEntry(t, "feh", next, `{"module":"feh","version":"2","data":{"own":[{"id":"state","kind":"state"}]}}`) + if trunk { + c.mu.Lock() + c.trunkBuilds = map[string]trunkBuild{"feh": {running: old, fp: next, manifest: map[string]any{"module": "feh", "version": "1"}}} + c.mu.Unlock() + } + changes, err := c.FormChanges(context.Background(), "feh", old, next) + switch { + case trunk && err != nil: + t.Errorf("the trunk's manifest answers, FormChanges = %v, %v", changes, err) + case !trunk && (err == nil || !strings.Contains(err.Error(), SourceEntry) || !strings.Contains(err.Error(), SourceComposition) || !strings.Contains(err.Error(), SourceTrunk)): + t.Errorf("no source answers, FormChanges says %v, want the three named", err) + } + } + // A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment // places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name // alone, and this node's own module is never laid from a placement. @@ -453,7 +476,11 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { env.Node = "n1" env.Entry = EntryCall(func(_ context.Context, _, verb string, _ any) (json.RawMessage, error) { if verb == meshcatalog.VerbModule { - return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk}}) + var man map[string]any + if tc.trunk != "" { + man = map[string]any{"module": "distribution", "version": "2"} + } + return json.Marshal(meshcatalog.ModuleAnswer{Module: meshcatalog.ModuleAnswerModule{Fp: tc.trunk, Manifest: man}}) } return nil, errors.New("not held") }) @@ -481,7 +508,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { if tc.node == "n2" && tc.build == "" && tc.trunk == "" && kept { t.Error("a trunk build that could not be had was kept, so it is asked once per process (A-461e)") } - if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) { + if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && tc.build != "") { t.Errorf("the placed build asked = %v", asked) } c.layModules() diff --git a/internal/selfcompose/running.go b/internal/selfcompose/running.go new file mode 100644 index 00000000..294f3371 --- /dev/null +++ b/internal/selfcompose/running.go @@ -0,0 +1,227 @@ +package selfcompose + +import ( + "crypto/sha256" + "encoding/hex" + "encoding/json" + "fmt" + "slices" + + "git.novox.be/novox/mesh-sdk/go/catalogue" + engcomp "github.com/novox/mesh-host/internal/compositions" +) + +// The one place that answers "the manifest of the build a module runs here" (design 47 G A-484, joining A-480, A-480a, A-483 and +// A-461d). Every step that needs it reads it here and nowhere else: what the module provides (a held module keeps providing +// what it runs, frombus.Scope.RunningManifest), what it keeps on the bus and whether that changes form (FormChanges), the +// artifact store's holder (layModules, A-461d), and the picture of the catalog the composer resolves from. It answers in this +// order: the entry of the running build; else the composition this node runs of that build; else the module's trunk manifest +// through the seat mesh-catalog's verb `module`. + +// The three sources of the one place, in the words it says them in. +const ( + SourceEntry = "the entry of the running build" + SourceComposition = "the composition this node runs of it" + SourceTrunk = "the module's trunk manifest in the catalog" +) + +// runningAnswer is what the one place answers of one module. +type runningAnswer struct { + // Source is the source that answered; empty when none did, and Why then names the three. + Source string + // FP is the build the answer is of: the running build for an entry, the composition's build, or the trunk's. + FP string + // Known says the manifest itself was read (an entry or the trunk); a composition names its build and whether it keeps + // data, which is all it holds of the manifest. + Known bool + Manifest catalogue.Manifest + Raw []byte + Digest string + // Data is, from the composition, whether the running build keeps data on the bus. + Data bool + // Repository, Commit and Path are where the manifest's entry or the trunk's answer says it is built from. + Repository, Commit, Path string + // Why names what each of the three said, when none answered. + Why string + // RunFP is the running build the trunk manifest is asked for and kept against (A-461b). + RunFP string + // NeedTrunk says the trunk manifest is the one source left and is not held yet: the composer asks it beside the pass. + NeedTrunk bool + // Said is the line to say, once per module and source (principle 3); empty when it was said before. + Said string +} + +// runningFpsLocked are the fingerprints of the build module runs on node, as the node's own record says (c.mu held), most direct +// first: the build its running event names; on this node else the hint the caller knows and the build of the composition it runs; +// on another node also the build its placement names, the mesh's truth of what runs there (A-461). +func (c *Composer) runningFpsLocked(running []engcomp.Composed, node, module, hint string) (fps []string) { + add := func(fp string) { + if fp != "" && !slices.Contains(fps, fp) { + fps = append(fps, fp) + } + } + if r, ok := c.heard[node][module]; ok && !r.stopped { + add(r.fingerprint) + } + if node != c.env.Node { + add(c.placedBuild(node, module)) + return fps + } + add(hint) + for _, r := range running { + if r.Module == module { + add(r.FP) + } + } + return fps +} + +// runningLocked answers the manifest of the build module runs on node (c.mu held; running is what this node runs, read before +// the lock), from the three sources in order, and says which answered once per module and source. +func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint string) runningAnswer { + fps := c.runningFpsLocked(running, node, module, hint) + fp := "" + if len(fps) > 0 { + fp = fps[0] + } + var a runningAnswer + entryWhy, compWhy, trunkWhy := "", "", "" + // 1. The entry of the running build. + for _, f := range fps { + k, ok := c.keptEnt[f] + if !ok || k.entry.Module == "" { + continue + } + if digest, raw, err := entryManifest(k.entry); err == nil { + if man, err := catalogue.Decode(raw); err == nil { + a = runningAnswer{Source: SourceEntry, FP: f, Known: true, Manifest: man, Raw: raw, Digest: digest, + Repository: k.entry.Repository, Commit: k.entry.Commit, Path: k.entry.Path} + break + } + } + } + if a.Source == "" { + entryWhy = fmt.Sprintf("no entry of the build %s is held", orNone(fp)) + // 2. The composition this node runs of that build, whatever the want's build. + if node == c.env.Node { + for _, r := range running { + if r.Module != module || r.FP == "" { + continue + } + // The composition holds no manifest, only its build and whether that keeps data; its build's entry, if held, was + // read as the running build's above. + a = runningAnswer{Source: SourceComposition, FP: r.FP, Data: r.Data} + break + } + if a.Source == "" { + compWhy = "this node runs no composition of it" + } + } else { + compWhy = "only the node itself runs compositions of its modules" + } + } + // 3. The module's trunk manifest through the seat's verb `module`. + if !a.Known { + if t, ok := c.trunkBuilds[module]; ok && t.running == fp && len(t.manifest) > 0 { + if raw, err := json.Marshal(t.manifest); err == nil { + if man, err := catalogue.Decode(raw); err == nil { + keep := a // the composition's words stay: it says whether the build keeps data + a = runningAnswer{Source: SourceTrunk, FP: t.fp, Known: true, Manifest: man, Raw: raw, Digest: digestOf(raw), + Repository: t.repository, Commit: t.commit, Path: t.path, Data: keep.Data} + } + } + } + if !a.Known { + trunkWhy = c.trunkWhy[module] + if trunkWhy == "" { + trunkWhy = "the seat mesh-catalog's verb module has not answered" + } + a.NeedTrunk, a.RunFP = true, fp + } + } + if a.Source == "" || (!a.Known && a.Source == SourceComposition) { + a.Why = fmt.Sprintf("the manifest of the build %s runs here is read from none of: %s (%s); %s (%s); %s (%s)", module, + SourceEntry, orWords(entryWhy, "its entry is held without a manifest"), SourceComposition, + orWords(compWhy, "it names the build "+a.FP+" and no entry of that build is held"), SourceTrunk, trunkWhy) + } + if a.Source != "" { + line := fmt.Sprintf("%s runs a build whose manifest is read from %s", module, a.Source) + key := "running-manifest:" + node + "/" + module + "/" + a.Source + if c.told == nil { + c.told = map[string]bool{} + } + if !c.told[key] { + c.told[key] = true + a.Said = line + } + } + return a +} + +// runningManifest is runningLocked with the lock taken here: what runs is read first, since the agent's record may wait. +func (c *Composer) runningManifest(node, module, hint string) runningAnswer { + var running []engcomp.Composed + if c.env.Running != nil { + running = c.env.Running() + } + c.mu.Lock() + a := c.runningLocked(running, node, module, hint) + c.mu.Unlock() + if a.Said != "" { + c.env.Say(a.Said) + } + return a +} + +// countsAsRunning says this node holds module on as it runs it (A-482, c.mu held): it is heard running here, in what the agent +// runs, or its have names a build in the phase running or held. A module wanted here with none of these runs nothing here. +func (c *Composer) countsAsRunning(module string) bool { + if run := c.heard[c.env.Node][module]; run.stopped { + return false + } + return c.runsHere(module) || c.haveRuns[module] +} + +// RunningManifest is what the one place says of module's running build here, in words, for the tool composition: the source that +// answered with its build, or the words naming the three it tried. +func (c *Composer) RunningManifest(module string) (source, fp, words string) { + a := c.runningManifest(c.env.Node, module, "") + if a.Source == "" || (!a.Known && a.Why != "") { + return a.Source, a.FP, a.Why + } + return a.Source, a.FP, fmt.Sprintf("the manifest of the build %s runs here is read from %s", module, a.Source) +} + +// runningFor is the manifest of the build a module runs on node, for frombus.Scope.RunningManifest: only a module counted as +// running here (A-482) answers, and only a manifest read, never a composition alone. +func (c *Composer) runningFor(node string) func(module string) (catalogue.Manifest, bool) { + return func(module string) (catalogue.Manifest, bool) { + c.mu.Lock() + counts := node != c.env.Node || c.countsAsRunning(module) + c.mu.Unlock() + if !counts { + return catalogue.Manifest{}, false + } + a := c.runningManifest(node, module, "") + return a.Manifest, a.Known + } +} + +func digestOf(raw []byte) string { + sum := sha256.Sum256(raw) + return "sha256:" + hex.EncodeToString(sum[:]) +} + +func orNone(s string) string { + if s == "" { + return "(none named)" + } + return s +} + +func orWords(s, otherwise string) string { + if s == "" { + return otherwise + } + return s +} diff --git a/internal/selfcompose/running_test.go b/internal/selfcompose/running_test.go new file mode 100644 index 00000000..254f06a5 --- /dev/null +++ b/internal/selfcompose/running_test.go @@ -0,0 +1,76 @@ +package selfcompose + +import ( + "encoding/json" + "strings" + "testing" + + "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" + "github.com/novox/mesh-host/internal/compositions" +) + +// A-484: the manifest of the build a module runs here is answered in one place, from the entry of the running build, else the +// composition this node runs of it, else the module's trunk manifest; it says its source once per module and source, and where +// none answers its words name the three. +func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) { + running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64) + other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64) + body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` + for _, tc := range []struct { + name string + entry string // the entry held, by fingerprint ("running", "other") or none + composition string // the composition this node runs: its build ("running", "other") or none + data bool + trunk bool + wantSource string + wantKnown bool + }{ + {"its entry answers first", "running", "running", false, true, SourceEntry, true}, + {"the entry of the composition's build is the running build's", "other", "other", true, true, SourceEntry, true}, + {"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, SourceTrunk, true}, + {"a composition and no trunk answer: its build and its data alone", "", "running", true, false, SourceComposition, false}, + {"the trunk alone", "", "", false, true, SourceTrunk, true}, + {"none answers", "", "", false, false, "", false}, + } { + t.Run(tc.name, func(t *testing.T) { + env := newFakeBus().env() + env.Node = "n1" + var said []string + env.Say = func(s string) { said = append(said, s) } + if tc.composition != "" { + fp := map[string]string{"running": running, "other": other}[tc.composition] + env.Running = func() []compositions.Composed { + return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}} + } + } + c := New(env) + c.mu.Lock() + c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}} + c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}} + if tc.trunk { + var man map[string]any + _ = json.Unmarshal([]byte(body), &man) + c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}} + } + c.mu.Unlock() + if tc.entry != "" { + c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body) + } + a := c.runningManifest("n1", "xorg", "") + again := c.runningManifest("n1", "xorg", "") + if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) { + t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown) + } + if tc.wantSource != "" && (len(said) != 1 || again.Said != "" || !strings.Contains(said[0], tc.wantSource)) { + t.Errorf("said %q (and %q again), want its source once", said, again.Said) + } + if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry { + t.Errorf("the composition's data = %v, want %v", a.Data, tc.data) + } + if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceComposition) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) { + t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why) + } + }) + } +} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index f2f463a4..4c9a23f7 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -217,7 +217,9 @@ type Composer struct { trunkBuilds map[string]trunkBuild // trunkAsking is, by module, a trunk build being asked beside the pass (askTrunkBuilds), under mu. trunkAsking map[string]bool - heardRead bool + // trunkWhy is, by module, why the last ask of its trunk build gave none, for the words of the one place (A-484). + trunkWhy map[string]string + heardRead bool // ends is, by module, the last build end naming no branch the builder said of it (NoteBuildEnded), its newest build that // ended, under mu; endsRead is whether the first read of the builder's stream ended (BuildEndsRead) (design 47 G A-293). ends map[string]builds.BuildEnded @@ -1036,7 +1038,7 @@ func (c *Composer) compose(ctx context.Context) []agent.Update { var keptMu sync.Mutex var holds map[string]compose.Hold fromManifest := map[string]string{} // by module, why it is composed from the indexer's manifest and not a build - scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) { + scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node), Engine: c.noteEngine, OwnFingerprint: os.Getenv(engcomp.FingerprintVar), Kept: func(module, words string) { keptMu.Lock() defer keptMu.Unlock() if !slices.Contains(keptRuns[module], words) { @@ -1899,7 +1901,7 @@ func (c *Composer) ComposedToday(ctx context.Context, module, fp string) (string if c.env.Running != nil { running = c.env.Running() } - scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow()} + scope := frombus.Scope{Node: c.env.Node, KeptAt: kept, InOwn: inOwn, Running: running, Heard: c.heardNow(), RunningManifest: c.runningFor(c.env.Node)} comps, _, held, err := frombus.Compose(ctx, reader{c: c}, c.env.Mesh, scope, fps) if err != nil || held[module] != "" { return "", false @@ -2325,7 +2327,13 @@ func (c *Composer) WhyUnmade(module string) string { return c.last.Unmade[module] } -type trunkBuild struct{ running, fp string } +// trunkBuild is a module's trunk build as the seat mesh-catalog's verb module answered it for the running build it was asked for +// (A-461b, A-484): its fingerprint, its manifest and where it is built from. +type trunkBuild struct { + running, fp string + manifest map[string]any + repository, commit, path string +} // heardRun is one running event as the composer keeps it, with when it was said. type heardRun struct { diff --git a/internal/selfcompose/shadow.go b/internal/selfcompose/shadow.go index 8fb993c5..5a571bab 100644 --- a/internal/selfcompose/shadow.go +++ b/internal/selfcompose/shadow.go @@ -682,7 +682,7 @@ func (s *Shadow) answerProposal(ctx context.Context, proposal string) (nodeengin given[node] = &without } a := frombus.Answer(ctx, reader{c: c}, c.env.Mesh, frombus.Scope{Node: node, KeptAt: kept, Assignments: given, InOwn: inOwn, - SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded)}, fps, running, proposal, rev) + SameValue: c.sameValue, HeldToday: s.heldToday(heldAdded), RunningManifest: c.runningFor(node)}, fps, running, proposal, rev) for _, module := range slices.Sorted(maps.Keys(heldAdded)) { a.Held = append(a.Held, nodeengine.CandidateRefusal{Module: module, Why: heldAdded[module]}) } -- 2.54.0 From 91dc064f92095916d2054a97b60eb19666002fa0 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 00:49:53 +0100 Subject: [PATCH 17/18] selfcompose: the running statement's manifest is the second source of the one place; a composition answers only whether the build keeps data (A-484a) Builds: design 47 G A-484a, A-484 --- internal/selfcompose/entries.go | 2 +- internal/selfcompose/entries_test.go | 4 ++-- internal/selfcompose/running.go | 29 ++++++++++++++++++++++------ internal/selfcompose/running_test.go | 23 ++++++++++++++-------- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 99f878a1..6bb471a9 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -416,7 +416,7 @@ func (c *Composer) layModules() { switch { case !a.Known: return false - case a.Source == SourceTrunk: + case a.Source == SourceTrunk || a.Source == SourceStatement: modules[module] = meshcatalog.ModulesByModuleValue{Fp2: a.FP, Manifest: a.Digest, Repository: a.Repository, Commit: a.Commit, Path: a.Path} c.manifests[a.Digest] = a.Raw return true diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 64fae4ba..3fa58a39 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -291,7 +291,7 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { {"heard no running event, its have says running (A-480a, A-482)", false, "", false, true, old, false, true, "running", ""}, {"heard no running event, its have says held (A-482)", false, "", false, true, old, false, true, "held", ""}, {"wanted here, heard no running event, no have (A-482)", false, "", false, false, old, false, true, "", ""}, - {"its running event names a manifest this node holds: no source of the one place (A-484)", true, "", false, true, old, false, true, "", "held"}, + {"its running event names a manifest this node holds (A-484a)", true, "", false, true, old, false, true, "", "held"}, {"its running event names a manifest this node cannot read (A-480a)", true, "", false, true, old, false, true, "", "unread"}, {"runs a composition at another build, no manifest read (A-480a)", true, "", false, true, old, false, true, "other", ""}, {"heard stopped, trunk entry held (A-480a)", false, "", false, false, old, true, true, "running", ""}, @@ -444,7 +444,7 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { switch { case trunk && err != nil: t.Errorf("the trunk's manifest answers, FormChanges = %v, %v", changes, err) - case !trunk && (err == nil || !strings.Contains(err.Error(), SourceEntry) || !strings.Contains(err.Error(), SourceComposition) || !strings.Contains(err.Error(), SourceTrunk)): + case !trunk && (err == nil || !strings.Contains(err.Error(), SourceEntry) || !strings.Contains(err.Error(), SourceStatement) || !strings.Contains(err.Error(), SourceTrunk)): t.Errorf("no source answers, FormChanges says %v, want the three named", err) } } diff --git a/internal/selfcompose/running.go b/internal/selfcompose/running.go index 294f3371..f703c233 100644 --- a/internal/selfcompose/running.go +++ b/internal/selfcompose/running.go @@ -15,12 +15,14 @@ import ( // A-461d). Every step that needs it reads it here and nowhere else: what the module provides (a held module keeps providing // what it runs, frombus.Scope.RunningManifest), what it keeps on the bus and whether that changes form (FormChanges), the // artifact store's holder (layModules, A-461d), and the picture of the catalog the composer resolves from. It answers in this -// order: the entry of the running build; else the composition this node runs of that build; else the module's trunk manifest -// through the seat mesh-catalog's verb `module`. +// order: the entry of the running build; else the manifest its running statement names, when held (A-484a); else the module's trunk manifest +// through the seat mesh-catalog's verb `module`. The composition answers no manifest, only whether the build keeps data (A-483). // The three sources of the one place, in the words it says them in. const ( - SourceEntry = "the entry of the running build" + SourceEntry = "the entry of the running build" + SourceStatement = "the manifest its running statement names" + // SourceComposition answers no manifest: only the build and whether it keeps data on the bus (A-484a). SourceComposition = "the composition this node runs of it" SourceTrunk = "the module's trunk manifest in the catalog" ) @@ -100,9 +102,20 @@ func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint } } } + // 2. The manifest its running statement (the running event) names, when this node holds it (A-484a). + statementWhy := "its running event names no manifest" + if r, ok := c.heard[node][module]; ok && !r.stopped && a.Source == "" && r.manifest != "" { + if raw, held := c.manifests[r.manifest]; held { + if man, err := catalogue.Decode(raw); err == nil { + a = runningAnswer{Source: SourceStatement, FP: r.fingerprint, Known: true, Manifest: man, Raw: raw, Digest: r.manifest} + } + } else { + statementWhy = "this node holds no manifest " + r.manifest + } + } if a.Source == "" { entryWhy = fmt.Sprintf("no entry of the build %s is held", orNone(fp)) - // 2. The composition this node runs of that build, whatever the want's build. + // The composition this node runs of that build, whatever the want's build: it answers whether the build keeps data (A-483, A-484a). if node == c.env.Node { for _, r := range running { if r.Module != module || r.FP == "" { @@ -141,8 +154,12 @@ func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint } if a.Source == "" || (!a.Known && a.Source == SourceComposition) { a.Why = fmt.Sprintf("the manifest of the build %s runs here is read from none of: %s (%s); %s (%s); %s (%s)", module, - SourceEntry, orWords(entryWhy, "its entry is held without a manifest"), SourceComposition, - orWords(compWhy, "it names the build "+a.FP+" and no entry of that build is held"), SourceTrunk, trunkWhy) + SourceEntry, orWords(entryWhy, "its entry is held without a manifest"), SourceStatement, statementWhy, SourceTrunk, trunkWhy) + if a.Source == SourceComposition { + a.Why += fmt.Sprintf("; its composition names the build %s and says whether it keeps data: %v", a.FP, a.Data) + } else if compWhy != "" { + a.Why += "; " + compWhy + } } if a.Source != "" { line := fmt.Sprintf("%s runs a build whose manifest is read from %s", module, a.Source) diff --git a/internal/selfcompose/running_test.go b/internal/selfcompose/running_test.go index 254f06a5..2eabb1f9 100644 --- a/internal/selfcompose/running_test.go +++ b/internal/selfcompose/running_test.go @@ -23,15 +23,17 @@ func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) { composition string // the composition this node runs: its build ("running", "other") or none data bool trunk bool + statement bool // the running event names a manifest this node holds (A-484a) wantSource string wantKnown bool }{ - {"its entry answers first", "running", "running", false, true, SourceEntry, true}, - {"the entry of the composition's build is the running build's", "other", "other", true, true, SourceEntry, true}, - {"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, SourceTrunk, true}, - {"a composition and no trunk answer: its build and its data alone", "", "running", true, false, SourceComposition, false}, - {"the trunk alone", "", "", false, true, SourceTrunk, true}, - {"none answers", "", "", false, false, "", false}, + {"its entry answers first", "running", "running", false, true, false, SourceEntry, true}, + {"the entry of the composition's build is the running build's", "other", "other", true, true, false, SourceEntry, true}, + {"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, false, SourceTrunk, true}, + {"a composition and no trunk answer: its build and its data alone", "", "running", true, false, false, SourceComposition, false}, + {"the trunk alone", "", "", false, true, false, SourceTrunk, true}, + {"its running statement's manifest comes before the trunk's", "", "running", true, true, true, SourceStatement, true}, + {"none answers", "", "", false, false, false, "", false}, } { t.Run(tc.name, func(t *testing.T) { env := newFakeBus().env() @@ -48,6 +50,11 @@ func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) { c.mu.Lock() c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}} c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}} + if tc.statement { + digest := "sha256:" + strings.Repeat("9", 64) + c.heard["n1"]["xorg"] = heardRun{fingerprint: running, manifest: digest} + c.manifests[digest] = []byte(body) + } if tc.trunk { var man map[string]any _ = json.Unmarshal([]byte(body), &man) @@ -65,10 +72,10 @@ func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) { if tc.wantSource != "" && (len(said) != 1 || again.Said != "" || !strings.Contains(said[0], tc.wantSource)) { t.Errorf("said %q (and %q again), want its source once", said, again.Said) } - if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry { + if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry && a.Source != SourceStatement { t.Errorf("the composition's data = %v, want %v", a.Data, tc.data) } - if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceComposition) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) { + if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceStatement) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) { t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why) } }) -- 2.54.0 From 5cc26e2659e5c79ef2ef4cc4d690166bbf7d04bc Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 18 Nov 2026 01:02:10 +0100 Subject: [PATCH 18/18] selfcompose: the one place says its source at every caller, reads the have's build, answers HoldsData; the tool composition reads it outside the agent's lock (A-484, A-482) Builds: design 47 G A-484, A-484a, A-482 --- internal/agent/agent_test.go | 1 + internal/agent/composition.go | 9 ++- internal/selfcompose/entries.go | 21 ++++-- internal/selfcompose/entries_test.go | 109 +++++++++++++++++++++++++++ internal/selfcompose/running.go | 18 ++--- internal/selfcompose/running_test.go | 83 -------------------- internal/selfcompose/selfcompose.go | 33 ++++---- 7 files changed, 152 insertions(+), 122 deletions(-) delete mode 100644 internal/selfcompose/running_test.go diff --git a/internal/agent/agent_test.go b/internal/agent/agent_test.go index f4f8e4c2..fdc8c93b 100644 --- a/internal/agent/agent_test.go +++ b/internal/agent/agent_test.go @@ -1720,6 +1720,7 @@ func TestTheNodesOwnCompositionIsAppliedWhenItDiffersAndARecordMoveWaitsForAYes( } // Where the one place says what runs of it (A-484), the tool answers it though the want's build has no composition. b.ag.env.RunningManifest = func(string) (string, string, string) { + _ = b.ag.Running() // the one place reads what the agent runs: the tool must not hold the agent's lock while it does return "the module's trunk manifest in the catalog", "src2:t", "the manifest of the build ghost runs here is read from the module's trunk manifest in the catalog" } if view, err := b.ag.Composition(context.Background(), "ghost", "", false); err != nil || view.RunsManifest == nil || diff --git a/internal/agent/composition.go b/internal/agent/composition.go index b570f5f7..9856382f 100644 --- a/internal/agent/composition.go +++ b/internal/agent/composition.go @@ -189,10 +189,6 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo Held: att.Held, AnsweredRevision: att.AnsweredRev, Transient: att.Transient} } view.Started = a.checked[module] - if a.env.RunningManifest != nil && module != NodeModule { - src, rfp, words := a.env.RunningManifest(module) - view.RunsManifest = &RunsManifestView{Source: src, FP: rfp, Words: words} - } latest, haveLatest := a.compositionFor(module, fp) r, ran := a.running[module] from, known := a.runningComposition(module) @@ -205,6 +201,11 @@ func (a *Agent) Composition(ctx context.Context, module, digest string, diff boo } } a.mu.Unlock() + // Read outside the lock: the one place reads what the agent runs (Agent.Running takes it), and nothing it does is asked of the bus. + if a.env.RunningManifest != nil && module != NodeModule { + src, rfp, words := a.env.RunningManifest(module) + view.RunsManifest = &RunsManifestView{Source: src, FP: rfp, Words: words} + } if module != NodeModule && fp == "" { return view, fmt.Errorf("%s has no want and no have on %s, so no build of it is composed here", module, a.env.Node) } diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 6bb471a9..c3b5da11 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -413,6 +413,9 @@ func (c *Composer) layModules() { // layAnswer lays a module from the manifest the one place read of the build it runs (A-484): the entry's own fields, or the // trunk's answer, which holds none of an entry's checks. layAnswer := func(module string, a runningAnswer) bool { + if a.Said != "" { + said = append(said, a.Said) + } switch { case !a.Known: return false @@ -479,17 +482,15 @@ func (c *Composer) layModules() { } // Running here with no entry of its wanted build and none of the newest: it stands, for resolution alone, as the manifest of // the build it runs, from the one place (A-484), so the module that requires what it provides is no "nothing provides"; - // its want stays held. A running build whose entry is held is laid where it is heard (above) and is read by a held module's offer - // through the one place alone, so it is not laid again here. + // its want stays held. An answer from the entry of the running build is not laid here: that entry is laid where its module is heard + // (above), and laying it for a module that is not (heard nowhere yet, its want moving) made the node compose and apply the move twice + // (TestNatsTheBusServerIsTakenOver..., one run in five); a held module's offer reads that entry through the one place alone. if _, laid := modules[module]; !laid && c.countsAsRunning(module) { if a := c.runningLocked(running, c.env.Node, module, ""); a.Source != SourceEntry && layAnswer(module, a) { m := modules[module] m.Fp2 = w.Fp modules[module] = m said = append(said, fmt.Sprintf("%s runs a build whose entry the node does not hold, so it counts the manifest read from %s; its want stays held", module, a.Source)) - if a.Said != "" { - said = append(said, a.Said) - } continue } } @@ -562,6 +563,7 @@ func (c *Composer) needsAddressOf(node, module string) bool { func (c *Composer) askTrunkBuilds() (wait func()) { type ask struct{ node, module, running string } var asks []ask + var sayLines []string var running []engcomp.Composed if c.env.Running != nil { running = c.env.Running() @@ -582,7 +584,11 @@ func (c *Composer) askTrunkBuilds() (wait func()) { } else if !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) { continue } - if a := c.runningLocked(running, node, module, ""); a.NeedTrunk { + a := c.runningLocked(running, node, module, "") + if a.Said != "" { + sayLines = append(sayLines, a.Said) + } + if a.NeedTrunk { if had, asked := c.trunkBuilds[module]; !asked || had.running != a.RunFP { asks = append(asks, ask{node, module, a.RunFP}) if c.trunkAsking == nil { @@ -594,6 +600,9 @@ func (c *Composer) askTrunkBuilds() (wait func()) { } } c.mu.Unlock() + for _, line := range sayLines { + c.sayOnceEach(line) + } // Asked beside the pass, a few at a time: no pass waits on the catalog half's answer, and a module that waits for it is only // the one needing that address (A-461e). An answer asks a pass. var all sync.WaitGroup diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index 3fa58a39..937214b7 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -449,6 +449,115 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { } } + // A-484, A-484a, A-482: the manifest of the build a module runs here is answered in one place, from the entry of the running build, + // else the manifest its running statement names, else the module's trunk manifest; the composition says whether it keeps data. It + // says its source once per module and source, whoever asks, and where none answers its words name the three. + { + running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64) + other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64) + body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` + for _, tc := range []struct { + name string + entry string // the entry held, by fingerprint ("running", "other") or none + composition string // the composition this node runs: its build ("running", "other") or none + data bool + trunk bool + statement bool // the running event names a manifest this node holds (A-484a) + haveOnly bool // heard no running event: only its have names the build it runs (A-482) + wantSource string + wantKnown bool + }{ + {"its entry answers first", "running", "running", false, true, false, false, SourceEntry, true}, + {"the entry of the composition's build is the running build's", "other", "other", true, true, false, false, SourceEntry, true}, + {"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, false, false, SourceTrunk, true}, + {"a composition and no trunk answer: its build and its data alone", "", "running", true, false, false, false, SourceComposition, false}, + {"the trunk alone", "", "", false, true, false, false, SourceTrunk, true}, + {"its running statement's manifest comes before the trunk's", "", "running", true, true, true, false, SourceStatement, true}, + {"only its have names the build, whose entry is held (A-482)", "running", "", false, false, false, true, SourceEntry, true}, + {"none answers", "", "", false, false, false, false, "", false}, + } { + t.Run(tc.name, func(t *testing.T) { + env := newFakeBus().env() + env.Node = "n1" + var said []string + env.Say = func(s string) { said = append(said, s) } + if tc.composition != "" { + fp := map[string]string{"running": running, "other": other}[tc.composition] + env.Running = func() []compositions.Composed { + return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}} + } + } + c := New(env) + c.mu.Lock() + c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}} + c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}} + if tc.haveOnly { + c.heard = map[string]map[string]heardRun{} + c.haveRuns["xorg"], c.haveFp["xorg"] = true, running + } + if tc.statement { + digest := "sha256:" + strings.Repeat("9", 64) + c.heard["n1"]["xorg"] = heardRun{fingerprint: running, manifest: digest} + c.manifests[digest] = []byte(body) + } + if tc.trunk { + var man map[string]any + _ = json.Unmarshal([]byte(body), &man) + c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}} + } + c.mu.Unlock() + if tc.entry != "" { + c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body) + } + c.askTrunkBuilds()() + c.layModules() + a := c.runningManifest("n1", "xorg", "") + again := c.runningManifest("n1", "xorg", "") + if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) { + t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown) + } + sources := 0 + for _, line := range said { + if strings.Contains(line, "runs a build whose manifest is read from "+tc.wantSource) { + sources++ + } + } + if tc.wantSource != "" && (sources != 1 || again.Said != a.Said) { + t.Errorf("said %q, want its source once", said) + } + if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry && a.Source != SourceStatement { + t.Errorf("the composition's data = %v, want %v", a.Data, tc.data) + } + if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceStatement) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) { + t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why) + } + }) + } + + // A module counted as running here alone answers a held module's offer and what the module keeps (A-482): one wanted here that + // runs nothing and whose have names no build answers nothing, and HoldsData reads the manifest the one place read. + env := newFakeBus().env() + env.Node = "n1" + c := New(env) + c.holdEntry(t, "xorg", running, body) + c.mu.Lock() + c.wants["xorg"] = meshwants.WantsByWantNodeModuleValue{Fp: other} + c.haveFp["xorg"] = running + c.mu.Unlock() + if _, ok := c.runningFor("n1")("xorg"); ok { + t.Error("a module wanted here that runs nothing answered a manifest as running") + } + if data, known := c.HoldsData(context.Background(), "xorg"); data || !known { + t.Errorf("HoldsData = %v, %v, want a manifest read that declares no data", data, known) + } + c.mu.Lock() + c.haveRuns["xorg"] = true + c.mu.Unlock() + if man, ok := c.runningFor("n1")("xorg"); !ok || len(man.Provides) != 1 { + t.Error("a module its have says runs answered no manifest") + } + } + // A-461, A-461a, A-461b: another node's module whose running build has no entry is laid from the entry of the build the assignment // places for it on that node, or, where the placement names none, of its trunk build; with neither entry it stays as its name // alone, and this node's own module is never laid from a placement. diff --git a/internal/selfcompose/running.go b/internal/selfcompose/running.go index f703c233..902dfe54 100644 --- a/internal/selfcompose/running.go +++ b/internal/selfcompose/running.go @@ -49,7 +49,7 @@ type runningAnswer struct { RunFP string // NeedTrunk says the trunk manifest is the one source left and is not held yet: the composer asks it beside the pass. NeedTrunk bool - // Said is the line to say, once per module and source (principle 3); empty when it was said before. + // Said is the line saying the source, for sayOnceEach (once per module and source, principle 3); empty when none answered. Said string } @@ -70,6 +70,7 @@ func (c *Composer) runningFpsLocked(running []engcomp.Composed, node, module, hi return fps } add(hint) + add(c.haveFp[module]) // the build its have names (A-482) for _, r := range running { if r.Module == module { add(r.FP) @@ -162,15 +163,12 @@ func (c *Composer) runningLocked(running []engcomp.Composed, node, module, hint } } if a.Source != "" { - line := fmt.Sprintf("%s runs a build whose manifest is read from %s", module, a.Source) - key := "running-manifest:" + node + "/" + module + "/" + a.Source - if c.told == nil { - c.told = map[string]bool{} - } - if !c.told[key] { - c.told[key] = true - a.Said = line + // Said once per module and source by sayOnceEach, by whoever uses the answer (principle 3). + where := "" + if node != c.env.Node { + where = " on " + node } + a.Said = fmt.Sprintf("%s%s runs a build whose manifest is read from %s", module, where, a.Source) } return a } @@ -185,7 +183,7 @@ func (c *Composer) runningManifest(node, module, hint string) runningAnswer { a := c.runningLocked(running, node, module, hint) c.mu.Unlock() if a.Said != "" { - c.env.Say(a.Said) + c.sayOnceEach(a.Said) } return a } diff --git a/internal/selfcompose/running_test.go b/internal/selfcompose/running_test.go deleted file mode 100644 index 2eabb1f9..00000000 --- a/internal/selfcompose/running_test.go +++ /dev/null @@ -1,83 +0,0 @@ -package selfcompose - -import ( - "encoding/json" - "strings" - "testing" - - "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" - "github.com/novox/mesh-host/internal/compositions" -) - -// A-484: the manifest of the build a module runs here is answered in one place, from the entry of the running build, else the -// composition this node runs of it, else the module's trunk manifest; it says its source once per module and source, and where -// none answers its words name the three. -func TestTheManifestOfTheRunningBuildIsReadInOnePlace(t *testing.T) { - running := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64) - other := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64) - body := `{"module":"xorg","version":"1","provides":[{"name":"x11-display"}]}` - for _, tc := range []struct { - name string - entry string // the entry held, by fingerprint ("running", "other") or none - composition string // the composition this node runs: its build ("running", "other") or none - data bool - trunk bool - statement bool // the running event names a manifest this node holds (A-484a) - wantSource string - wantKnown bool - }{ - {"its entry answers first", "running", "running", false, true, false, SourceEntry, true}, - {"the entry of the composition's build is the running build's", "other", "other", true, true, false, SourceEntry, true}, - {"a composition with no manifest keeps the trunk's manifest and its data", "", "running", true, true, false, SourceTrunk, true}, - {"a composition and no trunk answer: its build and its data alone", "", "running", true, false, false, SourceComposition, false}, - {"the trunk alone", "", "", false, true, false, SourceTrunk, true}, - {"its running statement's manifest comes before the trunk's", "", "running", true, true, true, SourceStatement, true}, - {"none answers", "", "", false, false, false, "", false}, - } { - t.Run(tc.name, func(t *testing.T) { - env := newFakeBus().env() - env.Node = "n1" - var said []string - env.Say = func(s string) { said = append(said, s) } - if tc.composition != "" { - fp := map[string]string{"running": running, "other": other}[tc.composition] - env.Running = func() []compositions.Composed { - return []compositions.Composed{{Node: "n1", Module: "xorg", FP: fp, Data: tc.data}} - } - } - c := New(env) - c.mu.Lock() - c.assignments["n1"] = meshmoduleassigner.Assignments{Node: "n1", Modules: []meshmoduleassigner.PlacedModule{{Module: "xorg"}}} - c.heard = map[string]map[string]heardRun{"n1": {"xorg": {fingerprint: running}}} - if tc.statement { - digest := "sha256:" + strings.Repeat("9", 64) - c.heard["n1"]["xorg"] = heardRun{fingerprint: running, manifest: digest} - c.manifests[digest] = []byte(body) - } - if tc.trunk { - var man map[string]any - _ = json.Unmarshal([]byte(body), &man) - c.trunkBuilds = map[string]trunkBuild{"xorg": {running: running, fp: other, manifest: man}} - } - c.mu.Unlock() - if tc.entry != "" { - c.holdEntry(t, "xorg", map[string]string{"running": running, "other": other}[tc.entry], body) - } - a := c.runningManifest("n1", "xorg", "") - again := c.runningManifest("n1", "xorg", "") - if a.Source != tc.wantSource || a.Known != tc.wantKnown || (a.Known && len(a.Manifest.Provides) != 1) { - t.Fatalf("answered %q (known %v, provides %d), want %q (known %v)", a.Source, a.Known, len(a.Manifest.Provides), tc.wantSource, tc.wantKnown) - } - if tc.wantSource != "" && (len(said) != 1 || again.Said != "" || !strings.Contains(said[0], tc.wantSource)) { - t.Errorf("said %q (and %q again), want its source once", said, again.Said) - } - if tc.composition != "" && a.Data != tc.data && a.Source != SourceEntry && a.Source != SourceStatement { - t.Errorf("the composition's data = %v, want %v", a.Data, tc.data) - } - if !tc.wantKnown && !strings.Contains(a.Why, SourceEntry) || !tc.wantKnown && !strings.Contains(a.Why, SourceStatement) || !tc.wantKnown && !strings.Contains(a.Why, SourceTrunk) { - t.Errorf("the words of an answer that reads no manifest are %q, want the three sources named", a.Why) - } - }) - } -} diff --git a/internal/selfcompose/selfcompose.go b/internal/selfcompose/selfcompose.go index 4c9a23f7..7aadc3dc 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -182,7 +182,9 @@ type Composer struct { inOwn map[string]bool // haveRuns is, by module, whether this node's have of it names a build in the phase running or held: a module that // keeps running what it runs, though no running event says it (design 47 G A-482). - haveRuns map[string]bool + haveRuns map[string]bool + // haveFp is, by module, the build that have names, where haveRuns says it runs: one of the builds the one place reads (A-482, A-484). + haveFp map[string]string modules map[string]meshcatalog.ModulesByModuleValue told map[string]bool // lines said once each (sayOnceEach) values map[string]map[string]any // by module, this node's @@ -428,7 +430,7 @@ func New(env Env) *Composer { func newComposer(env Env) *Composer { return &Composer{env: env, wants: map[string]meshwants.WantsByWantNodeModuleValue{}, assignments: map[string]meshmoduleassigner.Assignments{}, assignmentKeys: meshmoduleassignerclient.NewKeys(), - records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, haveRuns: map[string]bool{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{}, + records: map[string]nodeengine.NodeRecord{}, inOwn: map[string]bool{}, haveRuns: map[string]bool{}, haveFp: map[string]string{}, modules: map[string]meshcatalog.ModulesByModuleValue{}, values: map[string]map[string]any{}, manifests: map[string][]byte{}, archives: map[string][]byte{}, handed: map[string]string{}, notTaken: map[string]string{}, unmadeSaid: map[string]string{}, rehand: make(chan struct{}, 1), sealedOwn: map[string]ownSealed{}, pkgs: map[string]compositions.Composed{}, asked: make(chan chan Pass, 8)} } @@ -867,9 +869,10 @@ func (c *Composer) takeModuleHave(u agent.Update) bool { if err != nil || isNode || node != c.env.Node { return false } - in, runs := false, false + in, runs, haveFp := false, false, "" if !u.Deleted { if h, err := nodeengineclient.DecodeHave(u.Value); err == nil { + haveFp = h.Fp runs = (h.Phase == nodeengineclient.PhaseRunning || h.Phase == nodeengineclient.PhaseHeld) && h.Fp != "" // A have that names nothing it runs, failed (the node could not compose a module it never ran: NotComposed), is // no module run inside the node's own composition: taken as one, it was composed from its manifest past its @@ -888,8 +891,10 @@ func (c *Composer) takeModuleHave(u agent.Update) bool { changed := c.haveRuns[module] != runs if runs { c.haveRuns[module] = true + c.haveFp[module] = haveFp } else { delete(c.haveRuns, module) + delete(c.haveFp, module) } if c.inOwn[module] == in { return changed @@ -1414,25 +1419,15 @@ func (c *Composer) Policy(ctx context.Context, module string) string { return policy } -// HoldsData says whether a module's manifest declares data (catalogue.Manifest.DataItems), as a composition's Data says -// it, and whether the manifest could be read: the agent's Data for what runs of a module from the kept declaration +// HoldsData says whether the manifest of the build a module runs here declares data (catalogue.Manifest.DataItems), as a +// composition's Data says it, and whether that manifest could be read, from the one place (A-484): the agent's Data for what runs of a module from the kept declaration // (agent.Env.HoldsData, issue 924). -func (c *Composer) HoldsData(ctx context.Context, module string) (data, known bool) { - c.mu.Lock() - m, ok := c.modules[module] - c.mu.Unlock() - if !ok || m.Manifest == "" { +func (c *Composer) HoldsData(_ context.Context, module string) (data, known bool) { + a := c.runningManifest(c.env.Node, module, "") + if !a.Known { return false, false } - raw, err := reader{c: c}.Manifest(ctx, m.Manifest) - if err != nil { - return false, false - } - parsed, held, err := c.taken(module, m, raw) - if err != nil || held != "" { - return false, false - } - return len(parsed.DataItems()) > 0, true + return len(a.Manifest.DataItems()) > 0, true } // taken is a module's manifest as this engine reads it (novox/hq ADR 0578 §3): decoded leniently, judging nothing, with -- 2.54.0