Compare commits

..
Author SHA1 Message Date
jschoubben 7617dda5f6 steprun: an ask naming no recipe is not declined for its recipe
The runner names a step ask's toolchain by language and version; every node sat out every TypeScript step.

Builds: design 47 G §416 (A-104)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 16:27:26 +01:00
jschoubben 13db05ce60 steprun: the decline of a pipeline step is held by a test; RunsCounted cites A-489c
Builds: design 47 G §24; lead answers A-489a, A-489c

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:45:48 +01:00
jschoubben 334bc54767 steprun: an unread ask whose refusal cannot be written is given back; the unwritten-end and said-end cases assert what they claim; kit case RunsCounted
Builds: design 47 G §24; lead answers A-489a, A-489b

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:42:16 +01:00
jschoubben 92196dde3a steprun: an ask on its last delivery is ended, every end is acknowledged, an unwritten end is given back (A-489a)
Builds: design 47 G §24, §25; lead answers A-489, A-489a

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:38:16 +01:00
jschoubben 16feb56fd4 steprun: PriorRuns reads a module's ReadSteps shape
Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:24:37 +01:00
jschoubben 78adc23d70 steprun: only runs that started count toward poison; an ended ask is acknowledged and its poison end said (A-489)
The bus counts an ask given back before it ran as a delivery, so four asks were ended 'poison' having never run. Puller.Prior
(PriorRuns) counts the runs the step key says started. A poisoned pipeline step now says its step-ended, so the runner stops
waiting. refuseUnread, refuseAsker and the poison path acknowledge the ask once its end is written, not terminate it.

Builds: design 47 G §24, §25; lead answer A-489 (G-22-lead-answers-2.md)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:23:13 +01:00
jschoubben 79bca88c8a steprun: a build module whose steps cannot say a step's end fails its own test (conformance.StepEnds)
A step ask refused live with 'this build module says no step's end' (mesh-build-node set no SayStep). AskSteps.SaysItsEnds
and the kit case conformance.StepEnds refuse that where the module is built.

Builds: design 47 G §24 (Asked on a work queue, ended by an event)

Claude-Session: https://claude.ai/code/session_01JG73KHUnBze48rdua8u2sy
2026-11-19 15:23:13 +01:00
24 changed files with 491 additions and 772 deletions
@@ -93,11 +93,6 @@ type seatTools struct {
// seats is the seat list the bundle reads (seatlist.go): until it is read, propose judges no mesh seat the bootstrapped // seats is the seat list the bundle reads (seatlist.go): until it is read, propose judges no mesh seat the bootstrapped
// definitions do not name as held once (ADR 0636 §1). Nil reads nothing. // definitions do not name as held once (ADR 0636 §1). Nil reads nothing.
seatList *seatlist.Part seatList *seatlist.Part
// watched is the tools process's watched copy of the state seat-holders (tools.go wants.watched, which gate.Holders
// also reads: A-298), read by the verb assignments with seats instead of a bus get per key (issue 1982: under load
// that took about 14 s, where the watched copy answers at once). Nil, or a call it cannot answer, falls back to a
// direct listing.
watched *stdio.WatchedStates
} }
func newSeatTools(st seatStore, ask func(string, any) (json.RawMessage, error)) *seatTools { func newSeatTools(st seatStore, ask func(string, any) (json.RawMessage, error)) *seatTools {
@@ -559,43 +554,25 @@ func (s *seatTools) tools() []stdio.Tool {
return out return out
} }
// seatHolders is every key of the state seat-holders and its raw value: from the watched copy (s.watched) when // seats is the verb assignments with seats (ADR 0571 §4): who holds each seat and on which node, as the state seat-holders
// there is one and it answers, else a direct listing, key by key, as the verb answered before (issue 1982). // holds it; with node, the keys of seats held on that node.
func (s *seatTools) seatHolders() (map[string][]byte, error) { func (s *seatTools) seats(node string) (any, error) {
if s.watched != nil {
if vals, err := s.watched.Values(mma.StateSeatHolders); err == nil {
return vals, nil
}
}
keys, err := s.st.keys(mma.StateSeatHolders) keys, err := s.st.keys(mma.StateSeatHolders)
if err != nil { if err != nil {
return nil, fmt.Errorf("seat-holders cannot be listed: %w", err) return nil, fmt.Errorf("seat-holders cannot be listed: %w", err)
} }
out := make(map[string][]byte, len(keys)) sort.Strings(keys)
out := []mma.SeatHolders{}
for _, key := range keys { for _, key := range keys {
raw, _, found, err := s.st.get(mma.StateSeatHolders, key) raw, _, found, err := s.st.get(mma.StateSeatHolders, key)
if err != nil { if err != nil {
return nil, fmt.Errorf("seat-holders %s cannot be read: %w", key, err) return nil, fmt.Errorf("seat-holders %s cannot be read: %w", key, err)
} }
if found { if !found {
out[key] = raw continue
} }
}
return out, nil
}
// seats is the verb assignments with seats (ADR 0571 §4): who holds each seat and on which node, as the state seat-holders
// holds it; with node, the keys of seats held on that node.
func (s *seatTools) seats(node string) (any, error) {
raws, err := s.seatHolders()
if err != nil {
return nil, err
}
keys := slices.Sorted(maps.Keys(raws))
out := []mma.SeatHolders{}
for _, key := range keys {
var sh mma.SeatHolders var sh mma.SeatHolders
if json.Unmarshal(raws[key], &sh) != nil { if json.Unmarshal(raw, &sh) != nil {
continue continue
} }
if node != "" && sh.Node != node && !slices.ContainsFunc(sh.Holders, func(h mma.SeatHoldersHoldersItem) bool { return h.Node == node }) { if node != "" && sh.Node != node && !slices.ContainsFunc(sh.Holders, func(h mma.SeatHoldersHoldersItem) bool { return h.Node == node }) {
@@ -352,53 +352,6 @@ func TestTheSeatsVerbs(t *testing.T) {
t.Errorf("seats on ace = %+v, %v", out, err) t.Errorf("seats on ace = %+v, %v", out, err)
} }
}) })
t.Run("issue 1982: assignments with seats reads the tools process's watched copy of seat-holders, the store only while it cannot", func(t *testing.T) {
seeded := map[string][]byte{}
put := func(seat, node string, holders ...mma.SeatHoldersHoldersItem) {
raw, err := json.Marshal(mma.SeatHolders{Seat: seat, Node: node, Holders: holders})
if err != nil {
t.Fatal(err)
}
seeded[seat] = raw
}
put("mesh-broker", "", mma.SeatHoldersHoldersItem{Module: "nats", Node: "ace"})
put("node-shell.g14", "g14")
st := &countingSeatStore{memStore: memStore{mma.StateSeatHolders: &memKV{values: seeded}}}
sv := newSeatTools(st, nil)
watches := 0
sv.watched = stdio.WatchedStatesOver(func(state string, handle func(stdio.StateChange) error) error {
watches++
for k, v := range seeded {
if err := handle(stdio.StateChange{Key: k, Op: stdio.OpPut, Value: v, Current: true}); err != nil {
return err
}
}
return nil
}, func(state, key string) ([]byte, bool, error) {
v, ok := seeded[key]
return v, ok, nil
})
out, err := sv.seats("")
if err != nil {
t.Fatal(err)
}
if got := out.(map[string]any)["seats"].([]mma.SeatHolders); len(got) != 2 || watches != 1 || st.keysCalls != 0 || st.getCalls != 0 {
t.Errorf("seats from the watched copy = %+v, watched %d time(s), the store's own keys %d get %d (want none)",
got, watches, st.keysCalls, st.getCalls)
}
// The lead's answer on issue 1982: the verb falls back to the store's own listing only while the watched copy
// cannot be read (here, its watch refused); the answer's form does not change.
sv.watched = stdio.WatchedStatesOver(func(string, func(stdio.StateChange) error) error {
return errors.New("refused")
}, func(state, key string) ([]byte, bool, error) { return nil, false, nil })
out, err = sv.seats("")
if err != nil {
t.Fatal(err)
}
if got := out.(map[string]any)["seats"].([]mma.SeatHolders); len(got) != 2 || st.keysCalls != 1 || st.getCalls != 2 {
t.Errorf("seats falling back to the store = %+v, the store's own keys %d get %d (want 1, 2)", got, st.keysCalls, st.getCalls)
}
})
t.Run("research 072 row 37: a node is written as its keys, and history reads the node key", func(t *testing.T) { t.Run("research 072 row 37: a node is written as its keys, and history reads the node key", func(t *testing.T) {
ctx := context.Background() ctx := context.Background()
kv := &revKV{values: map[string][]byte{}, revs: map[string]uint64{}} kv := &revKV{values: map[string][]byte{}, revs: map[string]uint64{}}
@@ -797,23 +750,6 @@ func readManifest() (catalogue.Manifest, error) {
return catalogue.Decode(raw) return catalogue.Decode(raw)
} }
// countingSeatStore is a memStore that counts its calls to keys and get, to prove a reader takes the state from the
// watched copy and the store only while that copy cannot be read (issue 1982).
type countingSeatStore struct {
memStore
keysCalls, getCalls int
}
func (c *countingSeatStore) keys(state string) ([]string, error) {
c.keysCalls++
return c.memStore.keys(state)
}
func (c *countingSeatStore) get(state, key string) ([]byte, uint64, bool, error) {
c.getCalls++
return c.memStore.get(state, key)
}
// countingKV is a memKV that counts its puts. // countingKV is a memKV that counts its puts.
type countingKV struct { type countingKV struct {
memKV memKV
@@ -419,8 +419,6 @@ func serveTools() error {
wants.watched = stdio.NewWatchedStates() // the large states read whole from one watched copy (ADR 0580 clause 3) wants.watched = stdio.NewWatchedStates() // the large states read whole from one watched copy (ADR 0580 clause 3)
// The callers' seat entries are resolved from the assigner's own seat-holders, its watched copy (A-298). // The callers' seat entries are resolved from the assigner's own seat-holders, its watched copy (A-298).
gate.Holders(seatlist.HoldersIn(func() (map[string][]byte, error) { return wants.watched.Values(mma.StateSeatHolders) })) gate.Holders(seatlist.HoldersIn(func() (map[string][]byte, error) { return wants.watched.Values(mma.StateSeatHolders) }))
// The verb assignments with seats answers from the same watched copy, so every caller of it is fast too (issue 1982).
seatVerbs.watched = wants.watched
wants.revisions = runtimeObjects{busstate.ObjectsOf(assigngraph.RevisionsObjects)} wants.revisions = runtimeObjects{busstate.ObjectsOf(assigngraph.RevisionsObjects)}
tools = append(tools, wants.tools()...) tools = append(tools, wants.tools()...)
keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}} keeper := &inputKeeper{vals: stateobjects.ForState(buckets.InputsState), now: time.Now, logf: func(string, ...any) {}}
@@ -1,120 +0,0 @@
//go:build integration
package main
import (
"context"
"encoding/json"
"strings"
"sync/atomic"
"testing"
"time"
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-sdk/go/busretry"
"mesh-delivery-indexer/internal/index"
)
// TestIndexerFillsTheFloorOfAModuleWithTags (design 47 G §412 as A-490c to A-490h amend it): the whole indexer on a real bus, the
// seat git and the package holders stood in. A module of the trunk with a Go package and no version in `versions` stays unfilled
// while the forge does not answer, and is filled from the highest of its tags and the holder's versions once the forge answers,
// with no restart and no catalog revision: the kept call gives up after its bound (one second here, so that it is spent before the
// forge answers) and the fill asks it again at once (A-490i, ADR 0668 §3). The finding after five minutes is in the unit tests (the
// five minutes are not waited for here).
func TestIndexerFillsTheFloorOfAModuleWithTags(t *testing.T) {
t.Cleanup(busretry.Waits(time.Second, 50*time.Millisecond, 200*time.Millisecond)) // the form gives up after one second
const pkg = "git.novox.be/novox/mesh-delivery/modules/" + testIndexer
var serveTags func()
var prefix atomic.Value
js, ctx, _, _ := startIndexer(t, func(context.Context, buildLog) {}, func(ctx context.Context, js jetstream.JetStream) {
for _, bucket := range []string{index.Bucket(testIndexer, index.VersionsState), index.Bucket(testIndexer, index.HeardState)} {
if _, err := js.CreateKeyValue(ctx, jetstream.KeyValueConfig{Bucket: bucket, History: 1}); err != nil {
t.Fatal(err)
}
}
// the module's artifacts are Go packages here, so that the indexer's own entries carry their names (read from go.mod, §676)
e := trunkIndexerEntryOf(t, ctx, js, func(raw []byte) []byte {
var m map[string]any
if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err)
}
m["build"] = map[string]any{"artifacts": []any{map[string]any{"name": "go", "kind": "package", "language": "go"}}}
out, _ := json.Marshal(m)
return out
})
for i := range e.Artifacts {
e.Artifacts[i].Package = &meshcatalog.ArtifactPackage{Ecosystem: index.EcosystemGo, Name: pkg}
}
seedBuildModules(t, ctx, js, map[string]meshcatalog.CatalogEntry{testIndexer: e})
reply := func(m *nats.Msg, body map[string]any) {
body["node"] = "n0"
raw, _ := json.Marshal(body)
_ = m.Respond(raw)
}
serve := func(subject string, h func(m *nats.Msg)) {
if _, err := js.Conn().Subscribe(subject, h); err != nil {
t.Fatal(err)
}
}
// the forge answers no one until the test lets it (nobody serves the verb: a transport fault, which the kept call asks again)
serveTags = func() {
serve("mesh.seat.git.tool.tags", func(m *nats.Msg) {
var in git.TagsInput
_ = json.Unmarshal(m.Data, &in)
prefix.Store(in.Prefix)
reply(m, map[string]any{"result": git.TagsAnswer{Repository: in.Repository, Tags: []string{in.Prefix + "0.4.2", in.Prefix + "0.4.10", "unrelated"}}})
})
}
// the package's name is read from the revision's own files (§676): its go.mod
serve("mesh.seat.git.tool.file", func(m *nats.Msg) {
var in git.FileInput
_ = json.Unmarshal(m.Data, &in)
if strings.HasSuffix(in.Path, "go.mod") {
reply(m, map[string]any{"result": git.FileAnswer{Path: in.Path, Ref: in.Ref, Content: "module " + pkg + "\n\ngo 1.26\n"}})
return
}
reply(m, map[string]any{"result": git.FileAnswer{Path: in.Path, Ref: in.Ref, Absent: true}})
})
serve("mesh.seat.go-package-registry.tool.versions", func(m *nats.Msg) {
reply(m, map[string]any{"result": map[string]any{"name": pkg, "versions": []any{}}})
})
})
versions, err := js.KeyValue(ctx, index.Bucket(testIndexer, index.VersionsState))
if err != nil {
t.Fatal(err)
}
// the forge is asked at the start and does not answer: the form gives up and the module's clock is kept in the state heard
heard, err := js.KeyValue(ctx, index.Bucket(testIndexer, index.HeardState))
if err != nil {
t.Fatal(err)
}
for deadline := time.Now().Add(30 * time.Second); time.Now().Before(deadline); time.Sleep(50 * time.Millisecond) {
if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err == nil {
break
}
}
if _, err := heard.Get(ctx, index.FloorSinceKey(testIndexer)); err != nil {
t.Fatalf("the unanswered floor read of the module is not kept within 30 s: %v", err)
}
if keys, _ := versions.Keys(ctx); len(keys) != 0 {
t.Fatalf("versions holds %v while the forge does not answer, want nothing", keys)
}
serveTags()
var got []string
for deadline := time.Now().Add(30 * time.Second); time.Now().Before(deadline); time.Sleep(100 * time.Millisecond) {
if got, _ = versions.Keys(ctx); len(got) > 0 {
break
}
}
if len(got) != 1 || !strings.Contains(got[0], "0.4.10") {
t.Fatalf("versions holds %v within 30 s of the forge answering, want the floor 0.4.10 of its tags", got)
}
if p, _ := prefix.Load().(string); p != "modules/"+testIndexer+"/v" {
t.Errorf("the tags were read with the prefix %q, want the package's directory and /v", p)
}
}
@@ -392,17 +392,11 @@ func TestIndexerWhole(t *testing.T) { // 1238/AC2, AC10; 1585/T14, T15
// trunkIndexerEntry keeps the indexer's own manifest by its digest, accepted, and answers its trunk entry at an earlier commit. // trunkIndexerEntry keeps the indexer's own manifest by its digest, accepted, and answers its trunk entry at an earlier commit.
func trunkIndexerEntry(t *testing.T, ctx context.Context, js jetstream.JetStream) meshcatalog.CatalogEntry { func trunkIndexerEntry(t *testing.T, ctx context.Context, js jetstream.JetStream) meshcatalog.CatalogEntry {
return trunkIndexerEntryOf(t, ctx, js, func(raw []byte) []byte { return raw })
}
// trunkIndexerEntryOf is trunkIndexerEntry with the manifest's bytes changed by edit first.
func trunkIndexerEntryOf(t *testing.T, ctx context.Context, js jetstream.JetStream, edit func([]byte) []byte) meshcatalog.CatalogEntry {
t.Helper() t.Helper()
raw, err := os.ReadFile("../../module.json") raw, err := os.ReadFile("../../module.json")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
raw = edit(raw)
var m catalogue.Manifest var m catalogue.Manifest
if err := json.Unmarshal(raw, &m); err != nil { if err := json.Unmarshal(raw, &m); err != nil {
t.Fatal(err) t.Fatal(err)
@@ -491,7 +491,7 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro
ix.Registry = registry ix.Registry = registry
named.Changed = ix.RemoveUnlisted named.Changed = ix.RemoveUnlisted
// The first fill of the versions (design 47 G §372): at the start, and again at each catalog revision kept until it is made. // The first fill of the versions (design 47 G §372): at the start, and again at each catalog revision kept until it is made.
fill := &versionsFill{ix: ix, ctx: ctx, ask: versionsVia(calls.CallKeptWhileOpen, ix.ModuleInNewestView, logger.Printf), floor: index.FloorSources{Tags: tagsVia(calls.CallKept), Holder: holderVia(calls.CallKept)}, logf: logger.Printf} fill := &versionsFill{ix: ix, ctx: ctx, ask: versionsVia(calls.CallKeptWhileOpen, ix.ModuleInNewestView, logger.Printf), logf: logger.Printf}
fillFollow.Store(fill) fillFollow.Store(fill)
fill.kick() fill.kick()
ix.SeedModules = func(ctx context.Context) ([]index.SeedModule, error) { ix.SeedModules = func(ctx context.Context) ([]index.SeedModule, error) {
@@ -4,7 +4,6 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
@@ -13,14 +12,10 @@ import (
"git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner"
"git.novox.be/novox/mesh-contracts/go/seats/nodeengine" "git.novox.be/novox/mesh-contracts/go/seats/nodeengine"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/git"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/gopackageregistry"
"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/meshbuilds"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshcatalog"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/npmpackageregistry"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/trunk"
"git.novox.be/novox/mesh-sdk/go/process" "git.novox.be/novox/mesh-sdk/go/process"
"mesh-delivery-indexer/internal/index" "mesh-delivery-indexer/internal/index"
@@ -192,11 +187,10 @@ func versionsVia(call openCaller, inView func(ctx context.Context, module string
// versionsFill is the first fill of the versions in the background (design 47 G §372): started at the start and at each // versionsFill is the first fill of the versions in the background (design 47 G §372): started at the start and at each
// catalog revision kept, until it is made; one runs at a time, and a fill that fails is said and made again at the next. // catalog revision kept, until it is made; one runs at a time, and a fill that fails is said and made again at the next.
type versionsFill struct { type versionsFill struct {
ix *index.Indexer ix *index.Indexer
ctx context.Context ctx context.Context
ask index.VersionsAsker ask index.VersionsAsker
floor index.FloorSources // what the floor reads (A-490g); a nil reader fills none logf func(string, ...any)
logf func(string, ...any)
} }
func (f *versionsFill) kick() { func (f *versionsFill) kick() {
@@ -205,28 +199,6 @@ func (f *versionsFill) kick() {
f.logf("versions: the first fill waits: %v", err) f.logf("versions: the first fill waits: %v", err)
} }
}() }()
go f.fillFloors()
}
// fillFloors fills the floor of each module the versions hold none of, each on its own so that one unanswered read holds no other
// module's (A-490d, A-490f, A-490i): at every start and every revision, not waiting for the builder's half. A read is a kept call
// asked again until it answers, and the indexer holds no timer of its own (ADR 0437 §8).
func (f *versionsFill) fillFloors() {
if f.floor.Tags == nil && f.floor.Holder == nil {
return
}
modules, err := f.ix.FloorModules(f.ctx)
if err != nil {
f.logf("versions: the floor waits: %v", err)
return
}
for _, m := range modules {
go func() {
if err := f.ix.FillFloor(f.ctx, m, f.floor); err != nil {
f.logf("versions: the floor of %s waits for the next start or revision: %v", m, err)
}
}()
}
} }
// afterRevision runs the fill's kick after each catalog revision kept, once the fill is set. // afterRevision runs the fill's kick after each catalog revision kept, once the fill is set.
@@ -294,49 +266,3 @@ func runningWholeVia(js jetstream.JetStream) index.RunningReader {
} }
} }
} }
// tagsVia reads every tag of a repository that starts with a prefix from the seat git's verb tags as a kept call, page by
// page until none is more (design 47 G §412, A-490c: protected or not).
func tagsVia(call toolCaller) index.TagsReader {
return func(_ context.Context, repository, prefix string) ([]string, error) {
var out []string
for page := int64(1); ; page++ {
var a git.TagsAnswer
in := git.TagsInput{Repository: trunk.RepositoryName(repository), Prefix: prefix, Page: page}
if !strings.Contains(in.Repository, "/") {
return nil, fmt.Errorf("%q is not <owner>/<name>", repository)
}
if err := askGit(call, git.VerbTags, in, &a); err != nil {
return nil, err
}
out = append(out, a.Tags...)
if !a.More {
return out, nil
}
}
}
}
// holderVia reads the versions a package holder answers for a package: the seat npm-package-registry's or go-package-registry's
// verb versions (A-490g), as a kept call.
func holderVia(call toolCaller) index.HolderReader {
return func(_ context.Context, ecosystem, name string) ([]string, error) {
seat := npmpackageregistry.Seat
if ecosystem == index.EcosystemGo {
seat = gopackageregistry.Seat
}
raw, err := call("seat:"+seat+"."+npmpackageregistry.VerbVersions, npmpackageregistry.VersionsInput{Name: name, Kind: npmpackageregistry.ArtifactKindPackage})
if err != nil {
return nil, err
}
var a npmpackageregistry.VersionsAnswer
if err := json.Unmarshal(raw, &a); err != nil {
return nil, fmt.Errorf("the answer of %s.versions is not a package's versions: %w", seat, err)
}
var out []string
for _, v := range a.Versions {
out = append(out, v.Version)
}
return out, nil
}
}
@@ -174,7 +174,6 @@ type Indexer struct {
previews map[string]meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue // by previews key (previews.go) previews map[string]meshdeliverychecker.PreviewsByRepositoryHeadTrunkValue // by previews key (previews.go)
toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go) toolchains map[string]map[string]nodebuildgo.Toolchain // language, then node (toolchains.go)
buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go) buildModules map[string]BuildModule // by language: the build modules whose toolchains are taken in (buildmodules.go)
floors sync.Map // the modules whose floor FillFloor reads now (tag_floor.go), one fill each
versionsFilling atomic.Bool // a FillVersions runs (versions_fill.go) versionsFilling atomic.Bool // a FillVersions runs (versions_fill.go)
stepsSince map[string]time.Time // by build seat: since when its steps is unanswered (seed_steps.go) stepsSince map[string]time.Time // by build seat: since when its steps is unanswered (seed_steps.go)
tried map[string]bool // repository, commit and directory a registered module's manifest was tried at (registered.go) tried map[string]bool // repository, commit and directory a registered module's manifest was tried at (registered.go)
@@ -1,228 +0,0 @@
package index
import (
"context"
"encoding/json"
"errors"
"fmt"
"slices"
"strings"
"time"
mcc "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshconditionsclient"
"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/keys"
)
// The floor of the catalog's versions (design 47 G §412 as A-490c to A-490h amend it): for every module the state versions
// holds no version of, the highest version among every package its catalog entry names is its first version: the Go
// package's tags in the repository the entry was taken in from, read from the seat git's verb tags, protected or not
// (A-490c, A-490e), and what each package holder answers for the package through its seat's verb versions (A-490g). It is
// filled per module whenever the indexer starts and at each catalog revision kept, not once (A-490d, A-490f): the key
// versions-filled closes only the builder's half of the fill.
// FloorCall is the id of the finding call-unanswered when a floor read (the forge's tags or a package holder's versions) is
// unanswered five minutes after the first (A-490h).
const FloorCall = "mesh-catalog.versions-floor"
// TagsReader reads every tag of a repository that starts with prefix, all pages (the seat git's verb tags).
type TagsReader func(ctx context.Context, repository, prefix string) ([]string, error)
// HolderReader reads the versions a package holder answers for a package of an ecosystem (EcosystemGo, EcosystemNpm)
// through its seat's verb versions (A-490g).
type HolderReader func(ctx context.Context, ecosystem, name string) ([]string, error)
// FloorSources are what the floor reads: the forge's tags and each package holder's versions.
type FloorSources struct {
Tags TagsReader
Holder HolderReader
}
// tagPrefixOf is the prefix Go gives the tags of a Go package in its repository (A-490e): the package's directory in the
// repository followed by "/v" ("go/v" for the sdk, whose Go module lives in go/), "v" at the root; none when the package's
// name does not lie in the repository.
func tagPrefixOf(repository string, a meshcatalog.Artifact) (string, bool) {
if a.Package == nil || a.Package.Ecosystem != EcosystemGo || repository == "" {
return "", false
}
i := strings.Index(a.Package.Name, "/"+repository)
if i < 0 {
return "", false
}
switch rest := a.Package.Name[i+1+len(repository):]; {
case rest == "":
return "v", true
case strings.HasPrefix(rest, "/"):
return rest[1:] + "/v", true
}
return "", false
}
// FloorModules are the modules of the newest trunk revision the versions hold none of and that name a package a floor can be read
// of; each is filled by its own FillFloor, so one unanswered read holds no other module's floor (A-490i).
func (ix *Indexer) FloorModules(ctx context.Context) ([]string, error) {
if ix.Versions == nil || ix.Revisions == nil {
return nil, errors.New("the state versions or the catalog graph is not kept here")
}
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil {
return nil, err
}
if !found {
return nil, errors.New("the indexer keeps no trunk revision yet: the floor waits for its first")
}
var out []string
for _, e := range entries {
if !slices.ContainsFunc(e.Artifacts, func(a meshcatalog.Artifact) bool {
return a.Package != nil && (a.Package.Ecosystem == EcosystemGo || a.Package.Ecosystem == EcosystemNpm)
}) {
continue
}
if have, err := ModuleVersions(ctx, ix.Versions, e.Module); err != nil {
return nil, err
} else if len(have) == 0 {
out = append(out, e.Module)
}
}
return out, nil
}
// FillFloor fills one module's floor, the highest version among its packages' tags and holders' versions (A-490g). Its reads are
// kept calls made through mesh-sdk's form, which asks again through every transport fault; a read it gives up on (its own
// pause spent) is asked again at once, never given up, so the read has no bound (A-490i). The first unanswered try starts the
// module's clock: five minutes later the finding call-unanswered is written, and cleared when a read answers. A read the
// callee answered with a failure ends the fill, left for the next start or revision. One fill of a module runs at a time.
func (ix *Indexer) FillFloor(ctx context.Context, module string, src FloorSources) error {
if _, running := ix.floors.LoadOrStore(module, true); running {
return nil
}
defer ix.floors.Delete(module)
// Whatever way the fill ends but by the end of ctx, the module's call is no longer unanswered: it answered, or it left the
// trunk, or a release gave it a version, or the callee answered with a failure (ADR 0668 §3: the finding clears when the call
// is answered), and FloorModules never picks the module again to clear it.
defer func() {
if ctx.Err() == nil {
ix.floorAnswered(ctx, module)
}
}()
for ctx.Err() == nil {
entry, found, err := ix.newestEntry(ctx, module)
if err != nil || !found {
return err
}
if have, err := ModuleVersions(ctx, ix.Versions, module); err != nil || len(have) > 0 {
return err
}
first := ix.now() // the clock of the module's unanswered call starts at its try, not when the form gives up
top, err := ix.floorOf(ctx, entry, src)
if err == nil {
return ix.keepFloor(ctx, module, top)
}
if !busretry.Undelivered(err) && !busretry.TimedOut(err) {
return err // answered with a failure: the fill ends, said by the caller
}
ix.floorUnanswered(ctx, module, first, err)
}
return ctx.Err()
}
func (ix *Indexer) newestEntry(ctx context.Context, module string) (meshcatalog.CatalogEntry, bool, error) {
_, entries, found, err := readNewestOf(ctx, ix.Revisions, TrunkBranch)
if err != nil || !found {
return meshcatalog.CatalogEntry{}, false, err
}
for _, e := range entries {
if e.Module == module {
return e, true, nil
}
}
return meshcatalog.CatalogEntry{}, false, nil
}
// floorOf reads the highest version of the entry's packages; "" when none is held.
func (ix *Indexer) floorOf(ctx context.Context, e meshcatalog.CatalogEntry, src FloorSources) (string, error) {
top := ""
take := func(vs []string, prefix string) {
for _, t := range vs {
if !strings.HasPrefix(t, prefix) {
continue
}
if v := strings.TrimPrefix(t, prefix); versionOK(v) && (top == "" || compareVersions(v, top) > 0) {
top = v
}
}
}
for _, a := range e.Artifacts {
if a.Package == nil {
continue
}
if prefix, ok := tagPrefixOf(e.Repository, a); ok && src.Tags != nil {
tags, err := src.Tags(ctx, e.Repository, prefix)
if err != nil {
return "", fmt.Errorf("the tags of %s: %w", e.Repository, err)
}
take(tags, prefix)
}
if (a.Package.Ecosystem == EcosystemGo || a.Package.Ecosystem == EcosystemNpm) && src.Holder != nil {
vs, err := src.Holder(ctx, a.Package.Ecosystem, a.Package.Name)
if err != nil {
return "", fmt.Errorf("the versions of %s %s: %w", a.Package.Ecosystem, a.Package.Name, err)
}
take(vs, "")
}
}
return top, nil
}
func (ix *Indexer) keepFloor(ctx context.Context, module, top string) error {
if top == "" {
return nil
}
now := ix.now().UTC()
data, err := json.Marshal(meshcatalog.VersionEntry{V: int64(keys.Version), Module: module, Version: top, At: &now})
if err != nil {
return err
}
if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey(module, top), data); err != nil && !errors.Is(err, ErrConflict) {
return fmt.Errorf("the floor %s %s is not kept: %w", module, top, err)
}
ix.logf("versions: %s has none, filled with %s, the highest of its packages' tags and holders' versions", module, top)
return nil
}
func floorKey(module string) string { return FloorCall + "." + module }
// FloorSinceKey is the key of the state heard that holds when a module's floor call was first unanswered.
func FloorSinceKey(module string) string { return floorSinceKey(module) }
func floorSinceKey(module string) string { return "call-since." + keys.EscapeName(floorKey(module)) }
// floorUnanswered writes call-unanswered once the module's floor read is unanswered five minutes (the time kept in the own state).
func (ix *Indexer) floorUnanswered(ctx context.Context, module string, first time.Time, cause error) {
now := ix.now()
since := ix.unansweredSince(ctx, floorSinceKey(module), first)
if ix.Findings == nil || now.Sub(since) < mcc.CallUnansweredAfter {
return
}
at := since.UTC().Format(time.RFC3339)
f := ix.observed(mcc.ScopeCall, floorKey(module), mcc.KindCallUnanswered,
fmt.Sprintf("the floor of %s's versions is unanswered since %s", module, at),
"A call whose answer is kept is not answered",
fmt.Sprintf("The floor of %s's versions reads the forge's tags and the package holders' versions; a read is not answered since %s (%v), so it has no version.", module, at, cause),
"indexer."+mcc.KindCallUnanswered)
if err := ix.Findings.Write(ctx, f); err != nil {
ix.logf("floor: the finding %s is not written: %v", floorKey(module), err)
}
}
func (ix *Indexer) floorAnswered(ctx context.Context, module string) {
ix.answered(ctx, floorSinceKey(module))
if ix.Findings != nil {
if err := ix.clearFinding(ctx, mcc.ScopeCall, floorKey(module), mcc.KindCallUnanswered, "the floor's reads answer"); err != nil {
ix.logf("floor: the finding %s is not cleared: %v", floorKey(module), err)
}
}
}
func versionOK(v string) bool { _, ok := versionParts(v); return ok }
@@ -120,9 +120,9 @@ func (ix *Indexer) HearPackagePublished(ctx context.Context, p meshbuilds.Packag
return ix.hearBranchBuild(ctx, p) // releases no version; its edges are kept in build-edges (A-83) return ix.hearBranchBuild(ctx, p) // releases no version; its edges are kept in build-edges (A-83)
} }
} }
if raw, _, found, err := ix.Versions.Get(ctx, meshcatalog.VersionsByModuleVersionKey(p.Module, p.Version)); err != nil { if _, _, found, err := ix.Versions.Get(ctx, meshcatalog.VersionsByModuleVersionKey(p.Module, p.Version)); err != nil {
return err return err
} else if found && !isFloor(raw) { } else if found {
ix.logf("versions: %s %s is released already, so the package-published of %s is heard again and changes nothing", p.Module, p.Version, p.Artifact) ix.logf("versions: %s %s is released already, so the package-published of %s is heard again and changes nothing", p.Module, p.Version, p.Artifact)
return nil return nil
} }
@@ -212,14 +212,7 @@ func (ix *Indexer) releaseVersion(ctx context.Context, p meshbuilds.PackagePubli
if err != nil { if err != nil {
return err return err
} }
if err := ix.Versions.Create(ctx, key, data); errors.Is(err, ErrConflict) { if err := ix.Versions.Create(ctx, key, data); err != nil && !errors.Is(err, ErrConflict) {
// A floor entry (A-490h) holds no artifacts: this publish is that version's release, so it takes the entry's place.
if raw, rev, found, gerr := ix.Versions.Get(ctx, key); gerr == nil && found && isFloor(raw) {
if err := ix.Versions.Update(ctx, key, data, rev); err != nil && !errors.Is(err, ErrConflict) {
return err
}
}
} else if err != nil {
return err return err
} }
if late { if late {
@@ -346,9 +339,3 @@ func OutdatedTool(ix *Indexer) stdio.Tool {
return ix.Outdated(context.Background(), in) return ix.Outdated(context.Background(), in)
}} }}
} }
// isFloor says whether a kept version is a floor entry (A-490h): it holds no artifact, as no release does.
func isFloor(raw []byte) bool {
var v meshcatalog.VersionEntry
return json.Unmarshal(raw, &v) == nil && len(v.Artifacts) == 0
}
@@ -534,187 +534,3 @@ func TestAnInputIsDeletedAtTheStepEndedOfItsAsk(t *testing.T) {
t.Errorf("indexer_inputs counts a key by ask: %+v, %v", a, err) t.Errorf("indexer_inputs counts a key by ask: %+v, %v", a, err)
} }
} }
// Design 47 G §412 as A-490c, A-490d and A-490e amend it: a module the versions hold none of is filled from the highest tag of its
// Go package in the repository it was taken in from, per module and not once; a forge that does not answer fills nothing and
// raises call-unanswered after five minutes.
func TestTheTagFloorFillsAModuleWithNoVersionFromItsGoTags(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC)
w := newFindings()
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }}
entries := map[string]meshcatalog.CatalogEntry{
"mesh-sdk": {Module: "mesh-sdk", Repository: "novox/mesh-sdk", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
{Ref: "mesh-sdk:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mesh-sdk/go"}},
{Ref: "mesh-sdk:ts", Package: &meshcatalog.ArtifactPackage{Ecosystem: "npm", Name: "@novox/mesh-sdk"}}}},
"root": {Module: "root", Repository: "novox/root", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
{Ref: "root:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/root"}}}},
"held": {Module: "held", Repository: "novox/held", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "held:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/held"}}}},
"image": {Module: "image", Repository: "novox/image", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{{Ref: "image:image", Kind: "image"}}},
}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 3, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("held", "0.2.0"), []byte(`{"v":1,"module":"held","version":"0.2.0"}`)); err != nil {
t.Fatal(err)
}
tries := 0
var asked []string
read := func(_ context.Context, repo, prefix string) ([]string, error) {
asked = append(asked, repo+" "+prefix)
if repo == "novox/mesh-sdk" {
// the forge does not answer the sdk's tags for six minutes, a minute at a time: the fill asks again, never gives up
tries++
now = now.Add(time.Minute)
if tries == 5 && len(w.Held()) != 0 {
t.Error("the finding is written before five minutes from the first unanswered try")
}
if tries <= 6 {
return nil, errors.New("no responders available for request")
}
if len(w.Held()) != 1 || w.Held()[0].ID != FloorCall+".mesh-sdk" {
t.Errorf("the findings after six minutes: %+v", w.Held())
}
return []string{"go/v0.1.9", "go/v0.1.16", "go/v0.1.12", "go/vnext"}, nil
}
if repo == "novox/root" {
return []string{"v1.2.3", "vendor-x"}, nil
}
return nil, nil
}
holder := func(_ context.Context, eco, name string) ([]string, error) {
if eco == "npm" && name == "@novox/mesh-sdk" {
return []string{"0.1.18", "0.1.17"}, nil // A-490g: the npm holder is above the Go tags
}
return nil, nil
}
src := FloorSources{Tags: read, Holder: holder}
modules, err := ix.FloorModules(ctx)
if err != nil {
t.Fatal(err)
}
if !slices.Equal(modules, []string{"mesh-sdk", "root"}) {
t.Fatalf("the modules with a floor to read: %v (held has a version, image no package)", modules)
}
// each module's floor is read on its own: root is filled whatever the sdk's read waits for
if err := ix.FillFloor(ctx, "root", src); err != nil {
t.Fatal(err)
}
if err := ix.FillFloor(ctx, "mesh-sdk", src); err != nil {
t.Fatal(err)
}
if len(w.Held()) != 0 {
t.Errorf("the finding stands after the forge answered: %+v", w.Held())
}
if v, _ := ModuleVersions(ctx, ix.Versions, "mesh-sdk"); len(v) != 1 || v[0].Version != "0.1.18" {
t.Errorf("mesh-sdk's floor: %+v (the highest of its Go tags 0.1.16 and the npm holder's 0.1.18)", v)
}
if v, _ := ModuleVersions(ctx, ix.Versions, "root"); len(v) != 1 || v[0].Version != "1.2.3" {
t.Errorf("a root module's floor: %+v", v)
}
if v, _ := ModuleVersions(ctx, ix.Versions, "held"); len(v) != 1 || v[0].Version != "0.2.0" {
t.Errorf("a module with a version is filled: %+v", v)
}
for _, a := range asked {
if strings.HasPrefix(a, "novox/held") || strings.HasPrefix(a, "novox/image") {
t.Errorf("tags read for a module with a version or no Go package: %s", a)
}
}
}
// Design 47 G A-490h: a floor entry holds no artifacts, so the package-published heard later at its version is that version's
// release (the entry takes its artifacts and version-released is said), never dropped as released already.
func TestAFloorEntryIsReplacedByThePublishHeardAtItsVersion(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC)
var said []meshcatalog.VersionReleasedEvent
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: newFindings(), Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now },
SayVersionReleased: func(_ context.Context, e meshcatalog.VersionReleasedEvent, _ string) error {
said = append(said, e)
return nil
}}
entries := map[string]meshcatalog.CatalogEntry{"mod": {Module: "mod", Repository: "novox/mod", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
{Ref: "mod:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mod"}}}}}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
src := FloorSources{Tags: func(context.Context, string, string) ([]string, error) { return []string{"v0.3.0"}, nil }}
if err := ix.FillFloor(ctx, "mod", src); err != nil {
t.Fatal(err)
}
if err := ix.HearPackagePublished(ctx, meshbuilds.PackagePublished{Module: "mod", Artifact: "mod:go", Version: "0.3.0", Digest: "sha256:aa", Branch: "main", Source: 5}); err != nil {
t.Fatal(err)
}
v, _ := ModuleVersions(ctx, ix.Versions, "mod")
if len(v) != 1 || len(v[0].Artifacts) != 1 || v[0].Artifacts[0].Digest != "sha256:aa" || len(said) != 1 {
t.Fatalf("the floor 0.3.0 and its publish: versions %+v, version-released said %d", v, len(said))
}
}
// ADR 0668 §3, design 47 G A-490i: the finding call-unanswered of a module's floor clears, with its call-since key, on every way the
// fill ends but the end of its context: a release gave the module a version, the module left the trunk, or the callee answered with a
// failure (FloorModules never picks the module again to clear it).
func TestTheFloorFindingClearsOnEveryExitOfTheFill(t *testing.T) {
for name, exit := range map[string]func(ctx context.Context, t *testing.T, ix *Indexer) error{
"a release gave it a version": func(ctx context.Context, t *testing.T, ix *Indexer) error {
if err := ix.Versions.Create(ctx, meshcatalog.VersionsByModuleVersionKey("mod", "0.5.0"), []byte(`{"v":1,"module":"mod","version":"0.5.0","artifacts":[{"artifact":"mod:go"}]}`)); err != nil {
t.Fatal(err)
}
return errors.New("no responders available for request")
},
"it left the trunk": func(ctx context.Context, t *testing.T, ix *Indexer) error {
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 2, Kind: "trunk"}, map[string]meshcatalog.CatalogEntry{})
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
return errors.New("no responders available for request")
},
"the callee answered with a failure": func(context.Context, *testing.T, *Indexer) error { return errors.New("the forge refused") },
} {
t.Run(name, func(t *testing.T) {
ctx := context.Background()
now := time.Date(2026, 11, 19, 17, 0, 0, 0, time.UTC)
w := newFindings()
ix := &Indexer{Module: testSelf, Versions: newMem(), Heard: newMem(), Findings: w, Revisions: newMemObjects(1 << 20), Now: func() time.Time { return now }}
entries := map[string]meshcatalog.CatalogEntry{"mod": {Module: "mod", Repository: "novox/mod", Manifest: map[string]any{}, Artifacts: []meshcatalog.Artifact{
{Ref: "mod:go", Package: &meshcatalog.ArtifactPackage{Ecosystem: "go", Name: "git.novox.be/novox/mod"}}}}}
rev, objects, err := CatalogRevisionOf(meshcatalog.CatalogRevision{Revision: 1, Kind: "trunk"}, entries)
if err != nil {
t.Fatal(err)
}
if err := KeepRevision(ctx, ix.Revisions, rev, objects); err != nil {
t.Fatal(err)
}
tries := 0
read := func(context.Context, string, string) ([]string, error) {
tries++
now = now.Add(time.Minute)
if tries <= 6 {
return nil, errors.New("no responders available for request")
}
if len(w.Held()) != 1 {
t.Fatalf("the finding is not written before the exit: %+v", w.Held())
}
return nil, exit(ctx, t, ix)
}
_ = ix.FillFloor(ctx, "mod", FloorSources{Tags: read})
if h := w.Held(); len(h) != 0 {
t.Errorf("the finding stands after the fill ended: %+v", h)
}
if _, _, found, _ := ix.Heard.Get(ctx, FloorSinceKey("mod")); found {
t.Error("the call-since key stands after the fill ended")
}
})
}
}
@@ -178,7 +178,7 @@ func TestManifestDeclarations(t *testing.T) { // 1238/AC1, 1444 (reads the build
// Three invokes: the file of a registered module's manifest and lock files (registered.go), the forge's trees (the named paths' objects, since the indexer is the one reader of a manifest's paths: // Three invokes: the file of a registered module's manifest and lock files (registered.go), the forge's trees (the named paths' objects, since the indexer is the one reader of a manifest's paths:
// ADR 0499 clauses 2 and 3, ADR 0495 clause 1; and the module directories of the trunk, issue 1900) and whether a // ADR 0499 clauses 2 and 3, ADR 0495 clause 1; and the module directories of the trunk, issue 1900) and whether a
// commit is in another (issue 1900). // commit is in another (issue 1900).
if want := []string{"seat:git.trees", "seat:git.tags", "seat:go-package-registry.versions", "seat:npm-package-registry.versions", "seat:git.file", "seat:git.contains", "seat:git.open-pulls", "seat:git.branch", "mesh-delivery-forge-bridge.bridge_merged_message", "seat:node-engine.composition", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps", if want := []string{"seat:git.trees", "seat:git.file", "seat:git.contains", "seat:git.open-pulls", "seat:git.branch", "mesh-delivery-forge-bridge.bridge_merged_message", "seat:node-engine.composition", "seat:mesh-delivery.source", "seat:mesh-module-assigner.assignments", "seat:mesh-module-assigner.placement", "seat:mesh-hand-acts.hand-act", "seat:mesh-watchdogs.presence", "seat:node-build-go.steps",
"seat:node-build-node.steps", "seat:node-build-image.steps", "mesh-delivery-builder.builder_versions"}; !reflect.DeepEqual(m.Invokes, want) { "seat:node-build-node.steps", "seat:node-build-image.steps", "mesh-delivery-builder.builder_versions"}; !reflect.DeepEqual(m.Invokes, want) {
t.Errorf("invokes = %v, want %v", m.Invokes, want) t.Errorf("invokes = %v, want %v", m.Invokes, want)
} }
@@ -416,7 +416,7 @@ func TestEveryGiteaToolTheCodeCallsIsInInvokes(t *testing.T) {
if err != nil || len(files) == 0 { if err != nil || len(files) == 0 {
t.Fatalf("no program files: %v", err) t.Fatalf("no program files: %v", err)
} }
verbs := map[string]string{"VerbTrees": git.VerbTrees, "VerbFile": git.VerbFile, "VerbContains": git.VerbContains, "VerbOpenPulls": git.VerbOpenPulls, "VerbBranch": git.VerbBranch, "VerbTags": git.VerbTags} verbs := map[string]string{"VerbTrees": git.VerbTrees, "VerbFile": git.VerbFile, "VerbContains": git.VerbContains, "VerbOpenPulls": git.VerbOpenPulls, "VerbBranch": git.VerbBranch}
forge, asked := regexp.MustCompile(`gitea\.gitea_[a-z_]+`), regexp.MustCompile(`git\.Verb[A-Za-z]+`) forge, asked := regexp.MustCompile(`gitea\.gitea_[a-z_]+`), regexp.MustCompile(`git\.Verb[A-Za-z]+`)
seen := 0 seen := 0
for _, f := range files { for _, f := range files {
@@ -167,9 +167,6 @@
], ],
"invokes": [ "invokes": [
"seat:git.trees", "seat:git.trees",
"seat:git.tags",
"seat:go-package-registry.versions",
"seat:npm-package-registry.versions",
"seat:git.file", "seat:git.file",
"seat:git.contains", "seat:git.contains",
"seat:git.open-pulls", "seat:git.open-pulls",
+29 -4
View File
@@ -107,16 +107,41 @@ func (p *Puller) refuseAsker(msg *Pulled, ask sdkstep.StepAsk, why string) {
return return
} }
p.logf("the ask %s is refused on %s: %s", ask.ID, p.Node, why) p.logf("the ask %s is refused on %s: %s", ask.ID, p.Node, why)
p.sayAskEnded(msg, ask, sdkstep.OutcomeFailed, why)
_ = msg.Ack() // A-489: ended and written, so it leaves the work queue
}
// sayAskEnded says the end of an ask this holder ends without running it: its step-ended, an ask outside a pipeline as
// sayEnded says it, a pipeline step as its own form (design 47 G §602), so the runner that asked hears it.
func (p *Puller) sayAskEnded(msg *Pulled, ask sdkstep.StepAsk, outcome, said string) {
if ask.Step == nil { if ask.Step == nil {
p.sayEnded(msg, ask, sdkstep.OutcomeFailed, why, nil, "") p.sayEnded(msg, ask, outcome, said, nil, "")
} else if end, err := sdkstep.EndOf(ask, p.Node, sdkstep.OutcomeFailed); err == nil { } else if end, err := sdkstep.EndOf(ask, p.Node, outcome); err == nil {
// A pipeline step's end names its pipeline, step, commit and fingerprint (its own form, §602). // A pipeline step's end names its pipeline, step, commit and fingerprint (its own form, §602).
end.Said, end.At, end.Asker = why, now().UTC(), askerOf(msg, ask) end.Said, end.At, end.Asker = said, now().UTC(), askerOf(msg, ask)
if body, err := sdkstep.EncodeStepEnded(end); err == nil { if body, err := sdkstep.EncodeStepEnded(end); err == nil {
p.say("step-ended", json.RawMessage(body), "step-ended."+ask.ID) p.say("step-ended", json.RawMessage(body), "step-ended."+ask.ID)
} }
} }
_ = msg.Term() }
// PriorRuns is Puller.Prior over a steps state's read (a module's ReadSteps.Get): the Run of the step a key holds. Nil for no
// read (a test's), so the bus's delivery count stands.
func PriorRuns(get func(key string) (json.RawMessage, error)) func(string) int {
if get == nil {
return nil
}
return func(key string) int {
raw, err := get(key)
if err != nil || raw == nil {
return 0
}
var s sdkstep.Step
if json.Unmarshal(raw, &s) != nil {
return 0
}
return s.Run
}
} }
// giveBack hands an ask back to be judged again a little later, once the seat list says more. Why it cannot be judged is // giveBack hands an ask back to be judged again a little later, once the seat list says more. Why it cannot be judged is
@@ -65,7 +65,7 @@ func TestPullRefusesAKindItsAskerMayNotAsk(t *testing.T) {
key, _ := sdkstep.AskStepKey(asker, "shanks", c.ask.ID) key, _ := sdkstep.AskStepKey(asker, "shanks", c.ask.ID)
waitFor(t, "the step keyed "+key, func() bool { _, ok := st.get(key); return ok }) waitFor(t, "the step keyed "+key, func() bool { _, ok := st.get(key); return ok })
case "refused": case "refused":
waitFor(t, "the ask ended", func() bool { _, termed, _ := src.Fates(); return len(termed) == 1 }) waitFor(t, "the ask ended", func() bool { acked, _, _ := src.Fates(); return len(acked) == 1 }) // A-489: ended, written, acknowledged
key, _ := sdkstep.AskStepKey(asker, "shanks", c.ask.ID) key, _ := sdkstep.AskStepKey(asker, "shanks", c.ask.ID)
s, _ := st.get(key) s, _ := st.get(key)
if s.State != sdkstep.StepFailed || !strings.Contains(s.Reason, KindOf(c.ask)) || (strings.Contains(c.subject, "mesh-catalog") && !strings.Contains(s.Reason, asker)) { if s.State != sdkstep.StepFailed || !strings.Contains(s.Reason, KindOf(c.ask)) || (strings.Contains(c.subject, "mesh-catalog") && !strings.Contains(s.Reason, asker)) {
+19 -2
View File
@@ -3,6 +3,7 @@ package steprun
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"maps" "maps"
"path" "path"
@@ -56,6 +57,20 @@ type AskSteps struct {
SayStep func(end sdkstep.StepEnded) error SayStep func(end sdkstep.StepEnded) error
} }
// A-489b (G-22-lead-answers-2.md): SaysItsEnds is nil when these steps can be asked a pipeline step and say its end: a node to name in the end and a SayStep to
// publish it (design 47 G *Asked on a work queue, ended by an event*, §24). A build module whose steps cannot is refused where
// it is built (conformance.StepEnds, which every build module's test runs, and the catalogue check failurekit), never
// discovered live as a step ask refused with "says no step's end".
func (s AskSteps) SaysItsEnds() error {
switch {
case s.SayStep == nil:
return errors.New("its AskSteps has no SayStep, so a step ask is refused: set it to SayStepOn the seat's language and node")
case s.Node == "":
return errors.New("its AskSteps names no Node, so the end of a step ask names no node")
}
return nil
}
// RunAsk runs ask's job with steps and answers a sdkstep.BuildAnswer or a sdkstep.CheckAnswer. // RunAsk runs ask's job with steps and answers a sdkstep.BuildAnswer or a sdkstep.CheckAnswer.
func RunAsk(ctx context.Context, steps AskSteps, ask sdkstep.StepAsk) (any, error) { func RunAsk(ctx context.Context, steps AskSteps, ask sdkstep.StepAsk) (any, error) {
if ask.Build != nil { if ask.Build != nil {
@@ -150,7 +165,9 @@ func (s AskSteps) fetch(ctx context.Context, fetch *sdkstep.Fetch) (json.RawMess
// onToolchain is the toolchain this node builds with when the ask names one and this module reports its own, nil when // onToolchain is the toolchain this node builds with when the ask names one and this module reports its own, nil when
// either is absent. A node on another toolchain than the ask names answers a Declining: it is not on the agreed one and // either is absent. A node on another toolchain than the ask names answers a Declining: it is not on the agreed one and
// sits out, for a node that is to take the ask (novox/hq ADR 0584 clause 2). // sits out, for a node that is to take the ask (novox/hq ADR 0584 clause 2). The recipe is compared only when the ask names
// one: the runner names a step ask's language and version alone, the recipe and the node's digest being the seat's to report,
// not the runner's to know (design 47 G §416, A-104).
func (s AskSteps) onToolchain(ctx context.Context, want *sdkstep.ToolchainUsed) (*sdkstep.ToolchainUsed, error) { func (s AskSteps) onToolchain(ctx context.Context, want *sdkstep.ToolchainUsed) (*sdkstep.ToolchainUsed, error) {
if want == nil || s.Toolchain == nil { if want == nil || s.Toolchain == nil {
return nil, nil return nil, nil
@@ -159,7 +176,7 @@ func (s AskSteps) onToolchain(ctx context.Context, want *sdkstep.ToolchainUsed)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if !sdkstep.SameToolchainVersion(tc.Version, want.Version) || tc.Recipe != want.Recipe { if !sdkstep.SameToolchainVersion(tc.Version, want.Version) || (want.Recipe != "" && tc.Recipe != want.Recipe) {
return nil, &Declining{Lacks: []string{fmt.Sprintf("the agreed toolchain %s (recipe %s)", sdkstep.LanguageVersion(want.Version), want.Recipe)}, return nil, &Declining{Lacks: []string{fmt.Sprintf("the agreed toolchain %s (recipe %s)", sdkstep.LanguageVersion(want.Version), want.Recipe)},
Text: fmt.Sprintf("the ask is for %s (recipe %s) and this node builds with %s (recipe %s): it sits out, and the ask is left to a node on the agreed toolchain", Text: fmt.Sprintf("the ask is for %s (recipe %s) and this node builds with %s (recipe %s): it sits out, and the ask is left to a node on the agreed toolchain",
sdkstep.LanguageVersion(want.Version), want.Recipe, sdkstep.LanguageVersion(tc.Version), tc.Recipe)} sdkstep.LanguageVersion(want.Version), want.Recipe, sdkstep.LanguageVersion(tc.Version), tc.Recipe)}
@@ -512,3 +512,27 @@ func TestRunAskRunsAPipelineStepAndSaysItsEnd(t *testing.T) {
} }
} }
} }
// Design 47 G §416, A-104: the runner names a step ask's toolchain by language and version alone, so a node on that version
// takes it whatever its recipe; an ask that names a recipe still declines a node on another.
func TestAnAskNamingNoRecipeIsNotDeclinedForItsRecipe(t *testing.T) {
for _, c := range []struct {
name string
want sdkstep.ToolchainUsed
decline bool
}{
{"version, no recipe", sdkstep.ToolchainUsed{Version: "go1.26"}, false},
{"the same recipe", sdkstep.ToolchainUsed{Version: "go1.26", Recipe: "3"}, false},
{"another recipe", sdkstep.ToolchainUsed{Version: "go1.26", Recipe: "4"}, true},
{"another version, no recipe", sdkstep.ToolchainUsed{Version: "go1.27"}, true},
} {
s := AskSteps{Toolchain: func(context.Context) (sdkstep.ToolchainUsed, error) {
return sdkstep.ToolchainUsed{Version: "go1.26.2", Recipe: "3"}, nil
}}
_, err := s.onToolchain(context.Background(), &c.want)
var dec *Declining
if errors.As(err, &dec) != c.decline || (err != nil && !c.decline) {
t.Errorf("%s: err %v, want declined %v", c.name, err, c.decline)
}
}
}
@@ -11,7 +11,10 @@ package conformance
import ( import (
"embed" "embed"
"encoding/json"
"errors"
"fmt" "fmt"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/steprun"
"slices" "slices"
"strings" "strings"
"testing" "testing"
@@ -277,3 +280,34 @@ func judgePassing(c PassingCase, failed Failed) string {
} }
return "" return ""
} }
// A-489b: StepEnds is the case every build module runs on the steps it asks with: a pipeline step ask must be able to say its end
// (steprun.AskSteps.SaysItsEnds), or the module would refuse every step ask the runner sends, as mesh-build-node did on its
// first live pipeline (design 47 G §24). A catalogue check (failurekit) refuses a build module whose tests do not call it.
func StepEnds(t *testing.T, steps steprun.AskSteps) {
t.Helper()
if err := steps.SaysItsEnds(); err != nil {
t.Errorf("the build module's steps cannot say a step's end: %v", err)
}
}
// A-489c: RunsCounted is the case every build module runs on its puller (A-489a): the poison rule and a transport fault's run count the
// runs the module's steps state says started, so the puller is built with Prior over the module's own read of that state. The
// module builds its puller with read as its steps state's read; a step key it holds with a started run must count as that run.
func RunsCounted(t *testing.T, puller func(read func(key string) (json.RawMessage, error)) *steprun.Puller) {
t.Helper()
if err := runsCounted(puller); err != nil {
t.Error(err)
}
}
func runsCounted(puller func(read func(key string) (json.RawMessage, error)) *steprun.Puller) error {
p := puller(func(string) (json.RawMessage, error) { return json.RawMessage(`{"run":2}`), nil })
switch {
case p == nil || p.Prior == nil:
return errors.New("the build module's puller has no Prior: an ask given back would count toward poison")
case p.Prior("any") != 2:
return fmt.Errorf("Prior over a step key holding run 2 = %d, want 2: the puller does not read the module's steps state", p.Prior("any"))
}
return nil
}
@@ -181,3 +181,33 @@ func TestTheFailureContract(t *testing.T) {
} }
}) })
} }
// A build module whose steps cannot say a step's end fails the case; one that can passes.
func TestStepEndsRefusesStepsThatCannotSayTheirEnd(t *testing.T) {
say := func(sdkstep.StepEnded) error { return nil }
for _, c := range []struct {
name string
s steprun.AskSteps
bad bool
}{{"no SayStep", steprun.AskSteps{Node: "n"}, true}, {"no node", steprun.AskSteps{SayStep: say}, true}, {"both", steprun.AskSteps{Node: "n", SayStep: say}, false}} {
if (c.s.SaysItsEnds() != nil) != c.bad {
t.Errorf("%s: SaysItsEnds = %v, want refused %v", c.name, c.s.SaysItsEnds(), c.bad)
}
}
StepEnds(t, steprun.AskSteps{Node: "n", SayStep: say})
}
// A puller built without Prior, or with one that does not read the module's steps state, fails the case.
func TestRunsCountedRefusesAPullerThatDoesNotReadTheStepsState(t *testing.T) {
wired := func(read func(string) (json.RawMessage, error)) *steprun.Puller {
return &steprun.Puller{Prior: steprun.PriorRuns(read)}
}
if err := runsCounted(wired); err != nil {
t.Errorf("a wired puller: %v", err)
}
for name, p := range map[string]*steprun.Puller{"none": {}, "constant": {Prior: func(string) int { return 0 }}} {
if runsCounted(func(func(string) (json.RawMessage, error)) *steprun.Puller { return p }) == nil {
t.Errorf("%s: the case passed a puller that does not count the state's runs", name)
}
}
}
+65 -17
View File
@@ -32,6 +32,8 @@ type Pulled struct {
Subject string Subject string
// Delivered is how many times the bus has handed it over, this time included. // Delivered is how many times the bus has handed it over, this time included.
Delivered uint64 Delivered uint64
// Sequence is its sequence in the stream (0 for a source that has none), which the journal names for an ask that cannot be read.
Sequence uint64
// Ack ends it: it is never delivered again. InProgress tells the bus it is still being worked, restarting its // Ack ends it: it is never delivered again. InProgress tells the bus it is still being worked, restarting its
// acknowledgement wait. Nak hands it back to be delivered again at once (to this node or another). Term drops it. // acknowledgement wait. Nak hands it back to be delivered again at once (to this node or another). Term drops it.
Ack, InProgress, Nak, Term func() error Ack, InProgress, Nak, Term func() error
@@ -87,7 +89,11 @@ type Puller struct {
KeepOutput func(object string, body []byte) error KeepOutput func(object string, body []byte) error
// Callers says which seats the build seat's definition lists as callers of an accepted kind (CallersFromDefinitions); // Callers says which seats the build seat's definition lists as callers of an accepted kind (CallersFromDefinitions);
// found is false while the seat list holds no such kind. Nil checks no named asker (design 47 G §543, A-163). // found is false while the seat list holds no such kind. Nil checks no named asker (design 47 G §543, A-163).
Callers func(kind string) (callers []string, found bool) Callers func(kind string) (callers []string, found bool)
// Prior says how many runs of the ask under a step key started before (the Run of the step the key holds, PriorRuns; 0 for
// none), so the poison rule and the transport fault's run count only runs that started, never an ask given back before it
// ran. Nil counts the bus's deliveries (a test's).
Prior func(key string) int
ProgressEvery time.Duration ProgressEvery time.Duration
Logf func(format string, args ...any) Logf func(format string, args ...any)
// Load reads one key of the state the node's pause is kept in (nil and no error when it is absent). When set, Pull // Load reads one key of the state the node's pause is kept in (nil and no error when it is absent). When set, Pull
@@ -576,7 +582,8 @@ func (p *Puller) decline(msg *Pulled, ask sdkstep.StepAsk, lacks []string) {
return return
} }
p.logf("the ask %s is declined on %s: it needs %s, and this node lacks %s", ask.ID, p.Node, strings.Join(ask.Needs, ", "), strings.Join(lacks, ", ")) p.logf("the ask %s is declined on %s: it needs %s, and this node lacks %s", ask.ID, p.Node, strings.Join(ask.Needs, ", "), strings.Join(lacks, ", "))
_ = msg.Term() p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, "this node lacks "+strings.Join(lacks, ", "))
_ = msg.Ack() // A-489a: its end is written
p.mu.Lock() p.mu.Lock()
if p.declined == nil { if p.declined == nil {
p.declined = map[string]bool{} p.declined = map[string]bool{}
@@ -598,7 +605,7 @@ func (p *Puller) declineRun(msg *Pulled, ask sdkstep.StepAsk, key string, step s
return return
} }
p.logf("the ask %s is declined on %s: %s", ask.ID, p.Node, d.Text) p.logf("the ask %s is declined on %s: %s", ask.ID, p.Node, d.Text)
_ = msg.Term() _ = msg.Ack() // A-489a: its end is written (run() says it)
p.mu.Lock() p.mu.Lock()
if p.declined == nil { if p.declined == nil {
p.declined = map[string]bool{} p.declined = map[string]bool{}
@@ -625,16 +632,18 @@ func (p *Puller) refuseUnread(msg *Pulled, why error) {
step := sdkstep.Step{ID: probe.ID, Tool: tool, Node: p.Node, State: sdkstep.StepRefused, Started: at, Ended: at, step := sdkstep.Step{ID: probe.ID, Tool: tool, Node: p.Node, State: sdkstep.StepRefused, Started: at, Ended: at,
Reason: fmt.Sprintf("this build module on %s cannot read the ask: %v", p.Node, why), Owner: buildrun.Owner} Reason: fmt.Sprintf("this build module on %s cannot read the ask: %v", p.Node, why), Owner: buildrun.Owner}
if werr := writeEnd(p.Put, key, step); werr != nil { if werr := writeEnd(p.Put, key, step); werr != nil {
p.logf("the unread ask %s cannot be answered on %s: %v", probe.ID, p.Node, werr) p.logf("the unread ask %s cannot be answered on %s, so it is given back: %v", probe.ID, p.Node, werr)
_ = msg.Nak() // A-489a: an end that could not be written is given back, never acknowledged
return
} else { } else {
p.logf("an ask refused: %v", why) p.logf("an ask refused: %v", why)
_ = msg.Term() _ = msg.Ack() // A-489: ended and written, so it leaves the work queue
return return
} }
} }
} }
p.logf("an ask dropped: %v", why) p.logf("an ask dropped, no id to answer it by, acknowledged with this line as its only record (stream sequence %d): %v", msg.Sequence, why)
_ = msg.Term() _ = msg.Ack() // A-489a
} }
func withKind(msg *Pulled, kind string) *Pulled { func withKind(msg *Pulled, kind string) *Pulled {
@@ -644,6 +653,37 @@ func withKind(msg *Pulled, kind string) *Pulled {
return msg return msg
} }
// priorRuns is how many runs of the ask started before this delivery: its step key's (Puller.Prior), else the bus's delivery
// count less this one. The bus's count also counts an ask given back before it ran, which is no run.
func (p *Puller) priorRuns(msg *Pulled, ask sdkstep.StepAsk) int {
if p.Prior != nil {
if akey, kerr := sdkstep.StepKeyOf(keyAsker(msg), p.Node, ask.ID); kerr == nil {
return p.Prior(akey)
}
}
return int(msg.Delivered) - 1
}
// endUnrun ends an ask that is run no more (A-489, A-489a): poison when runs of it started and none ended, out of its
// deliveries when none did. Its step ends and its step-ended is said, and only then it is acknowledged; an end that could not
// be written gives it back, never acknowledged.
func (p *Puller) endUnrun(msg *Pulled, ask sdkstep.StepAsk, key string, step sdkstep.Step, prior int) {
var why error
if prior > 0 {
why = fmt.Errorf("the ask was taken %d times and no run of it ended: each took its build node down or died with it, so it is run no more (poison)", prior)
} else {
why = fmt.Errorf("the ask is on its last delivery (%d) and no run of it started: it is out of its deliveries and run no more", msg.Delivered)
}
p.logf("the ask %s is ended on %s: %v", ask.ID, p.Node, why)
if _, ferr := finish(p.Put, p.KeepOutput, key, step, nil, why, p.Logf); ferr != nil {
p.logf("the end of the ask %s could not be written on %s, so it is given back: %v", ask.ID, p.Node, ferr)
_ = msg.Nak()
return
}
p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, why.Error())
_ = msg.Ack()
}
// take starts one ask: it decodes it, refuses one that is not of this seat, and runs it as a step under its own id. // take starts one ask: it decodes it, refuses one that is not of this seat, and runs it as a step under its own id.
func (p *Puller) take(ctx context.Context, msg *Pulled) { func (p *Puller) take(ctx context.Context, msg *Pulled) {
kind := msg.Kind kind := msg.Kind
@@ -658,6 +698,18 @@ func (p *Puller) take(ctx context.Context, msg *Pulled) {
p.refuseUnread(msg, err) p.refuseUnread(msg, err)
return return
} }
if msg.Delivered >= sdkstep.AskMaxDeliver {
// Its last delivery (A-489a): the bus gives it no more, so it is ended here, run or not, never given back.
prior := p.priorRuns(msg, ask)
step, key, err := beginRun(p.Put, keyAsker(msg), p.Node, ask.Kind+" ask", ask.ID, buildrun.AskWhat(askRead(ask)), prior+1)
if err != nil {
p.logf("the ask %s is on its last delivery and cannot start its end on %s: %v", ask.ID, p.Node, err)
_ = msg.Nak()
return
}
p.endUnrun(msg, ask, key, step, prior)
return
}
if why, judged := p.askerRefusal(msg, ask); !judged { if why, judged := p.askerRefusal(msg, ask); !judged {
p.giveBack(msg, ask) p.giveBack(msg, ask)
return return
@@ -673,19 +725,15 @@ func (p *Puller) take(ctx context.Context, msg *Pulled) {
p.decline(msg, ask, lacks) p.decline(msg, ask, lacks)
return return
} }
step, key, err := beginRun(p.Put, keyAsker(msg), p.Node, ask.Kind+" ask", ask.ID, buildrun.AskWhat(askRead(ask)), int(msg.Delivered)) prior := p.priorRuns(msg, ask)
step, key, err := beginRun(p.Put, keyAsker(msg), p.Node, ask.Kind+" ask", ask.ID, buildrun.AskWhat(askRead(ask)), prior+1)
if err != nil { if err != nil {
p.logf("the ask %s cannot start on %s: %v", ask.ID, p.Node, err) p.logf("the ask %s cannot start on %s: %v", ask.ID, p.Node, err)
_ = msg.Nak() _ = msg.Nak()
return return
} }
if msg.Delivered > sdkstep.AskRuns { if prior >= sdkstep.AskRuns {
// Run AskRuns times and never ended: each run took its node down or died with it. It is run no more, and said p.endUnrun(msg, ask, key, step, prior)
// (issue 1907): the asker's key fails with why.
why := fmt.Errorf("the ask was taken %d times and no run of it ended: each took its build node down or died with it, so it is run no more (poison)", msg.Delivered-1)
p.logf("the ask %s is ended on %s: %v", ask.ID, p.Node, why)
_, _ = finish(p.Put, p.KeepOutput, key, step, nil, why, p.Logf) // run no more either way: the asker's bound says it then
_ = msg.Term()
return return
} }
module := "" module := ""
@@ -768,14 +816,14 @@ func (p *Puller) run(ctx context.Context, msg *Pulled, ask sdkstep.StepAsk, key
var dec *Declining var dec *Declining
if errors.As(err, &dec) && ctx.Err() == nil { if errors.As(err, &dec) && ctx.Err() == nil {
p.declineRun(msg, ask, key, step, dec) p.declineRun(msg, ask, key, step, dec)
p.sayEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text, nil, "") p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, dec.Text)
return return
} }
if ctx.Err() != nil { if ctx.Err() != nil {
// The process stops: the ask is neither ended nor acknowledged here, so the stream gives it to a node that runs. // The process stops: the ask is neither ended nor acknowledged here, so the stream gives it to a node that runs.
return return
} }
if run := int(msg.Delivered); err != nil && sdkstep.IsPassing(err) && run < sdkstep.AskRuns && msg.NakAfter != nil { if run := step.Run; err != nil && sdkstep.IsPassing(err) && run < sdkstep.AskRuns && msg.NakAfter != nil {
// A transport fault (ADR 0664 §1): the step says it is given again and the bus gives it after a delay, to this node or // A transport fault (ADR 0664 §1): the step says it is given again and the bus gives it after a delay, to this node or
// another; it is not acknowledged, so its asker sees no end. Run AskRuns times it ends failed, said as a transport fault. // another; it is not acknowledged, so its asker sees no end. Run AskRuns times it ends failed, said as a transport fault.
delay := sdkstep.AgainAfter(run) delay := sdkstep.AgainAfter(run)
@@ -116,11 +116,11 @@ func (s *JetStreamAsks) fetch(ctx context.Context, c jetstream.Consumer, wait ti
if !ok { if !ok {
return nil, batch.Error() return nil, batch.Error()
} }
var delivered uint64 = 1 var delivered, sequence uint64 = 1, 0
if meta, err := msg.Metadata(); err == nil && meta != nil { if meta, err := msg.Metadata(); err == nil && meta != nil {
delivered = meta.NumDelivered delivered, sequence = meta.NumDelivered, meta.Sequence.Stream
} }
return &Pulled{Data: append([]byte(nil), msg.Data()...), Subject: msg.Subject(), Delivered: delivered, return &Pulled{Data: append([]byte(nil), msg.Data()...), Subject: msg.Subject(), Delivered: delivered, Sequence: sequence,
Ack: msg.Ack, InProgress: msg.InProgress, Nak: msg.Nak, Term: msg.Term, Ack: msg.Ack, InProgress: msg.InProgress, Nak: msg.Nak, Term: msg.Term,
NakAfter: func(delay time.Duration) error { return msg.NakWithDelay(delay) }}, nil NakAfter: func(delay time.Duration) error { return msg.NakWithDelay(delay) }}, nil
case <-ctx.Done(): case <-ctx.Done():
@@ -146,12 +146,12 @@ func DeclareAskWorkers(ctx context.Context, js jetstream.JetStream, language str
subject, _ := sdkstep.AskSubject(language, kind) subject, _ := sdkstep.AskSubject(language, kind)
// Two workers whose filters do not overlap: main's subject and the asker's, `<main's>.<asker>` (design 47 G §544). // Two workers whose filters do not overlap: main's subject and the asker's, `<main's>.<asker>` (design 47 G §544).
if _, err := js.CreateOrUpdateConsumer(ctx, stream, jetstream.ConsumerConfig{Durable: worker, FilterSubjects: []string{subject}, if _, err := js.CreateOrUpdateConsumer(ctx, stream, jetstream.ConsumerConfig{Durable: worker, FilterSubjects: []string{subject},
AckPolicy: jetstream.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: 5}); err != nil { AckPolicy: jetstream.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: sdkstep.AskMaxDeliver}); err != nil {
return fmt.Errorf("the worker %s: %w", worker, err) return fmt.Errorf("the worker %s: %w", worker, err)
} }
named, _ := sdkstep.AskNamedWorker(language, kind) named, _ := sdkstep.AskNamedWorker(language, kind)
if _, err := js.CreateOrUpdateConsumer(ctx, stream, jetstream.ConsumerConfig{Durable: named, FilterSubjects: []string{subject + ".*"}, if _, err := js.CreateOrUpdateConsumer(ctx, stream, jetstream.ConsumerConfig{Durable: named, FilterSubjects: []string{subject + ".*"},
AckPolicy: jetstream.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: 5}); err != nil { AckPolicy: jetstream.AckExplicitPolicy, AckWait: ackWait, MaxDeliver: sdkstep.AskMaxDeliver}); err != nil {
return fmt.Errorf("the worker %s: %w", named, err) return fmt.Errorf("the worker %s: %w", named, err)
} }
} }
@@ -147,7 +147,8 @@ func (p *Puller) refuseDropped(msg *Pulled, ask sdkstep.StepAsk, d *nodebuildgo.
return return
} }
p.logf("the ask %s is refused on %s: it was dropped (%s)", ask.ID, p.Node, d.Why) p.logf("the ask %s is refused on %s: it was dropped (%s)", ask.ID, p.Node, d.Why)
_ = msg.Term() p.sayAskEnded(msg, ask, sdkstep.OutcomeCouldNotRun, "it was dropped: "+d.Why)
_ = msg.Ack() // A-489a: its end is written
p.forgetDrop(ask.ID) p.forgetDrop(ask.ID)
} }
@@ -0,0 +1,258 @@
package steprun
import (
"context"
"encoding/json"
"errors"
"strings"
"sync"
"testing"
"time"
nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo"
sdkstep "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-sdk/buildstep"
)
// Design 47 G *Asked on a work queue, ended by an event* (§24): the bus counts an ask given back before it ran (a seat list
// not read yet) as a delivery, and that is no run. Only runs that started count toward the poison rule (Puller.Prior, from the
// step key), and a poisoned pipeline step is ended by its step-ended event, so the runner that asked hears it.
func TestOnlyRunsThatStartedCountTowardPoison(t *testing.T) {
stepAsk := func() sdkstep.StepAsk {
return sdkstep.StepAsk{ID: sdkstep.NewID(), Kind: sdkstep.AskStep, Language: sdkstep.AskGo, Asker: "mesh-delivery-pipeline", At: time.Now(),
Step: &sdkstep.StepRun{Pipeline: "main.12.m", Step: sdkstep.StepLint, Module: "m", Artifact: "m:program", Commit: strings.Repeat("a", 40),
Fingerprint: "fp-1", Fetch: sdkstep.Fetch{Repository: "novox/x", Commit: strings.Repeat("a", 40), Dir: "modules/m"}}}
}
for _, c := range []struct {
name string
delivered uint64
prior int
ends string // what its end says; "" when it must run
}{
{"given back three times, never run", sdkstep.AskRuns + 1, 0, ""},
{"three runs started and none ended", 3, sdkstep.AskRuns, "poison"},
{"three runs started, delivered many times", sdkstep.AskRuns + 4, sdkstep.AskRuns, "poison"},
{"its last delivery, given back before and never run", sdkstep.AskMaxDeliver, 0, "out of its deliveries"},
{"its last delivery after a run that started", sdkstep.AskMaxDeliver, 1, "poison"},
} {
t.Run(c.name, func(t *testing.T) {
src, st := NewFakeAsks(), newSteps()
src.Delivered = c.delivered
a := stepAsk()
raw, err := sdkstep.EncodeStepAsk(a)
if err != nil {
t.Fatal(err)
}
src.Publish(sdkstep.AskCheck, raw) // a pipeline step rides the check queue
var mu sync.Mutex
var ended []sdkstep.StepEnded
ran := make(chan struct{}, 1)
p := &Puller{Source: src, Language: sdkstep.AskGo, Logf: t.Logf, Node: "shanks", Put: st.put, Capacity: func() int { return 1 },
PullWait: 10 * time.Millisecond, Heartbeat: time.Hour, Prior: func(string) int { return c.prior },
Say: func(event string, body any, id string) error {
if event == "step-ended" {
var e sdkstep.StepEnded
raw, _ := json.Marshal(body)
if err := json.Unmarshal(raw, &e); err == nil {
mu.Lock()
ended = append(ended, e)
mu.Unlock()
}
}
return nil
},
Run: func(ctx context.Context, a sdkstep.StepAsk) (any, error) { ran <- struct{}{}; return nil, nil }}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go p.Pull(ctx)
if c.ends != "" {
waitFor(t, "the poisoned ask's end said", func() bool { mu.Lock(); defer mu.Unlock(); return len(ended) == 1 })
mu.Lock()
e := ended[0]
mu.Unlock()
if e.Outcome != sdkstep.OutcomeCouldNotRun || !strings.Contains(e.Said, c.ends) || e.Pipeline != "main.12.m" {
t.Fatalf("the end said %+v, want could not run, poison, naming its pipeline", e)
}
if acked, termed, naked := src.Fates(); len(acked) != 1 || len(termed)+len(naked) != 0 {
t.Errorf("acked %v termed %v naked %v, want it acknowledged once its end is written (A-489a)", acked, termed, naked)
}
select {
case <-ran:
t.Fatal("an ended ask ran")
default:
}
return
}
select {
case <-ran:
case <-time.After(5 * time.Second):
t.Fatal("an ask only given back was ended as poison, and never ran")
}
})
}
}
// A-489a: an end that could not be written is given back, never acknowledged: the ask's start is written, its end is not
// (poison), and an unreadable ask with an id whose refusal cannot be written.
func TestAnEndThatCannotBeWrittenIsGivenBack(t *testing.T) {
was := EndAttempts
EndAttempts = 1
defer func() { EndAttempts = was }()
for _, c := range []struct {
name string
data func() []byte
prior int
}{
{"poison", func() []byte { raw, _ := sdkstep.EncodeStepAsk(testAsk(sdkstep.AskDelivery)); return raw }, sdkstep.AskRuns},
{"unread with an id", func() []byte { return []byte(`{"id":"mwn1abcdef0123","kind":"check","v":99}`) }, 0},
} {
t.Run(c.name, func(t *testing.T) {
src := NewFakeAsks()
src.Publish(sdkstep.AskCheck, c.data())
if c.prior > 0 { // a delivery of the delivery queue
src = NewFakeAsks()
src.Publish(sdkstep.AskDelivery, c.data())
}
var mu sync.Mutex
puts := 0
put := func(string, any) (uint64, error) {
mu.Lock()
defer mu.Unlock()
puts++
if puts > 1 || c.prior == 0 { // the start is written, the end is not
return 0, errors.New("the state is full")
}
return 1, nil
}
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: put, Capacity: func() int { return 1 }, PullWait: 10 * time.Millisecond,
Prior: func(string) int { return c.prior }, Run: func(context.Context, sdkstep.StepAsk) (any, error) { return nil, nil }}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go p.Pull(ctx)
waitFor(t, "the ask given back", func() bool { _, _, nk := src.Fates(); return len(nk) >= 1 })
if acked, termed, _ := src.Fates(); len(acked)+len(termed) != 0 {
t.Errorf("acked %v termed %v, want none: no end was written", acked, termed)
}
})
}
}
// A-489a: a decline at the take (a need the node lacks), a refused run (Declining) and a dropped ask each say their pipeline step's end as could not
// run, naming its pipeline, and are acknowledged once it is written.
func TestAnEndedPipelineStepIsSaidAndAcknowledged(t *testing.T) {
for _, c := range []string{"declined", "declined in its run", "dropped"} {
t.Run(c, func(t *testing.T) {
src, st := NewFakeAsks(), newSteps()
a := sdkstep.StepAsk{ID: sdkstep.NewID(), Kind: sdkstep.AskStep, Language: sdkstep.AskGo, Asker: "mesh-delivery-pipeline", At: time.Now(),
Step: &sdkstep.StepRun{Pipeline: "main.12.m", Step: sdkstep.StepLint, Module: "m", Artifact: "m:program", Commit: strings.Repeat("a", 40),
Fingerprint: "fp-1", Fetch: sdkstep.Fetch{Repository: "novox/x", Commit: strings.Repeat("a", 40), Dir: "modules/m"}}}
raw, eerr := sdkstep.EncodeStepAsk(a)
if eerr != nil {
t.Fatal(eerr)
}
src.Publish(sdkstep.AskCheck, raw)
var mu sync.Mutex
var ended []sdkstep.StepEnded
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: st.put, Capacity: func() int { return 1 }, PullWait: 10 * time.Millisecond,
Say: func(event string, body any, id string) error {
if event == "step-ended" {
var e sdkstep.StepEnded
b, _ := json.Marshal(body)
if json.Unmarshal(b, &e) == nil {
mu.Lock()
ended = append(ended, e)
mu.Unlock()
}
}
return nil
},
Run: func(context.Context, sdkstep.StepAsk) (any, error) {
return nil, &Declining{Text: "this node builds with another toolchain", Lacks: []string{"the toolchain"}}
}}
if c == "dropped" {
drop, _ := json.Marshal(nodebuildgo.Drop{V: int64(sdkstep.Version), By: "mesh-delivery-builder", Why: "superseded", At: ptr(time.Now())})
p.Load = func(key string) ([]byte, error) {
if key == sdkstep.DropKey(a.ID) {
return drop, nil
}
return nil, nil
}
}
if c == "declined" {
// The decoder refuses needs on a pipeline step ask, so no ask of the queue reaches the decline; the line is held
// by calling it with the ask built whole.
acked := 0
p.decline(&Pulled{Ack: func() error { acked++; return nil }, Term: func() error { return nil }, Nak: func() error { return nil }}, a, []string{"node-build-node"})
if acked != 1 {
t.Errorf("acked %d times, want once", acked)
}
src.Acked = append(src.Acked, "declined")
} else {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go p.Pull(ctx)
}
waitFor(t, "the end said", func() bool { mu.Lock(); defer mu.Unlock(); return len(ended) >= 1 })
waitFor(t, "the ask acknowledged", func() bool { ak, _, _ := src.Fates(); return len(ak) == 1 })
mu.Lock()
e := ended[0]
mu.Unlock()
if e.Outcome != sdkstep.OutcomeCouldNotRun || e.Pipeline != "main.12.m" {
t.Errorf("the end said %+v, want could not run naming its pipeline", e)
}
if _, termed, naked := src.Fates(); len(termed)+len(naked) != 0 {
t.Errorf("termed %v naked %v, want it acknowledged alone", termed, naked)
}
})
}
}
// ADR 0664 §1 with the bus's count above the runs that started: the ask was given back twice before its first run, so the
// bus says delivered 3 while the step key says 1 run began; a transport fault is run 2 (given again after 4 minutes), not 3.
func TestATransportFaultCountsRunsThatStartedNotDeliveries(t *testing.T) {
src, st := NewFakeAsks(), newSteps()
src.Delivered = 3
a := testAsk(sdkstep.AskDelivery)
_ = src.PublishAsk(a)
p := &Puller{Source: src, Language: sdkstep.AskGo, Node: "shanks", Put: st.put, Capacity: func() int { return 1 }, PullWait: 10 * time.Millisecond,
Prior: func(string) int { return 1 },
Run: func(context.Context, sdkstep.StepAsk) (any, error) {
return nil, &sdkstep.Passing{Err: errors.New("lookup proxy: i/o timeout")}
}}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go p.Pull(ctx)
waitFor(t, "the ask given again", func() bool { src.mu.Lock(); defer src.mu.Unlock(); return len(src.Delayed) == 1 })
key, _ := sdkstep.AskStepKey("", "shanks", a.ID)
s, _ := st.get(key)
src.mu.Lock()
delays := append([]time.Duration(nil), src.Delays...)
src.mu.Unlock()
if s.State != sdkstep.StepAgain || s.Run != 2 || len(delays) != 1 || delays[0] != sdkstep.AgainAfter(2) {
t.Errorf("step %+v, delays %v, want again in run 2 after %s", s, delays, sdkstep.AgainAfter(2))
}
}
// Puller.Prior over a steps state's read: the Run of the step the key holds, 0 for an absent key, a failed read or what is no
// step, and nil for no read.
func TestPriorRunsReadsTheRunOfTheStepAKeyHolds(t *testing.T) {
read := func(key string) (json.RawMessage, error) {
switch key {
case "running":
return json.RawMessage(`{"id":"x","run":2}`), nil
case "junk":
return json.RawMessage(`[`), nil
case "broken":
return nil, errors.New("no bus")
}
return nil, nil
}
prior := PriorRuns(read)
for key, want := range map[string]int{"running": 2, "absent": 0, "junk": 0, "broken": 0} {
if got := prior(key); got != want {
t.Errorf("PriorRuns(%s) = %d, want %d", key, got, want)
}
}
if PriorRuns(nil) != nil {
t.Error("PriorRuns(nil) is not nil")
}
}
@@ -244,7 +244,7 @@ func TestPullDropsWhatIsNoAsk(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
go p.Pull(ctx) go p.Pull(ctx)
waitFor(t, "three termed", func() bool { _, tm, _ := src.Fates(); return len(tm) == 3 }) waitFor(t, "three acknowledged", func() bool { ak, _, _ := src.Fates(); return len(ak) == 3 })
if ran { if ran {
t.Fatal("a wrong or a declined ask ran") t.Fatal("a wrong or a declined ask ran")
} }
@@ -269,7 +269,7 @@ func TestPullDropsWhatIsNoAsk(t *testing.T) {
return nil, &Declining{Text: "the ask is for 26.13.0 and this node builds with 26.12.1", Lacks: []string{"the agreed toolchain 26.13.0 (recipe 3)"}} return nil, &Declining{Text: "the ask is for 26.13.0 and this node builds with 26.12.1", Lacks: []string{"the agreed toolchain 26.13.0 (recipe 3)"}}
}} }}
go s2.Pull(ctx) go s2.Pull(ctx)
waitFor(t, "the ask termed on the node that sits out", func() bool { _, tm, _ := sit.Fates(); return len(tm) == 1 }) waitFor(t, "the ask acknowledged on the node that sits out", func() bool { ak, _, _ := sit.Fates(); return len(ak) == 1 })
sk, _ := sdkstep.AskStepKey("", "ace", toolchain.ID) sk, _ := sdkstep.AskStepKey("", "ace", toolchain.ID)
ss, _ := sitSteps.get(sk) ss, _ := sitSteps.get(sk)
if d, ok := sdkstep.DeclinedOf(ss); !ok || len(d.Lacks) != 1 || !strings.Contains(ss.Reason, "26.12.1") { if d, ok := sdkstep.DeclinedOf(ss); !ok || len(d.Lacks) != 1 || !strings.Contains(ss.Reason, "26.12.1") {
@@ -538,14 +538,14 @@ func TestAPoisonedAskIsSaidAndRunNoMore(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
go p.Pull(ctx) go p.Pull(ctx)
waitFor(t, "the ask termed", func() bool { _, tm, _ := src.Fates(); return len(tm) == 1 }) waitFor(t, "the ask acknowledged", func() bool { ak, _, _ := src.Fates(); return len(ak) == 1 })
key, _ := sdkstep.AskStepKey("", "shanks", a.ID) key, _ := sdkstep.AskStepKey("", "shanks", a.ID)
s, ok := st.get(key) s, ok := st.get(key)
if ran || !ok || s.State != sdkstep.StepFailed || !strings.Contains(s.Reason, "taken 3 times") || !strings.Contains(s.Reason, "poison") { if ran || !ok || s.State != sdkstep.StepFailed || !strings.Contains(s.Reason, "taken 3 times") || !strings.Contains(s.Reason, "poison") {
t.Fatalf("ran %v, step %+v", ran, s) t.Fatalf("ran %v, step %+v", ran, s)
} }
if acked, _, naked := src.Fates(); len(acked)+len(naked) != 0 { if _, termed, naked := src.Fates(); len(termed)+len(naked) != 0 { // A-489: its end written, it leaves the queue by ack
t.Errorf("acked %v naked %v, want it termed alone", acked, naked) t.Errorf("termed %v naked %v, want it acknowledged alone", termed, naked)
} }
// ADR 0664 §1 (issue 1748): a run that ends on a transport fault below AskRuns is written again, with its run and when the // ADR 0664 §1 (issue 1748): a run that ends on a transport fault below AskRuns is written again, with its run and when the
// bus gives it, and handed back with that delay, not acknowledged; the AskRuns-th ends failed, passing; a fault of the // bus gives it, and handed back with that delay, not acknowledged; the AskRuns-th ends failed, passing; a fault of the
@@ -620,7 +620,7 @@ func TestPullAnswersAnAskItCannotRead(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
defer cancel() defer cancel()
go p.Pull(ctx) go p.Pull(ctx)
waitFor(t, "both termed", func() bool { _, tm, _ := src.Fates(); return len(tm) == 2 }) waitFor(t, "both acknowledged", func() bool { ak, _, _ := src.Fates(); return len(ak) == 2 })
key, _ := sdkstep.AskStepKey("", "ace", good.ID) key, _ := sdkstep.AskStepKey("", "ace", good.ID)
s, ok := st.get(key) s, ok := st.get(key)
if !ok || s.State != sdkstep.StepRefused || !strings.Contains(s.Reason, "cannot read the ask") || !strings.Contains(s.Reason, "exactly one") { if !ok || s.State != sdkstep.StepRefused || !strings.Contains(s.Reason, "cannot read the ask") || !strings.Contains(s.Reason, "exactly one") {