From cecf4142e695f7eb3d445b29179cd4f772694ec4 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 02:56:51 +0100 Subject: [PATCH 1/9] DC2 branches-adopt-before-start: NewBranches adopts the catalog-revision event before the reader's Start MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a process reader NewBranches registers the seat mesh-catalog's catalog-revision event (AdoptEvent) before the reader's Start, so a branch first followed after Start adopts its view on a subscription the hub already holds and no first adopt of the event comes later; the hub refuses a pattern first registered after Start. A row in the branch follower's test starts a refusing hub before the branches come. Builds: design 47 H2b §836 3., H-A-854, H-A-861 --- .../go/clients/meshcatalogclient/branches.go | 16 +++++++++ .../meshcatalogclient/branches_test.go | 33 ++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches.go b/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches.go index 56b3b122e..7ee99a33b 100644 --- a/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches.go +++ b/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches.go @@ -48,6 +48,12 @@ func (w processWiring) Adopt(f *views.Follower, seat, event string, hear func(co } func (w processWiring) Drop(owner, state string) error { return w.r.Drop(owner, state) } +// AdoptEvent registers a seat's event on the process reader before its Start, with a handler that has nothing to do: the +// event's one subscription is made at Start and every follower adopted on it later shares it (design 47 H2b §836 3.). +func (w processWiring) AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error { + return w.r.AdoptEvent(seat, event, hear) +} + // ReaderWiring wires Branches on a bundle's reader. func ReaderWiring(r *views.Reader) Wiring { return readerWiring{r} } @@ -100,6 +106,16 @@ func NewBranches(w Wiring, call Call) (*Branches, error) { b.Registrations.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { b.reconcile() } b.source = sourcebranches.New(sourcebranches.Call(call)) b.source.Follower.Changed = func(string, json.RawMessage, bool, time.Time) { b.reconcile() } + // The event of a branch's view is registered here, before the reader's Start: the hub refuses a pattern first + // registered after Start (design 47 H2b §836 3.; H-A-854, H-A-861), and a branch first followed later adopts its view on + // this one subscription (a wiring that has no hub to refuse, a bundle's reader, subscribes it at its own Start). + if ew, ok := w.(interface { + AdoptEvent(seat, event string, hear func(context.Context, []byte) error) error + }); ok { + if err := ew.AdoptEvent(seat.Seat, seat.EventCatalogRevision, func(context.Context, []byte) error { return nil }); err != nil { + return nil, err + } + } if err := w.Adopt(b.Registrations.Follower, seat.Seat, seat.EventRegistrationChanged, b.hearRegistration); err != nil { return nil, err } diff --git a/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches_test.go b/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches_test.go index ed5911801..f75aba827 100644 --- a/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches_test.go +++ b/modules/mesh-delivery-contracts/go/clients/meshcatalogclient/branches_test.go @@ -28,6 +28,29 @@ type fakeWiring struct { follows []string values map[string]map[string]json.RawMessage followed chan string + // events are the seat events adopted, by `.`; started says the hub has started: it refuses an event + // adopted for the first time after that (design 47 H2b §836 3.). + events map[string]bool + started bool +} + +// AdoptEvent is the process reader's AdoptEvent: the event is heard on the one subscription the followers on it share. +func (w *fakeWiring) AdoptEvent(seat, event string, _ func(context.Context, []byte) error) error { + w.mu.Lock() + defer w.mu.Unlock() + return w.eventLocked(seat, event) +} + +func (w *fakeWiring) eventLocked(seat, event string) error { + name := seat + "." + event + if w.events == nil { + w.events = map[string]bool{} + } + if !w.events[name] && w.started { + return fmt.Errorf("the pattern %s is registered after Start", name) + } + w.events[name] = true + return nil } func (w *fakeWiring) Follow(owner, state, tool string) (func() map[string]json.RawMessage, error) { @@ -46,9 +69,12 @@ func (w *fakeWiring) Follow(owner, state, tool string) (func() map[string]json.R }, nil } -func (w *fakeWiring) Adopt(f *views.Follower, _, _ string, hear func(context.Context, []byte) error) error { +func (w *fakeWiring) Adopt(f *views.Follower, seat, event string, hear func(context.Context, []byte) error) error { w.mu.Lock() defer w.mu.Unlock() + if err := w.eventLocked(seat, event); err != nil { + return err + } name := f.Owner + "." + f.State if w.adopted[name] != nil { return fmt.Errorf("%s is followed already", name) @@ -164,6 +190,11 @@ func TestBranchesFollowSourceThenRegistrations(t *testing.T) { t.Fatal(err) } b.Logf = func(format string, args ...any) { said <- fmt.Sprintf(format, args...) } + // design 47 H2b §836 3. (H-A-854, H-A-861): the hub is started now and refuses a pattern first registered after it, + // so a branch followed from here on hears its catalog-revision only if NewBranches adopted the event before. + w.mu.Lock() + w.started = true + w.mu.Unlock() adopted := make(chan string, 8) b.Adopted = func(branch string, c *Catalog) { if c.Branch == branch { From f05fb8ab556d01fb4d8410462c0a89fd67829813 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 02:58:04 +0100 Subject: [PATCH 2/9] G1 durables-composed: the grants part says durables-composed for each module whose durables a pass composed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After a pass's last durable the part says the seat mesh-grants' event durables-composed.. once for each module whose durable the pass created or gave filters, naming each durable with its stream, and none for a pass that composed none. Rows in the account-consumer subtests of TestGrants. Builds: design 47 H2b §836 2. --- modules/mesh-grants/grants_test.go | 33 ++++++++++++++++++- .../mesh-grants/internal/grants/consumers.go | 32 ++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index b269dbbae..0d4e229cd 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -66,6 +66,8 @@ type fakeBus struct { events []string // seatEvents are the seat events said, as seat.event. seatEvents []string + // seatBodies are the bodies of the seat events said, in the same order. + seatBodies []any writes []string // Each membership's subject: the last membership said there, every notice, and whether it is refused. stream map[string][]byte @@ -485,13 +487,27 @@ func (b *fakeBus) Emit(event string, _ any) error { return nil } -func (b *fakeBus) EmitSeat(seat, event string, _ any) error { +func (b *fakeBus) EmitSeat(seat, event string, body any) error { b.mu.Lock() defer b.mu.Unlock() b.seatEvents = append(b.seatEvents, seat+"."+event) + b.seatBodies = append(b.seatBodies, body) return nil } +// composedSaid are the durables-composed events the part said, with their bodies. +func composedSaid(b *fakeBus) []meshgrants.DurablesComposed { + b.mu.Lock() + defer b.mu.Unlock() + var out []meshgrants.DurablesComposed + for i, e := range b.seatEvents { + if strings.HasPrefix(e, "mesh-grants."+meshgrants.EventDurablesComposed+".") { + out = append(out, b.seatBodies[i].(meshgrants.DurablesComposed)) + } + } + return out +} + func (b *fakeBus) count(key string) int { b.mu.Lock() defer b.mu.Unlock() @@ -2437,7 +2453,14 @@ func TestGrants(t *testing.T) { len(res.Consumers.Matched) != 1 { t.Fatalf("filters added %v, now %v, said %+v", b.filterAdds, b.consumers["EVENTS"], res.Consumers) } + // 1984/AC-836k: filters added to a held durable are a composed durable too, said once for its module. + if got := composedSaid(b); len(got) != 1 || got[0].Module != "mod-c" || got[0].Durables[0].Name != "b_mod-c" { + t.Errorf("durables-composed said %+v after filters were added", got) + } p.Compose() + if got := composedSaid(b); len(got) != 1 { + t.Errorf("a pass that added no filter said durables-composed again: %+v", got) + } if len(b.filterAdds) != 1 { t.Errorf("a consumer that holds every filter was added to again: %v", b.filterAdds) } @@ -4230,10 +4253,18 @@ func TestGrants(t *testing.T) { if made == nil || made["max_deliver"] != 5 || !slices.Contains(made["filters"].([]string), "mesh.mod.mod-y.event.done") { t.Errorf("b_mod-c was made as %v, not as the controller makes it", made) } + // 1984/AC-836k (design 47 H2b §836 2.): the pass that made the durable says durables-composed once, naming it. + if got := composedSaid(b); len(got) != 1 || got[0].Node != "b" || got[0].Module != "mod-c" || + len(got[0].Durables) != 1 || got[0].Durables[0].Name != "b_mod-c" || got[0].Durables[0].Stream != "EVENTS" { + t.Errorf("durables-composed said %+v, want one for b mod-c naming EVENTS b_mod-c", got) + } res = p.Compose() if len(res.Consumers.Created) != 0 || len(res.Consumers.Missing) != 0 || len(b.consumerCreates) != 1 { t.Errorf("a consumer the bus holds was asked again: %+v, %v", res.Consumers, b.consumerCreates) } + if got := composedSaid(b); len(got) != 1 { + t.Errorf("a pass that composed no durable said durables-composed again: %+v", got) + } // A held consumer that differs is never changed by a pass: it is raised as a condition naming it, and brought to // the composed configuration only by hand (grants_consumer_match), with no lease key too. var said, behind, orphaned []oc.Condition diff --git a/modules/mesh-grants/internal/grants/consumers.go b/modules/mesh-grants/internal/grants/consumers.go index e3bce4317..3f517bbeb 100644 --- a/modules/mesh-grants/internal/grants/consumers.go +++ b/modules/mesh-grants/internal/grants/consumers.go @@ -14,6 +14,8 @@ import ( "github.com/nats-io/nats.go/jetstream" + "git.novox.be/novox/mesh-contracts/identity-and-access/go/seats/meshgrants" + occ "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/clients/operatorchannelclient" oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel" "mesh-grants/internal/buscompose" @@ -231,8 +233,19 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) { defer func() { p.behindSeen = seen }() var orphans []string byStream := map[string][]buscompose.Consumer{} + ownerOf := map[string]buscompose.ModuleConsumer{} // the module and node of each composed durable, by `.` for _, mc := range wanted { byStream[mc.Consumer.Stream] = append(byStream[mc.Consumer.Stream], mc.Consumer) + ownerOf[mc.Consumer.Stream+"."+mc.Consumer.Name] = mc + } + // composedOf are the durables this pass created or gave filters, per module and node: each module's are said once, + // after the pass's last durable (design 47 H2b §836 2.). + composedOf := map[string][]meshgrants.DurablesComposedDurablesItem{} + composedAt := func(stream, name string) { + if mc, ok := ownerOf[stream+"."+name]; ok { + k := mc.Node + "\x00" + mc.Module + composedOf[k] = append(composedOf[k], meshgrants.DurablesComposedDurablesItem{Name: name, Stream: stream}) + } } // The durables no pass composes, the tool runner's twins it makes itself from the membership's spec and the plain one of a // module whose program left, are still judged here, held on the streams each consuming module's heard entries name @@ -304,6 +317,7 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) { p.Logf("consumer %s gained the filters %s", key, strings.Join(add, ", ")) } p.say(res, EventAsserted, map[string]any{"consumer": c.Name, "stream": stream, "filters-added": add}) + composedAt(stream, c.Name) h.Filters = append(slices.Clone(h.Filters), add...) } } @@ -335,6 +349,7 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) { p.Logf("consumer %s created", key) } p.say(res, EventAsserted, map[string]any{"consumer": c.Name, "stream": stream}) + composedAt(stream, c.Name) case errors.Is(err, ErrHeld): default: st.Missing = append(st.Missing, key) @@ -349,11 +364,28 @@ func (p *Part) consumers(res *Result, recs buscompose.Records, match string) { } } } + p.sayDurablesComposed(res, composedOf) p.sayDiffer(st) p.sayBehind(st) p.sayOrphaned(orphans) } +// sayDurablesComposed says the seat's event durables-composed once for each module and node whose durables the pass +// created or gave filters, after the pass's last durable, so a module's event hub binds a stream it could not bind at its +// start (design 47 H2b §836 2.). A pass that composed none of a module's says none, whether its membership changed or not. +func (p *Part) sayDurablesComposed(res *Result, composedOf map[string][]meshgrants.DurablesComposedDurablesItem) { + if p.Emit == nil { + return + } + for _, k := range sortedKeys(composedOf) { + node, module, _ := strings.Cut(k, "\x00") + body := meshgrants.DurablesComposed{At: p.now(), Durables: composedOf[k], Module: module, Node: node} + if err := p.Emit.EmitSeat(meshgrants.Seat, meshgrants.EventDurablesComposed+"."+node+"."+module, body); err != nil { + res.Errors = append(res.Errors, fmt.Sprintf("the seat event %s of %s on %s could not be said: %v", meshgrants.EventDurablesComposed, module, node, err)) + } + } +} + // sayDiffer raises the warning condition mesh-grants.consumer-differs while an account consumer the part owns (from the // controller's end) differs from its composed configuration, naming each with the fields that differ, and clears it when // they match. Said once per set of differences, again when it changes. From aef199cb832dfc231b794ed144cd2700ccd5def0 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 02:59:25 +0100 Subject: [PATCH 3/9] G2 keeper-kept-durables: the bus module's process gets a heard durable on each kept stream its module consumes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bus module's process (the keeper) gets, beside its consumer on EVENTS, a durable on each kept seat event's stream that carries a consume of its module, named as its durable on EVENTS, and the grants to read and acknowledge it as any process's heard durable has. Row in TestAProcessBusHearsWhatItsModuleConsumes. Builds: design 47 H2b §836 5. --- .../internal/buscompose/derived.go | 5 ++++ .../internal/buscompose/process_grants.go | 1 + .../mesh-grants/internal/buscompose/users.go | 3 ++ .../internal/grants/processbus_test.go | 28 +++++++++++++++++-- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/mesh-grants/internal/buscompose/derived.go b/modules/mesh-grants/internal/buscompose/derived.go index cd71b54ea..79b29f8a8 100644 --- a/modules/mesh-grants/internal/buscompose/derived.go +++ b/modules/mesh-grants/internal/buscompose/derived.go @@ -229,6 +229,11 @@ func ConsumersOf(users []Principal) []ModuleConsumer { if c, ok := keeperConsumer(p); ok { out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: c}) } + for _, h := range p.Hears { + if len(h.Filters) > 0 { + out = append(out, ModuleConsumer{Node: p.Node, Module: p.Module, Consumer: heardConsumer(p, h)}) + } + } } // Any other process hears what its bus consumes on consumers of its own: on EVENTS, and on each kept seat event's // stream (design 47 G A-340). diff --git a/modules/mesh-grants/internal/buscompose/process_grants.go b/modules/mesh-grants/internal/buscompose/process_grants.go index 27b6f79a2..31b239eee 100644 --- a/modules/mesh-grants/internal/buscompose/process_grants.go +++ b/modules/mesh-grants/internal/buscompose/process_grants.go @@ -126,6 +126,7 @@ func processGrants(p Principal) (pub, sub []string, err error) { if c, ok := keeperConsumer(p); ok { pub = append(pub, keeperConsumerGrants(c)...) } + pub = append(pub, heardGrants(p, p.Hears)...) // and its heard durable on each kept stream its module consumes (design 47 H2b §836 5.) pub = append(pub, ownStreamGrants(p.Module, p.Streams)...) pub = append(pub, p.SaysSeatEvents...) tp, ts := seatTrafficGrants(SeatTrafficOf(p.Module, nil, p.Uses, nil)) diff --git a/modules/mesh-grants/internal/buscompose/users.go b/modules/mesh-grants/internal/buscompose/users.go index 949947106..7ccd2876b 100644 --- a/modules/mesh-grants/internal/buscompose/users.go +++ b/modules/mesh-grants/internal/buscompose/users.go @@ -325,6 +325,9 @@ func Users(r Records) ([]Principal, error) { k.KeepsBus, k.KeepsBusState = true, BusStateNames(r.BusState, r.Bound) k.KeepsRestricted = restrictedStreamNames(r) k.Consumes, k.Streams = d.Consumes, d.Streams + // A kept seat event its module consumes is heard on the event's own stream, as every other process hears one + // (design 47 H2b §836 5.): its heard durable, named as its durable on EVENTS. + _, k.Hears = SplitKept(r.Kept, d.Consumes) k.Watches = d.Watches k.SaysSeatEvents = brokerSeatEvents(d.Holds) } diff --git a/modules/mesh-grants/internal/grants/processbus_test.go b/modules/mesh-grants/internal/grants/processbus_test.go index e1fc76fa7..f479f7f65 100644 --- a/modules/mesh-grants/internal/grants/processbus_test.go +++ b/modules/mesh-grants/internal/grants/processbus_test.go @@ -2,6 +2,7 @@ package grants import ( "encoding/json" + "slices" "strings" "testing" @@ -62,8 +63,12 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) { } const stream, subject = "SEAT_mesh-conditions_findings-asked", "mesh.seat.mesh-conditions.event.findings-asked" users, err := buscompose.Users(buscompose.Records{Nodes: []string{"ace"}, - Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}}, - Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)}}}}) + Kept: []buscompose.KeptEvent{{Seat: "mesh-conditions", Event: "findings-asked", Stream: stream, Filter: subject}}, + Assigned: map[string][]buscompose.Declared{"ace": {{Module: "zfs", Consumes: m.Consumes, Processes: processesOf(m)}, + // 1984/AC-836l (design 47 H2b §836 5.): the bus module's process hears what its module consumes of a kept seat event on + // the event's stream too, on a durable named as its durable on EVENTS. + {Module: "nats", SnapshotsTheBus: true, Consumes: []string{"mesh-conditions.findings-asked"}, + Processes: []buscompose.ProcessPrincipal{{Process: "bus-keeper", Keeps: true}}}}}}) if err != nil { t.Fatal(err) } @@ -86,6 +91,25 @@ func TestAProcessBusHearsWhatItsModuleConsumes(t *testing.T) { buscompose.MayPublish(perms["keeper"], s), buscompose.MayPublish(perms["mute"], s)) } } + for _, u := range users { + if u.Kind == buscompose.KindProcess && u.Process == "bus-keeper" { + pm, err := buscompose.PermissionsFor(u) + if err != nil { + t.Fatal(err) + } + const keeperDurable = "ace_nats_bus-keeper" + if !buscompose.MayPublish(pm, "$JS.API.CONSUMER.MSG.NEXT."+stream+"."+keeperDurable) || !buscompose.MayPublish(pm, "$JS.ACK."+stream+"."+keeperDurable+".1") { + t.Errorf("the bus module's process may not read its durable on %s", stream) + } + heard := false + for _, c := range buscompose.AccountConsumers(users) { + heard = heard || c.Module == "nats" && c.Consumer.Stream == stream && c.Consumer.Name == keeperDurable && slices.Equal(c.Consumer.Filters, []string{subject}) + } + if !heard { + t.Errorf("the bus module's process has no durable %s on %s", keeperDurable, stream) + } + } + } var made []string for _, c := range buscompose.AccountConsumers(users) { if c.Module == "zfs" && strings.HasPrefix(c.Consumer.Name, "ace_zfs_") && !strings.HasSuffix(c.Consumer.Name, buscompose.ToolsSuffix) { // the processes' own, not the module's nor its runner's From aea1e6129c89222c7d7cfb36ec8c3dd9ae1473f7 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:00:14 +0100 Subject: [PATCH 4/9] G3 program-long-running: a module whose processes run once or on a schedule declares no program MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hasOwnProcess counts a process without a bus of its own only when it runs for the module's whole life: a process marked run-once or carrying a schedule runs to its end and never pulls a durable, so no durable _ is composed for a module whose processes are all such. Row in the account-consumer subtest of TestGrants. Builds: design 47 H2b §838 --- modules/mesh-grants/grants_test.go | 15 +++++++++++++++ modules/mesh-grants/internal/grants/records.go | 8 +++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index 0d4e229cd..6a1db3bfe 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -4265,6 +4265,21 @@ func TestGrants(t *testing.T) { if got := composedSaid(b); len(got) != 1 { t.Errorf("a pass that composed no durable said durables-composed again: %+v", got) } + // 1984/AC-838a (design 47 H2b §838): a module whose processes are all run-once or on a schedule has no program, so + // no durable of its own is made for it; one with a long-running process without a bus has. + for module, resources := range map[string]string{ + "mod-once": `,"resources":[{"id":"step","type":"process","run":["./step"],"run-once":true}]`, + "mod-sched": `,"resources":[{"id":"step","type":"process","run":["./step"],"schedule":"daily"}]`, + "mod-long": programResource, + } { + b.manifestOf(module, `{"module":"`+module+`","version":"1","own-secrets":{"broker":"/var/lib/c/broker"},"consumes":["mod-y.done"]`+resources+`}`) + b.assign("b", module) + } + b.loaded = shadowOf(t, b) + res = p.Compose() + if !slices.Equal(res.Consumers.Created, []string{"EVENTS.b_mod-long"}) { + t.Errorf("modules with a run-once, a scheduled and a long-running process: created %v, want b_mod-long alone", res.Consumers.Created) + } // A held consumer that differs is never changed by a pass: it is raised as a condition naming it, and brought to // the composed configuration only by hand (grants_consumer_match), with no lease key too. var said, behind, orphaned []oc.Condition diff --git a/modules/mesh-grants/internal/grants/records.go b/modules/mesh-grants/internal/grants/records.go index 39a52c43e..e57cf0bdc 100644 --- a/modules/mesh-grants/internal/grants/records.go +++ b/modules/mesh-grants/internal/grants/records.go @@ -652,12 +652,14 @@ func queueOwnersOf(m catalogue.Manifest) []buscompose.QueueOwner { return out } -// hasOwnProcess says the manifest names a process resource with no `bus` of its own: one that runs on the module's own -// account and reads its consumer _ (H-A-472 second addendum). +// hasOwnProcess says the manifest names a process resource with no `bus` of its own that runs for the module's whole +// life: one that runs on the module's own account and reads its consumer _ (H-A-472 second addendum). A +// process marked `run-once: true` or carrying a `schedule` runs to its end and never pulls a durable, so it counts for +// nothing (design 47 H2b §838). func hasOwnProcess(m catalogue.Manifest) bool { buses := m.ProcessBuses() for _, r := range m.Resources { - if fmt.Sprint(r["type"]) != "process" { + if fmt.Sprint(r["type"]) != "process" || !catalogue.LongRunning(r) { continue } if _, bus := buses[fmt.Sprint(r["id"])]; !bus { From 499bb15eae7481bac2dca93315303ee64353a3d5 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:01:31 +0100 Subject: [PATCH 5/9] I1 wants-heard-in-order: the indexer orders a wanted by its want-revision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HearWanted keeps the want-revision beside at for each member: a wanted at a want-revision below the one held changes nothing whatever its time, a repeat writes nothing new, and a removal is ordered against a later want by it. An event naming none is ordered by at as before. A row holds that a tier-late said after its running changes nothing. Builds: design 47 H2b §832 5., H-A-832 --- .../internal/index/named.go | 44 +++++++++++++------ .../internal/index/pins_test.go | 2 + .../internal/index/wanted_names_test.go | 14 +++++- 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/named.go b/modules/mesh-delivery-indexer/internal/index/named.go index 0de600627..d77d8fde4 100644 --- a/modules/mesh-delivery-indexer/internal/index/named.go +++ b/modules/mesh-delivery-indexer/internal/index/named.go @@ -44,10 +44,13 @@ func NamedKey(fingerprint string) string { return keys.EscapeName(fingerprint) } // NamedMember is the member of a node's module in a set. func NamedMember(node, module string) string { return node + "." + module } -// namedAt is the fingerprint one source last named for a member, and when it said so. +// namedAt is the fingerprint one source last named for a member, and when it said so. rev is the `want-revision` a want +// carried (0 when it carried none, as an older event or a running build): a want is ordered by it, never by a say's time +// (design 47 H2b §832 5.). type namedAt struct { - fp string - at time.Time + fp string + at time.Time + rev int64 } // Named keeps the sets. What each member's want and running last named is held in memory only, read again at every start from @@ -65,6 +68,7 @@ type Named struct { want map[string]namedAt run map[string]namedAt gone map[string]time.Time // the want of a member removed (§693), when + goneR map[string]int64 // the `want-revision` of the write that removal removed, 0 when it named none reads map[string]bool // the streams read whole at the start ready bool // failed holds the first event that could not be applied while the start read ran: what it named is unknown, so the @@ -77,7 +81,7 @@ func NewNamed(store Store, logf func(string, ...any)) *Named { if logf == nil { logf = func(string, ...any) {} } - return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, reads: map[string]bool{}} + return &Named{Store: store, Logf: logf, want: map[string]namedAt{}, run: map[string]namedAt{}, gone: map[string]time.Time{}, goneR: map[string]int64{}, reads: map[string]bool{}} } // Ready says the two streams were read whole and the sets reconciled with them: until then no entry object is removed, so a @@ -102,7 +106,7 @@ func (n *Named) HearWanted(ctx context.Context, data []byte) error { if e.At != nil { at = *e.At } - return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.Removed) + return n.apply(ctx, NamedMember(e.Node, e.Module), true, e.Fp, at, e.WantRevision, e.Removed) } // HearRunning applies one running event: the build it names; a stopped one, or one with no fingerprint, names none (design 47 @@ -119,14 +123,14 @@ func (n *Named) HearRunning(ctx context.Context, data []byte) error { if r.Stopped { fp = "" } - return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, false) + return n.apply(ctx, NamedMember(r.Node, r.Module), false, fp, r.At, 0, false) } // apply changes what one source names for the member and writes the sets it moves; one at a time, so the two sources never // write one set from a stale view of each other. -func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) error { +func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) error { n.mu.Lock() - moved, err := n.applyLocked(ctx, member, wanted, fp, at, removed) + moved, err := n.applyLocked(ctx, member, wanted, fp, at, rev, removed) if err != nil && !n.ready && n.failed == nil { n.failed = err } @@ -137,13 +141,17 @@ func (n *Named) apply(ctx context.Context, member string, wanted bool, fp string return err } -func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, removed bool) (bool, error) { +func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp string, at time.Time, rev int64, removed bool) (bool, error) { src := n.run if wanted { src = n.want } old, had := src[member] - if had && at.Before(old.at) { + // A want that names its `want-revision` is ordered by it against one that names its own, never by the time it was said + // (design 47 H2b §832 5.): one at a revision below the held want's changes nothing, and a repeat of it writes nothing new. + // An event that names none, or a held one that named none, is ordered by `at`, as a running build is. + byRev := wanted && had && rev > 0 && old.rev > 0 + if byRev && rev < old.rev || !byRev && had && at.Before(old.at) { return false, nil // an event older than the one heard changes nothing } var touched []string @@ -158,22 +166,32 @@ func (n *Named) applyLocked(ctx context.Context, member string, wanted bool, fp delete(n.run, member) } delete(n.want, member) - n.gone[member] = at + n.gone[member], n.goneR[member] = at, rev touched = append(touched, fp) - case !n.gone[member].IsZero() && !at.After(n.gone[member]): + case !n.gone[member].IsZero() && n.goneRemoved(member, wanted, at, rev): return false, nil // an event older than the removal of the want it belongs to case fp == "": delete(src, member) default: if wanted { delete(n.gone, member) + delete(n.goneR, member) } - src[member] = namedAt{fp: fp, at: at} + src[member] = namedAt{fp: fp, at: at, rev: rev} touched = append(touched, fp) } return n.writeSets(ctx, member, touched) } +// goneRemoved says whether an event is older than the removal of the member's want: a want that names its `want-revision` +// is older when its revision does not pass the removed write's, any other event when it was said before the removal. +func (n *Named) goneRemoved(member string, wanted bool, at time.Time, rev int64) bool { + if wanted && rev > 0 && n.goneR[member] > 0 { + return rev <= n.goneR[member] + } + return !at.After(n.gone[member]) +} + // holds says whether either source names fp for the member. func (n *Named) holds(member, fp string) bool { return n.want[member].fp == fp || n.run[member].fp == fp diff --git a/modules/mesh-delivery-indexer/internal/index/pins_test.go b/modules/mesh-delivery-indexer/internal/index/pins_test.go index 42ef466a8..208d6a084 100644 --- a/modules/mesh-delivery-indexer/internal/index/pins_test.go +++ b/modules/mesh-delivery-indexer/internal/index/pins_test.go @@ -245,6 +245,8 @@ func TestTheIndexerRemovesARevisionOnlyWhenNoRecordPinsItAndItIsNotCurrent(t *te wanted(7, meshwants.PipelineWantedOutcomeRunning) wanted(7, meshwants.PipelineWantedOutcomeRunning) // heard twice: changes nothing more want("the newer release written everywhere", "main.7") + wanted(7, meshwants.PipelineWantedOutcomeTierLate) // 1984/AC-832l (design 47 H2b §832 5.): said again after its running, it changes nothing + want("a tier-late after its running", "main.7") if v, _, _, _ := ix.Pins.Get(ctx, "main.7"); !slices.Equal(mustRecords(t, v), []string{ReleaseRecord("main", "reader")}) { t.Errorf("the pin of main.7 holds %s, want its release alone", v) } diff --git a/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go b/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go index d7a136cd5..dd26653ee 100644 --- a/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go +++ b/modules/mesh-delivery-indexer/internal/index/wanted_names_test.go @@ -27,6 +27,7 @@ type namedEvent struct { module string fp string min int + rev int64 // the want-revision a wanted names, 0 for none removed bool stopped bool } @@ -37,7 +38,7 @@ func (e namedEvent) apply(t *testing.T, n *Named) { var data []byte var err error if e.wanted { - data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, Removed: e.removed, At: &at}) + data, err = json.Marshal(meshwants.WantedEvent{V: 1, Node: e.node, Module: e.module, Fp: e.fp, Revision: 1, WantRevision: e.rev, Removed: e.removed, At: &at}) if err == nil { err = n.HearWanted(context.Background(), data) } @@ -77,6 +78,17 @@ func TestNamedHoldsTheMembersWhoseWantOrRunningBuildNamesAFingerprint(t *testing {wanted: true, node: "n1", module: "m", fp: a, min: 1, removed: true}, {node: "n1", module: "m", fp: a, min: 0}}, map[string][]string{a: nil}}, {"an event older than the one heard changes nothing", []namedEvent{ {wanted: true, node: "n1", module: "m", fp: b, min: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 4}}, map[string][]string{a: nil, b: {"n1.m"}}}, + // 1984/AC-832l, AC-832t (design 47 H2b §832 5., H-A-832): a want is ordered by its want-revision, never by a say's time. + {"a want at a lower want-revision changes nothing, whatever its time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}}, map[string][]string{a: nil, b: {"n1.m"}}}, + {"a want at a higher want-revision wins over a later time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 4}, {wanted: true, node: "n1", module: "m", fp: b, min: 1, rev: 5}}, map[string][]string{a: nil, b: {"n1.m"}}}, + {"a repeat of an applied want writes nothing new, under any time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 3}, {wanted: true, node: "n1", module: "m", fp: a, min: 8, rev: 3}}, map[string][]string{a: {"n1.m"}, b: nil}}, + {"a removal of a write below the held want's changes nothing", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 6}, {wanted: true, node: "n1", module: "m", fp: a, min: 9, rev: 5, removed: true}}, map[string][]string{a: {"n1.m"}}}, + {"a want written after a removal at a higher want-revision brings the member back, whatever its time", []namedEvent{ + {wanted: true, node: "n1", module: "m", fp: a, min: 5, rev: 6, removed: true}, {wanted: true, node: "n1", module: "m", fp: a, min: 1, rev: 7}}, map[string][]string{a: {"n1.m"}}}, } { t.Run(c.name, func(t *testing.T) { st := newMem() From b44a9ee1dc4247023c5a908a019bee477bf375b4 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:01:31 +0100 Subject: [PATCH 6/9] I2 hub-start-alone: the indexer starts its event hub with Start alone MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Start binds the indexer's durable on EVENTS and on each kept seat event's stream it handles, so startHearing no longer calls StartKept, which mesh-sdk's hub no longer has. Builds: design 47 H2b §836 1. --- .../cmd/mesh-delivery-indexer/main_test.go | 7 +------ .../cmd/mesh-delivery-indexer/versions.go | 14 ++++---------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main_test.go index a23c8b75a..ebf2026a4 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main_test.go @@ -107,19 +107,14 @@ func ptr[T any](v T) *T { return &v } // noWire is a finding writer that is none: a non-nil WireWriter for the test of which emitter is made. type noWire struct{ views.WireWriter } -// startedHub records which of an event hub's starts were asked. +// startedHub is an event hub whose Start answers startErr. type startedHub struct { startErr error - kept bool } func (h *startedHub) Start(context.Context, jetstream.JetStream, process.Account) error { return h.startErr } -func (h *startedHub) StartKept(context.Context, jetstream.JetStream, process.Account) int { - h.kept = true - return 1 -} // H-A-578 (2): an event of a subject the indexer no longer consumes is acknowledged with no work, and the journal says // the subject once, at the first. diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go index 65ff8306d..ceffaca4b 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/versions.go @@ -46,19 +46,13 @@ func sayVersionReleased(conn *nats.Conn, cred process.Account) func(context.Cont // hubStarter is the event hub as startHearing starts it. type hubStarter interface { Start(ctx context.Context, js jetstream.JetStream, cred process.Account) error - StartKept(ctx context.Context, js jetstream.JetStream, cred process.Account) int } -// startHearing binds the indexer's durable on the shared events stream and then, beside it, its durable on each kept seat -// event's own stream (SEAT__) whose event it handles: package-published and the build seats' -// step-ended are never on EVENTS, and its tool runner reads only its own twin there, so the program hears them only so -// (design 47 G A-397; mesh-sdk process.EventHub.StartKept). +// startHearing starts the event hub once: its Start binds the indexer's durable on the shared events stream and, beside it, its +// durable on each kept seat event's own stream (SEAT__) whose event it handles, package-published and the build +// seats' step-ended being never on EVENTS (design 47 H2b §836 1.; mesh-sdk process.EventHub.Start). func startHearing(ctx context.Context, hub hubStarter, js jetstream.JetStream, cred process.Account) error { - if err := hub.Start(ctx, js, cred); err != nil { - return err - } - hub.StartKept(ctx, js, cred) - return nil + return hub.Start(ctx, js, cred) } // EventDeliveries is how many times the bus gives a message of the indexer's events consumer: the MaxDeliver the grants part From 51624652930d17615ef022ab9403abfb53fb007e Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:05:28 +0100 Subject: [PATCH 7/9] I3 word-and-event-edges: the indexer derives the edge from the node-engine mover to a mover with a new word, and from an emitter to a consumer of its new event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 H2b §870, H-A-838, H-A-851 --- .../cmd/mesh-delivery-indexer-tools/entry.go | 9 +- .../mesh-delivery-indexer-tools/entry_test.go | 7 ++ .../internal/index/catalog_branches_test.go | 35 ++++++ .../internal/index/catalog_edges.go | 105 ++++++++++++++++++ .../internal/index/catalog_edges_test.go | 69 ++++++++++++ .../internal/index/catalog_revisions.go | 14 +++ 6 files changed, 236 insertions(+), 3 deletions(-) diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry.go index 8eb969dd4..c27d0bc7d 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry.go @@ -6,6 +6,7 @@ import ( "strconv" "strings" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" stdio "git.novox.be/novox/mesh-sdk/go" "mesh-delivery-indexer/internal/index" @@ -21,6 +22,8 @@ type entryAnswer struct { Paths map[string][]string `json:"paths"` Fp string `json:"fp,omitempty"` ManifestDigest string `json:"manifest-digest,omitempty"` + // the entry's edges, each with its kind, the word it comes from and why (design 47 H §870, H-A-851) + Edges []meshcatalog.Edge `json:"edges,omitempty"` } // entryReadTool is indexer_entry (H-A-204; tools-are-how-a-module-is-spoken-to) over the indexer's catalog-revisions objects: @@ -29,8 +32,8 @@ type entryAnswer struct { func entryReadTool(o index.Objects) stdio.Tool { return stdio.Tool{Name: index.EntryPinsTool, Description: "Read one module's catalog graph entry pins: the packages it builds against with the version each is pinned to " + - "(an empty version while none is published), the paths each artifact is built from, its fingerprint and its manifest " + - "digest, at the newest trunk revision or at a trunk revision given; a small answer, for when the revision whole is too " + + "(an empty version while none is published), the paths each artifact is built from, its fingerprint, its manifest " + + "digest and its edges (kind, the word or event each comes from, why), at the newest trunk revision or at a trunk revision given; a small answer, for when the revision whole is too " + "large for the bus (H-A-204).", Input: map[string]any{"type": "object", "required": []string{"module"}, "properties": map[string]any{ "module": map[string]any{"type": "string", "description": "the module whose entry is read"}, @@ -50,7 +53,7 @@ func entryReadTool(o index.Objects) stdio.Tool { return nil, err } out := entryAnswer{Module: e.Module, Revision: rev.Revision, Packages: e.Packages, Paths: map[string][]string{}, - Fp: e.Fp, ManifestDigest: e.ManifestDigest} + Fp: e.Fp, ManifestDigest: e.ManifestDigest, Edges: e.Edges} if out.Packages == nil { out.Packages = map[string]string{} } diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry_test.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry_test.go index aefb9942a..99e323e69 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry_test.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer-tools/entry_test.go @@ -57,6 +57,11 @@ func TestEntryTool(t *testing.T) { Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}}, meshcatalog.CatalogEntry{Module: "other", Fp: "src2:o"}) keep(9, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:new", ManifestDigest: "sha256:b", Inputs: paths, Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}}) + // 1984/AC-870d (H-A-838, H-A-851): the entry's word edge and event edge are answered with kind 6, their word and why. + edges := []meshcatalog.Edge{ + {Kind: 6, From: "engine:program", To: "mesh-grants:program", Word: "word:build.artifacts.race", Why: "new at the revision: mesh-grants"}, + {Kind: 6, From: "emitter:program", To: "mesh-grants:program", Word: "emitter.made", Why: "new at the revision: emitter"}} + keep(5, meshcatalog.CatalogEntry{Module: "mesh-grants", Fp: "src2:edges", Edges: edges}) tool := entryReadTool(o) if tool.Name != "indexer_entry" { t.Fatalf("name %s", tool.Name) @@ -71,6 +76,8 @@ func TestEntryTool(t *testing.T) { Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.27", "busgrants": ""}, Paths: paths.Paths}, ""}, {"given", map[string]any{"module": "mesh-grants", "revision": float64(7)}, entryAnswer{Module: "mesh-grants", Revision: 7, Fp: "src2:old", ManifestDigest: "sha256:a", Packages: map[string]string{"git.novox.be/novox/mesh-sdk/go": "v0.1.26"}, Paths: paths.Paths}, ""}, + {"edges", map[string]any{"module": "mesh-grants", "revision": float64(5)}, entryAnswer{Module: "mesh-grants", Revision: 5, Fp: "src2:edges", + Packages: map[string]string{}, Paths: map[string][]string{}, Edges: edges}, ""}, {"given as digits, no paths", map[string]any{"module": "other", "revision": "7"}, entryAnswer{Module: "other", Revision: 7, Fp: "src2:o", Packages: map[string]string{}, Paths: map[string][]string{}}, ""}, {"not in the newest", map[string]any{"module": "other"}, entryAnswer{}, "holds no module other"}, diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go index ab31890f9..ff78823e5 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go @@ -153,3 +153,38 @@ func TestAHigherNeedsRulesDerivesTheUnmovedEntriesNeedsAgain(t *testing.T) { t.Errorf("a take-in at unchanged rules derived needs again: %v", needs) } } + +// Design 47 H §870 (1984/AC-870a): a take-in writes the word edge into the revision it keeps, against its base revision: the +// word new at the second take-in orders its mover after the node-engine mover, the one the first take-in named gets none. +func TestATakeInKeepsTheWordEdgesNewAgainstItsBase(t *testing.T) { + ctx := context.Background() + ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)} + engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil) + app := wordEntry("app", map[string]any{}, []string{"word:settings"}, nil) + mv := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "app"}} + if err := ix.KeepBranchEntries(ctx, "main", 1, map[string]meshcatalog.CatalogEntry{"engine": engine, "app": app}, mv); err != nil { + t.Fatal(err) + } + app.Needs = []string{"word:settings", "word:build.artifacts.race"} + if err := ix.KeepBranchEntries(ctx, "main", 2, map[string]meshcatalog.CatalogEntry{"engine": engine, "app": app}, mv); err != nil { + t.Fatal(err) + } + a, err := Revision(ctx, ix.Revisions, nil, meshcatalog.RevisionInput{Branch: "main", Source: 2}) + if err != nil { + t.Fatal(err) + } + for _, e := range a.Entries { + if e.Module != "app" { + continue + } + var words []string + for _, x := range e.Edges { + if x.Kind == 6 { + words = append(words, x.Word) + } + } + if !slices.Equal(words, []string{"word:build.artifacts.race"}) { + t.Errorf("app holds the word edges %v, want only the one new at the base", words) + } + } +} diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_edges.go b/modules/mesh-delivery-indexer/internal/index/catalog_edges.go index 15712a0b0..53f930baf 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_edges.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_edges.go @@ -494,3 +494,108 @@ func edgesOfPackages(a meshcatalog.CatalogEntry, all map[string]meshcatalog.Cata } } } + +// WithNewEdges adds, to the entries of a take-in's revision, the edges of kind 6 that its movers bring (design 47 H §870, +// H-A-838): a word and an event new at the revision, between the artifacts of the movers. base is the entries of the +// revision's base (none for a branch's first); entries are not changed. +// 1. A word: each need `word:` of a mover A that no entry of base names gives an edge from the artifact of each +// mover that holds the seat node-engine, the reader of every manifest word (ADR 0614 §4), to A's. +// 2. An event: each `consumes` entry of a mover A that names an event a mover B's manifest emits at the revision and +// did not at the base gives an edge from B's artifact to A's. +// +// An edge's `word` is the need, or `.`; its `why` says it is new at the revision and names the mover that +// brings it. A cycle of these edges with other delivery edges is delivered as one step (graph.RefusedCycle refuses only +// one holding a build edge). +func WithNewEdges(entries, base map[string]meshcatalog.CatalogEntry, movers []meshcatalog.TakeInEntry) map[string]meshcatalog.CatalogEntry { + moved := map[string]bool{} + for _, m := range movers { + moved[m.Module] = true + } + baseNeeds := map[string]bool{} + for _, b := range base { + for _, n := range b.Needs { + baseNeeds[n] = true + } + } + var engines []string + for _, m := range slices.Sorted(maps.Keys(entries)) { + if moved[m] && manifestOf(entries[m]).ClaimsSeat(nodeEngineSeat) { + engines = append(engines, m) + } + } + out := maps.Clone(entries) + for _, name := range slices.Sorted(maps.Keys(entries)) { + if !moved[name] { + continue + } + a := entries[name] + to := primaryOf(a) + if to == "" { + continue + } + var added []meshcatalog.Edge + for _, n := range a.Needs { + if !strings.HasPrefix(n, catalogue.ReadWord) || baseNeeds[n] { + continue + } + for _, e := range engines { + if from := primaryOf(entries[e]); e != name && from != "" { + added = append(added, meshcatalog.Edge{Kind: 6, From: from, To: to, Word: n, Why: "new at the revision: " + name}) + } + } + } + for _, subject := range a.Consumes { + for _, b := range slices.Sorted(maps.Keys(entries)) { + from := primaryOf(entries[b]) + if !moved[b] || b == name || from == "" { + continue + } + for _, ev := range emitsOf(entries[b]) { + word := b + "." + ev + if eventMatches(subject, word) && !slices.Contains(emitsOf(base[b]), ev) { + added = append(added, meshcatalog.Edge{Kind: 6, From: from, To: to, Word: word, Why: "new at the revision: " + b}) + } + } + } + } + if len(added) == 0 { + continue + } + a.Edges = slices.Clone(a.Edges) + for _, x := range added { + if !slices.Contains(a.Edges, x) { + a.Edges = append(a.Edges, x) + } + } + sortEdges(a.Edges) + out[name] = a + } + return out +} + +// nodeEngineSeat is the seat whose holder reads every manifest word (ADR 0614 §4). +const nodeEngineSeat = "node-engine" + +// emitsOf are the events the entry's manifest emits, named locally. +func emitsOf(e meshcatalog.CatalogEntry) []string { + if len(e.Manifest) == 0 { + return nil + } + return manifestOf(e).Emits +} + +// eventMatches says whether a consumed event, `.` with `*` for one name and `**` for the rest, names word. +func eventMatches(pattern, word string) bool { + p, w := strings.Split(pattern, "."), strings.Split(word, ".") + for i, t := range p { + switch { + case t == "**": + return true + case i >= len(w): + return false + case t != "*" && t != w[i]: + return false + } + } + return len(p) == len(w) +} diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go index 352d48874..e458a3ef6 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go @@ -318,3 +318,72 @@ func TestTheTrunkCataloguesHoldNoRefusedCycle(t *testing.T) { } } } + +func wordEntry(module string, manifest map[string]any, needs, consumes []string) meshcatalog.CatalogEntry { + manifest["module"], manifest["version"] = module, "1.0.0" + return meshcatalog.CatalogEntry{Module: module, Manifest: manifest, Needs: needs, Consumes: consumes, + Artifacts: []meshcatalog.Artifact{{Ref: meshcatalog.ArtifactRef(module + ":program"), Language: "go"}}} +} + +func kind6Words(e meshcatalog.CatalogEntry) []string { + var out []string + for _, x := range e.Edges { + if x.Kind == 6 { + out = append(out, x.From+" "+x.Word+" | "+x.Why) + } + } + return out +} + +// Design 47 H §870 1., 1984/AC-870a: a mover whose entry needs a word no base entry names gets the edge from the mover that holds +// the seat node-engine, and one whose word a base entry names gets none. +func TestAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover(t *testing.T) { + engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil) + newer := wordEntry("newer", map[string]any{}, []string{"word:build.artifacts.race"}, nil) + known := wordEntry("known", map[string]any{}, []string{"word:settings"}, nil) + base := map[string]meshcatalog.CatalogEntry{"old": {Module: "old", Needs: []string{"word:settings"}}} + movers := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "newer"}, {Module: "known"}} + got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"engine": engine, "newer": newer, "known": known}, base, movers) + if w := kind6Words(got["newer"]); !slices.Equal(w, []string{"engine:program word:build.artifacts.race | new at the revision: newer"}) { + t.Errorf("newer holds %v, want the edge from the node-engine mover", w) + } + if w := kind6Words(got["known"]); len(w) != 0 { + t.Errorf("known holds %v, want no edge: a base entry names its word", w) + } + if w := kind6Words(got["engine"]); len(w) != 0 { + t.Errorf("the node-engine mover holds %v, want none", w) + } +} + +// Design 47 H §870 2., 1984/AC-870b: a consumer of an event its emitter newly emits gets the edge from the emitter, and one +// whose emitter emitted it at the base gets none. +func TestAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter(t *testing.T) { + emitter := wordEntry("emitter", map[string]any{"emits": []any{"made", "kept"}}, nil, nil) + fresh := wordEntry("fresh", map[string]any{}, nil, []string{"emitter.made"}) + stale := wordEntry("stale", map[string]any{}, nil, []string{"emitter.kept", "*.nothing"}) + base := map[string]meshcatalog.CatalogEntry{"emitter": wordEntry("emitter", map[string]any{"emits": []any{"kept"}}, nil, nil)} + movers := []meshcatalog.TakeInEntry{{Module: "emitter"}, {Module: "fresh"}, {Module: "stale"}} + got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"emitter": emitter, "fresh": fresh, "stale": stale}, base, movers) + // AC-870d (H-A-838): kind 6, the event as `word`, "new at the revision" naming the mover as `why`. + if w := kind6Words(got["fresh"]); !slices.Equal(w, []string{"emitter:program emitter.made | new at the revision: emitter"}) { + t.Errorf("fresh holds %v, want the edge from the emitter", w) + } + if w := kind6Words(got["stale"]); len(w) != 0 { + t.Errorf("stale holds %v, want none: the emitter emitted it at the base", w) + } +} + +// Design 47 H §870 3., 1984/AC-870c: a cycle of a word edge and an event edge is delivered as one step, so it is no refused +// cycle (only one holding a build edge is). +func TestACycleOfAWordEdgeAndAnEventEdgeIsNotRefused(t *testing.T) { + engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, []string{"newer.said"}) + newer := wordEntry("newer", map[string]any{"emits": []any{"said"}}, []string{"word:resources.tool-files"}, nil) + movers := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "newer"}} + got := WithNewEdges(map[string]meshcatalog.CatalogEntry{"engine": engine, "newer": newer}, nil, movers) + if len(kind6Words(got["engine"])) != 1 || len(kind6Words(got["newer"])) != 1 { + t.Fatalf("edges %v and %v, want one each way", kind6Words(got["engine"]), kind6Words(got["newer"])) + } + if cycle := graph.RefusedCycle(got); cycle != nil { + t.Errorf("refused %v, want one step", cycle) + } +} diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go b/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go index 46827a484..03b917d44 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_revisions.go @@ -421,6 +421,20 @@ func (ix *Indexer) keepBranchEntries(ctx context.Context, branch string, src int if judge.NeedsRules > newest.NeedsRules { entries = withRuleNeeds(entries, movers) // H-A-605 (4): the rules moved since the base, so each unmoved entry is read again } + if len(movers) > 0 { + // design 47 H §870: the word and event edges the movers bring, new against the revision's base + base := map[string]meshcatalog.CatalogEntry{} + if newest.Revision > 0 { + _, held, _, err := readNewestOf(ctx, ix.Revisions, branch) + if err != nil { + return 0, fmt.Errorf("the base catalog graph revision: %w", err) + } + for _, e := range held { + base[e.Module] = e + } + } + entries = WithNewEdges(entries, base, movers) + } at := ix.now().UTC() rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: number, Kind: "trunk", Branch: branch, Source: src, Call: call.Call, NeedsRules: judge.NeedsRules, CallKind: call.Kind, Module: call.Module, Version: call.Version, Repository: call.Repository, At: &at}, entries) From 388626ac8293293e07d8f470c6ec6f37edadff8d Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:06:12 +0100 Subject: [PATCH 8/9] I4 set-aside-needs: the take-in names the need word: of each word its read set aside, and NeedsRules is 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 H2b §872 --- modules/mesh-delivery-indexer/judge/needs.go | 56 ++++++++++++++++++- .../mesh-delivery-indexer/judge/needs_test.go | 9 ++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/modules/mesh-delivery-indexer/judge/needs.go b/modules/mesh-delivery-indexer/judge/needs.go index dfdb404b7..f6cfd176b 100644 --- a/modules/mesh-delivery-indexer/judge/needs.go +++ b/modules/mesh-delivery-indexer/judge/needs.go @@ -22,7 +22,7 @@ import ( // NeedsRules is the version of the validator's need rules (design 47 H2, H-A-569 (2), H-A-605 (4)): raised with every // change of the rules that derive a need from a manifest. Each catalog revision the indexer writes carries it, and a // take-in derives the rule needs of unmoved entries again only when its own is higher than its base revision's. -const NeedsRules = 1 +const NeedsRules = 2 // requirementLong is one entry of `requires` in its long form, as catalogue reads it. type requirementLong struct { @@ -123,9 +123,63 @@ func ManifestNeeds(raw []byte) ([]string, error) { for _, s := range seatNamesUsed(top) { used[catalogue.ReadSeat+s] = true } + // A word the take-in's read set aside (design 47 H2b §872, H-A-813): the need of a word this reader does not know, + // in the form catalogue.ManifestReads() gives one, so a node-engine whose words lack it is held off the entry. + for _, path := range UnknownFields(raw) { + if word := readWordOf(path); word != "" { + used[catalogue.ReadWord+word] = true + } + } return sortedSet(used), nil } +// readWordOf is the path SetAside names for a word, `build.artifacts[0].race`, in the form catalogue.ManifestReads() gives +// a word: no list index, and no key of a map of the module's own names (a setting's, a requirement's), so +// `build.artifacts.race`. Where a path leaves the shape the contract knows, the keys after it are kept as they are. +func readWordOf(path string) string { + var segments []string + for _, seg := range strings.Split(path, ".") { + if i := strings.IndexByte(seg, '['); i >= 0 { + seg = seg[:i] + } + if seg != "" { + segments = append(segments, seg) + } + } + var t reflect.Type = reflect.TypeOf(catalogue.Manifest{}) + var out []string + for _, seg := range segments { + for t != nil { + t = deref(t) + if k := t.Kind(); k == reflect.Slice || k == reflect.Array { + t = t.Elem() + continue + } + break + } + switch { + case t == nil: + out = append(out, seg) + case t.Kind() == reflect.Map: + t = t.Elem() // a key of the module's own names + case t.Kind() == reflect.Struct: + if _, custom := wireKeys[t]; custom { + out, t = append(out, seg), nil + continue + } + out = append(out, seg) + if f, known := structFields(t)[seg]; known { + t = f.Type + } else { + t = nil + } + default: + out, t = append(out, seg), nil + } + } + return strings.Join(out, ".") +} + // ModuleNeeds is ManifestNeeds of a module whose files take their text from templates: what the manifest needs and // what each template's text writes, sorted. A template named and not given is no need. func ModuleNeeds(raw []byte, templates map[string]string) ([]string, error) { diff --git a/modules/mesh-delivery-indexer/judge/needs_test.go b/modules/mesh-delivery-indexer/judge/needs_test.go index 81a7ed76c..c609727ee 100644 --- a/modules/mesh-delivery-indexer/judge/needs_test.go +++ b/modules/mesh-delivery-indexer/judge/needs_test.go @@ -19,7 +19,14 @@ func TestManifestNeeds(t *testing.T) { {"a module with no account of its own", `{"module":"g","version":"1"}`, nil, []string{"word:module"}, []string{"directory-contents-owner"}}, {"a word the contract does not know", `{"module":"u","version":"1","newer-word":{"inside":1}}`, nil, - []string{"word:module"}, []string{"word:newer-word"}}, + []string{"word:module", "word:newer-word"}, nil}, + // design 47 H2b §872, 1984/AC-872a: a nested word set aside has its need in the reads' form, without the list index. + {"a nested word the contract does not know", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go","race":true}]}}`, nil, + []string{"word:module", "word:build.artifacts.race"}, []string{"word:build.artifacts[0].race"}}, + {"a word beneath a setting's own name", `{"module":"u","version":"1","settings":{"mine":{"type":"string","newer":1}}}`, nil, + []string{"word:settings.newer"}, []string{"word:settings.mine.newer"}}, + {"every word known", `{"module":"u","version":"1","build":{"artifacts":[{"name":"p","language":"go"}]}}`, nil, + []string{"word:module"}, []string{"word:build.artifacts.race", "word:race"}}, {"a template naming a seat's reach", `{"module":"z","version":"1","resources":[{"id":"f","type":"file","template":"files/d.json"}]}`, map[string]string{"files/d.json": `{"x":"${seat:container-image-registry:reach}"}`}, []string{"form:seat-reach"}, nil}, From 0c3c9309797f26d9a728da6c1f6ace73cebcb5c3 Mon Sep 17 00:00:00 2001 From: jochen Date: Fri, 27 Nov 2026 03:07:14 +0100 Subject: [PATCH 9/9] I3 test budget: the four edge tests of I3 are subtests of existing tests, no new top-level test function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Builds: design 47 H2b §870 (test-budget instruction) --- .../internal/index/catalog_branches_test.go | 3 ++- .../internal/index/catalog_edges_test.go | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go index ff78823e5..20f50d004 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_branches_test.go @@ -152,11 +152,12 @@ func TestAHigherNeedsRulesDerivesTheUnmovedEntriesNeedsAgain(t *testing.T) { if needs, _ := needsOf(2); !slices.Equal(needs, []string{"word:module"}) { t.Errorf("a take-in at unchanged rules derived needs again: %v", needs) } + t.Run("a take-in keeps the word edges new against its base (design 47 H2b §870)", rowATakeInKeepsTheWordEdgesNewAgainstItsBase) } // Design 47 H §870 (1984/AC-870a): a take-in writes the word edge into the revision it keeps, against its base revision: the // word new at the second take-in orders its mover after the node-engine mover, the one the first take-in named gets none. -func TestATakeInKeepsTheWordEdgesNewAgainstItsBase(t *testing.T) { +func rowATakeInKeepsTheWordEdgesNewAgainstItsBase(t *testing.T) { ctx := context.Background() ix := &Indexer{Module: testSelf, Revisions: newMemObjects(1 << 20)} engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil) diff --git a/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go b/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go index e458a3ef6..df0e2c6d9 100644 --- a/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go +++ b/modules/mesh-delivery-indexer/internal/index/catalog_edges_test.go @@ -70,6 +70,11 @@ func TestAnEntryCarriesItsEdgesOfKindsOneToFourAndSix(t *testing.T) { if got := WithEdges(entries)["app"].Edges; slices.ContainsFunc(got, func(e meshcatalog.Edge) bool { return e.Kind == 1 }) { t.Errorf("edges with a reported empty import set: %+v, want no kind 1", got) } + // design 47 H2b §870 (1984/AC-870a to AC-870c): the edges the movers bring, as rows + t.Run("a mover with a new word follows the node-engine mover", rowAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover) + t.Run("a consumer of a newly emitted event follows its emitter", rowAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter) + t.Run("a cycle of a word edge and an event edge is not refused", rowACycleOfAWordEdgeAndAnEventEdgeIsNotRefused) + } // Design 47 G A-208: a revision kept holds each entry with its edges, so the builder and the assigner read them from the entry. @@ -337,7 +342,7 @@ func kind6Words(e meshcatalog.CatalogEntry) []string { // Design 47 H §870 1., 1984/AC-870a: a mover whose entry needs a word no base entry names gets the edge from the mover that holds // the seat node-engine, and one whose word a base entry names gets none. -func TestAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover(t *testing.T) { +func rowAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover(t *testing.T) { engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, nil) newer := wordEntry("newer", map[string]any{}, []string{"word:build.artifacts.race"}, nil) known := wordEntry("known", map[string]any{}, []string{"word:settings"}, nil) @@ -357,7 +362,7 @@ func TestAMoverNeedingANewWordIsOrderedAfterTheNodeEngineMover(t *testing.T) { // Design 47 H §870 2., 1984/AC-870b: a consumer of an event its emitter newly emits gets the edge from the emitter, and one // whose emitter emitted it at the base gets none. -func TestAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter(t *testing.T) { +func rowAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter(t *testing.T) { emitter := wordEntry("emitter", map[string]any{"emits": []any{"made", "kept"}}, nil, nil) fresh := wordEntry("fresh", map[string]any{}, nil, []string{"emitter.made"}) stale := wordEntry("stale", map[string]any{}, nil, []string{"emitter.kept", "*.nothing"}) @@ -375,7 +380,7 @@ func TestAConsumerOfANewlyEmittedEventIsOrderedAfterItsEmitter(t *testing.T) { // Design 47 H §870 3., 1984/AC-870c: a cycle of a word edge and an event edge is delivered as one step, so it is no refused // cycle (only one holding a build edge is). -func TestACycleOfAWordEdgeAndAnEventEdgeIsNotRefused(t *testing.T) { +func rowACycleOfAWordEdgeAndAnEventEdgeIsNotRefused(t *testing.T) { engine := wordEntry("engine", map[string]any{"claims": []any{map[string]any{"name": "node-engine"}}}, nil, []string{"newer.said"}) newer := wordEntry("newer", map[string]any{"emits": []any{"said"}}, []string{"word:resources.tool-files"}, nil) movers := []meshcatalog.TakeInEntry{{Module: "engine"}, {Module: "newer"}}