From ba9d4787f94c41daf498e6fd838d9b032e38a875 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 23:46:03 +0100 Subject: [PATCH] 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