builder: say a message given up on the last delivery its consumer allows

The builder leaves an event it cannot take for the bus to give again, and the bus drops it after the fifth delivery its
durable allows without a word: the 0.1.6 published was lost so. On that last delivery the builder now says it gives the
message up, naming its subject, what it carries (a registry outcome's name and version, a version-released's module and
version) and the last refusal.

Builds: design 47 G A-420
This commit is contained in:
2026-11-15 03:19:10 +01:00
parent c677534e11
commit 61fff7da67
5 changed files with 33 additions and 0 deletions
@@ -228,6 +228,8 @@ type wakeMsg struct {
acked bool
naked bool
delayed time.Duration
// delivered is the delivery count Metadata says; 0 says no metadata.
delivered uint64
}
func (m *wakeMsg) Subject() string { return m.subject }
@@ -239,6 +241,9 @@ func (m *wakeMsg) NakWithDelay(d time.Duration) error {
return nil
}
func (m *wakeMsg) Metadata() (*jetstream.MsgMetadata, error) {
if m.delivered > 0 {
return &jetstream.MsgMetadata{NumDelivered: m.delivered}, nil
}
return nil, errors.New("no metadata")
}
func (m *wakeMsg) Headers() nats.Header {
@@ -297,6 +302,15 @@ func aFloorsWakeIsHeard(t *testing.T) {
if h.heard(context.Background(), &wakeMsg{subject: manifestAcceptedSubject}) {
t.Fatal("manifest-accepted was taken as a seat's outcome")
}
// Design 47 G A-420: a message left for the bus is said given up on the last delivery its consumer allows, never before.
for _, n := range []uint64{4, EventDeliveries} {
logs.Reset()
givenUp(&wakeMsg{subject: "mesh.seat.oci-artifact-registry.event.published", delivered: n}, "oci-artifact-registry's published of m/program@0.1.6", errors.New("down"), log.New(&logs, "", 0).Printf)
said := strings.Contains(logs.String(), "gives up mesh.seat.oci-artifact-registry.event.published: oci-artifact-registry's published of m/program@0.1.6, delivered 5 times, the most its consumer allows; the last refusal: down")
if said != (n == EventDeliveries) {
t.Errorf("delivery %d: log %q", n, logs.String())
}
}
}
// noVersions is a state versions that holds nothing.
@@ -140,6 +140,7 @@ func (g *republishing) heard(ctx context.Context, m jetstream.Msg, logf func(str
if nakErr := m.Nak(); nakErr != nil {
logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, "its event", err, logf)
return true
}
return false
@@ -192,6 +192,7 @@ func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
if nakErr := m.Nak(); nakErr != nil {
rv.logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, "the version-released of "+ev.Module+" "+ev.Version, err, rv.logf)
return true
}
gone, err := rv.r.Released(ctx, ev.Module, ev.Version)
@@ -200,6 +201,7 @@ func (rv *reservations) heard(ctx context.Context, m jetstream.Msg) bool {
if nakErr := m.Nak(); nakErr != nil {
rv.logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, "the version-released of "+ev.Module+" "+ev.Version, err, rv.logf)
return true
}
for _, k := range gone {
@@ -27,6 +27,7 @@ func (g *retaking) heard(ctx context.Context, m jetstream.Msg, logf func(string,
if nakErr := m.Nak(); nakErr != nil {
logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, "its event", err, logf)
return true
}
return false
@@ -67,6 +68,7 @@ func (d *decisions) hear(logf func(string, ...any)) func(pattern string, handle
if nakErr := m.Nak(); nakErr != nil {
logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, "the operator's warrant", err, logf)
return
}
if err := m.Ack(); err != nil {
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
"strings"
@@ -95,6 +96,7 @@ func (h *seatHearer) heard(ctx context.Context, m jetstream.Msg) bool {
if nakErr := m.Nak(); nakErr != nil {
h.logf("leaving %s for the bus to give again: %v", m.Subject(), nakErr)
}
givenUp(m, fmt.Sprintf("%s's %s of %s@%s", se.seat, se.event, o.Name, o.Version), err, h.logf)
return true
}
if h.pub != nil {
@@ -121,6 +123,18 @@ func deliveryOf(m jetstream.Msg) string {
return strconv.FormatUint(md.NumDelivered, 10)
}
// EventDeliveries is how many times the bus gives a message of the builder's events consumer: the MaxDeliver the grants part
// composes a module's durable with (mesh-grants buscompose).
const EventDeliveries = 5
// givenUp says, on the last delivery the events consumer allows, that the builder 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 givenUp(m jetstream.Msg, what string, err error, logf func(string, ...any)) {
if md, merr := m.Metadata(); 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)
}
}
func (h *seatHearer) ack(m jetstream.Msg) {
if err := m.Ack(); err != nil {
h.logf("acknowledging %s: %v", m.Subject(), err)