B10: build_current asks every build seat's holder its current, in turn

The tools bundle follows the seat-holders view of the claimant of
mesh-module-assigner, names each build seat's holder per node from it, asks
each holder's current at its node one after another and answers them
together, a holder that does not answer listed with why; it reads no presence
and chooses no node. The manifest lists the tool and the three build seats'
current among the module's invokes, outside the process's bus.

Builds: design 47 H2 §801; H-A-446 (1)
This commit is contained in:
2026-11-22 02:44:18 +01:00
parent 5e6ebefd47
commit f756718324
5 changed files with 187 additions and 6 deletions
@@ -0,0 +1,141 @@
package main
import (
"context"
"encoding/json"
"errors"
"fmt"
"sort"
"strings"
"sync"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
stdio "git.novox.be/novox/mesh-sdk/go"
"git.novox.be/novox/mesh-sdk/go/seatlist"
"git.novox.be/novox/mesh-sdk/go/views"
)
// BuildCurrentTool is build_current (design 47 H2 §801).
const BuildCurrentTool = "build_current"
// buildCurrentDescription is build_current's description.
const buildCurrentDescription = "What every holder of a build seat takes and runs now (design 47 H2 section 801): the holders named by the " +
"seat-holders view, each build seat on each node, and each holder's own answer to its seat's verb current, asked in turn and " +
"answered together: whether it takes asks and why not (paused, capacity 0, unhealthy) since when, and every ask it runs, whoever " +
"asked it. A holder that does not answer is listed with why. Read-only."
// seatHoldersState is the assigner's view of who holds which seat on which node (ADR 0571 §6).
const seatHoldersState = "seat-holders"
// heldBuildSeat is one holder of a build seat as build_current answers it: the seat, its node and module, and the holder's
// answer to current, or why there is none.
type heldBuildSeat struct {
Seat string `json:"seat"`
Node string `json:"node"`
Module string `json:"module,omitempty"`
Current json.RawMessage `json:"current,omitempty"`
Error string `json:"error,omitempty"`
}
// buildCurrentTool is build_current (§801; H-A-446 (1)): the holders of each build seat (seats) named from the seat-holders view
// (holders, keyed `<seat>.<node>`), each holder's current asked in turn at its node through ask (stdio.Ask), answered together;
// it reads no presence and chooses no node.
func buildCurrentTool(seats func() []string, holders func() (map[string]json.RawMessage, error), ask func(key string, body any) (json.RawMessage, error)) stdio.Tool {
return stdio.Tool{Name: BuildCurrentTool, Description: buildCurrentDescription,
Input: map[string]any{"type": "object", "properties": map[string]any{}},
Run: func(map[string]any) (any, error) {
view, err := holders()
if err != nil {
return nil, err
}
var out []heldBuildSeat
for _, seat := range seats() {
for key, raw := range view {
node, ok := strings.CutPrefix(key, seat+".")
if !ok || node == "" {
continue
}
var held struct {
Holders []struct {
Module string `json:"module"`
} `json:"holders"`
}
if json.Unmarshal(raw, &held) != nil || len(held.Holders) == 0 {
continue
}
out = append(out, heldBuildSeat{Seat: seat, Node: node, Module: held.Holders[0].Module})
}
}
sort.Slice(out, func(i, j int) bool {
if out[i].Seat != out[j].Seat {
return out[i].Seat < out[j].Seat
}
return out[i].Node < out[j].Node
})
for i := range out { // in turn, one holder at a time
raw, err := ask("seat:"+out[i].Seat+".current@"+out[i].Node, map[string]any{})
if err != nil {
out[i].Error = err.Error()
continue
}
out[i].Current = raw
}
if out == nil {
out = []heldBuildSeat{}
}
return map[string]any{"holders": out, "count": len(out)}, nil
}}
}
// seatHolders follows the seat-holders view of the claimant of the seat mesh-module-assigner once the catalog half names it.
type seatHolders struct {
mu sync.Mutex
values func() map[string]json.RawMessage
why string
}
// follow starts the follow when the bundle's first views stand (the claimant is read from the catalog half).
func (s *seatHolders) follow(ctx context.Context, branches *meshcatalogclient.Branches, r *views.Reader) {
s.mu.Lock()
s.why = "the catalog half's first views are not read yet"
s.mu.Unlock()
go func() {
select {
case <-ctx.Done():
return
case <-branches.FirstViews(ctx):
}
claimant, ok := branches.Claimant(seatlist.HolderSeat)
if !ok {
s.mu.Lock()
s.why = "no module claims the seat " + seatlist.HolderSeat + " on the catalog half"
s.mu.Unlock()
return
}
w, ok := meshcatalogclient.ReaderWiring(r).(interface {
Follow(owner, state, tool string) (func() map[string]json.RawMessage, error)
})
var values func() map[string]json.RawMessage
err := fmt.Errorf("the bundle's reader follows no plain view")
if ok {
values, err = w.Follow(claimant, seatHoldersState, claimant+"."+seatHoldersState)
}
s.mu.Lock()
defer s.mu.Unlock()
if err != nil {
s.why = fmt.Sprintf("the seat-holders view of %s is not followed: %v", claimant, err)
return
}
s.values, s.why = values, ""
}()
}
// read is the view's values, or why it is not read.
func (s *seatHolders) read() (map[string]json.RawMessage, error) {
s.mu.Lock()
defer s.mu.Unlock()
if s.values == nil {
return nil, errors.New("the seat-holders view is not read: " + s.why)
}
return s.values(), nil
}
@@ -465,6 +465,16 @@ func main() {
// states stand, and asking one again by hand (ADR 0615, DLV-M1).
tools = append(tools, views.StatusTools(os.Getenv(stdio.ServedAs), "builder_first_views", "builder_first_view_again", stdio.State(views.StatusState), meshhandactsclient.Recorder{Ask: stdio.Ask}, time.Now)...)
tools = append(tools, gate.Tools()...)
// build_current (design 47 H2 §801; H-A-446 (1)): each build seat's holders from the seat-holders view, each asked current.
holders := &seatHolders{}
holders.follow(context.Background(), branches, pk)
tools = append(tools, buildCurrentTool(func() []string {
var out []string
for _, m := range r.Seats.All() {
out = append(out, m.Seat)
}
return out
}, holders.read, stdio.Ask))
if err := stdio.Serve("", tools); err != nil {
fmt.Fprintf(os.Stderr, "[mesh-delivery-builder-tools] %v\n", err)
os.Exit(1)
@@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"strings"
"testing"
"time"
@@ -86,6 +87,31 @@ func TestAStateIsReadInOnePage(t *testing.T) {
t.Errorf("%s asked %v, answered %+v (%v): want the verb asked with the module, its answer carried with its cap", tools[1].Name, asked, a, err)
}
})
// Design 47 H2 §801, H-A-446 (1): build_current names the holders from the seat-holders view and asks each holder's current in
// turn at its node, answering them together; a holder that does not answer is listed with why.
t.Run("build_current asks every build seat's holder in turn", func(t *testing.T) {
view := map[string]json.RawMessage{
"node-build-go.g14": json.RawMessage(`{"holders":[{"module":"mesh-build-go"}]}`),
"node-build-go.ace": json.RawMessage(`{"holders":[{"module":"mesh-build-go"}]}`),
"node-build-node.ace": json.RawMessage(`{"holders":[{"module":"mesh-build-node"}]}`),
"mesh-builds": json.RawMessage(`{"holders":[{"module":"mesh-delivery-builder"}]}`)}
var asked []string
ask := func(key string, body any) (json.RawMessage, error) {
asked = append(asked, key)
if strings.HasSuffix(key, "@g14") {
return nil, errors.New("no answer")
}
return json.RawMessage(`{"takes":true,"asks":[{"id":"a1","asker":"mesh-delivery-builder"}]}`), nil
}
tool := buildCurrentTool(func() []string { return []string{"node-build-go", "node-build-node"} }, func() (map[string]json.RawMessage, error) { return view, nil }, ask)
raw, err := tool.Run(map[string]any{})
a, _ := raw.(map[string]any)
hs, _ := a["holders"].([]heldBuildSeat)
if err != nil || fmt.Sprint(asked) != "[seat:node-build-go.current@ace seat:node-build-go.current@g14 seat:node-build-node.current@ace]" ||
len(hs) != 3 || hs[1].Error != "no answer" || hs[0].Module != "mesh-build-go" || !strings.Contains(string(hs[2].Current), `"a1"`) {
t.Errorf("asked %v, answered %+v (%v): want each holder asked in turn at its node, answered together, the silent one with why", asked, hs, err)
}
})
t.Run("drop and first record the hand act, then ask the builder", func(t *testing.T) {
var order []string
ask := func(key string, value []byte) (json.RawMessage, error) {
@@ -156,7 +156,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
"seat:go-package-registry.publish", "seat:go-package-registry.remove", "seat:go-package-registry.versions", "seat:mesh-artifact-sweep.held", "seat:mesh-builds.reserved", "seat:mesh-builds.drop", "seat:mesh-builds.publish-queue", "seat:mesh-catalog.versions", "seat:mesh-hand-acts.hand-act", "seat:mesh-module-assigner.assignments", "seat:mesh-watchdogs.presence", "seat:node-build-go.drop", "seat:node-build-image.drop", "seat:node-build-node.drop", "seat:node-build-go.answer", "seat:node-build-image.answer", "seat:node-build-node.answer", "seat:node-engine.manifest-reads", "seat:npm-package-registry.publish", "seat:npm-package-registry.remove",
"seat:npm-package-registry.versions", "seat:oci-artifact-registry.publish", "seat:oci-artifact-registry.remove", "seat:oci-artifact-registry.versions",
// A-231: the build asks on each build seat's queue delivery (accept.delivery.<asker>).
"seat:node-build-go.accept.delivery", "seat:node-build-node.accept.delivery", "seat:node-build-image.accept.delivery", "nats.nats_drop"}; !reflect.DeepEqual(sorted(m.Invokes), sorted(want)) {
"seat:node-build-go.accept.delivery", "seat:node-build-node.accept.delivery", "seat:node-build-image.accept.delivery", "nats.nats_drop", "seat:node-build-go.current", "seat:node-build-image.current", "seat:node-build-node.current"}; !reflect.DeepEqual(sorted(m.Invokes), sorted(want)) {
t.Errorf("invokes = %v, want %v", m.Invokes, want)
}
// The builder hears the build seats' toolchain-reported and the node-engine seat's running (design 47 G §492, §546) and reads no
@@ -185,7 +185,7 @@ func TestManifestDeclarations(t *testing.T) { // 1607/AC1
t.Errorf("secrets-owner = %q", m.SecretsOwner)
}
// 1945: the builder's tools (builder_seat_queue: note 62), served by its tools bundle, and the event it says when it asks an ask again.
if want := []string{"builder_announce_again", "builder_ask_again", "builder_ask_drop", "builder_asks", "builder_bounds", "builder_build", "builder_build_again", "builder_builds_since", "builder_engine_reads", "builder_first_view_again", "builder_first_views",
if want := []string{"build_current", "builder_announce_again", "builder_ask_again", "builder_ask_drop", "builder_asks", "builder_bounds", "builder_build", "builder_build_again", "builder_builds_since", "builder_engine_reads", "builder_first_view_again", "builder_first_views",
"builder_floor_again", "builder_floor_waits", "builder_health", "builder_old_form", "builder_publish_again", "builder_publish_queue", "builder_release", "builder_reserve_done", "builder_reserved", "builder_reserved_drop", "builder_seat_list", "builder_seat_list_again", "builder_seat_queue", "builder_stuck", "builder_toolchains", "builder_toolchains_drop", "builder_unbuildable", "builder_versions", "builder_waits"}; !reflect.DeepEqual(sorted(m.Tools), want) {
t.Errorf("tools = %v, want %v", m.Tools, want)
}
@@ -288,7 +288,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
}
// Design 47 H2 §793, H-A-454 (second addendum): the process runs on an account of its own, its bus naming the work queue
// publishes in queues and what it does on the bus: the module's emits, consumes and state, and its invokes but the verb
// publish-queue it serves; its credential is broker-builder.
// publish-queue it serves and the build seats' current build_current asks (§801); its credential is broker-builder.
bus, _ := p["bus"].(map[string]any)
var states []string
for _, st := range m.State {
@@ -296,7 +296,7 @@ func TestManifestProcess(t *testing.T) { // 1607/AC1
}
var invokes []string
for _, i := range m.Invokes {
if i != "seat:mesh-builds.publish-queue" {
if !slices.Contains([]string{"seat:mesh-builds.publish-queue", "seat:node-build-go.current", "seat:node-build-image.current", "seat:node-build-node.current"}, i) { // the tools bundle's
invokes = append(invokes, i)
}
}
+6 -2
View File
@@ -45,7 +45,8 @@
"builder_asks",
"builder_versions",
"builder_first_views",
"builder_first_view_again"
"builder_first_view_again",
"build_current"
],
"emits": [
"build.asked-again",
@@ -125,7 +126,10 @@
"seat:node-build-go.accept.delivery",
"seat:node-build-node.accept.delivery",
"seat:node-build-image.accept.delivery",
"nats.nats_drop"
"nats.nats_drop",
"seat:node-build-go.current",
"seat:node-build-image.current",
"seat:node-build-node.current"
],
"state": [
{ "name": "builds", "history": 5, "max-mib": 128 },