H-A-303: a pass that holds a module for a part withheld composes the tool runner as it runs

The node-engine restarted the tool runner at every self-compose on three machines:
a module held for a part that did not answer (the catalog half's entry, the
registry seats' versions) had its slice of the runtime process rebuilt from what
runs, with its fingerprint set to its want's and its files words dropped, so
MESH_TOOL_MODULES and MESH_TOOL_ENV differed pass by pass. A held module's
entries and words are now copied verbatim from the running process, after the
fingerprints are laid, so a holding pass digests as what runs and writes no new
revision; a module whose parts answered and changed is still composed from its
build. The composition read's grants ask names the holder it asked and why, and
says it once in the journal until the grants part answers again.

Builds: design 47 H H-A-303 (1)-(3), H-A-306 (1)-(3); H-A-296
This commit is contained in:
2026-11-21 20:39:06 +01:00
parent d741386851
commit cd7acb52d1
7 changed files with 258 additions and 32 deletions
+143
View File
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"maps"
"slices"
"sort"
"strings"
@@ -210,6 +211,13 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
if err := json.Unmarshal(body, &envelope); err != nil {
return nil, nil, nil, nil, err
}
// What the tool runner's process runs as, whose slice of each held module the composed process keeps (H-A-306).
var runsRuntime map[string]string
for i := range reading.Nodes {
if reading.Nodes[i].Name == node {
runsRuntime = reading.Nodes[i].RunsRuntime
}
}
var kept []json.RawMessage
keptPaths := map[string]bool{}
foldedPaths := map[string]bool{}
@@ -290,6 +298,27 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
c.Filled = append(c.Filled, ownFilled...)
out[own] = c
}
if len(held) > 0 && runsRuntime != nil {
// A held module's slice of the runtime process is what runs of it, verbatim, its fingerprint included: a pass that
// holds it for a part withheld composes the runtime as it runs, and writes no new revision for it (design 47 H,
// H-A-303, H-A-306). Taken after Split, which gives each module's words the fingerprint of its want (§519).
for key, c := range out {
for i, raw := range c.Resources {
var head struct {
ID string `json:"id"`
Module string `json:"module"`
Type string `json:"type"`
}
if json.Unmarshal(raw, &head) != nil || runtimeOwner(head.ID, head.Module, head.Type) == "" {
continue
}
if c.Resources[i], err = keepHeldSlices(raw, runsRuntime, held); err != nil {
return nil, nil, nil, nil, err
}
}
out[key] = c
}
}
for key, c := range out {
if held[c.Module] {
delete(out, key) // its stub's: the node keeps what it last applied of it (Node.Held)
@@ -409,6 +438,120 @@ func ToolsRunning(running []engcomp.Composed) map[string][]catalogue.Bundle {
return out
}
// RuntimeRunning is the environment of the tool runner's process as the node runs it (`<its module>.runtime`,
// resolutionRuntimeProcess), or nil when running holds none (Node.RunsRuntime).
func RuntimeRunning(running []engcomp.Composed) map[string]string {
for _, c := range running {
for _, raw := range c.Resources {
var r struct {
ID string `json:"id"`
Module string `json:"module"`
Type string `json:"type"`
Env map[string]string `json:"env"`
}
if json.Unmarshal(raw, &r) == nil && runtimeOwner(r.ID, r.Module, r.Type) != "" && r.Env != nil {
return r.Env
}
}
}
return nil
}
// runtimeOwner is the module of the tool runner's process a resource is (`<its module>.runtime`), or "" when it is none.
func runtimeOwner(id, module, kind string) string {
if kind != "process" {
return ""
}
if module == "" {
module, _ = declaration.ModuleGuess(id)
}
if module == "" || id != module+"."+resolution.RuntimeProcessID() {
return ""
}
return module
}
// keepHeldSlices is the runtime process raw with each held module's slice taken verbatim from what runs (runs, the
// process's environment as it runs): its entries in catalogue.RuntimeToolModules and its words in
// catalogue.RuntimeToolEnv, its fingerprint among them (H-A-306). A held module the running process serves nothing of
// and gives no words keeps what the composition made of it (runningBundles: a drop already applied is undone). raw is
// answered unchanged when nothing differs.
func keepHeldSlices(raw json.RawMessage, runs map[string]string, held map[string]bool) (json.RawMessage, error) {
var fields map[string]json.RawMessage
if err := json.Unmarshal(raw, &fields); err != nil {
return nil, err
}
var env map[string]string
if json.Unmarshal(fields["env"], &env) != nil || env == nil {
return raw, nil
}
ranServed := map[string][]string{}
for _, entry := range servedEntries(runs[catalogue.RuntimeToolModules]) {
module, _, _ := strings.Cut(entry, "=")
ranServed[module] = append(ranServed[module], entry)
}
var ranWords, words map[string]json.RawMessage
_ = json.Unmarshal([]byte(runs[catalogue.RuntimeToolEnv]), &ranWords)
_ = json.Unmarshal([]byte(env[catalogue.RuntimeToolEnv]), &words)
keep := map[string]bool{}
for module, isHeld := range held {
if _, says := ranWords[module]; isHeld && (len(ranServed[module]) > 0 || says) {
keep[module] = true
}
}
if len(keep) == 0 {
return raw, nil
}
var served []string
for _, entry := range servedEntries(env[catalogue.RuntimeToolModules]) {
if module, _, _ := strings.Cut(entry, "="); !keep[module] {
served = append(served, entry)
}
}
for module := range keep {
served = append(served, ranServed[module]...)
if w, says := ranWords[module]; says {
if words == nil {
words = map[string]json.RawMessage{}
}
words[module] = w
} else {
delete(words, module)
}
}
sort.Strings(served)
kept := make(map[string]string, len(env))
for k, v := range env {
kept[k] = v
}
kept[catalogue.RuntimeToolModules] = strings.Join(served, ",")
delete(kept, catalogue.RuntimeToolEnv)
if len(words) > 0 {
body, err := json.Marshal(words)
if err != nil {
return nil, err
}
kept[catalogue.RuntimeToolEnv] = string(body)
}
if maps.Equal(kept, env) {
return raw, nil
}
body, err := json.Marshal(kept)
if err != nil {
return nil, err
}
fields["env"] = body
return json.Marshal(fields)
}
// servedEntries is the entries of a runtime's catalogue.RuntimeToolModules, `<module>=<path>` each; none for "".
func servedEntries(s string) []string {
if s == "" {
return nil
}
return strings.Split(s, ",")
}
// 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.
+65 -26
View File
@@ -6,6 +6,7 @@ import (
engcomp "github.com/novox/mesh-host/internal/compositions"
"slices"
"sort"
"strconv"
"strings"
"testing"
@@ -133,39 +134,62 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
t.Fatal(err)
}
served := "lamp=" + resolution.BundlePath("lamp", "tools") + "/lamp-tools"
runtimeRuns := func(dropped bool) engcomp.Composed {
runtimeRuns := func(dropped bool, ran string) engcomp.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)
}
if ran != "" {
env = ran
}
return engcomp.Composed{Node: "anchor", Module: "node-tools", 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":"` + resolution.BundlePath("lamp", "tools") + `"}`
// H-A-303, H-A-306: what runs of lamp in the runtime, its fingerprint and the paths it owns among its words, at a load
// its new build no longer names.
ranServed := "lamp=" + resolution.BundlePath("lamp", "tools") + "/lamp-tools-old"
ranWords := `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf","MESH_FINGERPRINT":"` + fpFor('0') + `","MESH_OWNED_PATHS":"/var/lib/lamp"}}`
ranEnv := `"MESH_TOOL_MODULES":"` + ranServed + `","MESH_TOOL_ENV":` + strconv.Quote(ranWords)
held := func(n *Node) engcomp.Composed {
n.Held = map[string]bool{"lamp": true}
lr := engcomp.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
}
for _, row := range []struct {
name string
set func(n *Node) engcomp.Composed // and what runs of lamp
fps map[string]string
dropped bool
ran string // the runtime's env as it runs, when not served's
// What the runtime is composed to serve of lamp, and its words, when not served and its manifest's words.
wantServed, wantWords string
}{
{"folded at a build of the old form", func(n *Node) engcomp.Composed {
n.InOwn = map[string]bool{"lamp": true}
n.RunsOwn = &engcomp.Composed{Node: "anchor", Resources: []json.RawMessage{json.RawMessage(lampRuns)}}
return *n.RunsOwn
}, map[string]string{}, false},
}, map[string]string{}, false, "", "", ""},
{"folded, the runtime already dropped it", func(n *Node) engcomp.Composed {
n.InOwn = map[string]bool{"lamp": true}
n.RunsOwn = &engcomp.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) engcomp.Composed {
n.Held = map[string]bool{"lamp": true}
lr := engcomp.Composed{Node: "anchor", Module: "lamp", Resources: []json.RawMessage{json.RawMessage(
}, map[string]string{}, true, "", "", ""},
// H-A-306: a held module's slice is what runs of it, verbatim: no fingerprint of its want where none runs.
{"held, its new build not delivered", held, map[string]string{"lamp": fpFor('1')}, false, "",
served, `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf"}}`},
// H-A-303, H-A-306: held for a part withheld, its load, its fingerprint and its files words are what runs.
{"held for a part withheld, its slice as it runs", held, map[string]string{"lamp": fpFor('1')}, false, ranEnv,
ranServed, ranWords},
// H-A-306 (3): a module whose parts answered and changed is composed from its build, not from what runs.
{"read, its build changed", func(n *Node) engcomp.Composed {
n.Kept = map[string]catalogue.Manifest{"lamp": newLamp}
return engcomp.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')}, false},
}, map[string]string{"lamp": fpFor('1')}, false, ranEnv, "", ""},
} {
tools := aMesh(t)
tools.Catalogue["node-tools"], tools.Catalogue["artifacts"], tools.Catalogue["lamp"] = runtime, store, lamp
@@ -173,32 +197,47 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "lamp")
tools.BusMinted = []string{"anchor." + "node-tools"}
anchor.SealingKey = keyOf(t, "anchor")
anchor.RunsTools = ToolsRunning([]engcomp.Composed{runtimeRuns(row.dropped), row.set(anchor)})
ran := []engcomp.Composed{runtimeRuns(row.dropped, row.ran), row.set(anchor)}
anchor.RunsTools, anchor.RunsRuntime = ToolsRunning(ran), RuntimeRunning(ran)
row.fps[overlay.Name], row.fps["artifacts"], row.fps["node-tools"] = fpFor('a'), fpFor('5'), fpFor('e')
out, _, _, err := CompositionsIn(tools, "anchor", row.fps, Foreseeing)
if err != nil {
t.Fatalf("%s: %v", row.name, err)
}
var digests []string
var env map[string]any
for _, c := range out {
for _, raw := range c.Resources {
var r struct {
ID string `json:"id"`
Env map[string]any `json:"env"`
}
if json.Unmarshal(raw, &r) == nil && r.ID == "node-tools.runtime" {
env = r.Env
for range 2 { // two passes over the same input compose the same runtime (H-A-303)
out, _, _, err := CompositionsIn(tools, "anchor", row.fps, Foreseeing)
if err != nil {
t.Fatalf("%s: %v", row.name, err)
}
for _, c := range out {
for _, raw := range c.Resources {
var r struct {
ID string `json:"id"`
Env map[string]any `json:"env"`
}
if json.Unmarshal(raw, &r) == nil && r.ID == "node-tools.runtime" {
env = r.Env
dig, err := engcomp.DigestOf(c)
if err != nil {
t.Fatal(err)
}
digests = append(digests, dig)
}
}
}
}
if len(digests) != 2 || digests[0] != digests[1] {
t.Errorf("%s: two passes composed the runtime at %v", row.name, digests)
}
// §519: the words each bundle's module is given hold the fingerprint of the want it applies, where there is one.
words := `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf"}}`
wantServed, words := served, `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf"}}`
if fp := row.fps["lamp"]; fp != "" {
words = `{"lamp":{"LAMP_CONF":"/var/lib/lamp/conf","MESH_FINGERPRINT":"` + fp + `"}}`
}
if env[catalogue.RuntimeToolModules] != served || env[catalogue.RuntimeToolEnv] != words {
t.Errorf("%s: the runtime serves %v with %v, want what runs of lamp, %s", row.name,
env[catalogue.RuntimeToolModules], env[catalogue.RuntimeToolEnv], served)
if row.wantServed != "" {
wantServed, words = row.wantServed, row.wantWords
}
if env[catalogue.RuntimeToolModules] != wantServed || env[catalogue.RuntimeToolEnv] != words {
t.Errorf("%s: the runtime serves %v with %v, want %s with %s", row.name,
env[catalogue.RuntimeToolModules], env[catalogue.RuntimeToolEnv], wantServed, words)
}
}
}
+2
View File
@@ -475,6 +475,8 @@ func readBase(ctx context.Context, r Reader, mesh Mesh, s Scope) (base, error) {
if node == s.Node {
// What its runtime serves as it runs: what a module composed as what runs of it contributes there (issue 1126).
n.RunsTools = compose.ToolsRunning(s.Running)
// And the runtime's process as it runs, whose slice of each held module is kept verbatim (H-A-306).
n.RunsRuntime = compose.RuntimeRunning(s.Running)
for _, module := range s.InOwn {
if n.InOwn == nil {
n.InOwn = map[string]bool{}
+5
View File
@@ -273,6 +273,11 @@ type Node struct {
// bundles, and a held module's new build's bundles are not delivered (issue 1126, 2026-10-29: shanks's runtime lost
// the folded systemd-resolved, novox's the folded nats).
RunsTools map[string][]catalogue.Bundle
// RunsRuntime is the environment of the tool runner's process as it runs (RuntimeRunning of what the node runs); nil
// when none runs. A held module's slice of the runtime process (its entries in catalogue.RuntimeToolModules, its words
// in catalogue.RuntimeToolEnv, its fingerprint among them) is copied from it verbatim, so a pass that holds a module
// for a part withheld composes the runtime as it runs (design 47 H, H-A-303, H-A-306).
RunsRuntime map[string]string
}
// ComposedHow is how a node-engine composes its node from an Input (Input.ComposedHow).