From 813963a35a73ec79b6bd734f7ee1e41b86839c54 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 22:16:37 +0100 Subject: [PATCH 1/3] G findings4 buildrun: the checker's and the indexer's reads of the build modules' toolchains keep the gate over the assignments, which BL8 took out with the builder's MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BL8 (8255eb28) replaced buildrun's ToolchainGate, ToolchainSet.Put and ToolchainsBucket by PlacedNodes and ToolchainSet.Set for the builder (§546, §604); no design line removes the checker's and the indexer's toolchain reads, so the three come back beside them, and FollowAssignments feeds either. Builds: design 47 G §492, §604, §546, §472, §574 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- .../mesh-delivery-builder/buildrun/names.go | 4 + .../buildrun/standing.go | 35 ++- .../buildrun/toolchaingate.go | 236 ++++++++++++++++ .../buildrun/toolchaingate_test.go | 260 ++++++++++++++++++ .../buildrun/toolchains.go | 36 +++ 5 files changed, 564 insertions(+), 7 deletions(-) create mode 100644 modules/mesh-delivery-builder/buildrun/toolchaingate.go create mode 100644 modules/mesh-delivery-builder/buildrun/toolchaingate_test.go diff --git a/modules/mesh-delivery-builder/buildrun/names.go b/modules/mesh-delivery-builder/buildrun/names.go index f42177cf3..0896d2ea5 100644 --- a/modules/mesh-delivery-builder/buildrun/names.go +++ b/modules/mesh-delivery-builder/buildrun/names.go @@ -11,3 +11,7 @@ const ( // StepsBucket is the bucket of a build module's state steps. func StepsBucket(module string) string { return module + "_steps" } + +// ToolchainsBucket is the bucket of a build module's state toolchains, which the checker and the indexer read (the builder +// hears the toolchain-reported events and keeps ToolchainsHeardBucket instead; design 47 G §492, §604). +func ToolchainsBucket(module string) string { return module + "_toolchains" } diff --git a/modules/mesh-delivery-builder/buildrun/standing.go b/modules/mesh-delivery-builder/buildrun/standing.go index 52a490b1d..6d1b19630 100644 --- a/modules/mesh-delivery-builder/buildrun/standing.go +++ b/modules/mesh-delivery-builder/buildrun/standing.go @@ -103,11 +103,33 @@ func (g *PlacedNodes) Settled() { g.known = true } +// assignmentsFollowed is what FollowAssignments feeds: the builder's PlacedNodes, or the ToolchainGate of the checker and the +// indexer. settle says the history is read and answers whether what the part passes on changed; placedTold tells its OnPlaced. +type assignmentsFollowed interface { + Assignments(key string, value []byte, deleted bool, at time.Time) bool + settle() bool + placedTold() +} + +func (g *PlacedNodes) settle() bool { g.Settled(); return true } +func (g *PlacedNodes) placedTold() { + if g.OnPlaced != nil { + g.OnPlaced() + } +} + +func (g *ToolchainGate) settle() bool { return g.Settled() } +func (g *ToolchainGate) placedTold() { + if g.OnPlaced != nil { + g.OnPlaced() + } +} + // FollowAssignments reads the seat mesh-module-assigner's assignments with its history into gate, says it settled, and follows it; changed // is told whenever what the gate passes on changed. Where the state cannot be read or watched (not there, or this part // may not read it) it says so and the gate passes every report on: not fatal, since an indexer, builder or checker that // stops for it stops every delivery (issue 1945). An error of the watch after that ends on the channel. -func FollowAssignments(ctx context.Context, js process.BucketOpener, gate *PlacedNodes, changed func(context.Context), logf func(string, ...any)) (<-chan error, error) { +func FollowAssignments(ctx context.Context, js process.BucketOpener, gate assignmentsFollowed, changed func(context.Context), logf func(string, ...any)) (<-chan error, error) { errs := make(chan error, 1) kv, err := js.KeyValue(ctx, AssignmentsBucket) if err != nil { @@ -138,11 +160,10 @@ func FollowAssignments(ctx context.Context, js process.BucketOpener, gate *Place put(e) } } - gate.Settled() - changed(ctx) - if gate.OnPlaced != nil { - gate.OnPlaced() + if gate.settle() { + changed(ctx) } + gate.placedTold() go func() { defer func() { _ = w.Stop() }() for { @@ -158,8 +179,8 @@ func FollowAssignments(ctx context.Context, js process.BucketOpener, gate *Place if e != nil && put(e) { changed(ctx) } - if e != nil && gate.OnPlaced != nil { - gate.OnPlaced() + if e != nil { + gate.placedTold() } } } diff --git a/modules/mesh-delivery-builder/buildrun/toolchaingate.go b/modules/mesh-delivery-builder/buildrun/toolchaingate.go new file mode 100644 index 000000000..0f6a8ae6d --- /dev/null +++ b/modules/mesh-delivery-builder/buildrun/toolchaingate.go @@ -0,0 +1,236 @@ +package buildrun + +import ( + "fmt" + "maps" + "slices" + "sort" + "sync" + "time" + + "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" + "git.novox.be/novox/mesh-delivery/contracts/go/clients/meshwantsclient" + meshwants "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants" + "git.novox.be/novox/mesh-delivery/sdk/buildstep" +) + +// A build module writes . of its toolchains state on every node it runs on, and nothing deletes the key +// when the module leaves a node: no part writes another module's state, and the module is gone. A report of a node the +// build module no longer runs on is therefore no builder's (issue 1940: mesh-build-node taken off ace on 2026-10-23 left +// ace.typescript at v26.12.0, and every Node fingerprint said "builders disagree"). +// +// ToolchainGate stands between the toolchains buckets and what takes their entries in (the indexer's PutToolchain, a +// ToolchainSet): an entry is passed on only while the assignments (the seat mesh-module-assigner's state `assignments`, held by +// the assigner, AssignmentsBucket, read by meshmoduleassignerclient.Placed; ADR 0567, ADR 0549 §3) places its build module on +// its node, and only once it was written since that assignments; it is passed on as deleted otherwise, said once, and +// passed on when its node writes it again. A report written before the assignments is one an earlier run of the module +// left (issue 1940, 2026-10-25 20:56: mesh-build-node put on ace again brought ace.typescript v26.12.0 of 2026-10-23 +// back into the agreement before the module ran there). Until the assignments is settled, and while no node's assignments +// is held (before the assigner's adopt writes the first one, or where the state cannot be read), every entry is passed +// on. Builders that run and report different versions still disagree: that refusal is the guard of novox/hq ADR 0465, +// and it stays. +// +// This replaces the copies of the gate the indexer, the builder and the checker each kept over the controller's +// assignments (issue 1940's subtask, issue 774: those go with the controller's lease, ADR 0549 §6). +type ToolchainGate struct { + mu sync.Mutex + modules map[string]bool // the build modules whose toolchains pass the gate + forward func(module, key string, value []byte, deleted bool) bool // answers whether it changed what it holds + logf func(format string, a ...any) + placed placementsSince + known bool // the assignments is settled + raw map[string]map[string][]byte // module -> toolchains key -> value, as the bucket holds it + left map[string]string // / -> why it was said left out, so each reason is said once + // OnPlaced is told, outside the gate's lock, once the assignments's history is read and after each revision of it + // FollowAssignments hears from then on (the counted nodes, Nodes, may have changed). Nil tells nobody. + OnPlaced func() +} + +// placementsSince is where the gate reads which modules stand on which node, and since when: the assigner's state +// (meshmoduleassignerclient.Placed, fed by Assignments) or the assignment half (meshwantsclient.Placed, fed by Revision). +type placementsSince interface { + Seeded() bool + Since(node, module string) (time.Time, bool) + ByNode() map[string][]string +} + +// NewToolchainGate is a gate over the toolchains of modules, passing what stands on to forward and saying with logf what +// it leaves out. +func NewToolchainGate(modules []string, forward func(module, key string, value []byte, deleted bool) bool, logf func(string, ...any)) *ToolchainGate { + g := &ToolchainGate{modules: map[string]bool{}, forward: forward, logf: logf, placed: meshmoduleassignerclient.NewPlaced(), + raw: map[string]map[string][]byte{}, left: map[string]string{}} + for _, m := range modules { + g.modules[m] = true + } + return g +} + +// UseModules replaces the build modules whose reports the gate passes on again when the assignments moves (a part that +// finds them from the seat list and the manifests, as the indexer does, gives them at each change), and passes every +// report it holds on again. It answers whether what it passed on changed. +func (g *ToolchainGate) UseModules(modules []string) bool { + g.mu.Lock() + defer g.mu.Unlock() + g.modules = map[string]bool{} + for _, m := range modules { + g.modules[m] = true + } + return g.all() +} + +// Toolchain takes one change of a build module's toolchains bucket in and answers whether what it passed on changed. +func (g *ToolchainGate) Toolchain(module, key string, value []byte, deleted bool) bool { + g.mu.Lock() + defer g.mu.Unlock() + if g.raw[module] == nil { + g.raw[module] = map[string][]byte{} + } + if deleted { + delete(g.raw[module], key) + } else { + g.raw[module][key] = value + } + return g.pass(module, key) +} + +// Assignments takes one revision of the seat mesh-module-assigner's assignments in (at is when the bus wrote it) and answers whether what it +// passed on changed. A value that does not read is said, and places nothing on its node. +func (g *ToolchainGate) Assignments(key string, value []byte, deleted bool, at time.Time) bool { + g.mu.Lock() + defer g.mu.Unlock() + placed, ok := g.placed.(*meshmoduleassignerclient.Placed) + if !ok { + g.logf("%s: %s is not read, the gate takes the assignment half (design 47)", AssignmentsBucket, key) + return false + } + was := placed.Seeded() + node, changed, err := placed.Put(key, value, deleted, at) + if err != nil { + g.logf("%s: %v (issue 1940)", AssignmentsBucket, err) + } + if !g.known { + return false + } + if was != g.placed.Seeded() { + // The first assignments came, or the last went: every report's standing changed. + return g.all() + } + return g.again(node, changed) +} + +// Revision takes one assignment graph revision the part's view holds in (design 47 *Each part acts on its own entries*: +// the placements come from the seat mesh-wants' assignment half, never the assigner's state; assignmentview's Held hands +// each) and answers whether what it passed on changed. The first revision taken settles the gate, as the assignments' +// history read does; a later one passes on again the reports of each node whose build modules' standing changed. A gate +// fed by Revision reads no Assignments. +func (g *ToolchainGate) Revision(r meshwants.AssignmentRevision) bool { + g.mu.Lock() + defer g.mu.Unlock() + placed, ok := g.placed.(*meshwantsclient.Placed) + if !ok { + placed = meshwantsclient.NewPlaced() + g.placed = placed + } + was := placed.Seeded() + changed := placed.Take(r) + if changed == nil { + return false + } + if !g.known || was != placed.Seeded() { + g.known = true + return g.all() + } + moved := false + for _, node := range slices.Sorted(maps.Keys(changed)) { + moved = g.again(node, changed[node]) || moved + } + return moved +} + +// Nodes are the nodes the assignments places any module on, sorted: the nodes the mesh counts (a node leaves the count +// when the assignments no longer names it; ADR 0624 §1). None until the assignments is read. +func (g *ToolchainGate) Nodes() []string { + var out []string + for node, modules := range g.placed.ByNode() { + if len(modules) > 0 { + out = append(out, node) + } + } + sort.Strings(out) + return out +} + +// Settled says the assignments's history is read: from now on only the reports of placed nodes pass, once a node's +// assignments is held. It answers whether what it passed on changed. +func (g *ToolchainGate) Settled() bool { + g.mu.Lock() + defer g.mu.Unlock() + g.known = true + return g.all() +} + +// all passes on every report again. The caller holds mu. +func (g *ToolchainGate) all() bool { + changed := false + for _, module := range slices.Sorted(maps.Keys(g.raw)) { + for _, k := range slices.Sorted(maps.Keys(g.raw[module])) { + changed = g.pass(module, k) || changed + } + } + return changed +} + +// again passes on every report of node by a build module among modules. The caller holds mu. +func (g *ToolchainGate) again(node string, modules []string) bool { + changed := false + for _, module := range modules { + if !g.modules[module] { + continue + } + for _, k := range slices.Sorted(maps.Keys(g.raw[module])) { + if n, _, err := buildstep.ParseToolchainKey(k); err == nil && n == node { + changed = g.pass(module, k) || changed + } + } + } + return changed +} + +// pass hands one key on as it stands: its value when its node is placed and wrote it since (or the assignments is not +// known), deleted otherwise. The caller holds mu. +func (g *ToolchainGate) pass(module, key string) bool { + value, held := g.raw[module][key] + if !held { + return g.forward(module, key, nil, true) + } + node, _, err := buildstep.ParseToolchainKey(key) + why := "" + if err == nil && g.known && g.placed.Seeded() { + why = g.leftOut(module, node, value) + } + if why == "" { + delete(g.left, module+"/"+key) + return g.forward(module, key, value, false) + } + if g.left[module+"/"+key] != why { + g.left[module+"/"+key] = why + g.logf("%s.%s is left out of the agreed toolchain: %s (issue 1940)", ToolchainsBucket(module), key, why) + } + return g.forward(module, key, nil, true) +} + +// leftOut is why a node's report is no builder's, or empty when it counts: the catalogue does not place the module on its +// node, or the report was written before it did. A value that is no toolchain is passed on for its reader to refuse. +// The caller holds mu. +func (g *ToolchainGate) leftOut(module, node string, value []byte) string { + since, placed := g.placed.Since(node, module) + if !placed { + return fmt.Sprintf("the catalogue does not place %s on %s, so it is no builder", module, node) + } + tc, err := buildstep.DecodeToolchain(value) + if err == nil && tc.At.Before(since) { + return fmt.Sprintf("it was written at %s, before %s was placed on %s at %s: it counts once %s writes it again", + tc.At.UTC().Format(time.RFC3339), module, node, since.UTC().Format(time.RFC3339), node) + } + return "" +} diff --git a/modules/mesh-delivery-builder/buildrun/toolchaingate_test.go b/modules/mesh-delivery-builder/buildrun/toolchaingate_test.go new file mode 100644 index 000000000..9e6521c39 --- /dev/null +++ b/modules/mesh-delivery-builder/buildrun/toolchaingate_test.go @@ -0,0 +1,260 @@ +package buildrun + +import ( + "bytes" + "context" + "errors" + "fmt" + "log" + "strings" + "testing" + "time" + + "git.novox.be/novox/mesh-contracts/go/clients/meshmoduleassignerclient" + meshwants "git.novox.be/novox/mesh-delivery/contracts/go/seats/meshwants" + "git.novox.be/novox/mesh-delivery/sdk/buildstep" +) + +func gateReport(t *testing.T, node, version string, at time.Time) (string, []byte) { + t.Helper() + key, _ := buildstep.ToolchainKey(node, "typescript") + value, err := buildstep.EncodeToolchain(buildstep.Toolchain{Language: "typescript", Version: version, Recipe: "f59571cf4be75adf", At: at}) + if err != nil { + t.Fatal(err) + } + return key, value +} + +// placing is a value of the state `assignments` placing modules on node. + +func agreedOf(set *ToolchainSet) (string, string) { + tc, none := buildstep.AgreedToolchain(set.Entries("typescript")) + return tc.Version, none +} + +// Issue 1940, the gate over the catalogue's assignments (issue 774, ADR 0549 §3): a build node's report counts only while +// the assignments places its build module on its node, and only once written since; before the assignments is settled, and +// while no node's assignments is held, every report counts. The live cases: mesh-build-node taken off ace left +// ace.typescript at v26.12.0 against v26.12.1 on the three others; put on ace again, its report of 2026-10-23 06:29 came +// back before the module ran there. +func TestToolchainGate(t *testing.T) { + old := time.Date(2026, 10, 23, 6, 29, 18, 0, time.UTC) // ace's report from its earlier run + placed := time.Date(2026, 10, 25, 19, 56, 45, 0, time.UTC) // mesh-build-node placed on ace again + three := []string{"g14", "novox", "shanks"} + start := func(t *testing.T, seeded bool) (*ToolchainGate, *ToolchainSet, *[]string) { + set := &ToolchainSet{} + said := &[]string{} + gate := NewToolchainGate([]string{GoBuildModule, NodeBuildModule}, set.Put, func(f string, a ...any) { *said = append(*said, fmt.Sprintf(f, a...)) }) + for _, node := range three { + if seeded { + key, value := placing(t, node, NodeBuildModule) + gate.Assignments(key, value, false, old.Add(-time.Hour)) + } + key, value := gateReport(t, node, "v26.12.1", placed.Add(time.Minute)) + gate.Toolchain(NodeBuildModule, key, value, false) + } + return gate, set, said + } + + t.Run("not placed on ace: its report is no builder's", func(t *testing.T) { + gate, set, said := start(t, true) + key, value := gateReport(t, "ace", "v26.12.0", old) + gate.Toolchain(NodeBuildModule, key, value, false) + if a := buildstep.ToolchainAgreement(set.Entries("typescript")); len(a.SittingOut) != 1 || a.SittingOut[0].Node != "ace" { // ADR 0584: the majority is agreed, ace's report counts as the one that sits out + t.Fatalf("before the assignments is settled every report counts; got %+v", a) + } + k, v := placing(t, "ace", GoBuildModule) // another build module on ace: no matter + gate.Assignments(k, v, false, old) + if !gate.Settled() { + t.Fatal("settling left ace's report out, so what was passed on changed") + } + if v, none := agreedOf(set); v != "v26.12.1" || none != "" { + t.Fatalf("the placed nodes agree on v26.12.1; got %q, %q", v, none) + } + if len(*said) != 1 || !strings.Contains((*said)[0], "does not place mesh-build-node on ace") { + t.Fatalf("ace's report is said left out once; said %q", *said) + } + if gate.Toolchain(NodeBuildModule, key, value, false) { + t.Fatal("a report of a node not placed changed what was passed on") + } + // Placed on ace with a report written since: it counts, and the builders really disagree. + k, v = placing(t, "ace", GoBuildModule, NodeBuildModule) + gate.Assignments(k, v, false, old.Add(-time.Minute)) + if a := buildstep.ToolchainAgreement(set.Entries("typescript")); a.Toolchain.Version != "v26.12.1" || len(a.SittingOut) != 1 || a.SittingOut[0].Version != "v26.12.0" { + t.Fatalf("builders that run different versions: the majority is agreed and ace sits out; got %+v", a) + } + // Taken off ace again (its key deleted): its report goes again. + if !gate.Assignments(k, nil, true, placed) { + t.Fatal("taking ace's assignments away passed nothing on") + } + if v, none := agreedOf(set); v != "v26.12.1" || none != "" { + t.Fatalf("got %q, %q", v, none) + } + // A report deleted from the bucket goes whether its node is placed or not. + key, _ = gateReport(t, "g14", "v26.12.1", placed) + if !gate.Toolchain(NodeBuildModule, key, nil, true) || len(set.Entries("typescript")) != 2 { + t.Fatalf("deleting g14's report: %d entries left, want novox and shanks", len(set.Entries("typescript"))) + } + }) + + t.Run("build modules given later pass their reports on when the assignments moves", func(t *testing.T) { + set := &ToolchainSet{} + gate := NewToolchainGate(nil, set.Put, func(string, ...any) {}) + gate.Settled() + k, v := placing(t, "novox", GoBuildModule) + gate.Assignments(k, v, false, old) + key, value := gateReport(t, "ace", "v26.12.1", placed.Add(time.Minute)) + gate.Toolchain(NodeBuildModule, key, value, false) // ace is not placed: left out + k, v = placing(t, "ace", NodeBuildModule) + if gate.Assignments(k, v, false, placed) || len(set.Entries("typescript")) != 0 { + t.Fatalf("a module the gate was not given passed on at the assignments: %v", set.Entries("typescript")) + } + if !gate.UseModules([]string{NodeBuildModule}) || len(set.Entries("typescript")) != 1 { + t.Fatalf("given mesh-build-node, ace's report placed since is passed on; entries %v", set.Entries("typescript")) + } + }) + + for _, c := range []struct { + name string + at time.Time // when ace wrote its report + counts bool + }{ + {"a report left before the assignments", old, false}, + {"a report written since the assignments", placed.Add(30 * time.Second), true}, + } { + t.Run(c.name, func(t *testing.T) { + gate, set, said := start(t, true) + k, v := placing(t, "ace") // ace's key, first heard placing nothing + gate.Assignments(k, v, false, old.Add(-time.Hour)) + gate.Settled() + k, v = placing(t, "ace", NodeBuildModule) + if gate.Assignments(k, v, false, placed) { + t.Fatal("assignments with no report passed something on") + } + key, value := gateReport(t, "ace", "v26.12.0", c.at) + if got := gate.Toolchain(NodeBuildModule, key, value, false); got != c.counts { + t.Fatalf("ace's report passed on: %v, want %v", got, c.counts) + } + // ace's assignments written again with another module beside: its standing does not move, nothing is said again. + k, v = placing(t, "ace", GoBuildModule, NodeBuildModule) + if gate.Assignments(k, v, false, placed.Add(time.Minute)) { + t.Fatal("the same assignments of mesh-build-node changed what was passed on") + } + if c.counts { + return + } + if v, none := agreedOf(set); v != "v26.12.1" || none != "" { + t.Fatalf("ace's left report is no builder's; got %q, %q", v, none) + } + if len(*said) != 1 || !strings.Contains((*said)[0], "before mesh-build-node was placed on ace at 2026-10-25T19:56:45Z") { + t.Fatalf("said %q, want once why ace's report is left out", *said) + } + key, value = gateReport(t, "ace", "v26.12.1", placed.Add(time.Minute)) + if !gate.Toolchain(NodeBuildModule, key, value, false) || len(set.Entries("typescript")) != 4 { + t.Fatal("ace's new report was not passed on") + } + }) + } + + t.Run("no assignments held: every report counts", func(t *testing.T) { + gate, set, _ := start(t, false) + key, value := gateReport(t, "ace", "v26.12.0", old) + gate.Toolchain(NodeBuildModule, key, value, false) + gate.Settled() + if n := len(set.Entries("typescript")); n != 4 { + t.Fatalf("before the first assignments file every report counts; got %d", n) + } + k, v := placing(t, "g14", NodeBuildModule) + if !gate.Assignments(k, v, false, old.Add(-time.Hour)) || len(set.Entries("typescript")) != 1 { + t.Fatalf("the first assignments leaves every node it does not place out; got %d", len(set.Entries("typescript"))) + } + if !gate.Assignments(k, nil, true, placed) || len(set.Entries("typescript")) != 4 { + t.Fatal("the last assignments gone: every report counts again") + } + }) + + // Design 47 *Each part acts on its own entries*: fed by the assignment half's revisions, the gate settles at the first, + // leaves out a node no revision places the build module on, and counts a node placed in a later revision only by a + // report written since that revision's time. + t.Run("fed by the assignment half", func(t *testing.T) { + set := &ToolchainSet{} + said := &[]string{} + gate := NewToolchainGate([]string{GoBuildModule, NodeBuildModule}, set.Put, func(f string, a ...any) { *said = append(*said, fmt.Sprintf(f, a...)) }) + for _, node := range append([]string{"ace"}, three...) { + key, value := gateReport(t, node, "v26.12.1", placed.Add(time.Minute)) + if node == "ace" { + key, value = gateReport(t, node, "v26.12.0", old) + } + gate.Toolchain(NodeBuildModule, key, value, false) + } + revision := func(n int64, at time.Time, nodes ...string) meshwants.AssignmentRevision { + r := meshwants.AssignmentRevision{Revision: n, Kind: "trunk", At: &at} + for _, node := range nodes { + r.Entries = append(r.Entries, meshwants.NodeEntryRef{Node: node, Module: NodeBuildModule, Digest: "d-" + node}) + } + return r + } + if !gate.Revision(revision(7, old.Add(-time.Hour), three...)) || len(set.Entries("typescript")) != 3 { + t.Fatalf("the first revision settles the gate and leaves ace out; %d entries", len(set.Entries("typescript"))) + } + if gate.Revision(revision(7, old.Add(-time.Hour), three...)) { + t.Fatal("the same revision again changed what was passed on") + } + if gate.Revision(revision(8, placed, "ace", "g14", "novox", "shanks")); len(set.Entries("typescript")) != 3 { + t.Fatal("ace's report from before revision 8 placed it counts") + } + if len(*said) < 2 || !strings.Contains((*said)[len(*said)-1], "before mesh-build-node was placed on ace at 2026-10-25T19:56:45Z") { + t.Fatalf("said %q, want why ace's old report is left out", *said) + } + key, value := gateReport(t, "ace", "v26.12.1", placed.Add(time.Minute)) + if !gate.Toolchain(NodeBuildModule, key, value, false) || len(set.Entries("typescript")) != 4 { + t.Fatal("ace's report written since revision 8 is not passed on") + } + if !gate.Revision(revision(9, placed.Add(time.Hour), "ace", "novox", "shanks")) || len(set.Entries("typescript")) != 3 || len(gate.Nodes()) != 3 { + t.Fatalf("g14 taken off in revision 9: %d entries, nodes %v", len(set.Entries("typescript")), gate.Nodes()) + } + }) + + t.Run("the history: a module in the first revision heard of a key stands since before it", func(t *testing.T) { + p := meshmoduleassignerclient.NewPlaced() + // ace's node key is the first revision heard of it: its module stands since before. + k, v := placing(t, "ace", NodeBuildModule) + p.Put(k, v, false, old) + if _, changed, _ := p.Put("ace."+NodeBuildModule, []byte("{}"), false, placed); len(changed) != 0 { + t.Errorf("a module key says which modules stand: %v", changed) + } + k2, v2 := placing(t, "g14") + p.Put(k2, v2, false, old) + k2, v2 = placing(t, "g14", NodeBuildModule) + if _, changed, _ := p.Put(k2, v2, false, placed); strings.Join(changed, ",") != NodeBuildModule { + t.Errorf("a module placed says changed %v", changed) + } + if _, _, err := p.Put("novox.node", []byte("not json"), false, old); err == nil { + t.Error("a value that does not read was not said") + } + if s, ok := p.Since("ace", NodeBuildModule); !ok || !s.IsZero() { + t.Errorf("ace's module stands since %v, %v; want the zero time", s, ok) + } + if s, ok := p.Since("g14", NodeBuildModule); !ok || !s.Equal(placed) { + t.Errorf("g14's module stands since %v, %v; want the revision that placed it", s, ok) + } + if got := p.PlacedNodes(NodeBuildModule); strings.Join(got, ",") != "ace,g14" || len(p.ByNode()) != 2 || !p.Seeded() { + t.Errorf("PlacedNodes = %v, ByNode = %v", got, p.ByNode()) + } + }) + + t.Run("assignments the bus refuses is said, and the part goes on", func(t *testing.T) { + var logs bytes.Buffer + logger := log.New(&logs, "", 0) + refused := errors.New("nats: permissions violation for publish to $JS.API.CONSUMER.CREATE.KV_mesh-delivery-assigner_assignments") + gate, _, _ := start(t, false) + for _, bus := range []refusingBus{{err: refused}, {refuseOpen: true, err: refused}} { + if _, err := FollowAssignments(context.Background(), bus, gate, func(context.Context) {}, logger.Printf); err != nil { + t.Errorf("a refused assignments stopped the start: %v", err) + } + } + if !strings.Contains(logs.String(), "cannot be watched") || !strings.Contains(logs.String(), "cannot be read") { + t.Errorf("the refusals were not said: %q", logs.String()) + } + }) +} diff --git a/modules/mesh-delivery-builder/buildrun/toolchains.go b/modules/mesh-delivery-builder/buildrun/toolchains.go index ba2368c64..af1f53e64 100644 --- a/modules/mesh-delivery-builder/buildrun/toolchains.go +++ b/modules/mesh-delivery-builder/buildrun/toolchains.go @@ -91,3 +91,39 @@ const ( ToolchainsTool = "builder_toolchains" ToolchainsDropTool = "builder_toolchains_drop" ) + +// Put takes a change of a build module's toolchains bucket in: a put of a node's entry (key .) or its +// delete. It answers whether the language's entries changed (a node's version or recipe, or a node appearing or going). +// A key or a value that is not an entry of the module's language is left out. +func (s *ToolchainSet) Put(module, key string, value []byte, deleted bool) bool { + language, ok := LanguageOf[module] + if !ok { + return false + } + node, keyLanguage, err := buildstep.ParseToolchainKey(key) + if err != nil || keyLanguage != language { + return false + } + s.mu.Lock() + defer s.mu.Unlock() + if deleted { + if _, had := s.by[language][node]; !had { + return false + } + delete(s.by[language], node) + return true + } + tc, err := buildstep.DecodeToolchain(value) + if err != nil || tc.Language != language { + return false + } + if s.by == nil { + s.by = map[string]map[string]buildstep.Toolchain{} + } + if s.by[language] == nil { + s.by[language] = map[string]buildstep.Toolchain{} + } + cur, had := s.by[language][node] + s.by[language][node] = tc + return !had || cur.Version != tc.Version || cur.Recipe != tc.Recipe || cur.Digest != tc.Digest +} From 84d1a5b1568c5203b4db4c37fc249ba7345dd226 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 22:18:58 +0100 Subject: [PATCH 2/3] G findings4 builder: the builder's findings are the seat's generated finding written through views.NewHeldWriter, its findings stream in manifest and bed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G A-29, A-30, A-17, A-26, A-3, §689, §686, §383 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- .../cmd/mesh-delivery-builder/findings.go | 196 ++++++++---------- .../mesh-delivery-builder/integration_test.go | 5 + .../cmd/mesh-delivery-builder/main.go | 18 +- .../cmd/mesh-delivery-builder/readscall.go | 6 +- .../cmd/mesh-delivery-builder/refused_test.go | 60 +++--- .../cmd/mesh-delivery-builder/reserve_test.go | 6 +- .../cmd/mesh-delivery-builder/unput.go | 6 +- .../mesh-delivery-builder/manifest_test.go | 8 +- modules/mesh-delivery-builder/module.json | 4 +- 9 files changed, 155 insertions(+), 154 deletions(-) diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/findings.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/findings.go index b730238db..d184ad300 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/findings.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/findings.go @@ -2,38 +2,41 @@ package main import ( "context" + "encoding/json" "errors" + "fmt" + "strings" "time" - "github.com/nats-io/nats.go/jetstream" - - "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" - "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" - "git.novox.be/novox/mesh-sdk/go/process" - + mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard" + mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/builds" + "git.novox.be/novox/mesh-sdk/go/views" "mesh-delivery-builder/internal/versions" ) // findingsBucket is the builder's findings (novox/hq ADR 0564 §2): what it sees wrong now, written at its raise and // deleted at its clear, which the condition keeper raises and clears. -var findingsBucket = meshconditionsclient.FindingsBucket(builds.BuilderModule) +var findingsBucket = builds.BuilderModule + "_" + mcseat.StateFindings -// findings writes the builder's findings into its state, once bound; until then each is said in the log only. -type findings struct { - kv *process.AwaitedBucket - logf func(string, ...any) - now func() time.Time - // store stands in for kv in a test. - store findingStore +// heldWriter is the builder's finding writer: its findings are raised as they happen, so the writer holds them (design 47 G +// A-29); its `findings-asked` subject is the seat's, from the generated contract (A-17). +type heldWriter = views.HeldWriter[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent] + +// findingWriter is the part of the held writer the builder's findings use. +type findingWriter interface { + Write(ctx context.Context, f mcseat.Finding) error + Clear(ctx context.Context, scope, id, kind, why string) error } -// findingStore is the part of the findings bucket written. -type findingStore interface { - Get(ctx context.Context, key string) (jetstream.KeyValueEntry, error) - Put(ctx context.Context, key string, value []byte) (uint64, error) - Delete(ctx context.Context, key string, opts ...jetstream.KVDeleteOpt) error +// findings writes the builder's findings through its held finding writer (design 47 G §689, A-29): a finding written before the +// writer starts is held and stated at its start. +type findings struct { + w findingWriter + logf func(string, ...any) + now func() time.Time } // finding is one of the builder's findings: its kind, what it is about, and its words. @@ -41,21 +44,43 @@ type finding struct { kind, scope, id string summary, headline, explanation, resolved, needs string severity string + machine, said, source string } -func (f *findings) bucket() findingStore { - switch { - case f == nil: - return nil - case f.store != nil: - return f.store - case f.kv == nil: - return nil +// seatFinding is fd as the seat's generated finding at at, its id made safe as a key's part. +func (fd finding) seatFinding(at time.Time) mcseat.Finding { + at = at.UTC() + id := keyID(fd.id) + sev := fd.severity + if sev == "" { + sev = mcseat.FindingSeverityWarning } - if kv := f.kv.KV(); kv != nil { - return kv + said, source := fd.said, fd.source + if said == "" { + said = fd.summary } - return nil + if source == "" { + source = "builder." + fd.kind + } + return mcseat.Finding{Scope: fd.scope, ID: id, Kind: fd.kind, Severity: sev, Summary: fd.summary, Headline: fd.headline, + Explanation: fd.explanation, Needs: fd.needs, Source: source, Observer: builds.BuilderModule, At: at, + Evidence: []mcseat.Evidence{{At: at, Said: said}}, + Subject: mcseat.Subject{Scope: fd.scope, ID: id, Machine: fd.machine}} +} + +// keyID is an id as the parts of a key: each dot-separated part made safe for a bus key, as the key of a condition is. +func keyID(id string) string { + key := mcc.Key("x", id, "x") + return key[len("x.") : len(key)-len(".x")] +} + +// callUnanswered is the finding of a kept call to callee about id, unanswered since since, its last fault said (ADR 0668 §3): +// its key is `call..call-unanswered`. +func callUnanswered(id, callee, machine, fault, source string, since time.Time) finding { + return finding{scope: mcc.ScopeCall, id: id, kind: mcc.KindCallUnanswered, machine: machine, said: fault, source: source, + summary: "the call " + callee + " about " + id + " is unanswered since " + since.UTC().Format(time.RFC3339), + headline: "A call whose answer is kept is not answered", + explanation: "The call " + callee + " is made again on every transport fault and on the callee's event; it has not been answered since " + since.UTC().Format(time.RFC3339) + ". Its last fault: " + fault + "."} } // BuildFailed is the finding of a failed trunk build (DLV-B7, design 25), about its module. @@ -69,106 +94,63 @@ func (f *findings) buildEnded(ctx context.Context, e builds.BuildLogEntry) { } switch e.Outcome { case builds.BuildFailed: - f.raise(ctx, finding{kind: BuildFailed, scope: meshconditionsclient.ScopeModule, id: e.Module, + f.raise(ctx, finding{kind: BuildFailed, scope: mcc.ScopeModule, id: e.Module, summary: "the trunk build of " + e.Module + " at " + e.FP + " (commit " + e.Commit + ") failed", headline: "A module's trunk build failed", explanation: "The builder built " + e.Module + " from the trunk and the build failed, so its new version is not delivered.", resolved: "A later trunk build of " + e.Module + " is done.", needs: "builder_builds_since shows the build; builder_build_again builds it again."}) case builds.BuildDone: - f.clear(ctx, BuildFailed, meshconditionsclient.ScopeModule, e.Module) + f.clear(ctx, BuildFailed, mcc.ScopeModule, e.Module) } } -// raise writes fd; it is written again only when its words changed, so the keeper's condition moves only then. +// raise writes fd through the writer. func (f *findings) raise(ctx context.Context, fd finding) { - f.raiseObservation(ctx, meshconditionsclient.Observation{Scope: fd.scope, ID: fd.id, Kind: fd.kind, Severity: fd.severity, - Summary: fd.summary, Headline: fd.headline, Explanation: fd.explanation, Resolved: fd.resolved, Needs: fd.needs, - Source: "builder." + fd.kind}) -} - -// raiseObservation writes o, as raise does. -func (f *findings) raiseObservation(ctx context.Context, o meshconditionsclient.Observation) { - kv := f.bucket() - if kv == nil { - f.logf("finding %s (not written, %s is not on the bus yet): %s", o.Key(), findingsBucket, o.Summary) + x := fd.seatFinding(f.now()) + if f.w == nil { + f.logf("finding %s (not written, no finding writer): %s", views.FindingKey(x.Scope, x.ID, x.Kind), x.Summary) return } - if _, err := meshconditionsclient.Raise(findingBucket{ctx, kv}, builds.BuilderModule, "", o, f.now()); err != nil { - f.logf("the finding %s cannot be written: %v", o.Key(), err) + if err := f.w.Write(ctx, x); err != nil { + f.logf("the finding %s cannot be written: %v", views.FindingKey(x.Scope, x.ID, x.Kind), err) } } -// clear deletes the finding of kind about scope and id; one not there is nothing to clear. +// clear clears the finding of kind about scope and id; one not there is nothing to clear. func (f *findings) clear(ctx context.Context, kind, scope, id string) { - kv := f.bucket() - if kv == nil { + if f.w == nil { return } - if _, err := meshconditionsclient.Clear(findingBucket{ctx, kv}, scope, id, kind); err != nil { - f.logf("the finding %s cannot be cleared: %v", meshconditionsclient.Key(scope, id, kind), err) + if err := f.w.Clear(ctx, scope, keyID(id), kind, "the builder no longer observes it"); err != nil { + f.logf("the finding %s cannot be cleared: %v", views.FindingKey(scope, keyID(id), kind), err) } } -// findingBucket is the builder's findings store as the bucket the conditions client raises and clears in. -type findingBucket struct { - ctx context.Context - kv findingStore -} - -func (b findingBucket) Get(key string) ([]byte, bool, error) { - e, err := b.kv.Get(b.ctx, key) - switch { - case errors.Is(err, jetstream.ErrKeyNotFound): - return nil, false, nil - case err != nil: - return nil, false, err - } - return e.Value(), true, nil -} - -func (b findingBucket) Put(key string, value []byte) error { - _, err := b.kv.Put(b.ctx, key, value) - return err -} - -func (b findingBucket) Delete(key string) error { - if err := b.kv.Delete(b.ctx, key); err != nil && !errors.Is(err, jetstream.ErrKeyNotFound) { - return err - } - return nil -} - -// notHeard is the writer of the builder's finding of a family it does not hear (heard.Writer, ADR 0615 §5): written into -// its findings once bound, said in the log until then. +// notHeard is the writer of the builder's finding of a family it does not hear (heard.Writer, ADR 0615 §5): written through the +// finding writer, said in the log until it starts. func (f *findings) notHeard(ctx context.Context) heard.Writer { - on := func(do func(findingStore)) { - switch { - case f.store != nil: - do(f.store) - case f.kv != nil: - f.kv.Ready(func(kv jetstream.KeyValue) { do(kv) }) - } - } return heard.Writer{Observer: builds.BuilderModule, Logf: f.logf, Now: f.now, - Put: func(key string, value []byte) error { - on(func(kv findingStore) { - if _, err := kv.Put(ctx, key, value); err != nil { - f.logf("the finding %s cannot be written: %v", key, err) - } - }) - return nil + Put: func(_ string, value []byte) error { + var x mcseat.Finding + if err := json.Unmarshal(value, &x); err != nil { + return err + } + if f.w == nil { + return errors.New("no finding writer") + } + return f.w.Write(ctx, x) }, Delete: func(key string) error { - on(func(kv findingStore) { - if _, err := kv.Get(ctx, key); err != nil { - return // none stands - } - if err := kv.Delete(ctx, key); err != nil { - f.logf("the finding %s cannot be cleared: %v", key, err) - } - }) - return nil + scope, rest, _ := strings.Cut(key, ".") + i := strings.LastIndex(rest, ".") + if i < 0 { + return fmt.Errorf("%q is no finding's key", key) + } + if f.w == nil { + return nil + } + return f.w.Clear(ctx, scope, rest[:i], rest[i+1:], "the builder hears it") }} } @@ -177,10 +159,10 @@ func (f *findings) notHeard(ctx context.Context) heard.Writer { func (f *findings) floorSaid(ctx context.Context) func(versions.FloorWait, bool) { return func(w versions.FloorWait, raised bool) { if !raised { - f.clear(ctx, versions.FloorSilent, meshconditionsclient.ScopeModule, w.Name) + f.clear(ctx, versions.FloorSilent, mcc.ScopeModule, w.Name) return } - f.raise(ctx, finding{kind: versions.FloorSilent, scope: meshconditionsclient.ScopeModule, id: w.Name, summary: w.Finding(), + f.raise(ctx, finding{kind: versions.FloorSilent, scope: mcc.ScopeModule, id: w.Name, summary: w.Finding(), headline: "A version's floor is not known", explanation: "The builder numbers a name only once its registry seat, the forge bridge's tags and the indexer's requirements all answered; one of them did not.", resolved: "All three answered.", diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/integration_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/integration_test.go index fbfc0f505..7feaa2943 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/integration_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/integration_test.go @@ -309,6 +309,11 @@ func startBedWith(t *testing.T, closed bool) *bed { AllowDirect: true}); err != nil { t.Fatal(err) } + // The builder's own stream of its findings' events (design 47 G A-30, §383), which its finding writer says into. + if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: "BUILDER_FINDINGS", Subjects: []string{"mesh.stream.mesh-delivery-builder.event.finding-written.*", + "mesh.stream.mesh-delivery-builder.event.finding-cleared.*", "mesh.stream.mesh-delivery-builder.event.findings-stated.*"}}); err != nil { + t.Fatal(err) + } b.fake = &fakeBuildModules{js: js, ctx: ctx, calls: map[string]int{}} b.fake.closed.Store(closed) b.fake.serve(t, "mesh-build-go", "n1", "n2") diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go index fa35f4ac8..b873b4c20 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/main.go @@ -21,7 +21,7 @@ import ( "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" - sdkfindings "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/findings" + mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "git.novox.be/novox/mesh-contracts/go/clients/nodeengineclient/enginereads" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-builder/buildrun" @@ -92,7 +92,19 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro hub := process.NewEventHub(logger.Printf) reader := &views.ProcessReader{Module: builds.BuilderModule, Call: calls.Call, Logf: logger.Printf, Hub: hub} findingsKV := process.AwaitBucket(ctx, js, conn, findingsBucket, "the builder's findings, a first view unanswered past its bound among them, are said in its log only", logger.Printf) - reader.Findings = func() views.FindingWriter { return sdkfindings.Writer(ctx, findingsKV.KV) } + // The builder's findings are raised as they happen, so its one finding writer holds them (design 47 G A-29, §689): it + // is started once the state is bound, and what is written before is stated at its start. + fw, err := views.NewHeldWriter(views.WriterConfig[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]{ + Module: cred.Module, State: calls.State("findings"), Node: cred.Node, Asked: mcseat.SubjectFindingsAsked, JS: js, Conn: conn, Logf: logger.Printf}) + if err != nil { + return err + } + findingsKV.Ready(func(jetstream.KeyValue) { + if err := fw.Start(ctx); err != nil { + logger.Printf("the finding writer cannot start, its findings are kept in the state alone: %v", err) + } + }) + reader.Findings = func() views.WireWriter { return fw } modules, err := reader.Follow(indexerModule, modulesState, indexerModule+".indexer_read_modules") if err != nil { return err @@ -151,7 +163,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro // The builder numbers each trunk build at its claim (novox/hq design 51 *The versions*): its state versions, bound once // the bus holds it; the floor's three sources asked as its own account. versionsKV := process.AwaitBucket(ctx, js, conn, versions.Bucket, "no trunk build is numbered: each is built unnumbered and published by its digest", logger.Printf) - found := &findings{kv: findingsKV, logf: logger.Printf, now: time.Now} + found := &findings{w: fw, logf: logger.Printf, now: time.Now} floorWaits := &versions.FloorWaits{Logf: logger.Printf, Said: found.floorSaid(context.WithoutCancel(ctx))} // The names waiting on their floor are kept in the state floor-waits (DLV-B4): a restarted builder takes them in, so // their silent sources' events still wake them; until the state is bound they are kept here only. diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/readscall.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/readscall.go index 4217ca6b8..2cd141571 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/readscall.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/readscall.go @@ -43,9 +43,9 @@ func heardBy(call func(key string, body any) (json.RawMessage, error)) func(cont func (r *engineReads) callsOf(f *findings, bounds func() jetstream.KeyValue, heard func(context.Context, string) (bool, error), logf func(string, ...any)) *enginereads.ReadsCalls { c := &enginereads.ReadsCalls{Keeper: r.keeper, Nodes: r.named, Heard: heard, Bound: mcc.CallUnansweredAfter, Logf: logf, Raise: func(ctx context.Context, u enginereads.UnansweredCall) error { - o := mcc.CallUnanswered(enginereads.CallID(u.Node), enginereads.Invoke, u.Node, u.Words, "builder."+mcc.KindCallUnanswered, u.Since) - o.Needs = "builder_engine_reads with ask_again asks the node again now and shows its statement." - f.raiseObservation(ctx, o) + o := callUnanswered(enginereads.CallID(u.Node), enginereads.Invoke, u.Node, u.Words, "builder."+mcc.KindCallUnanswered, u.Since) + o.needs = "builder_engine_reads with ask_again asks the node again now and shows its statement." + f.raise(ctx, o) return nil }, Clear: func(ctx context.Context, node string) error { diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go index cafc3e8a0..af0276d6a 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/refused_test.go @@ -15,7 +15,9 @@ import ( "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient/heard" + mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "git.novox.be/novox/mesh-sdk/go/process" + "git.novox.be/novox/mesh-sdk/go/views" "github.com/nats-io/nats.go" "github.com/nats-io/nats.go/jetstream" @@ -151,7 +153,7 @@ func theCountedNodesEngineReads(t *testing.T) { asked = append(asked, key, body) return json.Marshal(meshwatchdogs.PresenceAnswer{Machine: "n2", Online: online}) }) - calls := r2.callsOf(&findings{store: st, logf: t.Logf, now: clock}, func() jetstream.KeyValue { return nil }, heard, t.Logf) + calls := r2.callsOf(&findings{w: st, logf: t.Logf, now: clock}, func() jetstream.KeyValue { return nil }, heard, t.Logf) calls.Arm = func(_ context.Context, node string, ends time.Time) error { armed[node] = ends; return nil } key := meshconditionsclient.Key(meshconditionsclient.ScopeCall, "manifest-reads.n2", meshconditionsclient.KindCallUnanswered) r2.placed() // n2 asked, unanswered at 1000 @@ -165,7 +167,7 @@ func theCountedNodesEngineReads(t *testing.T) { } online = true r2.expiredCall("n2") - f, err := meshconditionsclient.DecodeFinding(st.vals[key]) + f, err := decodeFinding(st.vals[key]) if err != nil || f.Observer != builds.BuilderModule || f.Kind != meshconditionsclient.KindCallUnanswered || len(asked) != 4 { t.Fatalf("heard five minutes on: finding %+v, %v (keys %v), presence asked %v", f, err, slices.Collect(maps.Keys(st.vals)), asked) } @@ -327,7 +329,7 @@ func (failingVersions) KeysOf(context.Context, string) ([]string, error) { func aFailedTrunkBuildIsAFinding(t *testing.T) { st := &memFindings{vals: map[string][]byte{}} - f := &findings{store: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} + f := &findings{w: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} ended := func(outcome, ref string) builds.BuildLogEntry { return builds.BuildLogEntry{Event: builds.BuildEndedEvent, Module: "m", FP: "f1", Commit: "c", Ref: ref, Outcome: outcome} } @@ -337,7 +339,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { t.Fatalf("a candidate's failed build is a finding: %v", st.vals) } f.buildEnded(context.Background(), ended(builds.BuildFailed, "")) - got, err := meshconditionsclient.DecodeFinding(st.vals[key]) + got, err := decodeFinding(st.vals[key]) if err != nil || got.Observer != builds.BuilderModule || !strings.Contains(got.Summary, "trunk build of m at f1") { t.Fatalf("the finding = %+v, %v", got, err) } @@ -349,7 +351,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { fw := &versions.FloorWaits{Said: f.floorSaid(context.Background())} fw.Wait("m/lib", versions.SeatGoPackages, "", versions.Floor{Silent: []string{versions.SourceTags}}, nil, time.Unix(0, 0)) floorKey := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m/lib", versions.FloorSilent) - if got, err := meshconditionsclient.DecodeFinding(st.vals[floorKey]); err != nil || !strings.Contains(got.Summary, "bridge_tags did not answer") { + if got, err := decodeFinding(st.vals[floorKey]); err != nil || !strings.Contains(got.Summary, "bridge_tags did not answer") { t.Fatalf("the floor finding = %+v, %v", got, err) } fw.Answered("m/lib") @@ -374,23 +376,23 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { if !h.heard(context.Background(), refused) || !refused.acked { t.Fatalf("a refusal: acked %v", refused.acked) } - if got, err := meshconditionsclient.DecodeFinding(st.vals[refusedKey]); err != nil || !strings.Contains(got.Summary, "refused to publish m/program@0.1.3") || !strings.Contains(got.Summary, "bytes differ") { + if got, err := decodeFinding(st.vals[refusedKey]); err != nil || !strings.Contains(got.Summary, "refused to publish m/program@0.1.3") || !strings.Contains(got.Summary, "bytes differ") { t.Fatalf("a holder's refused: the finding = %+v, %v", got, err) } pubs.ended(context.Background(), purged{key: versions.PublishBoundKey("m/program", "0.1.4")}) unansweredKey := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m/program", versions.PublishUnanswered) - if got, err := meshconditionsclient.DecodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "neither published nor refused of m/program@0.1.4") { + if got, err := decodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "neither published nor refused of m/program@0.1.4") { t.Fatalf("a bound ended unanswered: the finding = %+v, %v", got, err) } // Review round 2: a bound that cannot be written is publish-unanswered at once; a watch of bounds that cannot start // is family-not-heard naming the state. delete(st.vals, unansweredKey) pubs.arm(context.Background(), versions.Entry{Name: "m/program", Version: "0.1.4", Seat: "oci-artifact-registry"}) - if got, err := meshconditionsclient.DecodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "its bound could not be written") { + if got, err := decodeFinding(st.vals[unansweredKey]); err != nil || !strings.Contains(got.Summary, "its bound could not be written") { t.Fatalf("a bound not written: the finding = %+v, %v", got, err) } watchBounds(context.Background(), refusedWatch{err: errors.New("permissions violation")}, func(jetstream.KeyValueEntry) {}, f.notHeard(context.Background()), nil, t.Logf) - if got, err := meshconditionsclient.DecodeFinding(st.vals[heard.Key(builds.BuilderModule, versions.BoundsState)]); err != nil || !strings.Contains(got.Summary, "permissions violation") { + if got, err := decodeFinding(st.vals[heard.Key(builds.BuilderModule, versions.BoundsState)]); err != nil || !strings.Contains(got.Summary, "permissions violation") { t.Fatalf("bounds not watched: the finding = %+v, %v", got, err) } delete(st.vals, heard.Key(builds.BuilderModule, versions.BoundsState)) @@ -432,7 +434,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { } keys.memVersions[buildKey], looking = building, false u.expired(context.Background(), purged{key: versions.UnputBoundKey(buildKey)}) - if got, err := meshconditionsclient.DecodeFinding(st.vals[callKey]); err != nil || got.Kind != meshconditionsclient.KindCallUnanswered || !strings.Contains(got.Summary, buildKey) || !strings.Contains(got.Needs, build.BuildAgainTool) { + if got, err := decodeFinding(st.vals[callKey]); err != nil || got.Kind != meshconditionsclient.KindCallUnanswered || !strings.Contains(got.Summary, buildKey) || !strings.Contains(got.Needs, build.BuildAgainTool) { t.Fatalf("the bound's end of a key left building: the finding = %+v, %v", got, err) } u.ended(context.Background(), buildKey) @@ -441,7 +443,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { } u.bounds = func() jetstream.KeyValue { return nil } u.left(context.Background(), buildKey, "nats: timeout") - if got, err := meshconditionsclient.DecodeFinding(st.vals[callKey]); err != nil || !strings.Contains(got.Explanation, "nor its bound") { + if got, err := decodeFinding(st.vals[callKey]); err != nil || !strings.Contains(got.Explanation, "nor its bound") { t.Fatalf("a bound not written: the finding = %+v, %v", got, err) } delete(st.vals, callKey) @@ -449,7 +451,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { notHeard := f.notHeard(context.Background()) unheardKey := heard.Key(builds.BuilderModule, "FORGE") _ = notHeard.Bind("FORGE", "a branch's end is not heard", func() error { return errors.New("consumer not found") }) - if got, err := meshconditionsclient.DecodeFinding(st.vals[unheardKey]); err != nil || got.Kind != heard.Kind || !strings.Contains(got.Summary, "does not hear FORGE") { + if got, err := decodeFinding(st.vals[unheardKey]); err != nil || got.Kind != heard.Kind || !strings.Contains(got.Summary, "does not hear FORGE") { t.Fatalf("a consumer not there: the finding = %+v, %v", got, err) } _ = notHeard.Bind("FORGE", "a branch's end is not heard", func() error { return nil }) @@ -499,7 +501,7 @@ func aFailedTrunkBuildIsAFinding(t *testing.T) { } now = now.Add(versions.FindingAfter) window.step(context.Background(), []string{"a", "b"}, counted) - if got, err := meshconditionsclient.DecodeFinding(st.vals[heldKey]); err != nil || !strings.Contains(got.Summary, "the node-engine of b") { + if got, err := decodeFinding(st.vals[heldKey]); err != nil || !strings.Contains(got.Summary, "the node-engine of b") { t.Fatalf("seven days held: the finding = %+v, %v", got, err) } counted["b"] = newest @@ -581,25 +583,21 @@ func (p purged) Operation() jetstream.KeyValueOp { return jetstream.KeyValuePurg // memFindings is a findings bucket in memory. type memFindings struct{ vals map[string][]byte } -type memEntry struct { - jetstream.KeyValueEntry - v []byte +// Write keeps the finding under its key, as the held writer does in the state. +func (m *memFindings) Write(_ context.Context, f mcseat.Finding) error { + v, err := json.Marshal(f) + m.vals[views.FindingKey(f.Scope, f.ID, f.Kind)] = v + return err } -func (e memEntry) Value() []byte { return e.v } - -func (m *memFindings) Get(_ context.Context, key string) (jetstream.KeyValueEntry, error) { - v, ok := m.vals[key] - if !ok { - return nil, jetstream.ErrKeyNotFound - } - return memEntry{v: v}, nil -} -func (m *memFindings) Put(_ context.Context, key string, v []byte) (uint64, error) { - m.vals[key] = v - return 1, nil -} -func (m *memFindings) Delete(_ context.Context, key string, _ ...jetstream.KVDeleteOpt) error { - delete(m.vals, key) +// Clear deletes the finding of scope, id and kind. +func (m *memFindings) Clear(_ context.Context, scope, id, kind, _ string) error { + delete(m.vals, views.FindingKey(scope, id, kind)) return nil } + +// decodeFinding reads a finding as the writer kept it. +func decodeFinding(v []byte) (mcseat.Finding, error) { + var f mcseat.Finding + return f, json.Unmarshal(v, &f) +} diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go index 679e1b951..dca519a1d 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/reserve_test.go @@ -75,7 +75,7 @@ func (b *boundsKV) Delete(_ context.Context, key string, _ ...jetstream.KVDelete func TestTheCatalogsWordsMoveTheReservations(t *testing.T) { ctx := context.Background() st := &memFindings{vals: map[string][]byte{}} - found := &findings{store: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} + found := &findings{w: st, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} bounds := &boundsKV{keys: map[string]bool{}} woke := 0 call := func(addr string, body any) (json.RawMessage, error) { @@ -109,7 +109,7 @@ func TestTheCatalogsWordsMoveTheReservations(t *testing.T) { t.Fatal("a reservation's bound was not taken in") } key := meshconditionsclient.Key(meshconditionsclient.ScopeModule, "m", versions.VersionUnreleased) - got, err := meshconditionsclient.DecodeFinding(st.vals[key]) + got, err := decodeFinding(st.vals[key]) if err != nil || !strings.Contains(got.Summary, "m:b unpublished") || strings.Contains(got.Summary, "m:a unpublished") || !strings.Contains(got.Summary, "1.4.3") { t.Fatalf("finding = %+v (%v), want version-unreleased naming m:b of 1.4.3", got, err) } @@ -146,7 +146,7 @@ func TestAReleasedVersionIsTaggedAtTheCommitItWasBuiltFrom(t *testing.T) { tags = append(tags, body.(git.TagInput)) return json.Marshal(git.TagAnswer{Performed: refuse == "", Error: refuse}) } - found := &findings{store: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} + found := &findings{w: &memFindings{vals: map[string][]byte{}}, logf: t.Logf, now: func() time.Time { return time.Unix(0, 0) }} rv := newReservations(&memReserve{vals: map[string][]byte{}, revs: map[string]uint64{}}, call, func() jetstream.KeyValue { return &boundsKV{keys: map[string]bool{}} }, found, nil, t.Logf) rv.filled.Store(true) goPkg := versions.Source{Repository: "o/r", Commit: "c0ffee", GoPackage: true} diff --git a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/unput.go b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/unput.go index 55c9ccabf..19817b411 100644 --- a/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/unput.go +++ b/modules/mesh-delivery-builder/cmd/mesh-delivery-builder/unput.go @@ -78,7 +78,7 @@ func (u *unputs) expired(ctx context.Context, e jetstream.KeyValueEntry) { } func (u *unputs) raise(ctx context.Context, key, fault string, since time.Time) { - o := meshconditionsclient.CallUnanswered(key, unputCallee, "", fault, "builder."+meshconditionsclient.KindCallUnanswered, since) - o.Needs = build.BuildAgainTool + " builds the key again: an ask its stream holds is waited for, one never put is put; " + build.StuckTool + " shows it." - u.findings.raiseObservation(ctx, o) + o := callUnanswered(key, unputCallee, "", fault, "builder."+meshconditionsclient.KindCallUnanswered, since) + o.needs = build.BuildAgainTool + " builds the key again: an ask its stream holds is waited for, one never put is put; " + build.StuckTool + " shows it." + u.findings.raise(ctx, o) } diff --git a/modules/mesh-delivery-builder/manifest_test.go b/modules/mesh-delivery-builder/manifest_test.go index b35b278e3..79789582a 100644 --- a/modules/mesh-delivery-builder/manifest_test.go +++ b/modules/mesh-delivery-builder/manifest_test.go @@ -155,7 +155,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1 if want := []string{"container-image-registry.kept", "container-image-registry.published", "container-image-registry.refused", "container-image-registry.removed", "go-package-registry.kept", "go-package-registry.published", "go-package-registry.refused", "go-package-registry.removed", "mesh-artifact-sweep.artifacts-gone", "mesh-catalog.manifest-accepted", "mesh-catalog.version-released", "mesh-catalog.versions-filled", - "mesh-conditions.condition-cleared", "mesh-delivery-assigner.views.assignments", "mesh-delivery-forge-bridge.forge.**", + "mesh-conditions.condition-cleared", "mesh-conditions.findings-asked", "mesh-delivery-assigner.views.assignments", "mesh-delivery-forge-bridge.forge.**", "mesh-delivery-indexer.views.candidates", "mesh-delivery-indexer.views.manifests", "mesh-delivery-indexer.views.modules", "mesh-delivery-indexer.views.packages", "node-build-go.toolchain-reported", "node-build-node.toolchain-reported", "node-engine.manifest-reads-changed", "node-engine.running", "npm-package-registry.kept", "npm-package-registry.published", "npm-package-registry.refused", "npm-package-registry.removed", @@ -174,8 +174,10 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1 t.Errorf("tools = %v, want %v", m.Tools, want) } // Design 47 G §672: the toolchain waits' stream, kept 7 days within 16 MiB, and the bound's setting, 60 minutes. - if len(m.Streams) != 1 || m.Streams[0].Name != "waits" || !reflect.DeepEqual(m.Streams[0].Events, []string{"wait-held.**", "wait-ended.**"}) || m.Streams[0].MaxAgeDays != 7 || m.Streams[0].MaxMiB != 16 { - t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB", m.Streams) + // Design 47 G A-30, §383: and its own findings' events, which its finding writer says. + if len(m.Streams) != 2 || m.Streams[0].Name != "waits" || !reflect.DeepEqual(m.Streams[0].Events, []string{"wait-held.**", "wait-ended.**"}) || m.Streams[0].MaxAgeDays != 7 || m.Streams[0].MaxMiB != 16 || + m.Streams[1].Name != "mesh-delivery-builder-findings" || !reflect.DeepEqual(m.Streams[1].Events, []string{"finding-written.*", "finding-cleared.*", "findings-stated.*"}) { + t.Errorf("streams = %+v, want waits with wait-held.** and wait-ended.**, 7 days, 16 MiB, and the findings' stream", m.Streams) } if c, ok := m.Config["toolchain-wait-minutes"]; !ok || c.Default != float64(60) || len(m.Config) != 1 { t.Errorf("config = %+v, want toolchain-wait-minutes of 60", m.Config) diff --git a/modules/mesh-delivery-builder/module.json b/modules/mesh-delivery-builder/module.json index 0e4284363..ac053db92 100644 --- a/modules/mesh-delivery-builder/module.json +++ b/modules/mesh-delivery-builder/module.json @@ -40,6 +40,7 @@ "version.old-form-closed" ], "consumes": [ + "mesh-conditions.findings-asked", "container-image-registry.kept", "container-image-registry.published", "container-image-registry.refused", @@ -116,7 +117,8 @@ { "name": "first-views", "history": 1 } ], "streams": [ - { "name": "waits", "events": ["wait-held.**", "wait-ended.**"], "max-age-days": 7, "max-mib": 16 } + { "name": "waits", "events": ["wait-held.**", "wait-ended.**"], "max-age-days": 7, "max-mib": 16 }, + { "name": "mesh-delivery-builder-findings", "events": ["finding-written.*", "finding-cleared.*", "findings-stated.*"], "max-age-days": 7, "max-mib": 16 } ], "config": { "toolchain-wait-minutes": { From 00f5c1b8211ae7052d4b2402e544ec887a88ed13 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 11 Nov 2026 22:19:39 +0100 Subject: [PATCH 3/3] G findings4 mesh-enrolment: the enrolment's reader writes its findings through views.NewStdioHeldWriter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 G §639, A-37, A-29 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h --- .../cmd/mesh-enrolment/findings_test.go | 16 +++++++++++++ .../mesh-enrolment/cmd/mesh-enrolment/main.go | 24 ++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 modules/mesh-enrolment/cmd/mesh-enrolment/findings_test.go diff --git a/modules/mesh-enrolment/cmd/mesh-enrolment/findings_test.go b/modules/mesh-enrolment/cmd/mesh-enrolment/findings_test.go new file mode 100644 index 000000000..e178f12d2 --- /dev/null +++ b/modules/mesh-enrolment/cmd/mesh-enrolment/findings_test.go @@ -0,0 +1,16 @@ +package main + +import "testing" + +// The enrolment's findings are written through the held finding writer of a stdio module (design 47 G §639, A-37): it is made +// over the state findings with the node the runtime sets, and refused without one. +func TestFindingWriter(t *testing.T) { + t.Setenv("MESH_NODE", "n1") + if w, err := newFindingWriter(); err != nil || w == nil { + t.Fatalf("writer = %v, %v; want one", w, err) + } + t.Setenv("MESH_NODE", "") + if _, err := newFindingWriter(); err == nil { + t.Error("a writer without a node was made: its events' subjects name none") + } +} diff --git a/modules/mesh-enrolment/cmd/mesh-enrolment/main.go b/modules/mesh-enrolment/cmd/mesh-enrolment/main.go index 095bff365..8cd07317f 100644 --- a/modules/mesh-enrolment/cmd/mesh-enrolment/main.go +++ b/modules/mesh-enrolment/cmd/mesh-enrolment/main.go @@ -13,6 +13,7 @@ import ( "time" "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient" stdio "git.novox.be/novox/mesh-sdk/go" "git.novox.be/novox/mesh-sdk/go/views" @@ -120,10 +121,31 @@ const ( AssignmentsTool = assignerModule + ".assigner_read_assignments" ) +// heldWriter is the enrolment's finding writer. +type heldWriter = views.HeldWriter[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent] + +// newFindingWriter makes the enrolment's held finding writer over its state findings, its node from MESH_NODE (design 47 G §639, A-37). +func newFindingWriter() (*heldWriter, error) { + return views.NewStdioHeldWriter(views.WriterConfig[mcseat.Finding, mcseat.FindingCleared, mcseat.FindingsStated, mcseat.FindingsAskedEvent]{ + Module: Module, State: stdio.State(mcseat.StateFindings), Asked: mcseat.SubjectFindingsAsked, Logf: logf}) +} + // followed is the enrolment's pictures of the assigner's assignments, started at once: its first view asked through // AssignmentsTool, then the assigner's views family; past its bound the finding in the enrolment's own findings. func followed() *views.Reader { - v := &views.Reader{Module: Module, Logf: func(f string, a ...any) { logf("["+Module+"] "+f, a...) }, Findings: views.OwnFindings{}, + // The enrolment's findings go through the held finding writer of a stdio module (design 47 G §639, A-37): the reader + // writes its first-view finding through it, so the keeper's asks and statements hold it. + var findings views.WireWriter + w, err := newFindingWriter() + if err != nil { + logf("[%s] the finding writer cannot be made, so no finding is written: %v", Module, err) + } else { + if err := w.Start(context.Background()); err != nil { + logf("[%s] the finding writer cannot start, its findings are kept in the state alone: %v", Module, err) + } + findings = w + } + v := &views.Reader{Module: Module, Logf: func(f string, a ...any) { logf("["+Module+"] "+f, a...) }, Findings: findings, Acts: meshhandactsclient.Recorder{Ask: stdio.Ask}} v.Follow(assignerModule, assignmentsState, AssignmentsTool) v.Start(context.Background())