G-24: the node-engine's composer names the modules it blames #235

Merged
mesh-tools merged 6 commits from fix/47-G-composer-blames into main 2026-11-17 12:15:37 +00:00
5 changed files with 96 additions and 76 deletions
Showing only changes of commit b4bf772de4 - Show all commits
+8 -5
View File
@@ -185,7 +185,7 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
}{
// G-24 H-AC1: a fixture module whose manifest is refused on the machine is blamed by name.
{"a module the change refuses is blamed by name", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)},
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "app", Problem: "repository"}}},
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 20, []blame{{Module: "app", Problem: "repository"}}},
// Held composing without the change (HeldBefore): left out of blamed.
{"a module held before the change is not blamed", map[string]string{"app": file("app", "/var/lib/app/env", `N=${secret:repository}\\n`)},
[]string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, 0, []blame{}},
@@ -200,17 +200,20 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) {
// G-24 H-AC5: a machine that fails with no module held is searched over the changed modules placed on it (here every
// one, the input naming no manifest its builds were made of, A-469k), in assignment order; the search ends at the
// first whose hold ends the problem, so m3 is never tried.
{"the search ends at the first module whose hold ends the problem", search, []string{"m1", "m2", "m3"}, nil, 20,
{"the search ends at the first module whose hold ends the problem", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 20,
[]blame{{Module: "m2", Problem: "repository"}}},
// A module whose case manifest is the one its build was made of is not changed (A-469k), so never held: m2's
// problem is then no changed module's, and none is blamed.
{"a module its build was made of is not tried", search, []string{"m1", "m2", "m3"},
&compose.ComposedHow{Node: "b", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}},
&compose.ComposedHow{Node: "a", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}},
// G-24 H-AC4: past the request's blame_tries the modules not yet tried are named so.
{"past blame_tries the untried are named", search, []string{"m1", "m2", "m3"}, nil, 1,
{"past blame_tries the untried are named", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 1,
[]blame{{Module: "m2", Problem: composer.NotTried}, {Module: "m3", Problem: composer.NotTried}}},
// A-468i: a request with no blame_tries gets no search; the machine fails on the node's own account (H-AC3).
{"a request with no blame_tries is not searched", search, []string{"m1", "m2", "m3"}, nil, 0, []blame{}},
{"a request with no blame_tries is not searched", search, []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 0, []blame{}},
// A-469j: one search, the composer's, inside the node-engine's composition (ComposeSent): an input that says not how
// its node composes is composed without one, so its failure is the node's own.
{"a node that says not how it composes is not searched", search, []string{"m1", "m2", "m3"}, nil, 20, []blame{}},
} {
t.Run(row.name, func(t *testing.T) {
r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), BlameTries: row.tries,
+8 -7
View File
@@ -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), nil)
composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), 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 {
@@ -332,10 +332,11 @@ func standsInFor(x, node string) (string, string) {
// (culprit): de-spiegel's routes, its names unset, leave route-proxy without them while mailu keeps its smtp account,
// and the hold says so.
//
// owned, where not nil, is told each culprit held for a refusal that names paths two modules both own, with those pairs
// (resolution.Refusal.OwnedTwice): a composer blames both owners with the path (design 47 G §721; A-468l).
// search says a refusal is laid on a culprit (culprit). The node composing itself always searches; a composer's sandbox
// (ComposeSent) does not, since it runs the one search for culprits itself, bounded by its request (design 47 G §721;
// A-469j): there the first refusal no hold of the read answers is the node's (err).
func composeEach(in compose.Input, node string, fps map[string]string, applied bool, running []compositions.Composed, failed map[string]string,
ran func(module string) (catalogue.Manifest, bool), owned func(culprit string, twice []resolution.OwnedTwice)) (out map[string]compositions.Composed, skipped, stood []string, err error) {
ran func(module string) (catalogue.Manifest, bool), search bool) (out map[string]compositions.Composed, skipped, stood []string, err error) {
mode := compose.Foreseeing
if applied {
mode = compose.Reading
@@ -382,13 +383,13 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b
var leftOut map[string]string
out, skipped, stood, leftOut, err = compose.CompositionsHolding(in, node, fps, mode)
if err != nil {
if !search {
return nil, nil, nil, err
}
module, leave := culprit(in, node, fps, mode, failed, err)
if module == "" {
return nil, nil, nil, firstReason(err, failed)
}
if refusal := (*resolution.Refusal)(nil); owned != nil && errors.As(err, &refusal) && len(refusal.OwnedTwice) > 0 {
owned(module, refusal.OwnedTwice)
}
hold(module, err.Error(), leave)
continue
}
+69 -27
View File
@@ -703,7 +703,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), nil)
out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), true)
return out, skipped, held, err
}
@@ -731,49 +731,56 @@ func ComposingInput(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[s
// ComposeSent composes node from an input ComposingInput read, through the path Compose takes (composeEach, the read's holds
// first): what a check's sandbox runs. False when the input says no way of composing node (an input from a node-engine
// before ComposedHow): the caller cannot compose it as the node does. A node the change refuses is a *Refuses.
func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bool, error) {
//
// It runs the one search for culprits (design 47 G §721; A-469j, A-468i): where the composition fails with no module held
// that the node held neither in the read nor before the change, and no path owned twice names its owners, each of
// s.Changed is held in turn, one composition each, and the first whose hold ends the problem (the try composes or fails
// otherwise) is blamed with it. At most s.Tries tries; past them each module not yet tried is blamed NotTried. With no
// tries there is no search: the failure is the node's own (err).
func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Composed, bool, error) {
c := in.ComposedHow
if c == nil || c.Node != node {
return nil, false, nil
}
held := maps.Clone(c.Held)
if held == nil {
held = map[string]string{}
}
twice := map[string][]resolution.OwnedTwice{}
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, func(culprit string, pairs []resolution.OwnedTwice) {
for _, p := range pairs {
if p.Modules[0] == culprit || p.Modules[1] == culprit {
twice[culprit] = append(twice[culprit], p)
compose1 := func(also string) (map[string]engcomp.Composed, map[string]string, error) {
held := maps.Clone(c.Held)
if held == nil {
held = map[string]string{}
}
// A module the node holds composing without the change is held as there: the candidate keeps it as the node does,
// which is no change and no search (issue 1126; design 47 G §721, HeldBefore left out of blamed).
for m, why := range c.HeldBefore {
if _, was := held[m]; !was {
held[m] = why
}
}
})
if err != nil {
return nil, true, err
if also != "" {
held[also] = triedHeld
}
out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, false)
return out, held, err
}
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
// review of the sandbox input).
var refused []string
blamed := map[string]string{}
ours := func(m string) bool {
_, was := c.Held[m]
_, before := c.HeldBefore[m]
return !was && !before
}
out, held, err := compose1("")
// A module the sandbox held that the node-engine held neither in the read nor composing without the change is the change
// refusing it: the node does not compose, said in that module's words, never passed with the rest composed (issue 774,
// review of the sandbox input).
var refused []string
blamed := map[string]string{}
for _, m := range sortedKeys(held) {
if ours(m) {
refused = append(refused, m+": "+held[m])
blamed[m] = held[m]
}
}
if len(refused) == 0 {
return out, true, nil
}
// Two modules owning one path are each blamed, with that path, the one held for it and the one it was held beside
// (design 47 G §721; A-468l).
for _, m := range sortedKeys(blamed) {
for _, p := range twice[m] {
// Two modules owning one path are each blamed, with that path, outside the search (design 47 G §721; A-468l).
var refusal *resolution.Refusal
if err != nil && errors.As(err, &refusal) {
for _, p := range refusal.OwnedTwice {
words := fmt.Sprintf("%s and %s both declare the path %q", p.Modules[0], p.Modules[1], p.Path)
for _, owner := range p.Modules {
if ours(owner) {
@@ -782,13 +789,48 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo
}
}
}
e := &Refuses{Node: node, words: strings.Join(refused, "; ")}
if err != nil && len(blamed) == 0 && s.Tries > 0 {
problem := err.Error()
for i, mod := range s.Changed {
if i == s.Tries {
for _, untried := range s.Changed[i:] {
blamed[untried] = NotTried
}
break
}
if _, _, again := compose1(mod); again == nil || again.Error() != problem {
blamed[mod] = problem
break
}
}
}
if len(blamed) == 0 {
return out, true, err
}
words := strings.Join(refused, "; ")
if err != nil {
words = err.Error()
}
e := &Refuses{Node: node, words: words}
for _, m := range sortedKeys(blamed) {
e.Blamed = append(e.Blamed, Blamed{Module: m, Problem: blamed[m]})
}
return nil, true, e
}
// Search is the composer's one search for culprits in ComposeSent (design 47 G §721): the candidate's changed modules
// placed on the node, in assignment order, and the request's blame_tries.
type Search struct {
Changed []string
Tries int
}
// NotTried is the problem of a changed module the search for culprits did not hold, its bound reached (design 47 G §721).
const NotTried = "not tried: the search reached its bound"
// triedHeld is the words a module is held with while the search for culprits tries it.
const triedHeld = "held by the composer's search for the module the machine's problem is of"
// Refuses is ComposeSent's refusal of a node by the change, answered structured (design 47 G §721; A-469j): each module
// the sandbox held that its node-engine held neither in the read nor composing without the change (HeldBefore), and
// each other owner of a path one of them was held for, with its problem.
+10 -36
View File
@@ -247,8 +247,11 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
if len(never) > 0 {
at = heldAgain(in, held, never)
}
m := machine(at, node, depth, r.Declarations)
problem := problemOf(m) // what the search for culprits holds a module against, before any words are added
// The one search for culprits runs inside the node-engine's composition (frombus.ComposeSent), over the case's
// changed modules on node, bounded by the request's blame_tries; a request with none gets no search (design 47 G
// §721; A-468i, A-469j, A-469k).
search := frombus.Search{Changed: changedOn(in, node, c, held.ComposedHow), Tries: r.BlameTries}
m := machine(at, node, depth, r.Declarations, search)
if words := awaitedOn(at, node, pending); words != "" {
// Composed without the build it runs at: named per node and module, never a silent pass (issue 1921). The
// machine is then not judged, as for a node whose running state its engine does not send (ADR 0593 §9). Where
@@ -260,11 +263,11 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
how := "composed from the change's manifest without its build: "
if !m.Composes && m.NotJudged == "" {
lifted := heldAgain(at, held, pending)
switch again := machine(lifted, node, depth, r.Declarations); {
switch again := machine(lifted, node, depth, r.Declarations, search); {
case again.Composes:
m, how = again, "composed with it held as its node-engine holds it, since it does not compose without its build: "
case again.NotJudged == "":
m, how, at, problem = again, "refused with it held as its node-engine holds it, since it does not compose without its build: ", lifted, problemOf(again)
m, how = again, "refused with it held as its node-engine holds it, since it does not compose without its build: "
}
}
words = how + words
@@ -277,11 +280,6 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) {
if len(never) > 0 && m.NotJudged == "" {
m = blameNever(m, never, c.None) // after the awaited words, which judge it again where it does not compose
}
// A machine that does not compose with no module held is searched for the module whose hold ends its problem, bounded
// by the request's blame_tries; a request with none gets no search (design 47 G §721; A-468i, A-469j).
if !m.Composes && m.NotJudged == "" && len(m.Blamed) == 0 && r.BlameTries > 0 {
m.Blamed = culprits(at, held, node, depth, r.Declarations, changedOn(at, node, c, held.ComposedHow), r.BlameTries, problem)
}
if m.Blamed == nil {
m.Blamed = []blame{} // always written, so a verdict blaming none is told from an old composer's (A-469h)
}
@@ -518,7 +516,7 @@ func HoldingsOf(shelf map[string]catalogue.Manifest, nodes []compose.Node) []cat
return out
}
func machine(in compose.Input, node, depth string, declarations bool) Machine {
func machine(in compose.Input, node, depth string, declarations bool, search frombus.Search) Machine {
if depth == DepthResolve {
if _, err := compose.Resolve(in, node); err != nil {
return Machine{Reason: err.Error(), Blamed: ownedTwice(err)}
@@ -528,7 +526,7 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
// Composed as the node-engine composes it, when its input says how (compose.Input.ComposedHow, issue 774): the same
// path, at the same builds, a module folded in its own composition kept as it runs.
if !declarations {
if _, how, err := frombus.ComposeSent(in, node); how {
if _, how, err := frombus.ComposeSent(in, node, search); how {
if err != nil {
m := Machine{Reason: err.Error()}
var refuses *frombus.Refuses
@@ -564,31 +562,7 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine {
}
// NotTried is the problem of a changed module the search for culprits did not hold, its bound reached (design 47 G §721).
const NotTried = "not tried: the search reached its bound"
// triedHeld is the words a module is held with while the search for culprits tries it.
const triedHeld = "held by the composer's search for the module the machine's problem is of"
// culprits holds each of changed on node, one at a time, as its node-engine holds a module (heldAgain), each try
// composing once more, and blames the first whose hold ends problem: the try composes, or fails otherwise, as culprit
// blames a stub (frombus). At most tries tries; past them each module not yet tried is named NotTried (design 47 G §721).
// None ends it: no module is blamed, and the machine fails on the node's own account.
func culprits(in, held compose.Input, node, depth string, declarations bool, changed []string, tries int, problem string) []blame {
for i, mod := range changed {
if i == tries {
var out []blame
for _, untried := range changed[i:] {
out = append(out, blame{Module: untried, Problem: NotTried})
}
return out
}
try := machine(heldAgain(in, held, map[string]string{mod: triedHeld}), node, depth, declarations)
if try.NotJudged == "" && (try.Composes || problemOf(try) != problem) {
return []blame{{Module: mod, Problem: problem}}
}
}
return nil
}
const NotTried = frombus.NotTried
// problemOf is a machine's problem in words: why it does not compose, with what the validator refuses.
func problemOf(m Machine) string {
+1 -1
View File
@@ -164,7 +164,7 @@ func TestARequestItCannotRunIsRefused(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if m := refused.Cases[0].Machines["a"]; m.Composes || !strings.Contains(m.Reason, "app: ") || !strings.Contains(m.Reason, "repository") {
if m := refused.Cases[0].Machines["a"]; m.Composes || !strings.Contains(m.Reason, "app has a file") || !strings.Contains(m.Reason, "repository") {
t.Errorf("a module the change refuses on a node composed as its node-engine does: %+v", m)
}
// Held composing without the change, blamed for a refusal beyond the read (issue 1960's unset names): no refusal of