From 06781d4dbcf56dc697afaac245d88946ae685038 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 11:19:54 +0100 Subject: [PATCH 1/6] composer: a machine's verdict names the modules it blames (G-24 H1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The assigner fails only the composition steps of the modules a machine blames, so the composer names them: the modules the change refuses that the node held neither in its read nor composing without the change, answered structured by ComposeSent, and both owners of a path two modules own, from the resolution's pairs. Blamed is always written, so a verdict blaming none is told from an old composer's. The two request-file tests are one, for the test budget. Builds: design 47 G §721, §733; A-468h, A-468l, A-469h, A-469j --- cmd/mesh-compose/main.go | 6 +- cmd/mesh-compose/main_test.go | 91 ++++++++++++++++++++++---- internal/compose/frombus/answer.go | 10 ++- internal/compose/frombus/frombus.go | 62 +++++++++++++++--- internal/compose/resolution/resolve.go | 32 +++++++-- internal/composer/composer.go | 44 ++++++++++++- 6 files changed, 215 insertions(+), 30 deletions(-) diff --git a/cmd/mesh-compose/main.go b/cmd/mesh-compose/main.go index d8f5d8a6..dc12980d 100644 --- a/cmd/mesh-compose/main.go +++ b/cmd/mesh-compose/main.go @@ -152,7 +152,11 @@ func runWithSeats(req composer.Request) (composer.Verdict, error) { for i := range v.Cases { v.Cases[i].Machines = map[string]composer.Machine{} for _, node := range machines { - v.Cases[i].Machines[node] = composer.Machine{NotJudged: NoSeatList} + // Blamed is always written, blaming none here (design 47 G §721, A-469h). + v.Cases[i].Machines[node] = composer.Machine{NotJudged: NoSeatList, Blamed: []struct { + Module string `json:"module"` + Problem string `json:"problem"` + }{}} } } return v, nil diff --git a/cmd/mesh-compose/main_test.go b/cmd/mesh-compose/main_test.go index eeef56c4..04efce78 100644 --- a/cmd/mesh-compose/main_test.go +++ b/cmd/mesh-compose/main_test.go @@ -161,9 +161,77 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { if m := resolverMachine(true); strings.Contains(m.Reason+strings.Join(m.Problems, " "), "both declare") || m.NotJudged != "" { t.Errorf("with the seat list, the uplink's and the resolver's holders on one machine: %+v, want the uplink's stepping back", m) } - if m := resolverMachine(false); m.Composes || m.NotJudged != NoSeatList || m.Reason != "" { - t.Errorf("without a seat list: %+v, want not judged, saying why", m) + if m := resolverMachine(false); m.Composes || m.NotJudged != NoSeatList || m.Reason != "" || m.Blamed == nil { + t.Errorf("without a seat list: %+v, want not judged, saying why, blaming none", m) } + + // Design 47 G §721, §733 (the node-engine's composer): a machine's verdict names the modules it blames, each with its + // problem, and always writes blamed (A-469h). On a node composed as its node-engine composes it (ComposedHow), blamed is + // the modules the change refuses that the node held neither in its read nor composing without the change (A-469j). + file := func(module, path, content string) string { + return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path + + `", "mode": "0600", "content": "` + content + `"}]}` + } + for _, row := range []struct { + name string + manifests map[string]string + assigned []string + how *compose.ComposedHow + blamed []blame // each module blamed, its problem holding the words given + }{ + // 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{}}, []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"}}, []blame{}}, + // G-24 H-AC2 (A-468l): two modules owning one path are both blamed, with that path. + {"two modules owning one path are both blamed", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, + []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, + []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, + // The same, on a node whose input says not how it composes: nothing is held, both owners are blamed from the refusal. + {"two path owners, composed without how the node composes", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, + []string{"one", "two"}, nil, + []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, + } { + t.Run(row.name, func(t *testing.T) { + r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), + Cases: []composer.Case{{Name: "change", Manifests: map[string]composer.Manifest{}}}} + for name, raw := range row.manifests { + r.Cases[0].Manifests[name] = composer.Manifest{Raw: json.RawMessage(raw)} + } + r = withInput(t, r, compose.Input{Nodes: []compose.Node{{Name: "a", Assigned: row.assigned}}, ComposedHow: row.how}) + var out, errOut bytes.Buffer + if code := run(nil, bytes.NewReader(encode(t, r)), &out, &errOut); code != 0 { + t.Fatalf("exit %d: %s", code, errOut.String()) + } + if !strings.Contains(out.String(), `"blamed":`) { + t.Errorf("the verdict writes no blamed: %s", out.String()) + } + var v composer.Verdict + if err := json.Unmarshal(out.Bytes(), &v); err != nil { + t.Fatal(err) + } + m := v.Cases[0].Machines["a"] + if len(row.blamed) > 0 && m.Composes { + t.Errorf("a machine that blames a module composes: %+v", m) + } + if len(m.Blamed) != len(row.blamed) { + t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m) + } + for i, b := range row.blamed { + if m.Blamed[i].Module != b.Module || !strings.Contains(m.Blamed[i].Problem, b.Problem) { + t.Errorf("blamed %+v, want %+v", m.Blamed, row.blamed) + } + } + }) + } +} + +// blame is one module a machine's verdict blames (composer.Machine.Blamed). +type blame = struct { + Module string `json:"module"` + Problem string `json:"problem"` } // 1621/AC3: over the captured catalogue and a mesh of three machines, the command's verdict equals, machine for @@ -211,6 +279,9 @@ func TestTheCommandAnswersWhatTheLinkedCompositionAnswers(t *testing.T) { } } } + // G-24 H-AC3 (§721): a machine that does not compose and blames no module (ace: its own sealing key) fails on the + // node's own account, blamed written empty. + want.Blamed = []blame{} if !reflect.DeepEqual(got, want) { t.Errorf("%s: %s: command %+v, linked %+v", depth, node, got, want) } @@ -249,8 +320,8 @@ func TestACatalogueCheckoutIsComposedForANode(t *testing.T) { } } -// A run step hands the command no standard input: the request is read from the file -request names, and a file that is -// not there is a request it cannot read. +// A run step hands the command no standard input: the request is read from the file -request names, or from the one +// MESH_RUN_INPUT names, and a file that is not there is a request it cannot read. func TestTheRequestIsReadFromAFile(t *testing.T) { file := filepath.Join(t.TempDir(), "request.json") r := composer.Request{V: composer.Version, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{ @@ -265,14 +336,10 @@ func TestTheRequestIsReadFromAFile(t *testing.T) { if code, _, stderr := runJSON(t, []string{"-request", file + ".gone"}, nil); code != 1 || !strings.Contains(stderr, "cannot be read") { t.Errorf("a request file that is not there: exit %d, %q", code, stderr) } -} -// A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the last -// line of standard output (design 47 G A-167). -func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) { - file := filepath.Join(t.TempDir(), "input.json") - r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Cases: []composer.Case{{Name: "only", Manifests: map[string]composer.Manifest{ - "demo": {Raw: json.RawMessage(`{"module":"demo","version":"1"}`)}}}}} + // A pipeline step names its input file in MESH_RUN_INPUT: the command reads the request there and the verdict is the + // last line of standard output (design 47 G A-167). + r.Depth = composer.DepthCompose if err := os.WriteFile(file, encode(t, r), 0o600); err != nil { t.Fatal(err) } @@ -282,7 +349,7 @@ func TestThePipelineStepReadsMESH_RUN_INPUT(t *testing.T) { t.Fatalf("exit %d: %s", code, errOut.String()) } lines := strings.Split(strings.TrimRight(out.String(), "\n"), "\n") - var v composer.Verdict + v = composer.Verdict{} if err := json.Unmarshal([]byte(lines[len(lines)-1]), &v); err != nil || len(v.Cases) != 1 || !v.Cases[0].Manifests["demo"].Accepted { t.Fatalf("last line is no verdict: %v\n%s", err, out.String()) } diff --git a/internal/compose/frombus/answer.go b/internal/compose/frombus/answer.go index 660d5c7f..be47d419 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)) + composed, skipped, stood, err := composeEach(in, s.Node, fps, false, s.Running, failed, ranOf(ctx, r, mesh, s.Running, fps), nil) 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 { @@ -331,8 +331,11 @@ func standsInFor(x, node string) (string, string) { // else the manifest it is composed from. Only the part of the offer that cannot compose is left out, by provision // (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). 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)) (out map[string]compositions.Composed, skipped, stood []string, err error) { + ran func(module string) (catalogue.Manifest, bool), owned func(culprit string, twice []resolution.OwnedTwice)) (out map[string]compositions.Composed, skipped, stood []string, err error) { mode := compose.Foreseeing if applied { mode = compose.Reading @@ -383,6 +386,9 @@ func composeEach(in compose.Input, node string, fps map[string]string, applied b 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 } diff --git a/internal/compose/frombus/frombus.go b/internal/compose/frombus/frombus.go index 2cc0868d..30a1de65 100644 --- a/internal/compose/frombus/frombus.go +++ b/internal/compose/frombus/frombus.go @@ -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)) + out, skipped, _, err = composeEach(in, s.Node, fps, true, s.Running, held, ranOf(ctx, r, mesh, s.Running, fps), nil) return out, skipped, held, err } @@ -730,7 +730,7 @@ 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. +// 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) { c := in.ComposedHow if c == nil || c.Node != node { @@ -740,7 +740,14 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo if held == nil { held = map[string]string{} } - out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil) + 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) + } + } + }) if err != nil { return nil, true, err } @@ -748,18 +755,57 @@ func ComposeSent(in compose.Input, node string) (map[string]engcomp.Composed, bo // 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 - for _, m := range sortedKeys(held) { + blamed := map[string]string{} + ours := func(m string) bool { _, was := c.Held[m] - if _, before := c.HeldBefore[m]; !was && !before { + _, before := c.HeldBefore[m] + return !was && !before + } + for _, m := range sortedKeys(held) { + if ours(m) { refused = append(refused, m+": "+held[m]) + blamed[m] = held[m] } } - if len(refused) > 0 { - return nil, true, fmt.Errorf("on %s the change refuses %s", node, strings.Join(refused, "; ")) + if len(refused) == 0 { + return out, true, nil } - 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] { + 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) { + blamed[owner] = words + } + } + } + } + e := &Refuses{Node: node, words: strings.Join(refused, "; ")} + for _, m := range sortedKeys(blamed) { + e.Blamed = append(e.Blamed, Blamed{Module: m, Problem: blamed[m]}) + } + return nil, true, e } +// 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. +type Refuses struct { + Node string + Blamed []Blamed + words string +} + +// Blamed is one module a refusal of the change blames, with its problem. +type Blamed struct { + Module string + Problem string +} + +func (e *Refuses) Error() string { return fmt.Sprintf("on %s the change refuses %s", e.Node, e.words) } + // Plans is the provisioning plan of each module handed to the provisioner on the scope's node, composed from the bus // alone (novox/hq ADR 0570 clause 2): the controller's handedPlans over the same input (mesh-control // cmd/mesh-controller/compose_sdk.go), its rendering in the Foreseeing mode with the mesh's generators. A plan names diff --git a/internal/compose/resolution/resolve.go b/internal/compose/resolution/resolve.go index 34b8fe93..37e1f5d5 100644 --- a/internal/compose/resolution/resolve.go +++ b/internal/compose/resolution/resolve.go @@ -20,7 +20,19 @@ func heldKey(claim, kind string) string { // // Every reason at once rather than the first, and each says what to do about it. A person // resolving these fixes them in one pass or in four. -type Refusal struct{ Problems []string } +type Refusal struct { + Problems []string + // OwnedTwice is each path two modules both own among Problems, as a pair: a composer blames both owners with the + // path, never by the words (design 47 G §721; A-468l). + OwnedTwice []OwnedTwice +} + +// OwnedTwice is one path two modules both declare as their own (checkResources), the module that declared it first +// first. +type OwnedTwice struct { + Path string + Modules [2]string +} func (r *Refusal) Error() string { return "these assignments cannot be applied:\n - " + strings.Join(r.Problems, "\n - ") @@ -616,7 +628,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No // Listed after the holding: an optional consumer of a requirement nothing answers is left absent there (ADR 0330 §3, §7). resolution.Absent = absentOf(absent, order, catalogue) problems = append(problems, unheld...) - problems = append(problems, checkResources(resolution.Modules)...) + owned, twice := resourceProblems(resolution.Modules) + problems = append(problems, owned...) resolution.Claims = claims // Judged over the closure — what this node will actually run — so a holder pulled in by a @@ -641,7 +654,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No problems = append(problems, why) } sort.Strings(problems) - return mcat.Resolution{}, nil, &Refusal{Problems: problems} + return mcat.Resolution{}, nil, &Refusal{Problems: problems, OwnedTwice: twice} } return resolution, held, nil } @@ -910,6 +923,13 @@ func canonicalSeat(name string) string { // resolves with no refusal. What is refused is the contradiction — a path one module owns and // another merely accesses — because shared data is the operator's and nobody's to own. func checkResources(modules []mcat.Manifest) []string { + problems, _ := resourceProblems(modules) + return problems +} + +// resourceProblems is checkResources' problems, with each path two modules both own as a pair beside its words. +func resourceProblems(modules []mcat.Manifest) ([]string, []OwnedTwice) { + var twice []OwnedTwice // Judged as the machine composes them: where the node-resolver holder writes the resolver file, the // uplink holder's rendering of it is not composed, so it is not a second owner (novox/hq ADR 0247). modules = steppedBack(modules) @@ -987,6 +1007,9 @@ func checkResources(modules []mcat.Manifest) []string { if other, taken := owner[key]; taken && other != m.Module { problems = append(problems, fmt.Sprintf( "%s and %s both declare the %s %q", other, m.Module, field, value)) + if field == "path" { + twice = append(twice, OwnedTwice{Path: value, Modules: [2]string{other, m.Module}}) + } } owner[key] = m.Module if field == "path" { @@ -1007,6 +1030,7 @@ func checkResources(modules []mcat.Manifest) []string { if other, taken := owner[key]; taken && other != m.Module { problems = append(problems, fmt.Sprintf( "%s and %s both declare the path %q", other, m.Module, fact.Path)) + twice = append(twice, OwnedTwice{Path: fact.Path, Modules: [2]string{other, m.Module}}) } owner[key] = m.Module ownedPath[fact.Path] = m.Module @@ -1042,7 +1066,7 @@ func checkResources(modules []mcat.Manifest) []string { } } } - return problems + return problems, twice } // meshNetwork is what to assign to a machine that needs to reach another one. diff --git a/internal/composer/composer.go b/internal/composer/composer.go index c95bc208..1bf54522 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -9,6 +9,7 @@ package composer import ( "encoding/json" + "errors" "fmt" "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" @@ -27,6 +28,7 @@ import ( "github.com/novox/mesh-host/internal/compose" "github.com/novox/mesh-host/internal/compose/frombus" + "github.com/novox/mesh-host/internal/compose/resolution" ) // The shapes of mesh-sdk's composer package, by the names this package's code was written with. @@ -261,6 +263,9 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { m.Reason += "; " + words } } + if m.Blamed == nil { + m.Blamed = []blame{} // always written, so a verdict blaming none is told from an old composer's (A-469h) + } cv.Machines[node] = m } return cv, nil @@ -455,7 +460,7 @@ func HoldingsOf(shelf map[string]catalogue.Manifest, nodes []compose.Node) []cat func machine(in compose.Input, node, depth string, declarations bool) Machine { if depth == DepthResolve { if _, err := compose.Resolve(in, node); err != nil { - return Machine{Reason: err.Error()} + return Machine{Reason: err.Error(), Blamed: ownedTwice(err)} } return Machine{Composes: true} } @@ -464,7 +469,14 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine { if !declarations { if _, how, err := frombus.ComposeSent(in, node); how { if err != nil { - return Machine{Reason: err.Error()} + m := Machine{Reason: err.Error()} + var refuses *frombus.Refuses + if errors.As(err, &refuses) { + for _, b := range refuses.Blamed { + m.Blamed = append(m.Blamed, blame{Module: b.Module, Problem: b.Problem}) + } + } + return m } return Machine{Composes: true} } @@ -478,7 +490,7 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine { return Machine{NotJudged: NotJudged + strings.Join(folded, ", ") + " (its own composition carries them as they run, and the sandbox cannot): " + err.Error()} } - return Machine{Reason: err.Error()} + return Machine{Reason: err.Error(), Blamed: ownedTwice(err)} } m := Machine{Composes: len(problems) == 0, Problems: problems, Refusals: d.Refusals()} if len(problems) > 0 { @@ -490,6 +502,32 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine { return m } +// blame is one module a machine's verdict blames, with its problem (Machine.Blamed, design 47 G §721). +type blame = struct { + Module string `json:"module"` + Problem string `json:"problem"` +} + +// ownedTwice blames both owners of each path a refusal names two modules owning, with that path (design 47 G §721; +// A-468l), where nothing held either: a composition that holds no module. +func ownedTwice(err error) []blame { + var refusal *resolution.Refusal + if !errors.As(err, &refusal) { + return nil + } + problem := map[string]string{} + for _, p := range refusal.OwnedTwice { + for _, owner := range p.Modules { + problem[owner] = fmt.Sprintf("%s and %s both declare the path %q", p.Modules[0], p.Modules[1], p.Path) + } + } + var out []blame + for _, m := range slices.Sorted(maps.Keys(problem)) { + out = append(out, blame{Module: m, Problem: problem[m]}) + } + return out +} + // NotJudged opens the words of a machine the sandbox does not judge (Machine.NotJudged, the contract's field, ADR 0593 §9): // its node-engine sent an input that does not say how it composes (compose.Input.ComposedHow), and the node runs modules // folded in its own composition. The machine is then neither composed nor refused; a reader decides by the field. From 8700aabba3b3710da2f73c9c70d0c3afc1679480 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 11:21:49 +0100 Subject: [PATCH 2/6] composer: a machine that fails with no module held is searched for its culprit, bounded by blame_tries (G-24 H2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composer program has no settings, so the assigner bounds the search through the request: only the candidate's changed modules placed on the machine are held, one at a time, the search ending at the first whose hold ends the problem; past the bound the untried are named. A request with no blame_tries gets no search. Builds: design 47 G §721, §733; A-468h, A-468i, A-469i, A-469j, A-469k --- cmd/mesh-compose/main_test.go | 42 +++++++++++++++---- internal/composer/composer.go | 77 +++++++++++++++++++++++++++++++++-- 2 files changed, 109 insertions(+), 10 deletions(-) diff --git a/cmd/mesh-compose/main_test.go b/cmd/mesh-compose/main_test.go index 04efce78..24a58563 100644 --- a/cmd/mesh-compose/main_test.go +++ b/cmd/mesh-compose/main_test.go @@ -172,30 +172,48 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { return `{"module": "` + module + `", "version": "1", "resources": [{"id": "f", "type": "file", "path": "` + path + `", "mode": "0600", "content": "` + content + `"}]}` } + plain := func(module string) string { return `{"module": "` + module + `", "version": "1"}` } + secret := `N=${secret:repository}\\n` + search := map[string]string{"m1": plain("m1"), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")} for _, row := range []struct { name string manifests map[string]string assigned []string how *compose.ComposedHow + tries int // the request's blame_tries blamed []blame // each module blamed, its problem holding the words given }{ // 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{}}, []blame{{Module: "app", Problem: "repository"}}}, + []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []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"}}, []blame{}}, + []string{"app"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}, HeldBefore: map[string]string{"app": "held"}}, 0, []blame{}}, // G-24 H-AC2 (A-468l): two modules owning one path are both blamed, with that path. {"two modules owning one path are both blamed", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, - []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, + []string{"one", "two"}, &compose.ComposedHow{Node: "a", Builds: map[string]string{}}, 0, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, // The same, on a node whose input says not how it composes: nothing is held, both owners are blamed from the refusal. {"two path owners, composed without how the node composes", map[string]string{"one": file("one", "/etc/shared.conf", "x"), "two": file("two", "/etc/shared.conf", "y")}, - []string{"one", "two"}, nil, + []string{"one", "two"}, nil, 20, []blame{{Module: "one", Problem: `one and two both declare the path "/etc/shared.conf"`}, {Module: "two", Problem: `one and two both declare the path "/etc/shared.conf"`}}}, + // 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, + []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{}}, + // 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, + []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{}}, } { t.Run(row.name, func(t *testing.T) { - r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), + r := composer.Request{V: composer.Version, Depth: composer.DepthCompose, Machines: []string{"a"}, Seats: seats(t), BlameTries: row.tries, Cases: []composer.Case{{Name: "change", Manifests: map[string]composer.Manifest{}}}} for name, raw := range row.manifests { r.Cases[0].Manifests[name] = composer.Manifest{Raw: json.RawMessage(raw)} @@ -213,8 +231,8 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { t.Fatal(err) } m := v.Cases[0].Machines["a"] - if len(row.blamed) > 0 && m.Composes { - t.Errorf("a machine that blames a module composes: %+v", m) + if held := row.how != nil && row.how.HeldBefore != nil; m.Composes != held { + t.Errorf("composes = %v, want %v: %+v", m.Composes, held, m) } if len(m.Blamed) != len(row.blamed) { t.Fatalf("blamed %+v, want %+v (%+v)", m.Blamed, row.blamed, m) @@ -228,6 +246,16 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { } } +// digest is the content digest of a manifest (compose.ContentDigest). +func digest(t *testing.T, raw string) string { + t.Helper() + d, err := compose.ContentDigest([]byte(raw)) + if err != nil { + t.Fatal(err) + } + return d +} + // blame is one module a machine's verdict blames (composer.Machine.Blamed). type blame = struct { Module string `json:"module"` diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 1bf54522..3a470ece 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -238,7 +238,9 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { } cv.Machines = map[string]Machine{} for _, node := range r.Machines { - m := machine(in, node, depth, r.Declarations) + at := in // the input m is composed from + m := machine(at, node, depth, r.Declarations) + problem := problemOf(m) // what the search for culprits holds a module against, before any words are added if words := awaitedOn(in, node, awaited); 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 @@ -249,11 +251,12 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { // shanks). how := "composed from the change's manifest without its build: " if !m.Composes && m.NotJudged == "" { - switch again := machine(heldAgain(in, held, awaited), node, depth, r.Declarations); { + lifted := heldAgain(in, held, awaited) + switch again := machine(lifted, node, depth, r.Declarations); { 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 = again, "refused with it held as its node-engine holds it, since it does not compose without its build: " + 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) } } words = how + words @@ -263,6 +266,11 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { m.Reason += "; " + words } } + // 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) } @@ -502,6 +510,69 @@ func machine(in compose.Input, node, depth string, declarations bool) Machine { return m } +// 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 +} + +// problemOf is a machine's problem in words: why it does not compose, with what the validator refuses. +func problemOf(m Machine) string { + if len(m.Problems) == 0 { + return m.Reason + } + return m.Reason + ": " + strings.Join(m.Problems, "; ") +} + +// changedOn is each module placed on node, in assignment order, whose case manifest's content digest differs from the +// manifest its build was made of as the input names it (ComposedHow.Manifests), or that the input names none for: the +// candidate's changed modules (design 47 G §721; A-469k). A module the case carries no manifest of is not changed. +func changedOn(in compose.Input, node string, c Case, how *compose.ComposedHow) []string { + var out []string + for _, mod := range assignedOn(in, node) { + man, carried := c.Manifests[mod] + if !carried || len(man.Raw) == 0 { + continue + } + if digest, err := compose.ContentDigest(man.Raw); err == nil && digest == manifestOf(how, mod) { + continue + } + out = append(out, mod) + } + return out +} + +// assignedOn is the modules placed on node, in assignment order. +func assignedOn(in compose.Input, node string) []string { + for _, n := range in.Nodes { + if n.Name == node { + return n.Assigned + } + } + return nil +} + // blame is one module a machine's verdict blames, with its problem (Machine.Blamed, design 47 G §721). type blame = struct { Module string `json:"module"` From c5f76cb97431f917c37a2f7f173ece5536621f48 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 12:04:20 +0100 Subject: [PATCH 3/6] composer: a build that can never be made is blamed, not a reason to judge no machine (G-24 H3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A module awaited on a machine whose revision gives it no fingerprint (the case's none) is held as its node-engine holds it, the machine judged from that composition, and the module blamed with the revision's none words, so only its own pipelines fail. An awaited build with a fingerprint keeps the machine not judged. Builds: design 47 G §721, §722, A-470j, A-470k --- internal/composer/composer.go | 57 ++++++++++++++++++++++++++++-- internal/composer/composer_test.go | 32 +++++++++++++---- 2 files changed, 80 insertions(+), 9 deletions(-) diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 3a470ece..5ed52035 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -238,10 +238,18 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { } cv.Machines = map[string]Machine{} for _, node := range r.Machines { + // A module awaited on node whose build can never be made, the revision giving it no fingerprint (Case.None), does + // not leave the machine not judged: it is held as its node-engine holds it, the machine judged from that + // composition, and the module blamed with the revision's none words (design 47 G A-470j, A-470k). Each other + // awaited build keeps the machine not judged, as below. + never, pending := neverOn(in, node, awaited, c.None) at := in // the input m is composed from + 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 - if words := awaitedOn(in, node, awaited); words != "" { + 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 // it does not compose without that build (a tool runner's bundle), it is composed with the module held as its @@ -251,7 +259,7 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { // shanks). how := "composed from the change's manifest without its build: " if !m.Composes && m.NotJudged == "" { - lifted := heldAgain(in, held, awaited) + lifted := heldAgain(at, held, pending) switch again := machine(lifted, node, depth, r.Declarations); { case again.Composes: m, how = again, "composed with it held as its node-engine holds it, since it does not compose without its build: " @@ -266,6 +274,9 @@ func runCase(r Request, c Case, depth string) (CaseVerdict, error) { m.Reason += "; " + words } } + 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 { @@ -428,6 +439,48 @@ func heldAgain(in, held compose.Input, awaited map[string]string) compose.Input return in } +// neverOn splits the modules overrule lifted with their build awaited: never is each placed on node whose build can never +// be made, the case naming it in None (the revision gives it no fingerprint), with its awaited words; pending is awaited +// without them (design 47 G A-470j, A-470k). +func neverOn(in compose.Input, node string, awaited, none map[string]string) (never, pending map[string]string) { + pending = awaited + for _, mod := range assignedOn(in, node) { + if _, unbuildable := none[mod]; !unbuildable || awaited[mod] == "" { + continue + } + if never == nil { + never, pending = map[string]string{}, maps.Clone(awaited) + } + never[mod] = awaited[mod] + delete(pending, mod) + } + return never, pending +} + +// blameNever is m judged with each of never held: it composes with none of them, so it does not compose, says why, and +// blames each with the revision's none words, in place of any problem its composition gave it (design 47 G §721, A-470j). +func blameNever(m Machine, never, none map[string]string) Machine { + mods := slices.Sorted(maps.Keys(never)) + var said []string + for _, mod := range mods { + said = append(said, mod+" ("+none[mod]+")") + } + words := "composed with it held as its node-engine holds it, since its build can never be made: " + strings.Join(said, ", ") + if m.Composes { + m.Composes, m.Reason = false, words + } else { + m.Reason += "; " + words + } + for _, mod := range mods { + if i := slices.IndexFunc(m.Blamed, func(b blame) bool { return b.Module == mod }); i >= 0 { + m.Blamed[i].Problem = none[mod] + continue + } + m.Blamed = append(m.Blamed, blame{Module: mod, Problem: none[mod]}) + } + return m +} + // awaitedOn is the words of each module placed on node that is composed without its build (overrule), joined, sorted. func awaitedOn(in compose.Input, node string, awaited map[string]string) string { var out []string diff --git a/internal/composer/composer_test.go b/internal/composer/composer_test.go index fcf7cacc..269769dc 100644 --- a/internal/composer/composer_test.go +++ b/internal/composer/composer_test.go @@ -324,20 +324,27 @@ func TestARequestItCannotRunIsRefused(t *testing.T) { name, raw, digest string words string // in NotJudged, its build's paths not declared; "" composes at its build beside string // a module the change refuses on the same node: words are then in the refusal + none string // the revision's none words for app (Case.None): judged held, app blamed with them }{ - {"the digest of the case's manifest", plain, same, "", ""}, - {"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), ""}, - {"no digest, the same contract", plain, "", "", ""}, + {"the digest of the case's manifest", plain, same, "", "", ""}, + {"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), "", ""}, + {"no digest, the same contract", plain, "", "", "", ""}, {"no digest, another contract", strings.Replace(plain, `"version": "1"`, `"version": "2"`, 1), "", - "app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", ""}, + "app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", "", ""}, {"a tool runner, its bundle awaited", runner, "", - "composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", ""}, + "composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", "", ""}, // The group check of c5d32074c945, shanks: the change refused lab there, and the words were those of the // composition from the change's manifests unbuilt ("mesh-build-go runs as its own account and its build // produced no bundle to serve"), not of the one with them held, so the lift's own refusals failed the node. {"a tool runner awaited beside a module the change refuses", runner, "", "refused with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", - `{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}`}, + `{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}`, ""}, + // G-24 H3 (A-470j, A-470k; live at revision 449, lidarr, radarr and gitea): a build the revision gives no + // fingerprint can never be made, so it does not leave the machine not judged: the machine is judged held, and + // app is blamed with the revision's none words. An awaited build the case does not name so stays not judged + // (the rows above). + {"a build that can never be made, its machine judged held", plain, strings.Repeat("b", 64), "", "", "builders disagree: node 22 and node 24"}, + {"a tool runner whose bundle can never be made", runner, "", "", "", "no build module"}, } { in := compose.Input{Catalogue: map[string]catalogue.Manifest{"app": built}, Nodes: []compose.Node{{Name: "a", Assigned: []string{"app"}}}, ComposedHow: &compose.ComposedHow{Node: "a", Builds: map[string]string{"app": "fp1"}}} @@ -345,16 +352,27 @@ func TestARequestItCannotRunIsRefused(t *testing.T) { in.ComposedHow.Manifests = map[string]string{"app": row.digest} } manifests := map[string]Manifest{"app": {Raw: json.RawMessage(row.raw)}} + var none map[string]string + if row.none != "" { + none = map[string]string{"app": row.none} + } if row.beside != "" { manifests["office"] = Manifest{Raw: json.RawMessage(row.beside)} in.Nodes[0].Assigned = append(in.Nodes[0].Assigned, "office") } v, err := Run(withInput(t, Request{V: Version, Machines: []string{"a"}, Depth: DepthCompose, Declarations: true, - Cases: []Case{{Name: "change", Manifests: manifests}}}, in)) + Cases: []Case{{Name: "change", Manifests: manifests, None: none}}}, in)) if err != nil { t.Fatal(err) } m := v.Cases[0].Machines["a"] + if row.none != "" { + if m.NotJudged != "" || m.Composes || len(m.Blamed) != 1 || m.Blamed[0].Module != "app" || m.Blamed[0].Problem != row.none || + !strings.Contains(m.Reason, "its build can never be made") { + t.Errorf("%s: machine %+v, want it judged with app held and blamed with %q", row.name, m, row.none) + } + continue + } if row.beside != "" { said := fmt.Sprint(m.Reason, m.Problems, m.Refusals) if m.Composes || m.NotJudged != "" || !strings.Contains(said, "office") || strings.Contains(said, "bundle") || !strings.Contains(m.Reason, row.words) { From b4bf772de42fda97dbd89cd291d410fa6c35ec6a Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 13:03:15 +0100 Subject: [PATCH 4/6] composer: one search for culprits, inside the node-engine's composition, bounded by blame_tries (G-24 H2 review r1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ComposeSent no longer runs the node-engine's own culprit search (fixed at eight modules), and the composer's own loop, which reran that search at every try, is gone: ComposeSent holds the case's changed modules on the machine one at a time, one composition each, at most blame_tries, and blames the first whose hold ends the problem; past the bound the untried are named. Without blame_tries there is no search. A module the node holds composing without the change is held as there, and two owners of one path are blamed outside the search. Builds: design 47 G §721, A-468i, A-468l, A-469j, A-469k, A-470c --- cmd/mesh-compose/main_test.go | 13 ++-- internal/compose/frombus/answer.go | 15 ++--- internal/compose/frombus/frombus.go | 96 +++++++++++++++++++++-------- internal/composer/composer.go | 46 +++----------- internal/composer/composer_test.go | 2 +- 5 files changed, 96 insertions(+), 76 deletions(-) diff --git a/cmd/mesh-compose/main_test.go b/cmd/mesh-compose/main_test.go index 24a58563..5b374069 100644 --- a/cmd/mesh-compose/main_test.go +++ b/cmd/mesh-compose/main_test.go @@ -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, diff --git a/internal/compose/frombus/answer.go b/internal/compose/frombus/answer.go index be47d419..cf2ca2b0 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), 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 } diff --git a/internal/compose/frombus/frombus.go b/internal/compose/frombus/frombus.go index 30a1de65..a6270d30 100644 --- a/internal/compose/frombus/frombus.go +++ b/internal/compose/frombus/frombus.go @@ -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. diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 5ed52035..1ea277c7 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -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 { diff --git a/internal/composer/composer_test.go b/internal/composer/composer_test.go index 269769dc..0774c66c 100644 --- a/internal/composer/composer_test.go +++ b/internal/composer/composer_test.go @@ -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 From f21b8c202d9faea0b573d726b68b642185599d38 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 13:05:38 +0100 Subject: [PATCH 5/6] composer: a build that can never be made is blamed after the held composition is judged (G-24 H3 review r1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The held composition's own blames and its search come first; the module whose build can never be made is then blamed beside them. A held composition that still fails and blames nobody stays on the node's own account, so the module is not blamed in its place. Builds: design 47 G §721, §722, A-470j, A-470k --- internal/composer/composer.go | 12 ++++++-- internal/composer/composer_test.go | 45 ++++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/internal/composer/composer.go b/internal/composer/composer.go index 1ea277c7..5013e4e8 100644 --- a/internal/composer/composer.go +++ b/internal/composer/composer.go @@ -278,7 +278,7 @@ 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 + m = blameNever(m, never, c.None) // after the held composition is judged, its search and the awaited words included } if m.Blamed == nil { m.Blamed = []blame{} // always written, so a verdict blaming none is told from an old composer's (A-469h) @@ -455,8 +455,10 @@ func neverOn(in compose.Input, node string, awaited, none map[string]string) (ne return never, pending } -// blameNever is m judged with each of never held: it composes with none of them, so it does not compose, says why, and -// blames each with the revision's none words, in place of any problem its composition gave it (design 47 G §721, A-470j). +// blameNever is m, judged with each of never held (its blames and the search already in it), with each of never blamed +// with the revision's none words, in place of any problem its composition gave it: the machine composes with none of +// them, so it does not compose, and says why (design 47 G §721, A-470j). A held composition that still fails and blames +// nobody stays on the node's own account (§722): none of never is blamed in its place. func blameNever(m Machine, never, none map[string]string) Machine { mods := slices.Sorted(maps.Keys(never)) var said []string @@ -464,6 +466,10 @@ func blameNever(m Machine, never, none map[string]string) Machine { said = append(said, mod+" ("+none[mod]+")") } words := "composed with it held as its node-engine holds it, since its build can never be made: " + strings.Join(said, ", ") + if !m.Composes && len(m.Blamed) == 0 { + m.Reason += "; " + words + return m + } if m.Composes { m.Composes, m.Reason = false, words } else { diff --git a/internal/composer/composer_test.go b/internal/composer/composer_test.go index 0774c66c..c5c33b43 100644 --- a/internal/composer/composer_test.go +++ b/internal/composer/composer_test.go @@ -13,6 +13,7 @@ import ( engcomp "github.com/novox/mesh-host/internal/compositions" "os" "reflect" + "slices" "strings" "testing" @@ -320,31 +321,39 @@ func TestARequestItCannotRunIsRefused(t *testing.T) { } runner := `{"module": "app", "version": "1", "tool-runner": true, ` + `"build": {"artifacts": [{"name": "runtime", "kind": "bundle", "language": "go", "from": "cmd/runner", "binary": "runner"}]}}` + office := `{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}` for _, row := range []struct { name, raw, digest string words string // in NotJudged, its build's paths not declared; "" composes at its build beside string // a module the change refuses on the same node: words are then in the refusal none string // the revision's none words for app (Case.None): judged held, app blamed with them + tries int // the request's blame_tries }{ - {"the digest of the case's manifest", plain, same, "", "", ""}, - {"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), "", ""}, - {"no digest, the same contract", plain, "", "", "", ""}, + {"the digest of the case's manifest", plain, same, "", "", "", 20}, + {"another digest, the same contract", plain, strings.Repeat("b", 64), "of another manifest than the change's (its build was made of the manifest " + strings.Repeat("b", 64), "", "", 20}, + {"no digest, the same contract", plain, "", "", "", "", 20}, {"no digest, another contract", strings.Replace(plain, `"version": "1"`, `"version": "2"`, 1), "", - "app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", "", ""}, + "app is composed by the running node-engine at its build fp1, of another manifest than the change's (its node-engine names no manifest", "", "", 20}, {"a tool runner, its bundle awaited", runner, "", - "composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", "", ""}, + "composed with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", "", "", 20}, // The group check of c5d32074c945, shanks: the change refused lab there, and the words were those of the // composition from the change's manifests unbuilt ("mesh-build-go runs as its own account and its build // produced no bundle to serve"), not of the one with them held, so the lift's own refusals failed the node. {"a tool runner awaited beside a module the change refuses", runner, "", "refused with it held as its node-engine holds it, since it does not compose without its build: app is composed by the running node-engine at its build fp1", - `{"module": "office", "version": "1", "resources": [{"id": "c", "type": "file", "path": "/etc/office.conf", "template": "x"}]}`, ""}, + office, "", 20}, // G-24 H3 (A-470j, A-470k; live at revision 449, lidarr, radarr and gitea): a build the revision gives no // fingerprint can never be made, so it does not leave the machine not judged: the machine is judged held, and // app is blamed with the revision's none words. An awaited build the case does not name so stays not judged // (the rows above). - {"a build that can never be made, its machine judged held", plain, strings.Repeat("b", 64), "", "", "builders disagree: node 22 and node 24"}, - {"a tool runner whose bundle can never be made", runner, "", "", "", "no build module"}, + {"a build that can never be made, its machine judged held", plain, strings.Repeat("b", 64), "", "", "builders disagree: node 22 and node 24", 20}, + {"a tool runner whose bundle can never be made", runner, "", "", "", "no build module", 20}, + // The held composition is judged first, the search included, and the build that can never be made is blamed + // beside what it blames (review round 1: office refused beside it went unblamed). + {"a build that can never be made beside a module the change refuses", runner, "", "", office, "no build module", 20}, + // A held composition that still fails and blames nobody else (no search asked) fails on the node's own + // account: the build that can never be made is not blamed in its place (§722). + {"a build that can never be made beside a refusal nobody is blamed for", runner, "", "", office, "no build module", 0}, } { in := compose.Input{Catalogue: map[string]catalogue.Manifest{"app": built}, Nodes: []compose.Node{{Name: "a", Assigned: []string{"app"}}}, ComposedHow: &compose.ComposedHow{Node: "a", Builds: map[string]string{"app": "fp1"}}} @@ -360,16 +369,30 @@ func TestARequestItCannotRunIsRefused(t *testing.T) { manifests["office"] = Manifest{Raw: json.RawMessage(row.beside)} in.Nodes[0].Assigned = append(in.Nodes[0].Assigned, "office") } - v, err := Run(withInput(t, Request{V: Version, Machines: []string{"a"}, Depth: DepthCompose, Declarations: true, + // A row with a build that can never be made beside a refused module is composed as its node-engine composes it + // (no declarations), where the search for culprits runs (frombus.ComposeSent). + v, err := Run(withInput(t, Request{V: Version, Machines: []string{"a"}, Depth: DepthCompose, Declarations: row.none == "" || row.beside == "", BlameTries: row.tries, Cases: []Case{{Name: "change", Manifests: manifests, None: none}}}, in)) if err != nil { t.Fatal(err) } m := v.Cases[0].Machines["a"] if row.none != "" { - if m.NotJudged != "" || m.Composes || len(m.Blamed) != 1 || m.Blamed[0].Module != "app" || m.Blamed[0].Problem != row.none || + want, problem := []string{"app"}, map[string]string{} + switch { + case row.beside != "" && row.tries == 0: + want = nil + case row.beside != "": + want = append(want, "office") + } + var got []string + for _, b := range m.Blamed { + got, problem[b.Module] = append(got, b.Module), b.Problem + } + slices.Sort(got) + if m.NotJudged != "" || m.Composes || !slices.Equal(got, want) || (want != nil && problem["app"] != row.none) || !strings.Contains(m.Reason, "its build can never be made") { - t.Errorf("%s: machine %+v, want it judged with app held and blamed with %q", row.name, m, row.none) + t.Errorf("%s: machine %+v, want it judged with app held and blamed with %q, and %v blamed", row.name, m, row.none, want) } continue } From ed7cefb5d8ad6174c92d4fb65e19eb6e0207a519 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 13:10:51 +0100 Subject: [PATCH 6/6] composer: the search for culprits goes on past a hold that changes the problem (G-24 review r2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A hold that changes the problem but leaves the machine not composing keeps that module held and blamed, and the search goes on against the retry's problem within the same blame_tries, until the machine composes or no hold changes it: every module the change refuses is blamed, never only the first. Builds: design 47 G §721, §722, A-470c, A-470v --- cmd/mesh-compose/main_test.go | 4 +++ internal/compose/frombus/frombus.go | 52 ++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/cmd/mesh-compose/main_test.go b/cmd/mesh-compose/main_test.go index 5b374069..07d216b7 100644 --- a/cmd/mesh-compose/main_test.go +++ b/cmd/mesh-compose/main_test.go @@ -206,6 +206,10 @@ func TestTheCommandWritesOneVerdictPerManifestAndMachine(t *testing.T) { // 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: "a", Manifests: map[string]string{"m2": digest(t, search["m2"])}}, 20, []blame{}}, + // A-470v: a hold that changes the problem but leaves the machine not composing keeps that module held and blamed, + // and the search goes on against the retry's problem: both modules the change refuses are blamed. + {"every module the change refuses is blamed", map[string]string{"m1": file("m1", "/var/lib/m1/env", secret), "m2": file("m2", "/var/lib/m2/env", secret), "m3": plain("m3")}, + []string{"m1", "m2", "m3"}, &compose.ComposedHow{Node: "a"}, 20, []blame{{Module: "m1", Problem: "repository"}, {Module: "m2", Problem: "repository"}}}, // 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"}, &compose.ComposedHow{Node: "a"}, 1, []blame{{Module: "m2", Problem: composer.NotTried}, {Module: "m3", Problem: composer.NotTried}}}, diff --git a/internal/compose/frombus/frombus.go b/internal/compose/frombus/frombus.go index a6270d30..991efd3b 100644 --- a/internal/compose/frombus/frombus.go +++ b/internal/compose/frombus/frombus.go @@ -735,14 +735,14 @@ func ComposingInput(ctx context.Context, r Reader, mesh Mesh, s Scope, fps map[s // 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 +// otherwise) is blamed with it; one that leaves the machine not composing stays held, and the search goes on (A-470v). 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 } - compose1 := func(also string) (map[string]engcomp.Composed, map[string]string, error) { + compose1 := func(also ...string) (map[string]engcomp.Composed, map[string]string, error) { held := maps.Clone(c.Held) if held == nil { held = map[string]string{} @@ -754,8 +754,8 @@ func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Co held[m] = why } } - if also != "" { - held[also] = triedHeld + for _, m := range also { + held[m] = triedHeld } out, _, _, err := composeEach(in, node, c.Builds, false, c.Running, held, nil, false) return out, held, err @@ -765,7 +765,7 @@ func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Co _, before := c.HeldBefore[m] return !was && !before } - out, held, err := compose1("") + 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). @@ -789,19 +789,41 @@ func ComposeSent(in compose.Input, node string, s Search) (map[string]engcomp.Co } } } + // A hold that changes the problem but leaves the machine not composing keeps that module held and blamed, and the + // search goes on against the retry's problem, from the first changed module not held, within the same tries, until the + // machine composes or no hold changes it (A-470v): every module the change refuses is blamed, never only the first. 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 + problem, tries := err.Error(), 0 + var kept []string + search: + for { + tried := map[string]bool{} // against the problem of now + for _, mod := range s.Changed { + if slices.Contains(kept, mod) { + continue + } + if tries == s.Tries { + for _, untried := range s.Changed { + if _, done := blamed[untried]; !done && !tried[untried] { + blamed[untried] = NotTried + } + } + break search + } + tries++ + tried[mod] = true + _, _, again := compose1(append(slices.Clone(kept), mod)...) + if again == nil { + blamed[mod] = problem + break search + } + if again.Error() != problem { + blamed[mod], problem = problem, again.Error() + kept = append(kept, mod) + continue search } - break - } - if _, _, again := compose1(mod); again == nil || again.Error() != problem { - blamed[mod] = problem - break } + break // no hold changes the problem } } if len(blamed) == 0 {