Files
mesh-host/internal/compose/resolution/holding.go
T
jschoubben 94a2e6ede0 H-A-335: a held module's share of a holder's words is what runs
The reads runtime on ace restarted twice in two minutes because its
MESH_SECRET_PLACES changed: the holders of node-reads and node-files were
told the node's secret places and owned paths from held modules' stubs,
which differ pass by pass while a part is withheld. While a module is held,
the resolution now takes its share from each runtime process as it runs:
the secret places are those the modules not held compose merged with every
place that runs, and the owned paths keep each running entry a held module
owns. Two passes with the same held set compose every runtime process the
same; a module that answered and changed is still composed from its build.

Builds: design 47 H H-A-335, H-A-337, H-A-306 (2), (3)
2026-11-21 22:10:50 +01:00

60 lines
2.0 KiB
Go

package resolution
import (
"encoding/json"
"strings"
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
)
// Holding is what a node holds while it composes itself (design 47 H, H-A-306, H-A-335, H-A-337): the modules held this
// pass, each composed as its stub, and each runtime process as it runs. A holder's words that every module gives a share
// of (the secret places, the owned paths) take a held module's share from what runs, never from its stub, so two passes
// with the same held set compose every runtime process the same. The zero Holding holds nothing: everything is composed
// from the manifests, as before.
type Holding struct {
// Held is each module held on this node this pass (compose.Node.Held).
Held map[string]bool
// Runs is the environment of each runtime process as it runs, by its id: the tool runner's (`<module>.runtime`) and
// each runtime of a module of its own account (`<module>.own-runtime`).
Runs map[string]map[string]string
}
// ran is module's words in process's mcat.RuntimeToolEnv as it runs, or nil when nothing is held, the process does not
// run, or it gives module no words.
func (h Holding) ran(process, module string) map[string]string {
if len(h.Held) == 0 {
return nil
}
env, runs := h.Runs[process]
if !runs {
return nil
}
var words map[string]map[string]string
if json.Unmarshal([]byte(env[mcat.RuntimeToolEnv]), &words) != nil {
return nil
}
return words[module]
}
// notHeld is r with only the modules not in held, or r itself when none is held.
func notHeld(r mcat.Resolution, held map[string]bool) mcat.Resolution {
if len(held) == 0 {
return r
}
modules := make([]mcat.Manifest, 0, len(r.Modules))
for _, m := range r.Modules {
if !held[m.Module] {
modules = append(modules, m)
}
}
r.Modules = modules
return r
}
// ownerOf is the module an owned path's entry names (resolutionOwnedPaths: `<module> (<why>)`).
func ownerOf(entry string) string {
module, _, _ := strings.Cut(entry, " (")
return module
}