From 0be2b3d01a121fe34ca781d2fade109e404a925c Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 14:57:12 +0100 Subject: [PATCH 1/2] assigner: the watchman's machine-away and machine-back have one hearer, the world's, so a durable on their streams no longer splits them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The composition step's own hub handler for machine-away and machine-back shared the durable of hearDelivery on the kept streams, so each event went to one of the two and a machine away was often not known away to the delivery judge. The step now asks the world. Builds: design 47 G §389, §64 --- .../mesh-delivery-assigner/compositionrun.go | 56 ++----------------- .../compositionrun_test.go | 3 +- .../cmd/mesh-delivery-assigner/delivered.go | 2 + .../cmd/mesh-delivery-assigner/main.go | 12 +--- 4 files changed, 9 insertions(+), 64 deletions(-) diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go index 0bf7224e..c2aad0c6 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun.go @@ -43,36 +43,6 @@ const ( seatDefinitionsKey = "seat:" + meshcatalog.Seat + "." + meshcatalog.VerbSeatDefinitions ) -// awayNodes are the machines the watchman said away (machine-away of the seat mesh-watchdogs, §389) and not back since. -type awayNodes struct { - mu sync.Mutex - away map[string]bool -} - -// set keeps machine away (true) or back (false). -func (a *awayNodes) set(machine string, away bool) { - a.mu.Lock() - defer a.mu.Unlock() - if a.away == nil { - a.away = map[string]bool{} - } - if away { - a.away[machine] = true - } else { - delete(a.away, machine) - } -} - -// is says machine is away. -func (a *awayNodes) is(machine string) bool { - if a == nil { - return false - } - a.mu.Lock() - defer a.mu.Unlock() - return a.away[machine] -} - // compositionRun runs a composition step. type compositionRun struct { // runs are the composition runs of the state composition-runs (compositionruns.go). @@ -85,7 +55,9 @@ type compositionRun struct { trunk func() (mcc.Half, bool) // running is the last `running` heard of a module on a node (world.runningOf), never the node-engine's bucket. running func(node, module string) (ne.Running, bool) - away *awayNodes + // away says the watchman holds machine away (machine-away, not back since): the one presence the assigner keeps (world.awayNow), + // so a durable on the watchman's streams has one hearer. + away func(machine string) bool // put puts a run ask on the build seat's check queue under the assigner's name. put func(ctx context.Context, a buildstep.StepAsk) error // reads shares the catalog reads among steps (compositionreads.go); sleep waits between two tries of a read (nil: a timer). @@ -122,7 +94,7 @@ func (r *compositionRun) run(ctx context.Context, id string, step meshwants.Step var ends []machineEnd var keys []string for _, node := range nodes { - if r.away.is(node) { + if r.away != nil && r.away(node) { ends = append(ends, machineEnd{warnings: []string{node + " is away (the watchman's machine-away), so it is not composed"}}) continue } @@ -633,26 +605,6 @@ func (r *compositionRun) programs(ctx context.Context, half mcc.Half) (func(node }, nil } -// heardPresence keeps a machine-away (away true) or machine-back of the seat mesh-watchdogs (§389, §436): the machine it names. -func heardPresence(a *awayNodes, away bool, m jetstream.Msg, logf func(string, ...any)) { - var e struct { - Machine string `json:"machine"` - } - if err := json.Unmarshal(m.Data(), &e); err != nil || e.Machine == "" { - logf("%s holds no machine, left: %v", m.Subject(), err) - } else { - a.set(e.Machine, away) - if away { - logf("%s is away (machine-away): a composition step does not compose it until its machine-back", e.Machine) - } else { - logf("%s is back (machine-back): a composition step composes it again", e.Machine) - } - } - if err := m.Ack(); err != nil { - logf("acknowledging %s: %v", m.Subject(), err) - } -} - // trunkOf is the trunk's catalog half the assigner's views hold, trunk naming the first watched branch, or false while none is // held. func trunkOf(iv *catalogViews, trunk func() string) func() (mcc.Half, bool) { diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go index a7cc38e6..30dec563 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/compositionrun_test.go @@ -102,8 +102,7 @@ func newRunStand(t *testing.T, revisionEngine, trunkEngine, seatDigest string) * return json.RawMessage(`{"candidate":"main.7","node":"` + node + `","verdict":"composed","input":{"node":"` + node + `"},"modules":[],"own":{},"took":1,"v":1}`), nil } running := map[string]string{"ace": "src2:e1", "g14": "src2:e2"} - away := &awayNodes{} - away.set("shanks", true) + away := func(machine string) bool { return machine == "shanks" } keeper := testKeeper(&objectsMem{objs: map[string][]byte{}}, time.Now) s.runs = newCompositionRuns(newRunsMem(), defaultRunSettings, time.Now, t.Logf) s.r = &compositionRun{runs: s.runs, diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/delivered.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/delivered.go index ced1cd13..8a2bf3ee 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/delivered.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/delivered.go @@ -123,6 +123,7 @@ func hearDelivery(ctx context.Context, js jetstream.JetStream, w *world, wake fu m, at, err := presenceOf(data) if err == nil { w.heardPresence(m, true, at) + logf("%s is away (machine-away): a composition step does not compose it until its machine-back", m) } return err }}, @@ -130,6 +131,7 @@ func hearDelivery(ctx context.Context, js jetstream.JetStream, w *world, wake fu m, at, err := presenceOf(data) if err == nil { w.heardPresence(m, false, at) + logf("%s is back (machine-back): a composition step composes it again", m) } return err }}, diff --git a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go index 0a455d59..55ec36cb 100644 --- a/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go +++ b/modules/mesh-delivery-assigner/cmd/mesh-delivery-assigner/main.go @@ -32,7 +32,6 @@ import ( mma "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" mcseat "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" - "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshwatchdogs" 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" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" @@ -527,9 +526,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, gate.Follow(seatlist.ProcessBus(bus.Call, hub), wake, logger.Printf) } // The build seat's step-ended of an ask deletes the input kept for it (design 47 G §354) and ends the composition run that waits - // for it (A-240); the watchman's machine-away and machine-back say which machines a composition step does not compose (§64, - // §389). Registered before the hub starts. - away := &awayNodes{} + // for it (A-240). The machines a composition step does not compose are the watchman's machine-away, heard once, in the world (§64, §389). // The composition runs (design 47 G §718, §719), watched in their own state; a build seat's step-ended of a run's ask ends // the run in its key. var runs *compositionRuns @@ -560,11 +557,6 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, return err } } - for subject, isAway := range map[string]bool{meshwatchdogs.SubjectMachineAwayAll: true, meshwatchdogs.SubjectMachineBackAll: false} { - if err := hub.Handle(subject, func(m jetstream.Msg) { heardPresence(away, isAway, m, logger.Printf) }); err != nil { - logger.Printf("%s is not heard, so a composition step asks a machine that sleeps: %v", subject, err) - } - } // The indexer's manifests, modules and module graph, through its first views and views family, never its buckets // (DLV-F2r, ADR 0631): the first pass waits for the three answers, as it waits for every watch to hand what stands. if iv != nil { @@ -712,7 +704,7 @@ func follow(ctx context.Context, js jetstream.JetStream, nc process.Subscriber, // The composition step (design 47 G §22, §354): the seat mesh-wants' accepted kind step, run by one run ask per machine. if bus != nil && js != nil && inputs != nil && p.publishWants != nil && runs != nil { run := &compositionRun{runs: runs, inputs: &compositionInputs{machines: w.machinesOf, callFile: bus.CallFile}, keeper: inputs, reads: &compositionReads{}, call: bus.CallKept, - trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: away, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf} + trunk: trunkOf(iv, w.trunkName), running: w.runningOf, away: func(machine string) bool { return w.awayNow()[machine] }, put: runAskPublisher(js), ask: bus.CallFile, now: time.Now, logf: logger.Printf} steps := &compositionSteps{node: thisNode, say: p.publishWants, run: run.run, resume: run.resume, ended: runs.stepEnded, now: time.Now, logf: logger.Printf, asker: stepAskerOf(seatlist.Definition(gate.Reader, meshwants.Seat))} move := steps.move(ctx) // the readers a rerun carried (§727, A-470d) -- 2.54.0 From 10d87dcc77bb0b5f381414e59d0b62f084393c98 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 15:03:47 +0100 Subject: [PATCH 2/2] mesh-grants: a module's consumer is composed from its own subjects, not from its account's wide grant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ConsumerFor drew its filters from PermissionsFor, which since every account may subscribe to every subject (e1476cfd) is ">": no filter named an event, so no module got an account consumer on EVENTS. The scoped permissions give them again. The integration subtests that read each account's own subjects run with the wide grant off, as the unit tests do. Builds: design 47 G A-434 (G-22-lead-answers-2.md: every account may do everything, the mechanisms stay whole), the grants part's account consumers (ADR 0561 §6) --- .../cmd/mesh-grants/integration_test.go | 17 ++++++++++++++--- .../internal/buscompose/buscompose_test.go | 5 +++++ .../mesh-grants/internal/buscompose/derived.go | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/mesh-grants/cmd/mesh-grants/integration_test.go b/modules/mesh-grants/cmd/mesh-grants/integration_test.go index 5aa60ab3..d84b24ee 100644 --- a/modules/mesh-grants/cmd/mesh-grants/integration_test.go +++ b/modules/mesh-grants/cmd/mesh-grants/integration_test.go @@ -35,6 +35,7 @@ import ( "git.novox.be/novox/mesh-sdk/go/seatlist" "git.novox.be/novox/mesh-sdk/go/views" + "mesh-grants/internal/buscompose" "mesh-grants/internal/grants" ) @@ -651,9 +652,19 @@ func TestTheGrantsPartWhole(t *testing.T) { }) // And what the part composes holds on a server that loads it (one integration test per module, the test budget). - t.Run("the composed grants hold on a server that loads them", theBusNodeFollowsTheSealedListUnderTheComposedGrants) - t.Run("the tool runner hears every event on a server that loads its grants", theToolRunnerHearsEveryEventOnTheBus) - t.Run("a runtime denied the marks is delivered no call on a marked subject", aRuntimeDeniedTheMarksHearsNoMarkedCall) + // These read each account's own subjects, which the part composes beneath the wide grant of every account (the unit tests' + // TestMain does the same): the mechanisms of the scoped grants are built whole all the same. + scoped := func(f func(*testing.T)) func(*testing.T) { + return func(t *testing.T) { + was := buscompose.EveryAccountMayDoEverything + buscompose.EveryAccountMayDoEverything = false + defer func() { buscompose.EveryAccountMayDoEverything = was }() + f(t) + } + } + t.Run("the composed grants hold on a server that loads them", scoped(theBusNodeFollowsTheSealedListUnderTheComposedGrants)) + t.Run("the tool runner hears every event on a server that loads its grants", scoped(theToolRunnerHearsEveryEventOnTheBus)) + t.Run("a runtime denied the marks is delivered no call on a marked subject", scoped(aRuntimeDeniedTheMarksHearsNoMarkedCall)) } // lockedLog is the part's log, read by the test while the part writes it. diff --git a/modules/mesh-grants/internal/buscompose/buscompose_test.go b/modules/mesh-grants/internal/buscompose/buscompose_test.go index d37475b0..683972e2 100644 --- a/modules/mesh-grants/internal/buscompose/buscompose_test.go +++ b/modules/mesh-grants/internal/buscompose/buscompose_test.go @@ -1698,6 +1698,11 @@ func TestEveryMeshAccountMayDoEverything(t *testing.T) { if err != nil || !slices.Equal(m.Publish, []string{AllSubjects}) || !slices.Equal(m.Subscribe, []string{AllSubjects}) { t.Fatalf("a module account = %v / %v (%v), want every subject both ways", m.Publish, m.Subscribe, err) } + // The wide grant leaves a module its consumer: its filters are its own events', never the grant's ">". + if c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "a", Module: "plain", Consumes: []string{"nats.done"}}); !ok || slices.Contains(c.Filters, AllSubjects) || + !slices.Contains(c.Filters, "mesh.mod.nats.event.done") { + t.Errorf("a module's consumer under the wide grant = %v, %v, want its own event filters", c.Filters, ok) + } e, err := PermissionsFor(Principal{Kind: KindEnrolment, Node: "new"}) if err == nil && slices.Contains(e.Publish, AllSubjects) { t.Errorf("an enrolling node is granted every subject: %v", e.Publish) diff --git a/modules/mesh-grants/internal/buscompose/derived.go b/modules/mesh-grants/internal/buscompose/derived.go index ddc633d8..d0772c42 100644 --- a/modules/mesh-grants/internal/buscompose/derived.go +++ b/modules/mesh-grants/internal/buscompose/derived.go @@ -148,7 +148,9 @@ func ConsumerFor(p Principal) (Consumer, bool) { if p.Kind != KindModule || (len(p.Consumes) == 0 && len(p.Watches) == 0 && !hearsItsOwn && !hearsAStream) { return Consumer{}, false } - perms, err := PermissionsFor(p) + // The module's own subjects, never its account's grant: every account may subscribe to every subject (EveryAccountMayDoEverything), + // and a filter drawn from ">" names no event, so no consumer would be composed for any module. + perms, err := scopedPermissionsFor(p) if err != nil { return Consumer{}, false } -- 2.54.0