R1: the runner puts a step's ask and asks published as kept calls, paced, within ask-unanswered-bound

A put that met a transport fault is put again under the ask's own id at the
kept-call pace instead of failing the step at the first fault.

Builds: design 47 H2 §775
This commit is contained in:
2026-11-22 00:15:07 +01:00
parent 125d6382ea
commit 1058b0eec6
3 changed files with 115 additions and 21 deletions
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"
"time"
"github.com/nats-io/nats.go"
@@ -11,17 +12,23 @@ import (
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient"
gitseat "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-pipeline/internal/pipeline"
)
// busStepAsker puts a step's ask on a build seat's work queue at the seat's accept subject, under the runner's own name; its
// duplicate id is the ask's own, so an ask put twice is kept once (design 47 G §22, §24).
// duplicate id is the ask's own, so an ask put twice is kept once (design 47 G §22, §24). The put is a kept call of the
// paced form (design 47 H2 §775): a put that met a transport fault is put again under the same id at the kept-call pace,
// until the runner's ask-unanswered-bound (bound); past it the error names every put's time and words. A refusal of the
// put returns at once.
type busStepAsker struct {
ctx context.Context
js jetstream.JetStream
cred process.Account
ctx context.Context
publish func(context.Context, *nats.Msg, ...jetstream.PublishOpt) (*jetstream.PubAck, error)
cred process.Account
bound time.Duration
logf func(string, ...any)
}
func (b busStepAsker) AskStep(accept, id string, body any) error {
@@ -29,18 +36,35 @@ func (b busStepAsker) AskStep(accept, id string, body any) error {
if err != nil {
return err
}
msg := nats.NewMsg(accept)
msg.Header.Set("x-event-id", id)
msg.Header.Set("x-source", b.cred.Module)
msg.Header.Set("x-node", b.cred.Node)
msg.Header.Set("x-time", time.Now().UTC().Format(time.RFC3339Nano))
msg.Header.Set("content-type", "application/json")
msg.Header.Set(nats.MsgIdHdr, id)
msg.Data = data
_, err = b.js.PublishMsg(b.ctx, msg)
seatName, kind := acceptedOf(accept)
k := busretry.Kept{Seat: seatName, Verb: "accept." + kind, Ask: id, Bound: b.bound, Logf: b.logf}
_, err = busretry.DoPaced(k, func() (*jetstream.PubAck, error) {
msg := nats.NewMsg(accept)
msg.Header.Set("x-event-id", id)
msg.Header.Set("x-source", b.cred.Module)
msg.Header.Set("x-node", b.cred.Node)
msg.Header.Set("x-time", time.Now().UTC().Format(time.RFC3339Nano))
msg.Header.Set("content-type", "application/json")
msg.Header.Set(nats.MsgIdHdr, id)
msg.Data = data
return b.publish(b.ctx, msg)
})
return err
}
// acceptedOf is the seat and the accepted kind an accept subject names (mesh.seat.<seat>.accept.<kind>); a subject of
// another form names itself as the seat.
func acceptedOf(accept string) (seatName, kind string) {
rest, ok := strings.CutPrefix(accept, "mesh.seat.")
if !ok {
return accept, ""
}
if i := strings.Index(rest, ".accept."); i >= 0 {
return rest[:i], rest[i+len(".accept."):]
}
return rest, ""
}
var _ pipeline.StepAsker = busStepAsker{}
// commitAuthor reads the forge's login of the author of a commit through the seat git's verb pull, by the commit that merged it
@@ -0,0 +1,67 @@
package main
import (
"context"
"errors"
"testing"
"time"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-sdk/go/busretry"
"git.novox.be/novox/mesh-sdk/go/process"
)
// A step's ask is a kept put of the paced form (design 47 H2 §775): put again under its own id through a transport fault
// until it lands, ended past ask-unanswered-bound naming every put, and a refusal returned at once.
func TestAStepsAskIsAKeptPut(t *testing.T) {
t.Cleanup(busretry.Waits(time.Minute, time.Millisecond, 2*time.Millisecond))
refused := errors.New("nats: permissions violation")
for _, tc := range []struct {
name string
faults []error // what each put meets before one lands; nil after them lands
always error // what every put meets, when set
bound time.Duration
puts int
want func(error) bool
}{
{name: "put again through no responders until it lands", faults: []error{nats.ErrNoResponders, nats.ErrTimeout},
bound: time.Minute, puts: 3, want: func(err error) bool { return err == nil }},
{name: "a refusal returns at once", always: refused, bound: time.Minute, puts: 1,
want: func(err error) bool { return errors.Is(err, refused) }},
{name: "past the bound every put is named", always: nats.ErrNoResponders, bound: 20 * time.Millisecond, puts: -1,
want: func(err error) bool {
var u *busretry.Unanswered
return errors.As(err, &u) && u.Seat == "mesh-wants" && u.Verb == "accept.step" && u.Ask == "ask-1" && len(u.Tries) > 1
}},
} {
t.Run(tc.name, func(t *testing.T) {
var ids []string
publish := func(_ context.Context, m *nats.Msg, _ ...jetstream.PublishOpt) (*jetstream.PubAck, error) {
ids = append(ids, m.Header.Get(nats.MsgIdHdr))
if tc.always != nil {
return nil, tc.always
}
if len(ids) <= len(tc.faults) {
return nil, tc.faults[len(ids)-1]
}
return &jetstream.PubAck{}, nil
}
a := busStepAsker{ctx: context.Background(), publish: publish, cred: process.Account{Module: "mesh-delivery-pipeline"},
bound: tc.bound, logf: func(string, ...any) {}}
err := a.AskStep("mesh.seat.mesh-wants.accept.step", "ask-1", map[string]string{"step": "composition"})
if !tc.want(err) {
t.Fatalf("AskStep = %v", err)
}
if tc.puts > 0 && len(ids) != tc.puts {
t.Fatalf("put %d times, want %d", len(ids), tc.puts)
}
for _, id := range ids {
if id != "ask-1" {
t.Fatalf("a put carried the id %q, want the ask's own", id)
}
}
})
}
}
@@ -154,21 +154,21 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
hearer.LogLast = stepLog{ctx: ctx, js: js, module: cred.Module}.Last
hearer.Where = routerRecordOf(cred.Module, calls.Call, calls.Ask)
hearer.Failures = &pipeline.Failures{Findings: rv.Findings, Observer: cred.Module, Author: commitAuthor(calls.Call), Logf: logger.Printf}
// Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state
// bounds. A step's ask is put as a kept call within the same bound (design 47 H2 §775).
askBound, err := askUnansweredBound(getenv)
if err != nil {
return err
}
// Its asking half (§22, §24): a pipeline's steps are placed from the module's registration and each build seat is asked
// for its step.
starter := &pipeline.Starter{Pipelines: store, Logf: logger.Printf, Say: say,
Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, js: js, cred: cred}, Name: cred.Module,
Registration: rv.Registrations.Registration, Steps: busStepAsker{ctx: ctx, publish: js.PublishMsg, cred: cred, bound: askBound, logf: logger.Printf}, Name: cred.Module,
Kept: keptReader(ctx, kept), Toolchain: toolchainReader(ctx, toolchains),
Fills: fills, Recovered: kvRecoveries{ctx, recovered}.Has, Holders: rv.Holders.Holders, Ended: hearer.EndedAtPlacing,
Findings: rv.Findings, Observer: cred.Module} // a mover waiting on its registration is registration-missing (H-A-262)
hearer.AskSteps = starter.AskSteps
hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4))
// Every ask but a test run's is bounded until its holder's first word (H-A-235, H-A-238), its bounds keys of the state
// bounds.
askBound, err := askUnansweredBound(getenv)
if err != nil {
return err
}
silentBound, err := askSilentBound(getenv)
if err != nil {
return err
@@ -180,7 +180,10 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
starter.Left = hearer.LeftInPlace // a same-source re-pin's superseded steps leave their runs (H-A-284)
starter.Revision = widener.Revision // a kept mover is placed from its kept revision (H-A-286)
// A mover's wait on a package is read first: a package published before the wait places it at once (H-A-326, H-A-328).
starter.AskPublished = publishedOf(boundedCalls(calls.Call, readBound, time.After, logger.Printf))
// It is a kept call within ask-unanswered-bound (design 47 H2 §775).
starter.AskPublished = publishedOf(func(key string, body any) (json.RawMessage, error) {
return calls.CallKeptAsk(process.KeptAsk{Bound: askBound}, key, body)
})
hearer.Unplaced = func(p seat.Pipeline, module string) string { return starter.Unplaced(p, module, rv.Catalog.View) }
hearer.AskPinHeld = func(key, module string, pins map[string]string) {
if _, err := starter.AskPinHeld(hearer.Store, key, module, pins, widener.Revision); err != nil {