From f8f33e54a7a18799cd5e1bca42d9dd99dded6adf Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 16 Nov 2026 19:58:46 +0100 Subject: [PATCH] Node-engine: judge a move's data forms from the entry kept of the running build; no endless handing again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The running build's entry stays held (kept in the composition state) while the node runs it, though the catalog half dropped it; the agent no longer tells the composer it waits for a composition it holds, and the composer hands again when the entry answers. Builds: design 47 G §296, §297, A-113, §614 --- internal/agent/kept.go | 6 ++-- internal/agent/kept_test.go | 7 ++++ internal/selfcompose/entries.go | 48 ++++++++++++++++++++++++++++ internal/selfcompose/entries_test.go | 31 ++++++++++++++++++ 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/internal/agent/kept.go b/internal/agent/kept.go index 1cbc3ef4..9645ef5b 100644 --- a/internal/agent/kept.go +++ b/internal/agent/kept.go @@ -239,9 +239,9 @@ func (a *Agent) keptStep(ctx context.Context, module string, w wantNow, comp com since := r.now() a.writeHave(ctx, Have{Module: module, FP: prev.Fp, Composed: prev.Composed, Phase: string(nodeengineclient.PhaseHeld), Detail: words, Wait: &nodeengine.Wait{Owner: nodeengine.Seat, Step: nodeengine.WaitStepCompose, Reason: "entry-missing", Since: since, Words: words}}) - if a.env.Waiting != nil { - a.env.Waiting(module, fp) - } + // The composition of the want is held: the wait is for an entry, not for a composition, so the composer is not told it + // is waited for (that handed the same composition again every pass, and the move failed the same way again); it + // hands the composition again when the entry answers (Composer.entryChanged). return true, nil } take, restore := keptMoves(changes, prev.Fp, fp) diff --git a/internal/agent/kept_test.go b/internal/agent/kept_test.go index cd671f79..efecc12d 100644 --- a/internal/agent/kept_test.go +++ b/internal/agent/kept_test.go @@ -30,6 +30,7 @@ type recoveryFake struct { catchUp []meshrecovery.CatchUp expired chan struct{} unknown error // FormChanges answers it + waited int // times the agent told the composer it waits for a composition } type fakeAnswer struct { @@ -110,6 +111,7 @@ func moveDB(t *testing.T, f *recoveryFake, ranFrom, to string, settle func(b *be } f.events, f.expired = make(chan Ending, 16), make(chan struct{}) b.env.Recovery = f.env() + b.env.Waiting = func(string, string) { f.mu.Lock(); f.waited++; f.mu.Unlock() } b.env.Stop = func(context.Context, string) Result { f.mu.Lock() f.calls = append(f.calls, "stop") @@ -289,6 +291,11 @@ func testAMoveAcrossAFormChange(t *testing.T) { t.Run("a form change not known moves nothing and waits for the entries (A-113)", func(t *testing.T) { f := &recoveryFake{unknown: fmt.Errorf("the entry is asked")} b := moveDB(t, f, "a", "b", heldHave) + f.mu.Lock() + if f.waited != 0 { + t.Errorf("the composer was told the agent waits for a composition %d times; it waits for an entry and holds the composition", f.waited) + } + f.mu.Unlock() if h := b.haves.last("db"); h.FP != fp("a") || !contains(h.Detail, "is not known") || h.Wait == nil || h.Wait.Reason != "entry-missing" { t.Fatalf("the have %+v", h) } diff --git a/internal/selfcompose/entries.go b/internal/selfcompose/entries.go index 5e6f25a4..3fd3ad88 100644 --- a/internal/selfcompose/entries.go +++ b/internal/selfcompose/entries.go @@ -21,6 +21,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/catalogue" "github.com/novox/mesh-host/internal/agent" + engcomp "github.com/novox/mesh-host/internal/compositions" ) // **The catalog half, read by fingerprint** (design 47 G §421, §683, §698; the lead's answers A-47 and A-50). The node-engine @@ -150,9 +151,42 @@ func (c *Composer) entryChanged(row meshcatalogclient.EntryRow) { c.keep(entryKey(row.Fingerprint), meshcatalog.EntryAnswer{Entry: *row.Entry}) } c.tellNotFound(row.Fingerprint, row.State == meshcatalogclient.EntryNotFound) + if row.State == meshcatalogclient.EntryAnswered { + c.handAgainFor(row.Fingerprint) + } c.askRehand() } +// handAgainFor forgets what was handed of each module of this node whose want or running build is fp, so the next pass hands it +// again and the node agent, which waits for this entry to judge a move (agent.keptStep), settles it again. +func (c *Composer) handAgainFor(fp string) { + var running []engcomp.Composed + if c.env.Running != nil { + running = c.env.Running() + } + c.mu.Lock() + defer c.mu.Unlock() + for module, w := range c.wants { + if module == agent.NodeModule || w.Fp == "" { + continue + } + // Only a move is judged by the entries (agent.keptStep): a module that runs the build its want names has none to wait on. + moves, runs := false, false + for _, r := range running { + if r.Module == module { + moves = moves || r.FP != w.Fp + runs = runs || r.FP == fp + } + } + if !moves || (w.Fp != fp && !runs) { + continue + } + if key, err := engcomp.Key(c.env.Node, module, w.Fp); err == nil { + delete(c.handed, key) + } + } +} + // tellNotFound tells the finding entry-not-found once when fp's entry is not found, and once when it no longer is (design 47 G §614, A-117). func (c *Composer) tellNotFound(fp string, notFound bool) { c.mu.Lock() @@ -222,6 +256,11 @@ func (c *Composer) entryOf(fp string) (meshcatalog.CatalogEntry, meshcatalogclie // wantedBuilds is each fingerprint a want of this node or a running heard names, of the new form, with whether a want names it. func (c *Composer) wantedBuilds() map[string]bool { out := map[string]bool{} + // 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() for module, w := range c.wants { @@ -244,6 +283,15 @@ func (c *Composer) wantedBuilds() map[string]bool { } } } + // 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 { + if r.Module != agent.NodeModule && strings.HasPrefix(r.FP, meshcatalogclient.SourcePrefix2) { + if _, named := out[r.FP]; !named { + out[r.FP] = false + } + } + } return out } diff --git a/internal/selfcompose/entries_test.go b/internal/selfcompose/entries_test.go index f22da6c9..e43f1f02 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -311,3 +311,34 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { }) } } + +// The node judges a move's data forms from the entry it kept of the build it runs, though the catalog half dropped that entry and no +// running event names it; and an answered entry has the composition handed again, which the agent waits on (novox, mesh-hand-acts). +func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { + old := meshcatalogclient.SourcePrefix2 + strings.Repeat("1", 64) + next := meshcatalogclient.SourcePrefix2 + strings.Repeat("2", 64) + env := newFakeBus().env() + env.Node = "n1" + env.Running = func() []compositions.Composed { + return []compositions.Composed{{Node: "n1", Module: "hand", FP: old}} + } + c := New(env) + c.mu.Lock() + c.wants["hand"] = meshwants.WantsByWantNodeModuleValue{Fp: next} + c.mu.Unlock() + if named, ok := c.wantedBuilds()[old]; !ok || named { + t.Errorf("the running build %s is asked of no want yet kept: %v, %v", old, named, ok) + } + key, _ := compositions.Key("n1", "hand", next) + c.mu.Lock() + c.handed[key] = "d" + c.mu.Unlock() + c.entryChanged(meshcatalogclient.EntryRow{Fingerprint: old, State: meshcatalogclient.EntryAnswered, + Entry: &meshcatalog.CatalogEntry{Module: "hand", Fp: old}}) + c.mu.Lock() + _, still := c.handed[key] + c.mu.Unlock() + if still { + t.Error("an entry of the running build was answered, and the composition was not handed again") + } +} -- 2.54.0