From bcf170a003cf9316ea804842f191109ad2246731 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 25 Nov 2026 17:25:45 +0100 Subject: [PATCH] I9 dropped-subjects-acked: the hub acknowledges toolchain-agreed and wait-ended with no work and says each subject once Builds: design 47 H2 H-A-578 (2), H-A-651, H-A-706 --- .../cmd/mesh-delivery-indexer/dropped.go | 27 +++++++++++++++++++ .../cmd/mesh-delivery-indexer/main.go | 5 ++++ .../cmd/mesh-delivery-indexer/main_test.go | 18 +++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/dropped.go diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/dropped.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/dropped.go new file mode 100644 index 000000000..fa9d56184 --- /dev/null +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/dropped.go @@ -0,0 +1,27 @@ +package main + +import ( + "sync" + + "github.com/nats-io/nats.go/jetstream" + + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds" + "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" +) + +// droppedSubjects are the subjects the indexer's manifest no longer consumes while its durable consumer's filter still +// holds them, since the grants part never narrows a filter for a dropped entry (design 47 H2 H-A-578 (2), H-A-651): the +// toolchain agreement of the builder and the end of a want's wait. Listed once, here, beside the hub's handlers. +var droppedSubjects = []string{meshbuilds.SubjectToolchainAgreed, meshwants.SubjectWaitEnded} + +// ackDropped is the hub's handler of a subject no longer consumed: it acknowledges each message at once, with no work, so +// the finding event-unhandled stays clear, and says one journal line for the subject at the first one after the start. +func ackDropped(subject string, logf func(string, ...any)) func(jetstream.Msg) { + var once sync.Once + return func(m jetstream.Msg) { + once.Do(func() { + logf("%s is no longer consumed: its events are acknowledged with no work (design 47 H2 H-A-578 (2))", subject) + }) + _ = m.Ack() + } +} diff --git a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go index 4bbc7f045..df3617cd5 100644 --- a/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go +++ b/modules/mesh-delivery-indexer/cmd/mesh-delivery-indexer/main.go @@ -616,6 +616,11 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, logger.Printf) }); err != nil { return err } + for _, subject := range droppedSubjects { + if err := hub.Handle(subject, ackDropped(subject, logger.Printf)); err != nil { + return err + } + } // The indexer's own room wakes every take-in held on a full catalog store (design 47 H ยง744, H-A-50). if err := hub.Handle(meshcatalog.SubjectRoom, func(m jetstream.Msg) { _ = m.Ack(); go sources.takeAgain() }); err != nil { return err 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 8ff5d8db6..cec137541 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 @@ -3,6 +3,8 @@ package main import ( "context" "encoding/json" + "fmt" + "strings" "testing" "time" @@ -113,3 +115,19 @@ func (h *startedHub) StartKept(context.Context, jetstream.JetStream, process.Acc 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. +func TestASubjectNoLongerConsumedIsAcknowledgedAndSaidOnce(t *testing.T) { + if len(droppedSubjects) != 2 { + t.Fatalf("the dropped subjects are %v, want the toolchain agreement and the wait's end", droppedSubjects) + } + var said []string + handle := ackDropped(droppedSubjects[0], func(format string, a ...any) { said = append(said, fmt.Sprintf(format, a...)) }) + first, second := &ackedMsg{}, &ackedMsg{} + handle(first) + handle(second) + if first.acked != 1 || second.acked != 1 || len(said) != 1 || !strings.Contains(said[0], droppedSubjects[0]) { + t.Errorf("acked %d and %d, said %q; want both acknowledged and the subject said once", first.acked, second.acked, said) + } +}