grants: compose and create each seat's one shared worker

The builder binds SEAT_MESH_BUILDS_worker and waits for the broker's part to make it, but the grants part made shared
workers only for seats pulled by kind, so no part made it and the seat's asks piled up unread. AskStreamsOf now keeps
the worker SeatQueue returns for every seat with an accept that is not pulled by kind; the grants principal carries
them, so AccountConsumers grants their create and the consumers pass creates them where the bus lacks them, leaving a
held one as it is and deleting none.

Builds: design 47 H2 H-A-468 (1)
This commit is contained in:
2026-11-22 11:33:53 +01:00
parent 0c3b9833cd
commit a85c9d4032
9 changed files with 101 additions and 6 deletions
+49
View File
@@ -291,6 +291,12 @@ func (g keptGate) Definitions() map[string]seatdef.Definition {
return map[string]seatdef.Definition{g.def.Seat: g.def}
}
// seatsGate is a seat list that has been read and holds these definitions.
type seatsGate map[string]seatdef.Definition
func (seatsGate) MayAct(...string) bool { return true }
func (g seatsGate) Definitions() map[string]seatdef.Definition { return g }
func newFakeBus() *fakeBus {
return &fakeBus{states: map[string]map[string][]byte{}, refused: map[string]bool{}, own: map[string]map[string][]byte{},
revs: map[string]uint64{}, refuseTo: map[string]bool{}}
@@ -2262,6 +2268,49 @@ func TestGrants(t *testing.T) {
}
})
// H-A-468 (design 47 H2): a seat with an accept that is not pulled by kind gets its one shared worker, SeatQueue's, made by
// the grants part where the bus lacks it (its holders bind it, never make it); a seat pulled by kind gets none (its
// per-queue workers are its holders' seat traffic's); a worker the bus holds is left as it is, and no pass deletes it.
t.Run("a seat's shared worker is made where the bus lacks it", func(t *testing.T) {
raw, err := os.ReadFile("module.json")
if err != nil {
t.Fatal(err)
}
b := fixture()
b.manifestOf("mesh-grants", string(raw))
b.assign("a", "mesh-grants")
b.loaded = shadowOf(t, b)
p := partOn(b)
p.Create, p.Consumers = b, b
p.SeatList = seatsGate{
"mesh-builds": {Seat: "mesh-builds", Accepts: []seatdef.Message{{Name: "step", AckWait: "2m", MaxDeliveries: 3}}},
"node-build-go": {Seat: "node-build-go", PulledByKind: true, Accepts: []seatdef.Message{{Name: "check"}}},
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
}
b.consumers = map[string][]map[string]any{"SEAT_MESH_WANTS": {{"name": "SEAT_MESH_WANTS_worker", "filters": []string{"mesh.seat.mesh-wants.accept.>"}, "max_deliver": 9}}}
res := p.Compose()
var made map[string]any
for _, c := range b.consumers["SEAT_MESH_BUILDS"] {
if c["name"] == "SEAT_MESH_BUILDS_worker" {
made = c
}
}
if made == nil || made["max_deliver"] != 3 || !slices.Equal(made["filters"].([]string), []string{"mesh.seat.mesh-builds.accept.>"}) ||
!slices.Contains(res.Consumers.Created, "SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker") {
t.Errorf("the builds seat's worker = %v (created %v)", made, res.Consumers.Created)
}
if strings.Contains(fmt.Sprint(b.consumerCreates), "SEAT_NODE_BUILD_GO_worker") {
t.Errorf("a seat pulled by kind got a shared worker: %v", b.consumerCreates)
}
if len(b.consumers["SEAT_MESH_WANTS"]) != 1 || b.consumers["SEAT_MESH_WANTS"][0]["max_deliver"] != 9 {
t.Errorf("the wants seat's held worker was changed: %v", b.consumers["SEAT_MESH_WANTS"])
}
p.Compose()
if len(b.consumers["SEAT_MESH_BUILDS"]) != 1 || len(b.consumers["SEAT_MESH_WANTS"]) != 1 {
t.Errorf("a pass changed the seats' workers: %v", b.consumers)
}
})
// 774 (ADR 0563 §2, §3): the node-engine's manifest (mesh-host) is placed on every node though no node is assigned it,
// so its declared state acts is created as a placed module's, and composed for the user list's create right.
t.Run("assertions: a held stream gains the subjects its manifest names, and loses, changes nothing else", func(t *testing.T) {
@@ -29,6 +29,8 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
}},
// The node-engine's own manifest, placed on every node though no node is assigned it (novox/hq ADR 0563 §2, §3).
Engine: &Declared{Module: EngineModule, State: []Bucket{{Module: EngineModule, Name: EngineActsState}}},
// A seat's one shared worker (H-A-468): the grants part makes it where the bus lacks it.
AskWorkers: []Consumer{{Name: "SEAT_MESH_BUILDS_worker", Stream: "SEAT_MESH_BUILDS", Filters: []string{"mesh.seat.mesh-builds.accept.>"}}},
}
users, err := Users(records)
if err != nil {
@@ -71,6 +73,8 @@ func theGrantsPartCreatesOnlyDeclaredStreams(t *testing.T) {
{GrantsModule, "$JS.API.STREAM.PURGE.KV_mesh-delivery-builder_steps", false},
{GrantsModule, "$JS.API.STREAM.CREATE.KV_mesh-delivery-builder_undeclared", false},
{GrantsModule, "$JS.API.STREAM.CREATE.EVENTS", false},
{GrantsModule, "$JS.API.CONSUMER.CREATE.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", true},
{GrantsModule, "$JS.API.CONSUMER.DELETE.SEAT_MESH_BUILDS.SEAT_MESH_BUILDS_worker", false},
{GrantsModule, "$JS.API.STREAM.CREATE.ASSIGNMENTS", false},
// Research 072 row 33: a runtime reads its membership from the grants part's state, never the assignments stream.
{"mesh-delivery-builder", "$JS.API.DIRECT.GET.ASSIGNMENTS.mesh.assignment.novox.mesh-delivery-builder", false},
@@ -299,6 +299,17 @@ func AccountConsumers(users []Principal) []ModuleConsumer {
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
}
}
// Each seat's one shared worker on its work queue (design 47 H2 H-A-468): its holders bind it and never make it, so the
// grants part makes it where the bus lacks it, as it makes the seat's stream.
for _, p := range users {
for _, c := range p.SeatWorkers {
if made[c.Stream+"."+c.Name] {
continue
}
made[c.Stream+"."+c.Name] = true
out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c})
}
}
return out
}
@@ -133,13 +133,17 @@ func SplitKept(kept []KeptEvent, consumes []string) (rest []string, hears []Hear
// a JetStream publish of an ask is answered by the bus. Before G the controller made these; a seat whose queues came with G
// (mesh-builds, mesh-wants) had none, so every ask to it timed out unanswered (lead-47, 2026-11-15). A seat whose
// settings SeatQueue refuses is named in refused and gets no stream. Sorted by stream.
func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamConfig, refused []string) {
//
// workers are the one shared worker SeatQueue names for each such seat that is not pulled by kind (design 47 H2 H-A-468):
// the grants part creates it where the bus lacks it, as it creates the seat's stream, for its holders bind it and never
// make it; a seat pulled by kind keeps its per-queue workers (SeatTrafficOf). Sorted by stream.
func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamConfig, workers []Consumer, refused []string) {
for _, name := range slices.Sorted(maps.Keys(defs)) {
d := defs[name]
if len(d.Accepts) == 0 || !safeSubject.MatchString(d.Seat) {
continue
}
st, _, ok, err := sdkbc.SeatQueue(d.Seat, d.Accepts)
st, w, ok, err := sdkbc.SeatQueue(d.Seat, d.Accepts)
if err != nil {
refused = append(refused, err.Error())
continue
@@ -151,7 +155,12 @@ func AskStreamsOf(defs map[string]seatdef.Definition) (out []jetstream.StreamCon
Retention: jetstream.WorkQueuePolicy, Storage: jetstream.FileStorage, Replicas: 1,
MaxAge: time.Duration(st.MaxAge) * time.Second, MaxMsgs: int64(st.MaxMsgs),
Duplicates: time.Duration(st.DuplicatesSeconds) * time.Second})
if !d.PulledByKind {
workers = append(workers, Consumer{Name: w.Name, Stream: w.Stream, Filters: slices.Clone(w.Filters),
AckWaitSeconds: w.AckWaitSeconds, MaxDeliver: w.MaxDeliver, MaxAckPending: w.MaxAckPending, Why: w.Why})
}
}
slices.SortFunc(out, func(a, b jetstream.StreamConfig) int { return strings.Compare(a.Name, b.Name) })
return out, refused
slices.SortFunc(workers, func(a, b Consumer) int { return strings.Compare(a.Stream, b.Stream) })
return out, workers, refused
}
@@ -308,6 +308,10 @@ type Principal struct {
// (novox/hq ADR 0561 §6): each placed module's on EVENTS and each process's on its work queue (AccountConsumers), by
// stream and name. Created only, never updated or deleted.
CreatesConsumers []ModuleConsumer
// SeatWorkers are the seats' shared workers the grants part's principal makes where the bus lacks them (Records'
// AskWorkers, design 47 H2 H-A-468): AccountConsumers names each as this principal's, so it is granted and created
// as an account consumer is, never deleted by a pass.
SeatWorkers []Consumer
// Login is a node principal's login when it is not `node.<n>`: its second login, `node.<n>--b`, composed beside or
// in place of the first as the vault's node-logins says (novox/hq ADR 0583 §1, issue 774). Each login is granted
@@ -178,6 +178,9 @@ type Records struct {
Kept []KeptEvent
// AskStreams are the seats' ask streams the grants part makes where the bus lacks them (AskStreamsOf), each its to create.
AskStreams []string
// AskWorkers are the seats' shared workers the grants part makes where the bus lacks them (AskStreamsOf's workers,
// design 47 H2 H-A-468), each its to create.
AskWorkers []Consumer
// Chunked is every verb the seat definitions say sends chunks (chunks.go, design 47 G §681): their subjects are granted to the
// principal that answers the verb and to an account naming it in `invokes`.
Chunked []ChunkVerb
@@ -365,6 +368,7 @@ func Users(r Records) ([]Principal, error) {
}
if d.Module == GrantsModule {
out[len(out)-1].CreatesStreams = declaredStreamsOf(r)
out[len(out)-1].SeatWorkers = r.AskWorkers
grants = len(out) - 1
}
// **The vault's holder asks the desks and the issuing providers itself** (issue 723), under the
@@ -37,8 +37,20 @@ func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) {
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
"git": {Seat: "git"},
"two-ways": {Seat: "two-ways", Accepts: []seatdef.Message{{Name: "a", MaxAge: "1h"}, {Name: "b", MaxAge: "2h"}}},
"node-build": {Seat: "node-build", PulledByKind: true, Accepts: []seatdef.Message{{Name: "check"}}},
}
asks, refused := buscompose.AskStreamsOf(defs)
asks, workers, refused := buscompose.AskStreamsOf(defs)
// Each seat that accepts work and is not pulled by kind has its one shared worker, SeatQueue's (H-A-468); the seat pulled
// by kind has its stream and no shared worker.
if len(workers) != 2 || workers[0].Name != "SEAT_MESH_BUILDS_worker" || workers[0].Stream != "SEAT_MESH_BUILDS" ||
!slices.Equal(workers[0].Filters, []string{"mesh.seat.mesh-builds.accept.>"}) || workers[0].MaxDeliver != 5 ||
workers[0].AckWaitSeconds != 60 || workers[1].Name != "SEAT_MESH_WANTS_worker" {
t.Errorf("workers = %+v", workers)
}
if len(asks) != 3 || asks[2].Name != "SEAT_NODE_BUILD" {
t.Fatalf("ask streams = %+v", asks)
}
asks = asks[:2]
if len(asks) != 2 || asks[0].Name != "SEAT_MESH_BUILDS" || asks[0].Retention != jetstream.WorkQueuePolicy ||
!slices.Equal(asks[0].Subjects, []string{"mesh.seat.mesh-builds.accept.>"}) || asks[0].MaxAge != 24*time.Hour ||
asks[0].MaxMsgs != 10000 || asks[0].Duplicates != 2*time.Minute || asks[1].MaxAge != 7*24*time.Hour {
@@ -193,6 +193,8 @@ type Inputs struct {
Kept []buscompose.KeptEvent
// AskStreams are the seats' ask streams (buscompose.AskStreamsOf), made where the bus lacks them.
AskStreams []jetstream.StreamConfig
// AskWorkers are the seats' shared workers (buscompose.AskStreamsOf), made where the bus lacks them (H-A-468).
AskWorkers []buscompose.Consumer
// Chunked is every verb the seat list says sends its answer's file in chunks (design 47 G §681): the part grants their subjects.
Chunked []buscompose.ChunkVerb
// EventSubjects are, by seat, the subjects of its events that carry parts, by the event's local name, as the definitions
@@ -386,7 +388,7 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
if d, ok := gate.(SeatDefinitions); ok {
in.Kept = buscompose.KeptEventsOf(d.Definitions())
var refused []string
in.AskStreams, refused = buscompose.AskStreamsOf(d.Definitions())
in.AskStreams, in.AskWorkers, refused = buscompose.AskStreamsOf(d.Definitions())
for _, why := range refused {
in.Gaps = append(in.Gaps, Gap{Input: "seat work queues", Why: why})
}
@@ -46,7 +46,7 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) {
out := buscompose.Records{Assigned: map[string][]buscompose.Declared{}, People: map[string][]string{},
Interchangeable: map[string]bool{}, Enrolling: slices.Clone(in.Enrolling),
// And each node's logins (ADR 0583 §1): both while it rotates.
NodeLogins: in.NodeLogins, Kept: in.Kept, AskStreams: askStreamNames(in.AskStreams), Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat],
NodeLogins: in.NodeLogins, Kept: in.Kept, AskStreams: askStreamNames(in.AskStreams), AskWorkers: in.AskWorkers, Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat],
// What the bus module's process may define: every manifest's bus state, and what it said it created (DLV-G2).
BusState: map[string][]catalogue.BusStateEntry{}, Bound: in.Bound,
// Each node's capability reading and what each node-engine said running (design 46 approval mark §6).