From 22c9ddd32b6a3ba842ccacc85a4b8d209c3e77cc Mon Sep 17 00:00:00 2001 From: jochen Date: Thu, 29 Oct 2026 01:37:47 +0100 Subject: [PATCH] A runtime that already dropped a carried module's tools serves them again, read from what runs and its build (issue 1126, review) rev-held2: ToolsRunning took a carried module's bundles from the runtime's MESH_TOOL_MODULES alone, and shanks had already applied the drop of systemd-resolved, so its runs stayed empty and the drop permanent. Now every bundle archive that runs at its module's BundlePath is a running bundle; one the runtime loads nothing of takes its loads and words from the module's build (its built bundles, else its build's artifacts, by catalogue.BundleLoads, the rule a build's resolution keeps, now one function). The runtime process and each archive are matched by their owning module too, not only by id and path. A row added: the runtime already dropped it. --- go/catalogue/build.go | 46 ++++++++++++++--------- go/compose/composed.go | 73 +++++++++++++++++++++++++------------ go/compose/composed_test.go | 31 +++++++++++----- 3 files changed, 100 insertions(+), 50 deletions(-) diff --git a/go/catalogue/build.go b/go/catalogue/build.go index 91e3460..0a2ff73 100644 --- a/go/catalogue/build.go +++ b/go/catalogue/build.go @@ -126,23 +126,7 @@ func (m Manifest) Resolve(built []Built) (Manifest, error) { continue } made := by[a.Name] - // What the runtime loads: what the artifact said, else every entrypoint of a module - // that declares tools, else nothing (the field's own rule; see Artifact.Loads). - // - // **Never, unasked, a bundle one of the module's own resources runs** (novox/hq issue 213). - // A process the host runs is the module's service, not its tools: the controller declares - // the verbs it answers as `tools` and serves them itself, and its bundle would otherwise - // have been launched a second time by the node's runtime, as an MCP child it is not. - loads := append([]string(nil), a.Loads...) - if a.Loads == nil && len(m.Tools) > 0 && !run[a.Name] { - loads = append([]string(nil), a.Entrypoints...) - // A bundle compiled to a binary has no entrypoints: the binary is what it is, and what - // the runtime starts to serve it (novox/hq ADR 0193). So a Go tools bundle is served - // as Go — the runtime execs it — exactly as a TypeScript one is through its launcher. - if bin := BinaryOf(a); bin != "" { - loads = []string{bin} - } - } + loads := BundleLoads(m, a, run) // **Kept, never routed** (ADR 0155): the builder publishes to the store at the address // it reached it by, and a manifest carrying that address names an installation — // registration refused node-tools for exactly this on 2026-10-02. The build record @@ -715,3 +699,31 @@ func undeliveredBundles(m Manifest) []string { } return problems } + +// BundleLoads is what the runtime loads of the bundle artifact a of m (run: the bundles one of m's own resources runs, +// runByAResource): what the artifact said, else every entrypoint of a module that declares tools, else nothing; a +// bundle compiled to a binary is served by its binary. The rule a build's resolution keeps on Bundle.Loads, and what a +// module composed as what runs of it reads again when the runtime already dropped it (issue 1126). +func BundleLoads(m Manifest, a Artifact, run map[string]bool) []string { + // What the runtime loads: what the artifact said, else every entrypoint of a module + // that declares tools, else nothing (the field's own rule; see Artifact.Loads). + // + // **Never, unasked, a bundle one of the module's own resources runs** (novox/hq issue 213). + // A process the host runs is the module's service, not its tools: the controller declares + // the verbs it answers as `tools` and serves them itself, and its bundle would otherwise + // have been launched a second time by the node's runtime, as an MCP child it is not. + loads := append([]string(nil), a.Loads...) + if a.Loads == nil && len(m.Tools) > 0 && !run[a.Name] { + loads = append([]string(nil), a.Entrypoints...) + // A bundle compiled to a binary has no entrypoints: the binary is what it is, and what + // the runtime starts to serve it (novox/hq ADR 0193). So a Go tools bundle is served + // as Go — the runtime execs it — exactly as a TypeScript one is through its launcher. + if bin := BinaryOf(a); bin != "" { + loads = []string{bin} + } + } + return loads +} + +// RunByAResource is the bundles of m one of its own resources runs (its service, not its tools). +func RunByAResource(m Manifest) map[string]bool { return runByAResource(m) } diff --git a/go/compose/composed.go b/go/compose/composed.go index 66fc29c..fd15ffe 100644 --- a/go/compose/composed.go +++ b/go/compose/composed.go @@ -140,7 +140,7 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli kept := make(map[string]catalogue.Manifest, len(n.Kept)) for m, man := range n.Kept { if man.Stubbed && man.RunsAs == "" { - man.Bundles = n.RunsTools[m] + man.Bundles = runningBundles(n.RunsTools[m], reading.Catalogue[m]) } kept[m] = man } @@ -309,13 +309,16 @@ func RunsAnyOf(runs *delivery.Composed, module string) bool { return false } -// ToolsRunning is, by module, the tools bundles the node's runtime serves as it runs (Node.RunsTools): read from the -// runtime's process in running (catalogue.RuntimeToolModules, catalogue.RuntimeToolEnv, the mesh's own words left out) -// and each bundle's archive there; nil when running holds no runtime process. +// ToolsRunning is, by module, the tools bundles that run on the node (Node.RunsTools): each bundle archive a module's +// resource unpacks at its BundlePath, with what the runtime's own process loads of it and the words it hands it +// (catalogue.RuntimeToolModules, catalogue.RuntimeToolEnv, the mesh's own words left out). A bundle the runtime loads +// nothing of has no Loads: the runtime dropped it, and the composition reads its loads again from the module's build +// (issue 1126, review: shanks had already applied the drop of systemd-resolved). Nil when running holds no runtime process. func ToolsRunning(running []delivery.Composed) map[string][]catalogue.Bundle { runtimeID := catalogue.RuntimeModule + "." + catalogue.RuntimeProcessID() type resource struct { ID string `json:"id"` + Module string `json:"module"` Type string `json:"type"` Path string `json:"path"` Source string `json:"source"` @@ -323,18 +326,25 @@ func ToolsRunning(running []delivery.Composed) map[string][]catalogue.Bundle { Env map[string]string `json:"env"` } var env map[string]string - archives := map[string]resource{} + out := map[string][]catalogue.Bundle{} for _, c := range running { for _, raw := range c.Resources { var r resource if json.Unmarshal(raw, &r) != nil { continue } + owner := r.Module + if owner == "" { + owner, _ = declaration.ModuleGuess(r.ID) + } switch { - case r.Type == "process" && r.ID == runtimeID: + case r.Type == "process" && r.ID == runtimeID && owner == catalogue.RuntimeModule: env = r.Env - case r.Type == "archive" && strings.HasPrefix(r.Path, catalogue.BundleRoot+"/"): - archives[r.Path] = r + case r.Type == "archive" && owner != "" && strings.HasPrefix(r.ID, owner+"."+catalogue.BundleID("")): + name := strings.TrimPrefix(r.ID, owner+"."+catalogue.BundleID("")) + if r.Path == catalogue.BundlePath(owner, name) { + out[owner] = append(out[owner], catalogue.Bundle{Name: name, Source: catalogue.Recorded(r.Source), Digest: r.Digest}) + } } } } @@ -343,15 +353,16 @@ func ToolsRunning(running []delivery.Composed) map[string][]catalogue.Bundle { } var words map[string]map[string]string _ = json.Unmarshal([]byte(env[catalogue.RuntimeToolEnv]), &words) - out := map[string][]catalogue.Bundle{} for _, entry := range strings.Split(env[catalogue.RuntimeToolModules], ",") { module, path, ok := strings.Cut(entry, "=") - if !ok { + if !ok || !strings.HasPrefix(path, catalogue.BundleRoot+"/"+module+"/") { continue } name, load, ok := strings.Cut(strings.TrimPrefix(path, catalogue.BundleRoot+"/"+module+"/"), "/") - if !ok || !strings.HasPrefix(path, catalogue.BundleRoot+"/"+module+"/") { - continue + bundles := out[module] + i := slices.IndexFunc(bundles, func(b catalogue.Bundle) bool { return b.Name == name }) + if !ok || i < 0 { + continue // no archive of it runs: nothing to load } var own map[string]string for w, v := range words[module] { @@ -363,18 +374,8 @@ func ToolsRunning(running []delivery.Composed) map[string][]catalogue.Bundle { } own[w] = v } - bundles := out[module] - i := slices.IndexFunc(bundles, func(b catalogue.Bundle) bool { return b.Name == name }) - if i < 0 { - a, delivered := archives[catalogue.BundlePath(module, name)] - if !delivered { - continue // no archive of it runs: nothing to load - } - bundles = append(bundles, catalogue.Bundle{Name: name, Source: catalogue.Recorded(a.Source), Digest: a.Digest, Env: own}) - i = len(bundles) - 1 - } bundles[i].Loads = append(bundles[i].Loads, load) - out[module] = bundles + bundles[i].Env = own } for _, bundles := range out { sort.Slice(bundles, func(i, j int) bool { return bundles[i].Name < bundles[j].Name }) @@ -382,6 +383,32 @@ func ToolsRunning(running []delivery.Composed) map[string][]catalogue.Bundle { return out } +// runningBundles is the bundles of a module composed as what runs of it (Node.RunsTools): each that runs, with what the +// runtime loads of it and its words; one the runtime loads nothing of takes its loads and words from the module's build +// (man: its built bundles, else its build's artifacts, catalogue.BundleLoads), so a drop already applied is undone. +func runningBundles(runs []catalogue.Bundle, man catalogue.Manifest) []catalogue.Bundle { + var out []catalogue.Bundle + for _, b := range runs { + if len(b.Loads) == 0 { + for _, built := range man.Bundles { + if built.Name == b.Name { + b.Loads, b.Env, b.Launchers, b.Binary = built.Loads, built.Env, built.Launchers, built.Binary + } + } + if man.Build != nil { + run := catalogue.RunByAResource(man) + for _, a := range man.Build.Artifacts { + if a.Kind == catalogue.ArtifactBundle && a.Name == b.Name { + b.Loads, b.Env, b.Binary = catalogue.BundleLoads(man, a, run), a.Env, catalogue.BinaryOf(a) + } + } + } + } + out = append(out, b) + } + return out +} + // NamesBuild says a manifest names what a build makes: its build, or a resource naming an artifact. A node cannot // compose such a module folded into its own composition: the build of the old form it runs is held by the controller // alone (issue 1126). diff --git a/go/compose/composed_test.go b/go/compose/composed_test.go index eb37442..a96ea85 100644 --- a/go/compose/composed_test.go +++ b/go/compose/composed_test.go @@ -112,35 +112,46 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { lamp := catalogue.Manifest{Module: "lamp", Version: "1", Tools: []string{"on"}, Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/lamp", "mode": "0700"}}, Build: &catalogue.Build{Artifacts: []catalogue.Artifact{{Name: "tools", Kind: catalogue.ArtifactBundle, - Language: "go", System: "arch", From: "cmd/lamp-tools"}}}} + Language: "go", System: "arch", From: "cmd/lamp-tools", Env: map[string]string{"LAMP_CONF": "/var/lib/lamp/conf"}}}}} newLamp, err := lamp.Resolve([]catalogue.Built{{Name: "tools", Kind: catalogue.ArtifactBundle, Reference: catalogue.ArtifactStoreScheme + "lamp/tools/blobs/" + dg('c'), Digest: dg('c')}}) if err != nil { t.Fatal(err) } served := "lamp=" + catalogue.BundlePath("lamp", "tools") + "/lamp-tools" - runsTools := []delivery.Composed{{Node: "anchor", Module: catalogue.RuntimeModule, Resources: []json.RawMessage{json.RawMessage( - `{"id":"node-tools.runtime","module":"node-tools","type":"process","name":"node-tools","env":{"MESH_TOOL_MODULES":"` + - served + `","MESH_TOOL_ENV":"{\"lamp\":{\"LAMP_CONF\":\"/var/lib/lamp/conf\"}}"}}`)}}} + runtimeRuns := func(dropped bool) delivery.Composed { + env := `"MESH_TOOL_MODULES":"` + served + `","MESH_TOOL_ENV":"{\"lamp\":{\"LAMP_CONF\":\"/var/lib/lamp/conf\"}}"` + if dropped { + env = `"MESH_TOOL_MODULES":""` // the drop already applied (shanks, 2026-10-29) + } + return delivery.Composed{Node: "anchor", Module: catalogue.RuntimeModule, Resources: []json.RawMessage{json.RawMessage( + `{"id":"node-tools.runtime","module":"node-tools","type":"process","name":"node-tools","env":{` + env + `}}`)}} + } lampRuns := `{"id":"lamp.bundle-tools","type":"archive","source":"` + catalogue.ArtifactStoreScheme + `lamp/tools/blobs/` + dg('b') + `","digest":"` + dg('b') + `","path":"` + catalogue.BundlePath("lamp", "tools") + `"}` for _, row := range []struct { - name string - set func(n *Node) delivery.Composed // and what runs of lamp - fps map[string]string + name string + set func(n *Node) delivery.Composed // and what runs of lamp + fps map[string]string + dropped bool }{ {"folded at a build of the old form", func(n *Node) delivery.Composed { n.InOwn = map[string]bool{"lamp": true} n.RunsOwn = &delivery.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}} return *n.RunsOwn - }, map[string]string{}}, + }, map[string]string{}, false}, + {"folded, the runtime already dropped it", func(n *Node) delivery.Composed { + n.InOwn = map[string]bool{"lamp": true} + n.RunsOwn = &delivery.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}} + return *n.RunsOwn + }, map[string]string{}, true}, {"held, its new build not delivered", func(n *Node) delivery.Composed { n.Held = map[string]bool{"lamp": true} lr := delivery.Composed{Node: "anchor", Module: "lamp", Resources: []json.RawMessage{json.RawMessage( strings.Replace(lampRuns, `"type"`, `"module":"lamp","type"`, 1))}} n.Kept = map[string]catalogue.Manifest{"lamp": Carried(newLamp, "lamp", &lr)} return lr - }, map[string]string{"lamp": fpFor('1')}}, + }, map[string]string{"lamp": fpFor('1')}, false}, } { tools := aMesh(t) tools.Catalogue[catalogue.RuntimeModule], tools.Catalogue["artifacts"], tools.Catalogue["lamp"] = runtime, store, lamp @@ -148,7 +159,7 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) { anchor.Assigned = append(anchor.Assigned, "artifacts", catalogue.RuntimeModule, "lamp") tools.BusMinted = []string{"anchor." + catalogue.RuntimeModule} anchor.SealingKey = keyOf(t, "anchor") - anchor.RunsTools = ToolsRunning(append(append([]delivery.Composed{}, runsTools...), row.set(anchor))) + anchor.RunsTools = ToolsRunning([]delivery.Composed{runtimeRuns(row.dropped), row.set(anchor)}) row.fps[overlay.Name], row.fps["artifacts"], row.fps[catalogue.RuntimeModule] = fpFor('a'), fpFor('5'), fpFor('e') out, _, _, err := CompositionsIn(tools, "anchor", row.fps, Foreseeing) if err != nil {