mesh-delivery-indexer: a message the indexer cannot take is given again after a doubling wait (H-A-773 (3); issues 1984, 1423)

On 25 Nov the bus refused JetStream for a moment while the indexer heard the watchman 0.1.170's two package-published:
leftForBus's immediate Nak spent all five deliveries in one second, and the release was lost. leftForBus now asks the
bus again after a wait that doubles with each delivery, from the new setting redeliver-pace-first (2 s: 2, 4, 8 and 16 s
between the five, about 30 s), so a refusal of a few seconds spends none of them. The backoff in the shared consumer is
the thorough fix of the kind (issue 1423), weighed after H2's delivery.

Builds: design 47 H2 H-A-773 (3), (4)
This commit is contained in:
2026-11-26 20:16:39 +01:00
parent 2dc707782f
commit b87689e990
8 changed files with 99 additions and 27 deletions
@@ -589,12 +589,15 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
_ = m.Ack() // nothing else the indexer consumes rides the shared stream
}
}
if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { heardPackagePublished(ctx, ix, m, logger.Printf) }); err != nil {
// A message the indexer could not take is given again after a wait that doubles with each delivery, from the setting
// redeliver-pace-first (design 47 H2 H-A-773 (3), (4)).
pace := durationSetting(index.RedeliverPaceSetting, index.DefaultRedeliverPace, logger.Printf)
if err := hub.Handle(meshbuilds.SubjectPackagePublished, func(m jetstream.Msg) { heardPackagePublished(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
// A release re-pins once, at its reservation (design 47 H2 §805): the builder's version-reserved, and the step-ended of
// a pipeline whose reservations settle then.
if err := hub.Handle(meshbuilds.SubjectVersionReserved, func(m jetstream.Msg) { heardVersionReserved(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(meshbuilds.SubjectVersionReserved, func(m jetstream.Msg) { heardVersionReserved(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
if err := hub.Handle(meshbuilds.SubjectStepEndedAll, func(m jetstream.Msg) { heardBuildStepEnded(ctx, ix, m, logger.Printf) }); err != nil {
@@ -622,16 +625,16 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
}
}()
})
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(nodebuildgo.SubjectStepEndedAll, func(m jetstream.Msg) { heardStepEnded(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
// A build's import set, said by its build module at its end (design 47 H2 H-A-517, H-A-532 DQ-2).
for _, subject := range []string{nodebuildgo.SubjectImportsReportedAll, nodebuildnode.SubjectImportsReportedAll} {
if err := hub.Handle(subject, func(m jetstream.Msg) { heardImportsReported(ctx, ix, m, logger.Printf) }); err != nil {
if err := hub.Handle(subject, func(m jetstream.Msg) { heardImportsReported(ctx, ix, m, pace, logger.Printf) }); err != nil {
return err
}
}
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, logger.Printf) }); err != nil {
if err := hub.Handle(decidedSubject(cred.Module), func(m jetstream.Msg) { heardDecided(ctx, registry, m, pace, logger.Printf) }); err != nil {
return err
}
for _, subject := range droppedSubjects {
@@ -83,11 +83,16 @@ type deliveredMsg struct {
data []byte
n uint64
naked bool
delay time.Duration // the delay it was naked with
}
func (d *deliveredMsg) Subject() string { return d.subject }
func (d *deliveredMsg) Data() []byte { return d.data }
func (d *deliveredMsg) Nak() error { d.naked = true; return nil }
func (d *deliveredMsg) NakWithDelay(delay time.Duration) error {
d.naked, d.delay = true, delay
return nil
}
func (d *deliveredMsg) Metadata() (*jetstream.MsgMetadata, error) {
return &jetstream.MsgMetadata{NumDelivered: d.n}, nil
}
@@ -165,7 +165,7 @@ func routerRecordOf(module string, call toolCaller, record func(bucket, id strin
// heardDecided is the handler of the decided events for this module: a warrant is applied by the registry; one it could not
// apply is left for the bus to give again, and said. On the last delivery its consumer allows the warrant is given up: its ask
// is answered as not applied and the registration said unwritten (design 47 H2 H-A-470 (2)).
func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, logf func(string, ...any)) {
func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var w oc.Warrant
if err := json.Unmarshal(m.Data(), &w); err != nil {
logf("%s holds what is no warrant, dropped: %v", m.Subject(), err)
@@ -175,7 +175,7 @@ func heardDecided(ctx context.Context, reg *index.Registry, m jetstream.Msg, log
if err := reg.Heard(ctx, w); err != nil {
reason := strings.TrimSpace(err.Error())
logf("the warrant of the ask %s is left unapplied and given again: %s", w.Ask, reason)
leftForBus(m, "the warrant of the ask "+w.Ask, err, logf)
leftForBus(m, pace, "the warrant of the ask "+w.Ask, err, logf)
if md, merr := m.Metadata(); merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
if gerr := reg.GiveUp(ctx, w, reason); gerr != nil {
logf("the warrant of the ask %s is given up, but its ask is not answered: %v", w.Ask, gerr)
@@ -5,8 +5,10 @@ import (
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"testing"
"time"
oc "git.novox.be/novox/mesh-contracts/operator-and-conversation/go/seats/operatorchannel"
stdio "git.novox.be/novox/mesh-sdk/go"
@@ -65,15 +67,16 @@ func TestAWarrantIsGivenUpOnItsLastDelivery(t *testing.T) {
_ = json.Unmarshal(v, &p)
return p
}
for n := uint64(1); n < EventDeliveries; n++ {
// Design 47 H2 H-A-773 (3), (4): each is given again after the setting redeliver-pace-first's wait, doubled with each delivery.
for n, delay := range map[uint64]time.Duration{1: 2 * time.Second, 2: 4 * time.Second, 3: 8 * time.Second, 4: 16 * time.Second} {
m := &deliveredMsg{subject: "decided", data: body, n: n}
heardDecided(ctx, reg, m, func(string, ...any) {})
if !m.naked || state().State != index.ProposalOpen || len(said) != 0 {
t.Fatalf("delivery %d: naked %t, key %+v, said %v; want it left for the bus, the key open, nothing said", n, m.naked, state(), said)
heardDecided(ctx, reg, m, index.DefaultRedeliverPace, func(string, ...any) {})
if !m.naked || m.delay != delay || state().State != index.ProposalOpen || len(said) != 0 {
t.Fatalf("delivery %d: naked %t after %v, key %+v, said %v; want it left for the bus after %v, the key open, nothing said", n, m.naked, m.delay, state(), said, delay)
}
}
m := &deliveredMsg{subject: "decided", data: body, n: EventDeliveries}
heardDecided(ctx, reg, m, func(string, ...any) {})
heardDecided(ctx, reg, m, index.DefaultRedeliverPace, func(string, ...any) {})
if p := state(); !m.naked || p.State != index.ProposalRefused || !strings.HasPrefix(p.Outcome, "not applied: ") || !strings.Contains(p.Outcome, "no response from stream") {
t.Fatalf("the last delivery: naked %t, key %+v; want it ended refused, not applied, naming the reason", m.naked, p)
}
@@ -81,3 +84,31 @@ func TestAWarrantIsGivenUpOnItsLastDelivery(t *testing.T) {
t.Fatalf("said %v; want registration-unwritten of source.novox.hq naming the ask and the reason", said)
}
}
// Design 47 H2 H-A-773 (3), (4): a package-published the indexer cannot keep (the bus refused JetStream for a few seconds) is left
// for the bus after a wait that doubles with each delivery from the setting redeliver-pace-first, so its five deliveries span
// about 30 s and are not spent at once; the last says it gives the message up.
func TestARefusedPackagePublishedIsGivenAgainAfterAGrowingWait(t *testing.T) {
ctx := context.Background()
body, _ := json.Marshal(map[string]any{"v": 1, "module": "mesh-delivery-watchman", "artifact": "mesh-delivery-watchman:program", "version": "0.1.170"})
ix := &index.Indexer{} // keeps no state versions, so each delivery is refused
for _, c := range []struct {
pace time.Duration
n uint64
delay time.Duration
}{{index.DefaultRedeliverPace, 1, 2 * time.Second}, {index.DefaultRedeliverPace, 2, 4 * time.Second}, {index.DefaultRedeliverPace, 3, 8 * time.Second},
{index.DefaultRedeliverPace, 4, 16 * time.Second}, {5 * time.Second, 2, 10 * time.Second}} {
var said []string
m := &deliveredMsg{subject: "mesh.seat.mesh-builds.event.package-published", data: body, n: c.n}
heardPackagePublished(ctx, ix, m, c.pace, func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) })
if !m.naked || m.delay != c.delay || slices.ContainsFunc(said, func(l string) bool { return strings.HasPrefix(l, "gives up") }) {
t.Errorf("delivery %d at a pace of %v: naked %t after %v, said %q; want it given again after %v, not given up", c.n, c.pace, m.naked, m.delay, said, c.delay)
}
}
var said []string
m := &deliveredMsg{subject: "mesh.seat.mesh-builds.event.package-published", data: body, n: EventDeliveries}
heardPackagePublished(ctx, ix, m, index.DefaultRedeliverPace, func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) })
if !slices.ContainsFunc(said, func(l string) bool { return strings.HasPrefix(l, "gives up") && strings.Contains(l, "0.1.170") }) {
t.Errorf("the last delivery said %q; want it given up, naming the version", said)
}
}
@@ -65,19 +65,35 @@ func startHearing(ctx context.Context, hub hubStarter, js jetstream.JetStream, c
// composes a module's durable with (mesh-grants buscompose).
const EventDeliveries = 5
// leftForBus leaves a message the indexer could not take for the bus to give again, and on the last delivery its consumer allows
// says that it gives the message up, naming its subject, what it carries and the last refusal (design 47 G A-420): past it the bus
// drops the message without a word.
func leftForBus(m jetstream.Msg, what string, err error, logf func(string, ...any)) {
_ = m.Nak()
if md, merr := m.Metadata(); merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
// leftForBus leaves a message the indexer could not take for the bus to give again after the delay of its delivery (redeliverDelay
// of pace, the setting redeliver-pace-first; design 47 H2 H-A-773 (3), (4)), and on the last delivery its consumer allows says that
// it gives the message up, naming its subject, what it carries and the last refusal (design 47 G A-420): past it the bus drops the
// message without a word.
func leftForBus(m jetstream.Msg, pace time.Duration, what string, err error, logf func(string, ...any)) {
md, merr := m.Metadata()
n := uint64(1)
if merr == nil && md != nil && md.NumDelivered > 0 {
n = md.NumDelivered
}
_ = m.NakWithDelay(redeliverDelay(pace, n))
if merr == nil && md != nil && md.NumDelivered >= EventDeliveries {
logf("gives up %s: %s, delivered %d times, the most its consumer allows; the last refusal: %v", m.Subject(), what, md.NumDelivered, err)
}
}
// redeliverDelay is the wait before the bus gives a message again after its delivery n (1 the first): pace, doubled with each
// delivery after the first (H-A-773 (4)).
func redeliverDelay(pace time.Duration, n uint64) time.Duration {
d := pace
for i := uint64(1); i < n && i < EventDeliveries; i++ {
d *= 2
}
return d
}
// heardPackagePublished takes one package-published of the seat mesh-builds into the catalog's versions (design 47 G §349):
// one that does not decode is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var p meshbuilds.PackagePublished
if err := json.Unmarshal(m.Data(), &p); err != nil {
logf("%s holds what is no package-published, left: %v", m.Subject(), err)
@@ -86,7 +102,7 @@ func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.M
}
if err := ix.HearPackagePublished(ctx, p); err != nil {
logf("versions: the package-published of %s %s could not be kept, so the bus gives it again: %v", p.Artifact, p.Version, err)
leftForBus(m, fmt.Sprintf("the package-published of %s %s", p.Artifact, p.Version), err, logf)
leftForBus(m, pace, fmt.Sprintf("the package-published of %s %s", p.Artifact, p.Version), err, logf)
return
}
_ = m.Ack()
@@ -94,7 +110,7 @@ func heardPackagePublished(ctx context.Context, ix *index.Indexer, m jetstream.M
// heardVersionReserved takes one version-reserved of the seat mesh-builds in (design 47 H2 §805): one that does not decode
// is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e meshbuilds.VersionReservedEvent
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no version-reserved, left: %v", m.Subject(), err)
@@ -103,7 +119,7 @@ func heardVersionReserved(ctx context.Context, ix *index.Indexer, m jetstream.Ms
}
if err := ix.HearVersionReserved(ctx, e); err != nil {
logf("versions: the version-reserved of %s %s could not be kept, so the bus gives it again: %v", e.Artifact, e.Version, err)
leftForBus(m, fmt.Sprintf("the version-reserved of %s %s", e.Artifact, e.Version), err, logf)
leftForBus(m, pace, fmt.Sprintf("the version-reserved of %s %s", e.Artifact, e.Version), err, logf)
return
}
_ = m.Ack()
@@ -125,7 +141,7 @@ func heardBuildStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg
}
// heardStepEnded deletes the input kept for the run ask a build seat's step-ended names (design 47 G §354, A-78 d).
func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e nodebuildgo.StepEnded
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no step-ended, left: %v", m.Subject(), err)
@@ -134,7 +150,7 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
}
if err := ix.HearInputEnded(ctx, e); err != nil {
logf("inputs: the input of the ask %s could not be deleted, so the bus gives it again: %v", e.Ask, err)
leftForBus(m, "the step-ended of the ask "+e.Ask, err, logf)
leftForBus(m, pace, "the step-ended of the ask "+e.Ask, err, logf)
return
}
_ = m.Ack()
@@ -142,7 +158,7 @@ func heardStepEnded(ctx context.Context, ix *index.Indexer, m jetstream.Msg, log
// heardImportsReported keeps a build's import set (design 47 H2 H-A-517, H-A-527): one that does not decode, or names no
// module or fingerprint, is said and acknowledged; one that cannot be kept is left, so the bus gives it again.
func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Msg, logf func(string, ...any)) {
func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Msg, pace time.Duration, logf func(string, ...any)) {
var e nodebuildgo.ImportsReported
if err := json.Unmarshal(m.Data(), &e); err != nil {
logf("%s holds what is no imports-reported, left: %v", m.Subject(), err)
@@ -155,7 +171,7 @@ func heardImportsReported(ctx context.Context, ix *index.Indexer, m jetstream.Ms
logf("%s: %v, left", m.Subject(), err)
case err != nil:
logf("imports: the import set of %s at %s could not be kept, so the bus gives it again: %v", e.Module, e.Fingerprint, err)
leftForBus(m, fmt.Sprintf("the imports-reported of %s at %s", e.Module, e.Fingerprint), err, logf)
leftForBus(m, pace, fmt.Sprintf("the imports-reported of %s at %s", e.Module, e.Fingerprint), err, logf)
return
}
_ = m.Ack()
@@ -10,6 +10,7 @@ import (
"slices"
"strconv"
"strings"
"time"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
@@ -38,6 +39,14 @@ const (
PendingPrefix = "pending."
)
// The setting redeliver-pace-first and its default (design 47 H2 H-A-773 (3), (4)): the first wait before the bus gives again a
// message of the indexer's events consumer that it could not take, doubled with each delivery (2, 4, 8 and 16 s between the
// consumer's five deliveries), so a bus refusal of a few seconds spends none of them.
const (
RedeliverPaceSetting = "redeliver-pace-first"
DefaultRedeliverPace = 2 * time.Second
)
// published is what a not yet released version holds: each artifact published at it, by reference.
type published struct {
Artifacts map[string]meshcatalog.VersionArtifact `json:"artifacts"`
@@ -246,7 +246,8 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
if m.Class != "core" {
t.Errorf("class = %q, want core", m.Class)
}
for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s", index.WaitingLineSetting: "1m", index.WaitingBoundSetting: "5m", index.RereadPaceFirstSetting: "5s", index.RereadPaceMaxSetting: "1m"} {
for key, def := range map[string]string{busretry.PaceFirstSetting: "1s", busretry.PaceMaxSetting: "30s", index.WaitingLineSetting: "1m", index.WaitingBoundSetting: "5m", index.RereadPaceFirstSetting: "5s", index.RereadPaceMaxSetting: "1m",
index.RedeliverPaceSetting: "2s"} { // H-A-773 (4): the wait before the bus gives a refused message again, 2 s doubling
if c, _ := m.Config[key].(map[string]any); c["default"] != def || c["runtime"] != true || c["type"] != "string" {
t.Errorf("config %s = %v, want a runtime string setting defaulting to %s", key, m.Config[key], def)
}
@@ -110,6 +110,13 @@
"default": "1s",
"runtime": true
},
"redeliver-pace-first": {
"type": "string",
"description": "the first wait before the bus gives again a message of the indexer's events consumer that it could not take, doubled with each delivery (2, 4, 8 and 16 s between the five), a Go duration (design 47 H2 H-A-773 (3), (4)).",
"trusted": false,
"default": "2s",
"runtime": true
},
"kept-call-pace-max": {
"type": "string",
"description": "the longest wait between two tries of a kept call after a transport fault, a Go duration (design 47 H2 §775).",