grants: make each seat's ask stream the bus lacks, from the seat list
The pipeline runner's step ask to mesh-builds timed out: it publishes on the seat's accept subject through JetStream and no stream held mesh.seat.mesh-builds.accept.>. Before G the controller made SEAT_<SEAT> for every seat that accepts work; the seats whose queues came with G (mesh-builds, mesh-wants) had none. The grants part now makes each such stream, from the seat list, at every pass, as it makes the seats' kept-event streams: only where the bus holds none.
This commit is contained in:
@@ -124,3 +124,28 @@ func SplitKept(kept []KeptEvent, consumes []string) (rest []string, hears []Hear
|
||||
}
|
||||
return rest, hears
|
||||
}
|
||||
|
||||
// AskStreamsOf is the work-queue stream of each seat of the seat list that accepts work (SeatStreams' rule, design 47 G §544):
|
||||
// `SEAT_<SEAT>` on `mesh.seat.<seat>.accept.>`, kept seven days, so an ask is held until one holder takes it, and 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). Sorted by stream.
|
||||
func AskStreamsOf(defs map[string]seatdef.Definition) []jetstream.StreamConfig {
|
||||
var seats []DeclaredSeat
|
||||
for _, d := range defs {
|
||||
if len(d.Accepts) == 0 || !safeSubject.MatchString(d.Seat) {
|
||||
continue
|
||||
}
|
||||
var accepts []string
|
||||
for _, a := range d.Accepts {
|
||||
accepts = append(accepts, a.Name)
|
||||
}
|
||||
seats = append(seats, DeclaredSeat{Name: d.Seat, Accepts: accepts})
|
||||
}
|
||||
var out []jetstream.StreamConfig
|
||||
for _, st := range SeatStreams(seats) {
|
||||
out = append(out, jetstream.StreamConfig{Name: st.Name, Description: st.Why, Subjects: st.Subjects,
|
||||
Retention: jetstream.WorkQueuePolicy, Storage: jetstream.FileStorage, Replicas: 1,
|
||||
MaxAge: time.Duration(st.MaxAge) * time.Second})
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/seatdef"
|
||||
|
||||
"mesh-grants/internal/buscompose"
|
||||
)
|
||||
|
||||
type askCreator struct{ made []string }
|
||||
|
||||
func (c *askCreator) CreateDeclared(cfg jetstream.StreamConfig) error {
|
||||
c.made = append(c.made, cfg.Name+" "+cfg.Subjects[0])
|
||||
return nil
|
||||
}
|
||||
func (c *askCreator) AddSubjects(string, []string) error { return nil }
|
||||
func (c *askCreator) RaiseMaxBytes(string, int64) (int64, bool, error) {
|
||||
return 0, false, nil
|
||||
}
|
||||
|
||||
// A seat whose queues came with G (mesh-builds) gets its work-queue ask stream from the seat list, as the controller made one for
|
||||
// every seat before G; a seat that accepts nothing gets none, and a stream the bus holds is never made again (lead-47, 2026-11-15).
|
||||
func TestEachSeatThatAcceptsWorkHasItsAskStream(t *testing.T) {
|
||||
defs := map[string]seatdef.Definition{
|
||||
"mesh-builds": {Seat: "mesh-builds", Accepts: []seatdef.Message{{Name: "step"}}},
|
||||
"mesh-wants": {Seat: "mesh-wants", Accepts: []seatdef.Message{{Name: "step"}}},
|
||||
"git": {Seat: "git"},
|
||||
}
|
||||
asks := buscompose.AskStreamsOf(defs)
|
||||
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 == 0 {
|
||||
t.Fatalf("ask streams = %+v", asks)
|
||||
}
|
||||
c := &askCreator{}
|
||||
made, notMade := createAskStreams(c, &creations{}, asks, map[string]Limits{"SEAT_MESH_WANTS": {}}, false)
|
||||
if !slices.Equal(made, []string{"SEAT_MESH_BUILDS"}) || len(notMade) != 0 ||
|
||||
!slices.Equal(c.made, []string{"SEAT_MESH_BUILDS mesh.seat.mesh-builds.accept.>"}) {
|
||||
t.Errorf("made %v (not %v), created %v: want only the builds seat's, the wants seat's being held", made, notMade, c.made)
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -192,6 +194,8 @@ type Inputs struct {
|
||||
// Kept is every seat event the seat list says is kept in a stream of its own (buscompose.KeptEventsOf): the part makes
|
||||
// each stream and each hearing module's durable on it. Empty while the list is unread.
|
||||
Kept []buscompose.KeptEvent
|
||||
// AskStreams are the seats' ask streams (buscompose.AskStreamsOf), made where the bus lacks them.
|
||||
AskStreams []jetstream.StreamConfig
|
||||
// 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
|
||||
@@ -388,6 +392,7 @@ func ReadInputs(r Reader, cache *Manifests) Inputs {
|
||||
// consumer only gains filters, so one made with such an event's subject on EVENTS would keep it).
|
||||
if d, ok := gate.(SeatDefinitions); ok {
|
||||
in.Kept = buscompose.KeptEventsOf(d.Definitions())
|
||||
in.AskStreams = buscompose.AskStreamsOf(d.Definitions())
|
||||
in.Chunked = buscompose.ChunkVerbsOf(d.Definitions())
|
||||
in.EventSubjects = eventSubjectsOf(d.Definitions())
|
||||
in.AcceptCallers = acceptCallersOf(d.Definitions())
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package grants
|
||||
|
||||
import (
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
@@ -187,3 +189,27 @@ func withVerbCallers(callers map[string]map[string][]string, d *buscompose.Decla
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// createAskStreams makes each seat's ask stream the bus lacks (buscompose.AskStreamsOf), as createKept makes a kept event's: only
|
||||
// where the bus was read and holds no stream of that name, never changed where it holds one.
|
||||
func createAskStreams(c Creator, done *creations, asks []jetstream.StreamConfig, held map[string]Limits, force bool) (made, notMade []string) {
|
||||
for _, cfg := range asks {
|
||||
if _, ok := held[cfg.Name]; ok {
|
||||
continue
|
||||
}
|
||||
digest := strings.Join(cfg.Subjects, " ")
|
||||
if !force && done.madeAt(cfg.Name) == digest {
|
||||
notMade = append(notMade, cfg.Name+": made at this definition and gone since; grants_assert makes it again")
|
||||
continue
|
||||
}
|
||||
switch err := c.CreateDeclared(cfg); {
|
||||
case err == nil:
|
||||
done.keep(cfg.Name, digest)
|
||||
made = append(made, cfg.Name)
|
||||
case errors.Is(err, ErrHeld):
|
||||
default:
|
||||
notMade = append(notMade, cfg.Name+": "+err.Error()+" (tried again at the next event)")
|
||||
}
|
||||
}
|
||||
return made, notMade
|
||||
}
|
||||
|
||||
@@ -569,6 +569,17 @@ func (p *Part) Compose() Result {
|
||||
for _, why := range notMade {
|
||||
res.NotAsserted = append(res.NotAsserted, "kept event "+why)
|
||||
}
|
||||
made, notMade = createAskStreams(p.Create, &p.made, in.AskStreams, held, forced != "")
|
||||
if len(made) > 0 {
|
||||
res.Asserted = append(res.Asserted, "the seats' ask streams: created "+strings.Join(made, ", "))
|
||||
p.say(&res, EventAsserted, map[string]any{"module": Module, "created": made})
|
||||
if p.Logf != nil {
|
||||
p.Logf("the seats' ask streams the bus lacked are created: %s", strings.Join(made, ", "))
|
||||
}
|
||||
}
|
||||
for _, why := range notMade {
|
||||
res.NotAsserted = append(res.NotAsserted, "ask stream "+why)
|
||||
}
|
||||
}
|
||||
createRefused := false
|
||||
for _, module := range sortedKeys(in.Manifests) {
|
||||
|
||||
Reference in New Issue
Block a user