From f6aff0182c9ce712bf34fa53e11fb02437cfa803 Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 22 Nov 2026 23:28:41 +0100 Subject: [PATCH] H-A-504 addendum runner: every pipeline has a sequence, and its end says it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runner took queue.next only for a pipeline that waited, so most pipelines kept seq 0 and the assigner had no order across pipelines for a want's run. queueStart now takes the next sequence for every pipeline it writes, queued or placed at once, and pipeline-ended carries the record's seq. Builds: design 47 H2 §813 (1), H-A-504 corrected, H-A-504 addendum --- .../queue_integration_test.go | 11 +++++---- .../internal/pipeline/ended_test.go | 7 ++++-- .../internal/pipeline/queue.go | 23 +++++++++++-------- .../internal/pipeline/queue_test.go | 13 ++++++----- .../internal/pipeline/steps.go | 5 ++-- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go index fd539a64b..5fda4dab6 100644 --- a/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go +++ b/modules/mesh-delivery-pipeline/cmd/mesh-delivery-pipeline/queue_integration_test.go @@ -268,13 +268,16 @@ func testTheQueueRunsPipelinesInTurn(t *testing.T) { waitFor(t, ctx, logs, func() bool { return get(key).Outcome == want }) } - // Two take-ins in a row: the first runs, its build asked; the second is written waiting under sequence 1 with no step, - // says pipeline-started and wait-held. + // Two take-ins in a row: the first runs at sequence 1 (every pipeline has one, H-A-504 addendum), its build asked; the + // second is written waiting under sequence 2 with no step, says pipeline-started and wait-held. take(3, "app") outcome("main.3", seat.PipelineOutcomeRunning) + if p := get("main.3"); p.Seq != 1 { + t.Fatalf("main.3 placed at once has seq %d, want 1", p.Seq) + } take(4, "lib") - if p := get("main.4"); p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != 1 || len(p.Steps) != 0 { - t.Fatalf("main.4 = %s seq %d with %d steps, want waiting at 1 with none", p.Outcome, p.Seq, len(p.Steps)) + if p := get("main.4"); p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != 2 || len(p.Steps) != 0 { + t.Fatalf("main.4 = %s seq %d with %d steps, want waiting at 2 with none", p.Outcome, p.Seq, len(p.Steps)) } waitFor(t, ctx, logs, func() bool { return wasSaid("wait-held.main.4") && wasSaid("pipeline-started.main.4") }) if r := running(); !slices.Equal(r, []string{"main.3"}) { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go index 9400620e0..1080f9715 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/ended_test.go @@ -223,11 +223,11 @@ func TestAReleasedVersionIsTheMoversVersion(t *testing.T) { } } -// Design 47 H2 §785: a pipeline of two movers ends with its taken, placed and ended times and each step kind's span, the +// Design 47 H2 §785: a pipeline of two movers ends with its sequence (H-A-504 addendum) and its taken, placed and ended times and each step kind's span, the // earliest start and the latest end across its movers; a kind none of whose steps started has none. func TestPipelineEndedCarriesEachStepKindsSpan(t *testing.T) { at := func(m int) *time.Time { v := time.Date(2026, 11, 22, 1, m, 0, 0, time.UTC); return &v } - p := seat.Pipeline{Pipeline: "main.7", Started: at(0), Ended: at(30), Outcome: seat.PipelineOutcomePassed, + p := seat.Pipeline{Pipeline: "main.7", Seq: 270, Started: at(0), Ended: at(30), Outcome: seat.PipelineOutcomePassed, Movers: []seat.Mover{{Module: "lib", Tier: 1}, {Module: "app", Tier: 2}}, Steps: []seat.StepResult{ {Module: "lib", Step: seat.StepResultStepBuild, Started: at(2), Ended: at(6)}, @@ -236,6 +236,9 @@ func TestPipelineEndedCarriesEachStepKindsSpan(t *testing.T) { {Module: "app", Step: seat.StepResultStepUnit, Started: at(10)}, {Module: "app", Step: seat.StepResultStepComposition}, }} + if seq := pipelineEnded(p).Seq; seq != 270 { + t.Errorf("pipeline-ended carries seq %d, want the record's 270 (H-A-504 addendum)", seq) + } ph := pipelineEnded(p).Phases if ph == nil || !ph.Taken.Equal(*at(0)) || !ph.Placed.Equal(*at(1)) || !ph.Ended.Equal(*at(30)) { t.Fatalf("phases %+v, want taken 01:00, placed 01:01, ended 01:30", ph) diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/queue.go b/modules/mesh-delivery-pipeline/internal/pipeline/queue.go index 9effe4847..ffa0fae70 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/queue.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/queue.go @@ -117,7 +117,7 @@ func (q *Queue) run(key string) (bool, error) { return true, nil } -// next is the sequence the next waiting pipeline gets: queue.next read and written one higher by compare-and-set, from 1. +// next is the sequence the next pipeline gets, waiting or placed: queue.next read and written one higher by compare-and-set, from 1. func (q *Queue) next() (int64, error) { for { raw, rev, err := q.Store.Get(seat.QueueByQueueNextKey()) @@ -180,23 +180,26 @@ func (s *Starter) sayQueueWait(event string, p seat.Pipeline, at time.Time, how } } -// queueStart judges a start against the bound (§748): under it, it answers true, the pipeline placed and its running key -// written once the pipeline is (ran); over it p gets the next sequence and state waiting, with no step, and its waiting key -// is written first, so a key whose pipeline was never written is dropped at its placing; it answers false and that key. A -// start with no queue is placed. +// queueStart gives p the next sequence of queue.next, whether it waits or is placed at once, so every pipeline's seq grows +// across the pipelines of a branch and the assigner writes it as its wants' run (design 47 H2 §813 (1), H-A-504 addendum); +// then it judges the start against the bound (§748): under it, it answers true, the pipeline placed and its running key +// written once the pipeline is (ran); over it p gets state waiting, with no step, and its waiting key is written first, so a +// key whose pipeline was never written is dropped at its placing; it answers false and that key. A start with no queue is +// placed. func (s *Starter) queueStart(p *seat.Pipeline) (bool, string, error) { if s.Queue == nil { return true, "", nil } - full, err := s.Queue.full() - if err != nil || !full { - return err == nil, "", err - } seq, err := s.Queue.next() if err != nil { return false, "", err } - p.Seq, p.Outcome = seq, seat.PipelineOutcomeWaiting + p.Seq = seq + full, err := s.Queue.full() + if err != nil || !full { + return err == nil, "", err + } + p.Outcome = seat.PipelineOutcomeWaiting return false, sequenceKey(seq), s.Queue.wait(seq, p.Pipeline) } diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/queue_test.go b/modules/mesh-delivery-pipeline/internal/pipeline/queue_test.go index 23b841668..a697a4433 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/queue_test.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/queue_test.go @@ -116,8 +116,9 @@ func TestThePipelinesWaitTheirTurn(t *testing.T) { take := takeIn(t, s, view) take(4, "app") first := len(asks.ids) - if p, _, _ := mem.Get("main.4"); p.Outcome != seat.PipelineOutcomeRunning || p.Seq != 0 || first == 0 { - t.Fatalf("the first pipeline = %s seq %d with %d asks, want running and asked", p.Outcome, p.Seq, first) + if p, _, _ := mem.Get("main.4"); p.Outcome != seat.PipelineOutcomeRunning || p.Seq != 1 || first == 0 { + // H-A-504 addendum: a pipeline placed at once has its sequence too + t.Fatalf("the first pipeline = %s seq %d with %d asks, want running at 1 and asked", p.Outcome, p.Seq, first) } if _, ok := q["running.main.4"]; !ok { t.Fatalf("the queue = %v, want running.main.4", q) @@ -127,15 +128,15 @@ func TestThePipelinesWaitTheirTurn(t *testing.T) { take(6, "tool") for i, key := range []string{"main.5", "main.6"} { p, _, _ := mem.Get(key) - if p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != int64(i+1) || len(p.Steps) != 0 { - t.Errorf("%s = %s seq %d with %d steps, want waiting at %d with none", key, p.Outcome, p.Seq, len(p.Steps), i+1) + if p.Outcome != seat.PipelineOutcomeWaiting || p.Seq != int64(i+2) || len(p.Steps) != 0 { + t.Errorf("%s = %s seq %d with %d steps, want waiting at %d with none", key, p.Outcome, p.Seq, len(p.Steps), i+2) } } if len(asks.ids) != first { t.Errorf("a waiting pipeline asked %d steps", len(asks.ids)-first) } - if _, ok := q["waiting.00000000000000000001"]; !ok || string(q["queue.next"].v) != "3" { - t.Errorf("the queue = %v, want waiting.<1 in 20 digits> and queue.next 3", q) + if _, ok := q["waiting.00000000000000000002"]; !ok || string(q["queue.next"].v) != "4" { + t.Errorf("the queue = %v, want waiting.<2 in 20 digits> and queue.next 4", q) } if !slices.Contains(*said, "pipeline-started.main.5") || !slices.Contains(*said, "wait-held.main.5") || len(*waits) != 2 || (*waits)[0].Step != seat.WaitStepPipeline || (*waits)[0].On != seat.WaitOnPipelinesAtOnce || (*waits)[0].Pipeline != "main.5" { diff --git a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go index 35156c372..23d4ecb90 100644 --- a/modules/mesh-delivery-pipeline/internal/pipeline/steps.go +++ b/modules/mesh-delivery-pipeline/internal/pipeline/steps.go @@ -693,7 +693,8 @@ func stepsOf(p seat.Pipeline, module string) []seat.StepResult { return out } -// pipelineEnded is p's pipeline-ended (design 47 H §746): its key, branch, source, call, revision and outcome, and per +// pipelineEnded is p's pipeline-ended (design 47 H §746): its key, branch, source, call, revision, sequence (H2 §813 (1), +// H-A-504 addendum) and outcome, and per // mover, in the delivery order of its tiers, its module, fingerprint, commit, widens (H-A-119), released version, step results // and tier; and the movers its end left unfinished (design 47 H2 §786). func pipelineEnded(p seat.Pipeline) seat.PipelineEnded { @@ -704,7 +705,7 @@ func pipelineEnded(p seat.Pipeline) seat.PipelineEnded { } sort.SliceStable(movers, func(i, j int) bool { return movers[i].Tier < movers[j].Tier }) return seat.PipelineEnded{V: 1, Pipeline: p.Pipeline, Branch: p.Branch, Source: p.Source, Call: p.Call, Revision: p.Revision, - Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers, + Seq: p.Seq, Run: p.Run, Outcome: p.Outcome, Why: p.Why, Started: p.Started, Ended: p.Ended, EndCount: p.EndCount, Movers: movers, Phases: phasesOf(p), Unfinished: unfinishedOf(p)} }