B8/B9 publish-in-progress: an item is marked in progress at the kept call's pace while its call waits; a call not answered within the bound (publish-ack-minutes) leaves the item to be given again, never ended as failed; the constant UnreleasedBound leaves the send

Builds: design 47 H2 H-A-613 (3), H-A-613 (4), H-A-745
This commit is contained in:
2026-11-25 19:28:19 +01:00
parent d4f9fd013d
commit c41168ff34
6 changed files with 125 additions and 7 deletions
@@ -298,6 +298,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
return err
}
pq.ackWait = time.Duration(publishAck) * time.Minute // a sent item unheard is given again after the publish bound (H-A-613 (3))
republish.Bound = pq.ackWait // a send's calls wait that long at most, then the item is given again (H-A-613 (3), H-A-745)
actedDays, err := numberFile(getenv("MESH_BUILDER_ACTED_DAYS_FILE"), versions.DefaultActedDays)
if err != nil {
return err
@@ -17,6 +17,7 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
"git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/process"
@@ -48,6 +49,9 @@ type publishItems struct {
// unreleased raises version-unreleased about a version with the words given (Republisher's Unreleased); nil raises none.
unreleased func(ctx context.Context, v versions.ReservedVersion, why string)
logf func(string, ...any)
// progressEvery is the pace the bus is told an item is in progress at while its send's calls wait: the kept call's pace
// (busretry.KeptPace's most) when zero (design 47 H2 H-A-613 (3)).
progressEvery time.Duration
mu sync.Mutex
held map[string][]heldItem // "<module> <version>": the items sent, their publish not yet heard
@@ -75,6 +79,7 @@ func (p *publishItems) Done(ctx context.Context, module, version string) {
// itemMsg is what take reads of an item pulled from the work queue (jetstream.Msg).
type itemMsg interface {
Data() []byte
InProgress() error
Ack() error
NakWithDelay(time.Duration) error
Term() error
@@ -133,7 +138,11 @@ func (p *publishItems) take(ctx context.Context, m itemMsg) {
}
fate := versions.SendFate{Failed: "this builder sends no publish"}
if p.send != nil {
// The item is marked in progress while its calls wait, so the bus gives it again only when the builder itself stopped
// (design 47 H2 H-A-613 (3)).
stop := p.inProgress(m)
fate = p.send(ctx, q)
stop()
}
if fate.Unread != "" {
// A read of the builder's own state that failed is no answer of a holder: the item is left unacknowledged, given again after the
@@ -152,6 +161,37 @@ func (p *publishItems) take(ctx context.Context, m itemMsg) {
return
}
p.hold(q, m)
// Its publish heard between the send and the hold would be missed by both: read again once held.
p.heard(ctx, q.Module, q.Version)
}
// inProgress tells the bus the item is in progress now and at the kept call's pace until the returned function is called.
func (p *publishItems) inProgress(m itemMsg) (stop func()) {
every := p.progressEvery
if every <= 0 {
every = busretry.KeptPace().Max
}
say := func() {
if err := m.InProgress(); err != nil {
p.logf("an item in progress is not said to the bus: %v", err)
}
}
done, ended := make(chan struct{}), make(chan struct{})
go func() {
defer close(ended)
say()
t := time.NewTicker(every)
defer t.Stop()
for {
select {
case <-t.C:
say()
case <-done:
return
}
}
}()
return func() { close(done); <-ended }
}
// allPublished says none of q's artifacts is missing from v: its publish is heard.
@@ -8,6 +8,7 @@ import (
"slices"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
@@ -103,14 +104,23 @@ func (l itemKeys) Stop() error { return nil }
// itemMsgFake is an item pulled from the work queue: what take settled it with.
type itemMsgFake struct {
progress atomic.Int64 // InProgress calls
onWorking func(n int64) // told the count after each
data []byte
delivered uint64 // the delivery count Metadata says; 0 says none
settled []string // ack, term, nak <delay>
}
func (m *itemMsgFake) Data() []byte { return m.data }
func (m *itemMsgFake) Ack() error { m.settled = append(m.settled, "ack"); return nil }
func (m *itemMsgFake) Term() error { m.settled = append(m.settled, "term"); return nil }
func (m *itemMsgFake) InProgress() error {
n := m.progress.Add(1)
if m.onWorking != nil {
m.onWorking(n)
}
return nil
}
func (m *itemMsgFake) Ack() error { m.settled = append(m.settled, "ack"); return nil }
func (m *itemMsgFake) Term() error { m.settled = append(m.settled, "term"); return nil }
func (m *itemMsgFake) Metadata() (*jetstream.MsgMetadata, error) {
if m.delivered == 0 {
return nil, errors.New("no metadata")
@@ -182,6 +192,33 @@ func TestAPublishIsPutOnceAtABuildsEndAndNeverOnATimer(t *testing.T) {
if len(sent) != 2 || len(m.settled) != 0 {
t.Fatalf("an unread send: sent %v, settled %v, want it left unacknowledged", sent, m.settled)
}
// design 47 H2 H-A-613 (3): while its calls wait the item is marked in progress at the kept call's pace, so the bus gives it again only
// when the builder itself stopped; the send here answers once the bus has been told three times.
told := make(chan struct{})
p.progressEvery = time.Millisecond
p.send = func(context.Context, versions.QueuedPublish) versions.SendFate {
select {
case <-told:
return versions.SendFate{Unread: "not answered within the bound"}
case <-time.After(10 * time.Second):
return versions.SendFate{Failed: "the item was never marked in progress"}
}
}
m = queuedMsg(t, "m", "0.1.2")
var once sync.Once
m.onWorking = func(n int64) {
if n >= 3 {
once.Do(func() { close(told) })
}
}
p.take(ctx, m)
if n := m.progress.Load(); n < 3 || len(m.settled) != 0 {
t.Fatalf("a send whose call waits: told in progress %d times, settled %v, want 3 or more and the item left, never ended", n, m.settled)
}
p.send = func(_ context.Context, q versions.QueuedPublish) versions.SendFate {
sent = append(sent, q.Module+" "+q.Version)
return fate
}
fate = versions.SendFate{Sent: true}
m = queuedMsg(t, "m", "0.1.2")
p.take(ctx, m)
@@ -14,6 +14,7 @@ import (
"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/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/busretry"
)
// **A reserved version of a done build is published by the builder until its release is written** (design 47 G §588, A-457a): the
@@ -199,6 +200,9 @@ type Republisher struct {
// Ended ends the publish item of a version that never publishes, its reservation withdrawn or taken over (H-A-290 (2));
// nil ends none.
Ended func(ctx context.Context, module, version string)
// Bound is how long one item's send waits on its calls, the setting publish-ack-minutes (design 47 H2 H-A-613 (3), H-A-745); past it
// the item is left to be given again, never ended. Zero bounds the send by its context alone.
Bound time.Duration
mu sync.Mutex
// lastQueued is the newest time a version was queued at: a clock that has not moved between two versions (a coarse clock,
@@ -711,17 +715,21 @@ func (r *Republisher) MoveQueued(ctx context.Context, vals []json.RawMessage) (i
// SendFate is what SendQueued did with one item (§793): Sent, every artifact sent (its item acknowledged when its publish is
// heard or confirmed); Ended, why the version never publishes (its item terminated); Failed, the holder's or the call's words
// (its item ended, the version staying reserved); Unread, why a read of the builder's own state failed: nothing was sent, the item is
// left unacknowledged and given again after the ack wait (design 47 H2 H-A-745).
// (its item ended, the version staying reserved); Unread, why a read of the builder's own state failed or a call was not answered within the bound:
// the item is left unacknowledged and given again after the ack wait (design 47 H2 H-A-745, H-A-613 (3)).
type SendFate struct {
Sent bool
Ended, Failed, Unread string
}
// SendQueued publishes one item's artifacts and says the outcome. Every call it makes honours the one bound it is given,
// UnreleasedBound (a context's bound, no timer, ADR 0437 §8), and a send that returns without sending says why (H-A-290 (4)).
// SendQueued publishes one item's artifacts and says the outcome. Every call it makes honours the one bound it is given, Bound
// (a context's bound, no timer, ADR 0437 §8), and a send that returns without sending says why (H-A-290 (4)). A call not answered
// within the bound, or stopped with the builder, leaves the item to be given again (Unread), never ended (H-A-613 (3), H-A-745).
func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate {
bound, cancel := context.WithTimeout(ctx, UnreleasedBound)
bound, cancel := ctx, context.CancelFunc(func() {})
if r.Bound > 0 {
bound, cancel = context.WithTimeout(ctx, r.Bound)
}
defer cancel()
all, err := r.Reserved.All(bound)
if err != nil {
@@ -816,6 +824,13 @@ func (r *Republisher) SendQueued(ctx context.Context, q QueuedPublish) SendFate
r.end(ctx, q.Module, q.Version, words)
return SendFate{Ended: words}
}
var unanswered *busretry.Unanswered
if bound.Err() != nil || errors.As(err, &unanswered) {
// Not answered within the bound, or the builder stopped: no holder refused it, so the item is left, given again after the ack
// wait, and the queue's tenth delivery ends it loud (design 47 H2 H-A-613 (3), H-A-745, H-A-653).
r.logf("publish again: %s %s: %s is not answered by %s: %v; the item is left, given again after the ack wait", q.Module, q.Version, ref, seat, err)
return SendFate{Unread: fmt.Sprintf("%s is not answered by %s: %v", ref, seat, err)}
}
r.logf("publish again: %s %s: %s refused by %s: %v", q.Module, q.Version, ref, seat, err)
words := err.Error()
if strings.Contains(words, strings.TrimSuffix(NotStoredWords, ": ")) {
@@ -16,6 +16,7 @@ import (
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"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/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/seatlist"
)
@@ -474,6 +475,25 @@ func TestAQueuedItemIsSentWhileItsBuildStands(t *testing.T) {
t.Errorf("an unreadable reservation answered %+v: want it unread", f)
}
})
// design 47 H2 H-A-613 (3), H-A-745: a call not answered within the bound, and one stopped with the builder, is no answer of a holder: the
// item is left to be given again, never ended as failed.
t.Run("a call not answered within the bound leaves the item to be given again", func(t *testing.T) {
b := newRepublishBed(t)
v := b.reserve(t, "u")
b.holders = map[string][]string{SeatArtifacts: {"oci"}}
b.Bound = time.Minute
b.Send = func(context.Context, Publish) error {
return fmt.Errorf("oci's publish of u: %w", &busretry.Unanswered{Seat: SeatArtifacts, Verb: VerbPublish, Bound: time.Minute, Last: errors.New("no responders")})
}
if f := b.SendQueued(ctx, b.queueAt(v, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" || f.Sent {
t.Errorf("a call not answered within the bound answered %+v, want it unread, given again", f)
}
stopped, stop := context.WithCancel(ctx)
b.Send = func(c context.Context, _ Publish) error { stop(); return c.Err() }
if f := b.SendQueued(stopped, b.queueAt(v, PublishClassLive, b.now)); f.Unread == "" || f.Failed != "" || f.Ended != "" {
t.Errorf("a send stopped with the builder answered %+v, want it unread, given again", f)
}
})
// design 47 H2 H-A-746: a publish dropped by hand is kept on its reservation, which its standing reads: an event does not put it,
// a send ends it unsent, and builder_publish_again puts it and clears the drop.
t.Run("a publish dropped by hand is passed over and asked anew by builder_publish_again", func(t *testing.T) {
@@ -354,6 +354,11 @@ func TestServesNoRequestSubjectAndHoldsNoTicker(t *testing.T) { // 1607/AC6 (ADR
}
// Design 47 H2 H-A-654: the publishes' dispatch takes the step queue's shape, bound again on the consumer's created and
// deleted advisories: the same one kind of subscription.
// Design 47 H2 H-A-613 (3): a publish item is marked in progress while its call waits, at the kept call's pace (the
// queue's own cadence, as the step queue's), so the bus gives it again only when the builder itself stopped.
if f == "time.NewTicker" && filepath.ToSlash(path) == "cmd/mesh-delivery-builder/publishitem.go" {
continue
}
if f == "Subscribe(" && filepath.ToSlash(path) == "cmd/mesh-delivery-builder/publishitem.go" {
continue
}