From 3d6daad925956f639b17196c7c510e344f3caab3 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 14 Nov 2026 18:58:20 +0100 Subject: [PATCH] Runner: reads each module's events on its own durable __tools, beside the program's (A-397) --- node-tools/internal/bus/bus.go | 9 ++++++++- node-tools/internal/bus/streams.go | 2 ++ node-tools/internal/meshtest/meshtest.go | 10 +++++----- node-tools/internal/runtime/runtime.go | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/node-tools/internal/bus/bus.go b/node-tools/internal/bus/bus.go index c6d8e4c..8e843af 100644 --- a/node-tools/internal/bus/bus.go +++ b/node-tools/internal/bus/bus.go @@ -1075,6 +1075,13 @@ func ConsumerOf(node, module string) string { return node + "_" + module } +// ToolsSuffix ends the name of the tool runner's own durable consumer of a module: the runner and the module's program each +// need every event, so each reads under a name of its own (lead answer A-397); only a work queue shares one name. +const ToolsSuffix = "_tools" + +// ToolsConsumerOf is the tool runner's durable consumer of a module on a machine: `__tools`. +func ToolsConsumerOf(node, module string) string { return ConsumerOf(node, module) + ToolsSuffix } + // NakDelay is how long an event a handler failed waits before it is offered again: a transient cause // gets another attempt, a permanent one exhausts the consumer's max-deliver rather than spinning. The // consumer then gives the event up, and the mesh keeps it in DEAD_LETTERS until a person delivers @@ -1125,7 +1132,7 @@ var tickHook func() // answers true (nil is always): a module whose children asked for no heartbeat costs the bus no consumer-info request. func (c *Conn) ConsumeAsBeatingWhen(module string, deliver func(Envelope) error, beat func(Beat), wanted func() bool) (func(), error) { asked := func() bool { return beat != nil && (wanted == nil || wanted()) } - durable := ConsumerOf(c.node, module) + durable := ToolsConsumerOf(c.node, module) js, err := jetstream.New(c.nc) if err != nil { return nil, err diff --git a/node-tools/internal/bus/streams.go b/node-tools/internal/bus/streams.go index 33e25e8..4f7b09e 100644 --- a/node-tools/internal/bus/streams.go +++ b/node-tools/internal/bus/streams.go @@ -269,6 +269,8 @@ func (h *hearing) reconcile() { if m := h.c.Membership(h.module); m != nil { for _, heard := range m.Hears { if heard.Stream != "" && heard.Consumer != "" { + // The runner's own durable beside the program's (A-397). + heard.Consumer += ToolsSuffix want[heard] = true } } diff --git a/node-tools/internal/meshtest/meshtest.go b/node-tools/internal/meshtest/meshtest.go index 3fc053e..04fca72 100644 --- a/node-tools/internal/meshtest/meshtest.go +++ b/node-tools/internal/meshtest/meshtest.go @@ -303,7 +303,7 @@ func (l *Logs) All() string { return strings.Join(l.lines, "\n") } // redelivery in seconds rather than the mesh's minutes. func (m *Mesh) Consumer(t *testing.T, node, module string, filters []string, ackWait time.Duration) { t.Helper() - cfg := &nats.ConsumerConfig{Durable: node + "_" + module, AckPolicy: nats.AckExplicitPolicy, + cfg := &nats.ConsumerConfig{Durable: node + "_" + module + "_tools", AckPolicy: nats.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: 10, DeliverPolicy: nats.DeliverNewPolicy} if len(filters) == 1 { cfg.FilterSubject = filters[0] @@ -340,7 +340,7 @@ func (m *Mesh) Publish(t *testing.T, subject string, body any) { // delivered. func (m *Mesh) Pending(t *testing.T, node, module string) (ackPending, notDelivered uint64) { t.Helper() - info, err := m.js.ConsumerInfo("EVENTS", node+"_"+module) + info, err := m.js.ConsumerInfo("EVENTS", node+"_"+module+"_tools") if err != nil { t.Fatal(err) } @@ -430,7 +430,7 @@ func (m *Mesh) ModuleStream(t *testing.T, module, name string) { // ConsumerOn makes a module's durable consumer on a machine on any stream, as Consumer does on EVENTS. func (m *Mesh) ConsumerOn(t *testing.T, stream, node, module string, filters []string, ackWait time.Duration) { t.Helper() - cfg := &nats.ConsumerConfig{Durable: node + "_" + module, AckPolicy: nats.AckExplicitPolicy, + cfg := &nats.ConsumerConfig{Durable: node + "_" + module + "_tools", AckPolicy: nats.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: 10, DeliverPolicy: nats.DeliverNewPolicy} if len(filters) == 1 { cfg.FilterSubject = filters[0] @@ -445,7 +445,7 @@ func (m *Mesh) ConsumerOn(t *testing.T, stream, node, module string, filters []s // PendingOn is what a module's consumer on a stream still holds, as Pending is on EVENTS. func (m *Mesh) PendingOn(t *testing.T, stream, node, module string) (ackPending, notDelivered uint64) { t.Helper() - info, err := m.js.ConsumerInfo(stream, node+"_"+module) + info, err := m.js.ConsumerInfo(stream, node+"_"+module+"_tools") if err != nil { t.Fatal(err) } @@ -466,7 +466,7 @@ func (m *Mesh) Messages(t *testing.T, stream string) uint64 { // it cannot narrow is withdrawn (novox/hq ADR 0363 ยง6). func (m *Mesh) RemoveConsumer(t *testing.T, stream, node, module string) { t.Helper() - if err := m.js.DeleteConsumer(stream, node+"_"+module); err != nil { + if err := m.js.DeleteConsumer(stream, node+"_"+module+"_tools"); err != nil { t.Fatal(err) } } diff --git a/node-tools/internal/runtime/runtime.go b/node-tools/internal/runtime/runtime.go index 46e9b13..f248a02 100644 --- a/node-tools/internal/runtime/runtime.go +++ b/node-tools/internal/runtime/runtime.go @@ -1063,7 +1063,7 @@ func (b *moduleBus) Subscribe(deliver func(json.RawMessage) error, beat func(jso return err } m.stop = stop - c.logf("[mesh-tools] %s's events arrive on its consumer %s", module, bus.ConsumerOf(c.conn.Node(), module)) + c.logf("[mesh-tools] %s's events arrive on its consumer %s", module, bus.ToolsConsumerOf(c.conn.Node(), module)) return nil }