diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go index 6020618e3..01ebd2af8 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/askbounds.go @@ -84,6 +84,32 @@ func askClock(ctx context.Context, bounds jetstream.KeyValue, bound time.Duratio }} } +// stepEndsWaiting reads, once, the runner's own durable named durable on onSeat's step-ended stream (issue 1984 notes 6, 7): +// its consumer's info, the step ends not yet delivered and those delivered and not yet acknowledged. A seat whose step-ended +// stream the runner does not know, and a stream or durable the bus does not hold, hold none. +func stepEndsWaiting(ctx context.Context, js jetstream.JetStream, durable string) func(onSeat string) (uint64, uint64, error) { + return func(onSeat string) (uint64, uint64, error) { + stream := "" + for _, bs := range pipeline.StepSeats { + if bs.Seat == onSeat { + stream = bs.Stream + } + } + if stream == "" { + return 0, 0, nil + } + c, err := js.Consumer(ctx, stream, durable) + if errors.Is(err, jetstream.ErrConsumerNotFound) || errors.Is(err, jetstream.ErrStreamNotFound) { + return 0, 0, nil + } + if err != nil { + return 0, 0, fmt.Errorf("the consumer %s on %s is not read: %w", durable, stream, err) + } + info := c.CachedInfo() // read by the one call that bound c + return info.NumPending, uint64(info.NumAckPending), nil + } +} + // progressed arms the bound of the ask on onSeat again from now, at a step-progress its holder says for it (H-A-395), // said when it fails: the bound then ends the step at its time. func progressed(c *pipeline.AskClock, onSeat, ask string, logf func(string, ...any)) { diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go index 6e433bff2..40d98124d 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/main.go @@ -187,6 +187,8 @@ func run(ctx context.Context, getenv func(string) string, logOut io.Writer) erro hearer.RegistrationWaits = func() { starter.JudgeRegistrationMissing(store) } // at every end (H-A-265 (4)) logger.Printf("asks: an ask's bound %s, counted from its put until its holder's ask-taken, then from the take and each step-progress; past it the step ends could not run and its ask is dropped", askBound) clock := askClock(ctx, bounds, askBound, rv.Findings, cred.Module, time.Now) + // A bound passing reads the runner's own step-ended durable first: an end waiting there is not the holder's silence (issue 1984). + clock.Waiting = stepEndsWaiting(ctx, js, cred.EventConsumerName()) starter.Asks, hearer.Asks = clock, clock starter.Supersede = func(newer seat.Pipeline) { hearer.SupersedeRunning(newer) } starter.Drop = hearer.DropOpen // a placing's end drops the asks still open (H-A-506) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go index 58272cbd4..7f1215003 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/run_integration_test.go @@ -56,6 +56,7 @@ func TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview(t *tes t.Run("a take-in said before the bind is still worked", testATakeInSaidBeforeTheBindIsStillWorked) t.Run("a takeins bind that failed is bound again on registration-changed", testATakeInsBindThatFailedIsBoundAgainOnRegistrationChanged) t.Run("step log read does not wait for a batch it cannot fill", testStepLogReadDoesNotWaitForABatchItCannotFill) + t.Run("a bound passing reads the runner's own step-ended durable", testABoundPassingReadsTheRunnersOwnStepEndedDurable) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() reg := catalog.Registration{Module: "app", Branches: []string{"main"}, Origin: "o/app", Policy: catalog.Policy{Steps: catalog.StepStatuses{Review: "optional", Validate: "bypass", Composition: "required", Approval: "bypass"}}} diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go new file mode 100644 index 000000000..bd5a18a01 --- /dev/null +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/stependswaiting_integration_test.go @@ -0,0 +1,80 @@ +//go:build integration + +package main + +import ( + "context" + "testing" + "time" + + "github.com/nats-io/nats.go" + "github.com/nats-io/nats.go/jetstream" + + wants "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshwants" + nodebuildgo "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/nodebuildgo" + "git.novox.be/novox/mesh-sdk/go/testbus" +) + +// testABoundPassingReadsTheRunnersOwnStepEndedDurable is a row of TestTheRunnerPlacesAPipelineAsksItsBuildTakesItsEndAndAnswersAReview +// (design 47 H2 §819: the module's tests are folded under its budget). 1984/AC2: as an ask's bound passes the runner reads its own +// durable on the seat's step-ended stream once, against the bus: the ends not yet delivered and those delivered and not +// acknowledged; a durable or stream the bus does not hold holds none; a read the bus does not answer is an error. +func testABoundPassingReadsTheRunnersOwnStepEndedDurable(t *testing.T) { + nc, err := nats.Connect(testbus.URL(t)) + if err != nil { + t.Fatal(err) + } + defer nc.Close() + js, _ := jetstream.New(nc) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + const durable = "n1_mesh-delivery-pipeline" + waiting := stepEndsWaiting(ctx, js, durable) + read := func(onSeat string) (uint64, uint64) { + t.Helper() + p, u, err := waiting(onSeat) + if err != nil { + t.Fatalf("the durable of %s: %v", onSeat, err) + } + return p, u + } + if _, err := js.CreateStream(ctx, jetstream.StreamConfig{Name: nodebuildgo.StreamStepEnded, Subjects: []string{nodebuildgo.SubjectStepEndedAll}}); err != nil { + t.Fatal(err) + } + if p, u := read(nodebuildgo.Seat); p+u != 0 { + t.Errorf("a stream with no durable of the runner holds %d and %d; want none", p, u) + } + if p, u := read(wants.Seat); p+u != 0 { + t.Errorf("a stream the bus does not hold holds %d and %d; want none", p, u) + } + if p, u := read("no-such-seat"); p+u != 0 { + t.Errorf("a seat with no step-ended stream holds %d and %d; want none", p, u) + } + c, err := js.CreateOrUpdateConsumer(ctx, nodebuildgo.StreamStepEnded, jetstream.ConsumerConfig{Durable: durable, + AckPolicy: jetstream.AckExplicitPolicy, FilterSubjects: []string{nodebuildgo.SubjectStepEndedAll}}) + if err != nil { + t.Fatal(err) + } + for range 3 { + if _, err := js.Publish(ctx, "mesh.seat.node-build-go.event.step-ended.n1", []byte(`{}`)); err != nil { + t.Fatal(err) + } + } + if p, u := read(nodebuildgo.Seat); p != 3 || u != 0 { + t.Errorf("three ends said and none taken: %d not yet delivered, %d unacknowledged; want 3 and 0", p, u) + } + b, err := c.Fetch(1) + if err != nil { + t.Fatal(err) + } + for range b.Messages() { + } + if p, u := read(nodebuildgo.Seat); p != 2 || u != 1 { + t.Errorf("one end taken and not acknowledged: %d not yet delivered, %d unacknowledged; want 2 and 1", p, u) + } + gone, stop := context.WithCancel(ctx) + stop() + if _, _, err := stepEndsWaiting(gone, js, durable)(nodebuildgo.Seat); err == nil { + t.Error("a read the bus does not answer says no error; want one, so the bound is armed once more") + } +} diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go index 364512a1c..4e2eae26c 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/testruns.go @@ -177,6 +177,16 @@ func (t testRunsKV) MarkAsk(ask string, mark pipeline.AskMark) error { return nil } +// MarkAskAgain writes the ask key of ask holding mark over the one written (issue 1984 note 7 (c)). +func (t testRunsKV) MarkAskAgain(ask string, mark pipeline.AskMark) error { + raw, err := json.Marshal(mark) + if err != nil { + return err + } + _, err = t.kv.Put(t.ctx, pipeline.AskKey(ask), raw) + return err +} + // AskOf reads the ask key of ask: the mark it holds, a key written before the H-A-506 addendum naming its run alone. func (t testRunsKV) AskOf(ask string) (pipeline.AskMark, bool, error) { e, err := t.kv.Get(t.ctx, pipeline.AskKey(ask)) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go index 60ad7e29c..0727ef8a4 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks.go @@ -41,6 +41,13 @@ func UnansweredWhy(ask string) string { return "its ask " + ask + " was not answered: its holder said nothing of it within ask-unanswered-bound" } +// unreadWhy is the why of a step whose bound passed twice in a row while the runner could not read its own step-ended +// durable of onSeat (issue 1984 note 7 (b)): whether its end waits there is not known, so its holder is not said silent. +func unreadWhy(onSeat, ask string) string { + return "its ask " + ask + " is not known to be answered: the runner could not read its own step-ended durable of " + onSeat + + " at two bounds in a row" +} + // UntakenWhy is the why of a step whose ask no holder of onSeat took within the bound after it was asked (§778). func UntakenWhy(onSeat string) string { return "its ask was not taken: " + onSeat + "'s holder takes none" @@ -58,6 +65,10 @@ type AskClock struct { Unbound func(key string) error Raise func(onSeat, ask string, bound time.Duration) error Clear func(onSeat, ask string) error + // Waiting reads, once, the runner's own durable on onSeat's step-ended stream (issue 1984 notes 6, 7): the step ends it + // holds not yet delivered and those delivered and not yet acknowledged, none for a durable or stream the bus does not + // hold; nil reads none, and a bound then ends its step as it passes. + Waiting func(onSeat string) (pending, unacknowledged uint64, err error) } // arm arms the bound of a, before it is put (§778); a test run's ask, and a nil clock, arm none. @@ -139,8 +150,23 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { if s.TakenAt == nil { why, said = UntakenWhy(onSeat), "was taken by no holder" } - h.logf("the ask %s of the %s step of %s on %s %s within %s: the step ends could not run and its ask is dropped (§778)", - s.Ask, s.Step, key, onSeat, said, c.bound()) + // Its end may wait in the runner's own step-ended durable, not yet taken: the runner's queue is never counted against + // the holder (issue 1984 notes 6, 7). + read, unread := "", false + if c.Waiting != nil && c.Rearm != nil { + var again bool + if read, again, unread = v.endsWaiting(c, key, onSeat, s); again { + return nil + } + } + if unread { + why = unreadWhy(onSeat, s.Ask) + h.logf("the ask %s of the %s step of %s on %s is not known to be answered within %s: the runner could not read its own step-ended durable of %s at this bound and the one before; the step ends could not run and its ask is dropped (§778)", + s.Ask, s.Step, key, onSeat, c.bound(), onSeat) + } else { + h.logf("the ask %s of the %s step of %s on %s %s within %s%s: the step ends could not run and its ask is dropped (§778)", + s.Ask, s.Step, key, onSeat, said, c.bound(), read) + } if err := h.endUnanswered(key, s.Ask, why); err != nil { return err } @@ -149,12 +175,75 @@ func (v Verbs) AskUnanswered(onSeat, ask string) error { h.logf("the ask %s on %s, ended by its bound, is not dropped: %v", s.Ask, onSeat, err) } } - if c.Raise != nil { + // The finding call-unanswered says its holder said nothing, which is not known of an ask whose ends were not read: its + // step's why and the pipeline's failure say it. + if c.Raise != nil && !unread { return c.Raise(onSeat, s.Ask, c.bound()) } return nil } +// endsWaiting reads the runner's own step-ended durable of onSeat once, as the bound of step s's ask passes (issue 1984 +// notes 6, 7): while step ends wait there, or at the first read that fails, the bound is armed again whole and said, again +// true; a read that fails at the bound after one that failed answers unread true; else it answers what the journal adds to +// the step's end, the count read, and the ask's mark loses its unread. +func (v Verbs) endsWaiting(c *AskClock, key, onSeat string, s seat.StepResult) (read string, again, unread bool) { + h := v.Hearer + boundKey := AskBoundKey(onSeat, s.Ask) + pending, unacked, err := c.Waiting(onSeat) + var mark AskMark + marked := false + if h.Clock != nil { + var merr error + if mark, marked, merr = h.Clock.AskOf(s.Ask); merr != nil { + h.logf("the mark of ask %s is not read, so the bound passing reads it as unmarked: %v", s.Ask, merr) + } + } + if !marked { + mark = AskMark{Pipeline: key, Module: s.Module, Step: s.Step} + } + if err != nil { + if mark.Unread != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read again (%v), as at the bound before (%s)", + s.Ask, s.Step, key, onSeat, onSeat, err, mark.Unread.Format(time.RFC3339)) + return "", false, true + } + if h.Clock == nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v); the runner keeps no ask marks to arm it once more", + s.Ask, s.Step, key, onSeat, onSeat, err) + return "", false, true + } + now := h.now() + mark.Unread = &now + if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v), and the ask's mark keeping that is not written (%v)", + s.Ask, s.Step, key, onSeat, onSeat, err, werr) + return "", false, true + } + if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { + h.logf("the bound of ask %s on %s is not armed again after its durable was not read: %v", s.Ask, onSeat, rerr) + } + h.logf("the bound of ask %s of the %s step of %s on %s passed and the runner's own step-ended durable of %s is not read (%v): the step is not ended and its bound is armed again with %s; a second failed read at that bound ends it", + s.Ask, s.Step, key, onSeat, onSeat, err, c.bound()) + return "", true, false + } + if mark.Unread != nil && h.Clock != nil { + mark.Unread = nil + if werr := h.Clock.MarkAskAgain(s.Ask, mark); werr != nil { + h.logf("the mark of ask %s keeps its unread, its durable read now: %v", s.Ask, werr) + } + } + if n := pending + unacked; n > 0 { + if rerr := c.Rearm(boundKey, c.bound()); rerr != nil { + h.logf("the bound of ask %s on %s is not armed again while step ends wait: %v", s.Ask, onSeat, rerr) + } + h.logf("the bound of ask %s of the %s step of %s on %s passed while %d step ends wait in the runner's own step-ended durable of %s (%d not yet delivered, %d delivered and not acknowledged): the step is not ended and its bound is armed again with %s", + s.Ask, s.Step, key, onSeat, n, onSeat, pending, unacked, c.bound()) + return "", true, false + } + return fmt.Sprintf(", and no step end waits in the runner's own step-ended durable of %s (0 not yet delivered, 0 unacknowledged)", onSeat), false, false +} + // OpenAsk is an ask a running step waits on, and when its holder last spoke of it: its taken-at, else its asked-at. type OpenAsk struct { Seat, Ask string diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go index c855dadf7..874d03ac1 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/asks_test.go @@ -1,6 +1,7 @@ package pipeline import ( + "errors" "fmt" "slices" "strings" @@ -141,6 +142,109 @@ func TestAnAsksBoundCountsFromThePullAndEndsItsStep(t *testing.T) { } } +// 1984/AC2 (issue 1984 notes 6 and 7): before a bound ends its step, the runner reads its own step-ended durable of the +// ask's seat once. While step ends wait there the step is not ended: its bound is armed again and the journal says how many +// wait. With none waiting the step ends as before, its why true, the journal naming the count read. A read that fails arms +// the bound once more, kept on the ask's mark; a second failed read at that bound ends the step saying the durable was not +// read, never that its holder said nothing, and raises no call-unanswered. A read that succeeds between clears the mark. +func TestABoundPassingWhileStepEndsWaitArmsItAgain(t *testing.T) { + type read struct { + pending, unacked uint64 + err error + } + for _, c := range []struct { + name string + reads []read + // what each bound's passing leaves: "armed" (the step still running, its bound armed again) or the why it ended with + want []string + }{ + {"step ends wait: armed again, then ended once none waits", []read{{3, 1, nil}, {0, 0, nil}}, []string{"armed", "unanswered"}}, + {"a failed read arms once more; a second ends saying the durable was not read", []read{{0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "unread"}}, + {"a read between two failed ones clears the first", []read{{0, 0, errors.New("timeout")}, {2, 0, nil}, {0, 0, errors.New("timeout")}, {0, 0, errors.New("timeout")}}, []string{"armed", "armed", "armed", "unread"}}, + } { + t.Run(c.name, func(t *testing.T) { + v, store, _, _, _, journal := verbsFixture() + now := time.Date(2026, 11, 23, 17, 0, 0, 0, time.UTC) + v.Hearer.Now = func() time.Time { return now } + var rearmed, raised, dropped []string + n := 0 + clock := &AskClock{Bound: 10 * time.Minute, + Arm: func(string, time.Duration) error { return nil }, + Rearm: func(key string, ttl time.Duration) error { rearmed = append(rearmed, key+" "+ttl.String()); return nil }, + Unbound: func(string) error { return nil }, + Raise: func(s, ask string, _ time.Duration) error { raised = append(raised, s+" "+ask); return nil }, + Waiting: func(onSeat string) (uint64, uint64, error) { + if onSeat != nodebuildgo.Seat { + t.Errorf("the durable of %s was read; want the ask's seat's", onSeat) + } + r := c.reads[n] + n++ + return r.pending, r.unacked, r.err + }} + v.Starter.Asks, v.Hearer.Asks = clock, clock + v.Hearer.DropRun = func(onSeat, _, ask, why string) error { dropped = append(dropped, ask+" "+why); return nil } + p, rev, _ := store.Get(pkey) + for i := range p.Steps { + if open(p.Steps[i]) { + p.Steps[i].Outcome = seat.StepResultOutcomePassed + } + } + p.Steps[stepIndex(p, "lint", "app:program")].Outcome = seat.StepResultOutcomeFailed + store.Update(pkey, p, rev) + r, err := v.Rerun("operator", seat.RerunInput{Pipeline: pkey, Step: "lint", Artifact: "app:program", Why: "retry"}) + if err != nil { + t.Fatal(err) + } + ask := r.Result.Ask + if _, err := v.Hearer.Taken(ask, "n1", now.Add(-10*time.Minute)); err != nil { + t.Fatal(err) + } + for i, want := range c.want { + *journal = nil + if err := v.AskUnanswered(nodebuildgo.Seat, ask); err != nil { + t.Fatal(err) + } + got, _, _ := store.Get(pkey) + s := got.Steps[stepIndex(got, "lint", "app:program")] + switch want { + case "armed": + if !open(s) || len(rearmed) != i+1 || rearmed[i] != AskBoundKey(nodebuildgo.Seat, ask)+" 10m0s" || len(dropped)+len(raised) != 0 { + t.Fatalf("bound %d: the step is %s (%s), armed again %v, dropped %v, raised %v; want it running and its bound armed again whole", + i+1, s.Outcome, s.Why, rearmed, dropped, raised) + } + if c.reads[i].err != nil && countLines(*journal, "is not read") != 1 { + t.Errorf("bound %d: the journal %q does not say the durable was not read", i+1, *journal) + } + if c.reads[i].err == nil && countLines(*journal, fmt.Sprintf("%d step ends wait", c.reads[i].pending+c.reads[i].unacked)) != 1 { + t.Errorf("bound %d: the journal %q does not say how many step ends wait", i+1, *journal) + } + m, _, _ := v.Hearer.Clock.AskOf(ask) + if (m.Unread != nil) != (c.reads[i].err != nil) { + t.Errorf("bound %d: the ask's mark keeps unread %v after a read that failed %v", i+1, m.Unread, c.reads[i].err != nil) + } + case "unanswered": + if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != UnansweredWhy(ask) || len(raised) != 1 { + t.Fatalf("bound %d: the step is %s (%s), raised %v; want could not run: %s, and its finding", i+1, s.Outcome, s.Why, raised, UnansweredWhy(ask)) + } + if countLines(*journal, "0 not yet delivered, 0 unacknowledged") != 1 { + t.Errorf("bound %d: the journal %q does not name the count read", i+1, *journal) + } + case "unread": + if s.Outcome != seat.StepResultOutcomeCouldNotRun || s.Why != unreadWhy(nodebuildgo.Seat, ask) || strings.Contains(s.Why, "said nothing") { + t.Fatalf("bound %d: the step is %s (%s); want could not run: %s", i+1, s.Outcome, s.Why, unreadWhy(nodebuildgo.Seat, ask)) + } + if len(raised) != 0 || len(dropped) != 1 { + t.Errorf("bound %d: raised %v, dropped %v; want no call-unanswered, which says its holder said nothing, and the ask dropped", i+1, raised, dropped) + } + } + } + if n != len(c.reads) { + t.Errorf("the durable was read %d times; want once at each bound, %d", n, len(c.reads)) + } + }) + } +} + // H-A-252: the pipeline's one validate ask names no mover (H-A-51), and its holder's end names the mover whose body it took: // it is matched by its ask alone and ends the validate step of every mover under it, whichever mover it names. func TestAValidateEndNamingOneMoverEndsEveryMoversValidate(t *testing.T) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go index 3b3a869cc..ebadac686 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/runends.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/runends.go @@ -57,6 +57,9 @@ type RunClock interface { // MarkAsk writes the ask key of ask (AskKey) holding mark, create-only: one written already is kept (H-A-500 addendum // (1), H-A-506 addendum). MarkAsk(ask string, mark AskMark) error + // MarkAskAgain writes the ask key of ask holding mark over the one written, or writes it when none is: its unread set or + // cleared as a bound passes (issue 1984 note 7 (c)). + MarkAskAgain(ask string, mark AskMark) error // AskOf reads the ask key of ask: the mark it holds; ok false when it is not written. AskOf(ask string) (mark AskMark, ok bool, err error) } @@ -74,12 +77,15 @@ func AskKey(ask string) string { return AskPrefix + ask } func IsRunAsk(key string) bool { return strings.HasPrefix(key, AskPrefix) } // AskMark is what an ask key holds (H-A-506 addendum): the pipeline that put the ask, the mover and the step it asks, and -// the test run it asks, empty for an ask of no test run. An ask key written before the addendum holds its run alone. +// the test run it asks, empty for an ask of no test run. An ask key written before the addendum holds its run alone. Unread +// is when the runner last could not read its own step-ended durable of the ask's seat as the ask's bound passed, cleared +// by a read that succeeds (issue 1984 note 7 (c)): a second failed read at the bound after ends the step. type AskMark struct { - Pipeline string `json:"pipeline,omitempty"` - Module string `json:"module,omitempty"` - Step string `json:"step,omitempty"` - Run string `json:"run,omitempty"` + Pipeline string `json:"pipeline,omitempty"` + Module string `json:"module,omitempty"` + Step string `json:"step,omitempty"` + Run string `json:"run,omitempty"` + Unread *time.Time `json:"unread,omitempty"` } // markOf is the mark of ask a, put by the pipeline key. diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index a2a7103b5..6b253e20b 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -27,6 +27,9 @@ type StepSeat struct { Seat string // Prefix is the subject before . Prefix string + // Stream is the stream the seat's step-ended is kept in, from its contract: the runner's own durable there holds the + // ends it has not taken yet, read as an ask's bound passes (issue 1984). + Stream string // Decode reads the seat's step-ended body; nil is the build seats' one form. Decode func([]byte) (StepEnded, error) // Shared reads the runs a step-ended names in `shared`, carried into the step's result as they came (A-468d); nil for @@ -41,14 +44,15 @@ type StepSeat struct { // StepSeats are the three build seats, from their contracts. var StepSeats = []StepSeat{ - {Seat: nodebuildgo.Seat, Prefix: strings.TrimSuffix(nodebuildgo.SubjectStepEndedAll, "*")}, - {Seat: nodebuildnode.Seat, Prefix: strings.TrimSuffix(nodebuildnode.SubjectStepEndedAll, "*")}, - {Seat: nodebuildimage.Seat, Prefix: strings.TrimSuffix(nodebuildimage.SubjectStepEndedAll, "*")}, + {Seat: nodebuildgo.Seat, Prefix: strings.TrimSuffix(nodebuildgo.SubjectStepEndedAll, "*"), Stream: nodebuildgo.StreamStepEnded}, + {Seat: nodebuildnode.Seat, Prefix: strings.TrimSuffix(nodebuildnode.SubjectStepEndedAll, "*"), Stream: nodebuildnode.StreamStepEnded}, + {Seat: nodebuildimage.Seat, Prefix: strings.TrimSuffix(nodebuildimage.SubjectStepEndedAll, "*"), Stream: nodebuildimage.StreamStepEnded}, // The seat mesh-builds answers the build step of a candidate, one entry named by its fingerprint (A-97, A-99). - {Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Decode: decodeBuildEnded, Pins: buildPins, - Superseding: buildSuperseding}, + {Seat: builds.Seat, Prefix: strings.TrimSuffix(builds.SubjectStepEndedAll, "*"), Stream: builds.StreamStepEnded, Decode: decodeBuildEnded, + Pins: buildPins, Superseding: buildSuperseding}, // The seat mesh-wants answers the composition step (§22, §24). - {Seat: wants.Seat, Prefix: strings.TrimSuffix(wants.SubjectStepEndedAll, "*"), Decode: decodeWantsEnded, Shared: wantsShared}, + {Seat: wants.Seat, Prefix: strings.TrimSuffix(wants.SubjectStepEndedAll, "*"), Stream: wants.StreamStepEnded, Decode: decodeWantsEnded, + Shared: wantsShared}, } // wantsShared is the composition runs a mesh-wants step-ended names, one per machine (design 47 G §723, §729; A-468d, diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go index 5446491fa..c35cc487d 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/testruns_test.go @@ -65,6 +65,13 @@ func (c *clockMem) MarkAsk(ask string, m AskMark) error { c.askRuns[AskKey(ask)] = m return nil } +func (c *clockMem) MarkAskAgain(ask string, m AskMark) error { + if c.askRuns == nil { + c.askRuns = map[string]AskMark{} + } + c.askRuns[AskKey(ask)] = m + return nil +} func (c *clockMem) AskOf(ask string) (AskMark, bool, error) { m, ok := c.askRuns[AskKey(ask)] return m, ok, nil