From 383e698254627c68fe4d629e290cdf401e54feeb Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 10 Oct 2026 20:16:46 +0200 Subject: [PATCH] mesh-delivery: rebase only a first phase that starts at the walk's merge; a class without a budget is said unknown --- modules/mesh-delivery/cmd/mesh-delivery/times.go | 9 ++++++++- .../mesh-delivery/cmd/mesh-delivery/times_test.go | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/modules/mesh-delivery/cmd/mesh-delivery/times.go b/modules/mesh-delivery/cmd/mesh-delivery/times.go index df1b37e8..b65172a3 100644 --- a/modules/mesh-delivery/cmd/mesh-delivery/times.go +++ b/modules/mesh-delivery/cmd/mesh-delivery/times.go @@ -98,7 +98,7 @@ func timeOf(d *Delivery, w Walk) *DeliveryTime { if ph.End == nil { continue } - if ph.State == phaseMeasured { + if ph.State == phaseMeasured && ph.Start != nil && ph.Start.Equal(*p.From) { start := from ph.Start = &start ph.TookMS = ph.End.Sub(from).Milliseconds() @@ -140,6 +140,9 @@ func longestOf(phases []WalkPhase) string { // timeWalk keeps, on every delivery the walk answers, its delivery time once the walk's end is known; a delivery // whose time did not change is not written again (issue 326). func (h *Holder) timeWalk(w Walk) { + if s, ok := h.walks[w.ID]; ok && s.walk.Revision > w.Revision { + w = s.walk // an older record arriving late: the newest says the time + } if w.Phases == nil || w.Phases.End == nil { return } @@ -247,6 +250,10 @@ func (h *Holder) times(days int) TimesAnswer { if d.Time.End.Before(since) { continue } + if _, ok := budgets[d.Time.Class]; !ok { + a.Unknown = append(a.Unknown, fmt.Sprintf("%s: took %s, its class %q has no budget", d.ID, d.Time.Took, d.Time.Class)) + continue + } took[d.Time.Class] = append(took[d.Time.Class], d) } sort.Strings(a.Unknown) diff --git a/modules/mesh-delivery/cmd/mesh-delivery/times_test.go b/modules/mesh-delivery/cmd/mesh-delivery/times_test.go index cfc800ee..98f08a6f 100644 --- a/modules/mesh-delivery/cmd/mesh-delivery/times_test.go +++ b/modules/mesh-delivery/cmd/mesh-delivery/times_test.go @@ -83,6 +83,19 @@ func TestADeliveryKeepsItsTimeFromItsOwnMerge(t *testing.T) { if d.Time.Phases[0].TookMS != 80000 || !strings.HasPrefix(d.Time.Longest, "judgement") { t.Fatalf("its window starts at its own merge (80s), longest judgement: %+v %s", d.Time.Phases[0], d.Time.Longest) } + // Its own merge after a first phase whose start is unknown: the unknown time moves, the sum holds. + p := phasesOf("leaf", from, ph{"window", 90 * time.Second}, ph{"build", 30 * time.Second}) + p.Phases[0] = WalkPhase{Name: "window", Tier: -1, State: phaseUnknown, End: p.Phases[0].End} + p.UnknownMS = 90000 + dt := timeOf(&Delivery{MergedAt: from.Add(10 * time.Second)}, Walk{ID: "w", Phases: p}) + if dt.UnknownMS != 80000 || dt.TookMS != 110000 { + t.Fatalf("unknown first phase: %+v", dt) + } + // Exactly its budget is within it. + p = phasesOf("leaf", from, ph{"build", 5*time.Minute + 10*time.Second}) + if dt := timeOf(&Delivery{MergedAt: from.Add(10 * time.Second)}, Walk{ID: "w", Phases: p}); dt.Over || dt.TookMS != 300000 { + t.Fatalf("five minutes is within a leaf's budget: %+v", dt) + } // Seen again, unchanged: not written again (issue 326). before := w.store.puts w.h.Reconcile()