mesh-grants: named asks stay in use while a held membership publishes one (A-413)

Builds: design 47 G §544, A-413, A-231
This commit is contained in:
2026-11-15 00:11:16 +01:00
parent 9eb143ab6c
commit c636642864
4 changed files with 77 additions and 2 deletions
@@ -127,6 +127,10 @@ type resolved struct {
// Inputs is what the shadow composes from, read from the bus.
type Inputs struct {
// CarriedNamedAsks says a membership held in the part's own state (composed, or carried over from the last published for
// a module the pass cannot compose) grants a named ask of a build seat's queue, `mesh.seat.<seat>.accept.<queue>.<asker>`
// (A-413); set once per pass by withCarriedNamedAsks.
CarriedNamedAsks bool
// Nodes is every machine seen: in a node agent's have or the assignments.
Nodes []string
// Assigned is what the seat's assignments puts on each machine, sorted (issue 774: never the controller's assignments).
@@ -4,9 +4,11 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/membership"
"mesh-grants/internal/buscompose"
)
@@ -30,7 +32,7 @@ type NamedPurger interface {
// NamedAsksUnused says the revision the part composes from holds entries and none invokes a queue of a build seat
// (catalogue.QueueInvoke); false while the catalog half is not read, so a failed read purges nothing.
func NamedAsksUnused(in Inputs) bool {
if in.CatalogUnread != "" || len(in.Manifests) == 0 {
if in.CatalogUnread != "" || len(in.Manifests) == 0 || in.CarriedNamedAsks {
return false
}
for _, m := range in.Manifests {
@@ -119,3 +121,46 @@ func (p *Part) AskNamedPurge(caller, why string, record func(what, why string) e
}
return map[string]any{"asked": rev, "says": "the part's process purges the named asks and deletes the named workers at this ask; its journal names each"}, nil
}
// NamedAskPublish says a seat-traffic publish subject is a named ask of a queue, `mesh.seat.<seat>.accept.<queue>.<asker>`: five
// or more tokens with `accept` the fourth; main's `accept.<queue>` has four.
func NamedAskPublish(subject string) bool {
t := strings.Split(subject, ".")
return len(t) >= 6 && t[0] == "mesh" && t[1] == "seat" && t[3] == "accept"
}
// withCarriedNamedAsks reads the memberships the part holds in its own state, which it publishes (composed in this pass or
// carried over for a module it cannot compose) and sets Inputs.CarriedNamedAsks where one grants a named ask (A-413). An
// unreadable state sets it, so a failed read purges nothing.
func (p *Part) withCarriedNamedAsks(in *Inputs) {
if p.Store == nil {
return
}
keys, err := p.Store.Keys(StateMemberships)
if err != nil {
in.CarriedNamedAsks = true
return
}
for _, k := range keys {
raw, _, found, err := p.Store.Get(StateMemberships, k)
if err != nil {
in.CarriedNamedAsks = true
return
}
if !found {
continue
}
bare, err := membership.BareGrantsMembership(raw)
if err != nil {
continue
}
var m membership.Membership
if json.Unmarshal(bare, &m) != nil || m.SeatTraffic == nil {
continue
}
if slices.ContainsFunc(m.SeatTraffic.Publish, NamedAskPublish) {
in.CarriedNamedAsks = true
return
}
}
}
@@ -3,9 +3,11 @@ package grants
import (
"errors"
"slices"
"strings"
"testing"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/membership"
"mesh-grants/internal/buscompose"
)
@@ -32,7 +34,15 @@ func (m memStore) Put(state, key string, value []byte) (uint64, error) {
m[state+"/"+key] = value
return uint64(len(m)), nil
}
func (m memStore) Keys(string) ([]string, error) { return nil, nil }
func (m memStore) Keys(state string) ([]string, error) {
var out []string
for k := range m {
if rest, ok := strings.CutPrefix(k, state+"/"); ok {
out = append(out, rest)
}
}
return out, nil
}
func (m memStore) Delete(state, key string) error { delete(m, state+"/"+key); return nil }
// Design 47 G §544, A-231: at the first revision in which no entry invokes a queue of a build seat the part purges each
@@ -97,6 +107,21 @@ func TestTheNamedAsksArePurgedAtTheFirstRevisionThatLeavesThem(t *testing.T) {
t.Errorf("granted %v: purged %v", c.granted, purgedNow)
}
}
// A-413: a membership held in the part's state (carried over for a module it cannot compose) that publishes a named ask keeps
// the named workers; main's own `accept.<queue>` does not.
for _, c := range []struct {
publish string
kept bool
}{{"mesh.seat.node-build-go.accept.delivery.mesh-builds", true}, {"mesh.seat.node-build-go.accept.delivery", false}} {
st := memStore{}
st.Put(StateMemberships, "shanks.mesh-delivery-builder", membership.EncodeGrantsMembership(membership.Membership{Node: "shanks", Module: "mesh-delivery-builder",
SeatTraffic: &membership.SeatTraffic{Publish: []string{c.publish}}}))
cin := unused
(&Part{Store: st}).withCarriedNamedAsks(&cin)
if NamedAsksUnused(cin) == c.kept {
t.Errorf("carried publish %s: unused = %v", c.publish, NamedAsksUnused(cin))
}
}
// The hand tool: nothing is asked when the hand act is not recorded; once it is, the process purges at its ask.
if _, err := p.AskNamedPurge("jochen@shanks", "the part stopped first", func(string, string) error { return errors.New("down") }); err == nil {
t.Error("asked though the hand act was not recorded")
@@ -339,6 +339,7 @@ func (p *Part) Compose() Result {
if err := p.withKeptNames(&in); err != nil {
res.Errors = append(res.Errors, err.Error())
}
p.withCarriedNamedAsks(&in)
for _, g := range in.Refused {
res.Refused = append(res.Refused, g.Input+": "+g.Why)
}