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 a83ace65..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. @@ -1539,7 +1543,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). @@ -1631,7 +1635,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} @@ -1643,7 +1647,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 8ea01aa6..fdc8c93b 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) } } @@ -848,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) @@ -869,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 = "", "" } @@ -1696,6 +1718,16 @@ 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) { + _ = 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 || + 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..9856382f 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"` @@ -190,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) } @@ -220,12 +236,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/agent/parts.go b/internal/agent/parts.go index 5d19152b..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. @@ -60,7 +68,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 +77,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/compose/frombus/answer.go b/internal/compose/frombus/answer.go index cf2ca2b0..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 { @@ -360,7 +360,9 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b } if ran != nil { if was, ok := ran(m); ok { - man.Contributes, man.ContributesMany, man.Listens = was.Contributes, was.ContributesMany, was.Listens + // 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 } } src[m] = man 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 05588031..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" @@ -337,4 +338,44 @@ 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 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 + // 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"}` + for _, row := range []struct { + name string + scope func(fps map[string]string, b *bus) Scope + provided bool + }{ + {"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) + 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"]) + } + } } diff --git a/internal/compose/node.go b/internal/compose/node.go index 1d52253f..30f05154 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,34 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) { return d, validate.Declaration(body), nil } +// 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, 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, held, err + } + if _, already := with.NotPlaced[none.Module]; already { + return catalogue.Composed{}, with, nil, 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 + if held == nil { + held = map[string]string{} + } + held[none.Module] = none.Error() + } +} + // 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 +217,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, storeHeld, err := composeWithoutStoreFetchers(plan, with) if err != nil { return Declared{}, err } @@ -202,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/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..6382bab2 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, @@ -95,13 +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). - out.storeHeld = modulesNeedingTheStore(plan.Modules, err) store, err = "", nil } if err != nil { @@ -338,29 +335,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..8777d324 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,51 @@ 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) + } + // 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) } + 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) 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 "" 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): 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 c5eb2705..c3b5da11 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" ) @@ -274,15 +276,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.needsAddressOf(node, pm.Module) && c.lacksEntry(node, pm.Module) && strings.HasPrefix(built, meshcatalogclient.SourcePrefix2) { if _, named := out[built]; !named { out[built] = false } @@ -376,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{} @@ -398,6 +410,22 @@ 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 { + if a.Said != "" { + said = append(said, a.Said) + } + switch { + case !a.Known: + return false + 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 + } + return lay(module, a.FP) + } nodes := make([]string, 0, len(c.heard)) for node := range c.heard { nodes = append(nodes, node) @@ -409,13 +437,29 @@ 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, "")) } } } } + // 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) + } + sort.Strings(placedOn) + for _, node := range placedOn { + if node == c.env.Node { + continue + } + for _, pm := range c.assignments[node].Modules { + if _, laid := modules[pm.Module]; laid || !c.needsAddressOf(node, pm.Module) || !c.lacksEntry(node, pm.Module) { + continue + } + layAnswer(pm.Module, c.runningLocked(running, node, pm.Module, "")) + } + } for module, w := range c.wants { if module == agent.NodeModule || w.Fp == "" { continue @@ -436,6 +480,20 @@ func (c *Composer) layModules() { } continue } + // 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. 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)) + 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 @@ -457,58 +515,137 @@ 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 "" } -// 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 || 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 == "" } +// 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 + var sayLines []string + var running []engcomp.Composed + if c.env.Running != nil { + running = c.env.Running() + } c.mu.Lock() - for node, mods := range c.heard { - for module, run := range mods { - if !c.lacksEntry(node, module, run) { + // 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 + if c.trunkAsking[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}) + if node == c.env.Node { + if !c.countsAsRunning(module) { + continue + } + } else if !c.needsAddressOf(node, module) || !c.lacksEntry(node, module) { + continue + } + 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 { + c.trunkAsking = map[string]bool{} + } + c.trunkAsking[module] = true } } } } c.mu.Unlock() - for _, a := range asks { - fp, _ := c.trunkFp(a.module) - 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() + 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 + 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 { + 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{} + } + 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 == "" { + // 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 @@ -683,9 +820,34 @@ func (c *Composer) FormChanges(_ context.Context, module, runningFp, appliedFp s } return catalogue.Decode(raw) } - running, err := read(runningFp) - if err != nil { - return nil, fmt.Errorf("%s's running manifest: %w", module, err) + // 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 ra.Source == SourceComposition && !ra.Data && len(wanted.DataItems()) == 0 { + return nil, nil + } + return nil, fmt.Errorf("%s's running manifest: %s", module, ra.Why) } applied, err := read(appliedFp) if err != nil { @@ -719,27 +881,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 30e89a7c..937214b7 100644 --- a/internal/selfcompose/entries_test.go +++ b/internal/selfcompose/entries_test.go @@ -44,7 +44,11 @@ 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 { + 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) mu.Unlock() @@ -268,21 +272,42 @@ 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 + 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) + have string // A-482: the phase its have says, naming the build it runs ("" for none) + 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}, - {"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, 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-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", ""}, } { 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 { + 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") + }) c := New(env) c.mu.Lock() c.wants["postgres"] = meshwants.WantsByWantNodeModuleValue{Fp: old, Newest: tc.newest} @@ -290,10 +315,32 @@ func runningModuleWithoutEntryStandsAsTheNewestBuild(t *testing.T) { if tc.runs { c.heard = map[string]map[string]heardRun{"n1": {"postgres": {fingerprint: old}}} } + 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}}} + } c.mu.Unlock() 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") } @@ -342,6 +389,175 @@ 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-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(), SourceStatement) || !strings.Contains(err.Error(), SourceTrunk)): + t.Errorf("no source answers, FormChanges says %v, want the three named", err) + } + } + + // 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. @@ -351,32 +567,57 @@ func TestRunningBuildEntryKeptAndHandedAgain(t *testing.T) { node string build, trunk string holds, laid bool + 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}, - {"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, ""}, + {"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() 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") }) 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": + 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() - if _, asked := c.wantedBuilds()[placedFp]; asked != (tc.node == "n2" && (tc.build != "" || tc.trunk != "")) { + 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 != "") { t.Errorf("the placed build asked = %v", asked) } c.layModules() @@ -390,3 +631,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/running.go b/internal/selfcompose/running.go new file mode 100644 index 00000000..902dfe54 --- /dev/null +++ b/internal/selfcompose/running.go @@ -0,0 +1,242 @@ +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 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" + 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" +) + +// 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 saying the source, for sayOnceEach (once per module and source, principle 3); empty when none answered. + 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) + add(c.haveFp[module]) // the build its have names (A-482) + 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 + } + } + } + // 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)) + // 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 == "" { + 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"), 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 != "" { + // 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 +} + +// 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.sayOnceEach(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/selfcompose.go b/internal/selfcompose/selfcompose.go index 994205c4..7aadc3dc 100644 --- a/internal/selfcompose/selfcompose.go +++ b/internal/selfcompose/selfcompose.go @@ -179,7 +179,12 @@ 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 + // 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 @@ -212,7 +217,11 @@ 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 - heardRead bool + // trunkAsking is, by module, a trunk build being asked beside the pass (askTrunkBuilds), under mu. + trunkAsking map[string]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 @@ -421,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{}, 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)} } @@ -860,9 +869,11 @@ func (c *Composer) takeModuleHave(u agent.Update) bool { if err != nil || isNode || node != c.env.Node { return false } - in := 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 // build (issue 1126, review round 1 of the builds). @@ -877,8 +888,16 @@ 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 + c.haveFp[module] = haveFp + } else { + delete(c.haveRuns, module) + delete(c.haveFp, module) + } if c.inOwn[module] == in { - return false + return changed } if in { c.inOwn[module] = true @@ -1024,7 +1043,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) { @@ -1400,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 @@ -1887,7 +1896,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 @@ -2313,7 +2322,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/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 { 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]}) }