mesh-delivery-pipeline: a lagging view drops no key for its own mover either (fix-770 round 5, issue 1984)

H-A-770 (6): H-A-770 (5) holds for H-A-761's drop of a key for its own mover too. While the
head is not newer than the revision of the pipeline a key names, the carry at a take-in
keeps the key and says so, runner_unfinished_place refuses naming both revisions and drops
nothing, and start reopens nothing and starts at the head as it does today, keeping the
key. The integration test's aged revision moves from 99 to 1, older than the head, since
a key naming a newer revision is now judged again rather than dropped.

Builds: design 47 H2 H-A-770 (5), (6), H-A-761
This commit is contained in:
2026-11-26 03:04:22 +01:00
parent 0049f591c5
commit 9e08d230e7
5 changed files with 85 additions and 10 deletions
@@ -39,6 +39,8 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
{Module: "free", Branches: []string{"main"}, Origin: "o/free", Policy: catalog.Policy{Steps: steps}}}
var newest atomic.Int64
newest.Store(1)
var aged atomic.Int64 // a revision the catalog keeps no more, none until the H-A-608 step ages revision 1 out
aged.Store(-1)
w := startWhole(t, ctx, regs, func(in []byte) catalog.RevisionAnswer {
var q catalog.RevisionInput
_ = json.Unmarshal(in, &q)
@@ -46,7 +48,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
if n == 0 {
n = newest.Load()
}
if n == 99 { // a revision the catalog keeps no more
if n == aged.Load() { // a revision the catalog keeps no more
return catalog.RevisionAnswer{}
}
lib, goFp := "l1", "src2:go"
@@ -368,12 +370,14 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
t.Error("main.gitea is still unfinished after main.8 passed")
}
// design 47 H2 H-A-608 (AC-P4), whole: free's key names revision 99, which the catalog keeps no more; the take-in of revision 9
// design 47 H2 H-A-608 (AC-P4), whole: free's key names revision 1, which the catalog keeps no more; the take-in of revision 9
// reads it at the head's revision, where free holds the key's fingerprint, and carries it; ghost's fingerprint is held at neither
// revision, so its key is dropped and the journal names the fingerprint and the revisions looked at.
// revision, so its key is dropped and the journal names the fingerprint and the revisions looked at. The keys name a revision
// older than the head's, since a head not newer than a key's pipeline drops nothing (H-A-770 (5), (6)).
aged.Store(1)
for key, entry := range map[string]string{
"main.free": `{"fingerprint":"src2:f2","revision":99,"pipeline":"main.99","outcome":"failed"}`,
"main.ghost": `{"fingerprint":"src2:zz","revision":99,"pipeline":"main.99","outcome":"failed"}`,
"main.free": `{"fingerprint":"src2:f2","revision":1,"pipeline":"main.1","outcome":"failed"}`,
"main.ghost": `{"fingerprint":"src2:zz","revision":1,"pipeline":"main.1","outcome":"failed"}`,
} {
if _, err := unfinished.Put(ctx, key, []byte(entry)); err != nil {
t.Fatal(err)
@@ -384,7 +388,7 @@ func TestAMoverLeftUnfinishedIsPutInTheNextPipelineAndWanted(t *testing.T) {
if pe := endOf(); pe.Pipeline != "main.9" || pe.Outcome != seat.PipelineEndedOutcomePassed || !moves("main.9", "app", "free") {
t.Fatalf("main.9 ended %s %s, moving free %t: want free read at the head's revision and carried\n%s", pe.Pipeline, pe.Outcome, moves("main.9", "free"), w.logs.String())
}
if _, ok := unfinishedEntry("main.ghost"); ok || !strings.Contains(w.logs.String(), "ghost is no longer unfinished at fingerprint src2:zz: its kept revision 99 is gone, the head's revision 9 of main holds it at") {
if _, ok := unfinishedEntry("main.ghost"); ok || !strings.Contains(w.logs.String(), "ghost is no longer unfinished at fingerprint src2:zz: its kept revision 1 is gone, the head's revision 9 of main holds it at") {
t.Errorf("main.ghost is kept, or the journal does not name its fingerprint and the revisions looked at:\n%s", w.logs.String())
}
@@ -202,8 +202,13 @@ func (v Verbs) ownFailedPipelines(branch, key string, movers []seat.Mover, half
}
// Only the newest pipeline that moves the module counts: a newer one that passed it leaves the failure behind.
found = found && best.Ended != nil && len(failedSteps(best, m.Module)) > 0
// H-A-761: it reopens only at the fingerprint the head's entry holds; otherwise its key is dropped and said.
if bm, _ := MoverOf(best, m.Module); found && bm.Fingerprint != m.Fingerprint {
// H-A-761: it reopens only at the fingerprint the head's entry holds; otherwise its key is dropped and said. While the head
// is not newer than that pipeline's revision, a lagging view, it reopens nothing and its key is kept (H-A-770 (5), (6)).
if bm, _ := MoverOf(best, m.Module); found && bm.Fingerprint != m.Fingerprint && half.Revision <= best.Revision {
s.logf("start of %s reopens nothing of %s, which moves it at %s: the head's revision %d of %s holds it at %s and is not newer than %s's revision %d, so its key is kept and it is judged again when the view moves (H-A-770 (5), (6))",
m.Module, best.Pipeline, bm.Fingerprint, half.Revision, branch, m.Fingerprint, best.Pipeline, best.Revision)
found = false
} else if found && bm.Fingerprint != m.Fingerprint {
if k := UnfinishedKey(branch, m.Module); s.Unfinished != nil {
if _, ok, _ := s.Unfinished.Entry(k); ok {
s.Unfinished.dropMoved(k, m.Module, bm.Fingerprint, fmt.Sprintf("%s moved it at %s (revision %d); the head's revision of %s holds it at %s (H-A-761)", best.Pipeline, bm.Fingerprint, best.Revision, branch, m.Fingerprint))
@@ -447,6 +452,11 @@ func (v Verbs) planUnfinished(key string) (handPlan, error) {
// the kept revision H-A-608 names stays the revision the record pins, and is only said.
kept := s.Unfinished.keptRevision(e, module)
head, hok := v.View(branch)
if he := head.Entries[module]; (!hok || he.Fp != e.Fingerprint) && head.Revision <= from.Revision {
// A lagging view: nothing is dropped and the key is judged again when the view moves (design 47 H2 H-A-770 (5), (6)).
return handPlan{}, fmt.Errorf("%s at fingerprint %s is not placed: the head's revision %d of %s holds it at %q and is not newer than the revision %d of its pipeline %s; its kept revision %d; nothing was dropped, it is judged again when the view moves (H-A-770 (5), (6))",
module, e.Fingerprint, head.Revision, branch, he.Fp, from.Revision, from.Pipeline, kept)
}
if he := head.Entries[module]; !hok || he.Fp != e.Fingerprint {
why := fmt.Sprintf("the head's revision %d of %s holds it at %q, not at the key's %q; its kept revision %d", head.Revision, branch, he.Fp, e.Fingerprint, kept)
s.Unfinished.dropMoved(key, module, e.Fingerprint, why)
@@ -725,6 +725,51 @@ func testAPredecessorANewerRevisionMovedTiesNothing(t *testing.T) {
}
}
})
// H-A-770 (6): the same holds for H-A-761's drop of a key for its own mover: the carry at a take-in of revision 5 or older keeps
// gitea's key of main.5, said, and carries nothing (the place's row is in TestTakenInStartsOnlyItsEntries).
t.Run("a lagging view: the carry at a take-in keeps the key", func(t *testing.T) {
for _, rev := range []int64{5, 4} {
var said []string
st := memUnfinished{"main.gitea": `{"fingerprint":"f2","revision":5,"pipeline":"main.5","outcome":"failed"}`}
u := &Unfinished{Store: st, Logf: func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }}
got := u.Carry("main", rev, map[string]catalog.CatalogEntry{"gitea": {Commit: "c7", Fp: "f2b"}}, nil)
if len(got) != 0 || st["main.gitea"] == "" || !strings.Contains(saidOf(said), "keeps its key") {
t.Errorf("a take-in of revision %d carried %+v, state %v, said %q: want the key kept and said, nothing carried", rev, got, st, said)
}
}
})
// H-A-770 (6): start with the view at revision 9, older than main.10, which failed app at src2:aa, while the view holds app at
// src2:a2: it reopens nothing, starts at the head as it does today, and keeps app's key, said.
t.Run("a lagging view: start keeps the key", func(t *testing.T) {
reg, entries := placeFixture()
e := entries["app"]
e.Fp, e.Commit = "src2:a2", "c2"
view := Half{Revision: 9, Source: 40, Entries: map[string]catalog.CatalogEntry{"app": e, "mesh-build-go": entries["mesh-build-go"]}}
store := &MoverStore{Raw: newMemRaw()}
end := time.Unix(50, 0)
old := seat.Pipeline{V: 1, Pipeline: Key("main", 10), Branch: "main", Revision: 10, Source: 41, Outcome: seat.PipelineOutcomeFailed, Ended: &end, EndCount: 1,
Movers: []seat.Mover{{Module: "app", Commit: "c1", Fingerprint: "src2:aa", Repository: "o/app"}},
Steps: []seat.StepResult{{Module: "app", Artifact: "app:program", Step: seat.StepResultStepLint, Status: seat.StepResultStatusRequired, Outcome: seat.StepResultOutcomeFailed, Ended: &end}}}
raw, _ := json.Marshal(old)
if err := store.Create(old.Pipeline, raw); err != nil {
t.Fatal(err)
}
u := memUnfinished{"main.app": `{"fingerprint":"src2:aa","revision":10,"pipeline":"` + old.Pipeline + `","outcome":"failed"}`}
var said []string
logf := func(f string, a ...any) { said = append(said, fmt.Sprintf(f, a...)) }
s := &Starter{Pipelines: store, Store: store, Steps: &stepAsks{}, Name: "the-runner", Now: ticking(), Say: func(string, any) error { return nil }, Logf: logf,
Revision: func(string, int64) (Half, error) { return view, nil },
Registration: func(m string) (catalog.Registration, bool) { return reg, m == "app" }, Unfinished: &Unfinished{Store: u, Logf: logf}}
v := Verbs{Starter: s, Hearer: &Hearer{Store: store, Unfinished: s.Unfinished, Say: func(string, any) error { return nil }},
View: func(string) (Half, bool) { return view, true }, Acts: &actLog{}}
a, err := v.Start("op@shanks", seat.StartInput{Branch: "main", Module: "app", Why: "again"})
if err != nil || a.Pipeline != Key("main", 9) || u["main.app"] == "" || !strings.Contains(saidOf(said), "reopens nothing of main.10") {
t.Errorf("start = %+v (%v), app's key %q, said %q: want main.9 started at the head, the key kept and said", a, err, u["main.app"], said)
}
if p, _, _ := store.Get(old.Pipeline); p.Ended == nil {
t.Errorf("main.10 was reopened, want it left ended")
}
})
// The finding pipeline-failed's held-behind list (H-A-625 (2)) reads the head as the carry does: gitea awaits the failed engine's
// package and mate awaits gitea's; a mover a newer revision moved is held behind nothing and holds nothing behind it.
t.Run("the finding's held-behind list", func(t *testing.T) {
@@ -555,7 +555,14 @@ func TestTakenInStartsOnlyItsEntries(t *testing.T) {
return Half{Revision: r, Source: 5, Entries: map[string]catalog.CatalogEntry{"batched": {Commit: "c0", Fp: "src2:o9"}}}, nil
}
u["main.batched"] = `{"fingerprint":"src2:o9","revision":9,"pipeline":"main.14","outcome":"failed"}`
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "older fingerprint"}); err == nil || !strings.Contains(err.Error(), "src2:o9") || !strings.Contains(err.Error(), "src2:bb") || !strings.Contains(err.Error(), "revision 9") || !strings.Contains(err.Error(), "revision 14") {
// H-A-770 (5), (6): with the view at main.14's own revision, a lagging view, the place is refused naming both revisions and
// nothing is dropped; at a newer head the key goes.
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "lagging view"}); err == nil || !strings.Contains(err.Error(), "is not placed") ||
!strings.Contains(err.Error(), "head's revision 14") || !strings.Contains(err.Error(), "revision 14 of its pipeline main.14") || u["main.batched"] == "" {
t.Errorf("place-unfinished with the view at the pipeline's revision = %v, key %q: want it refused naming both revisions and the key kept", err, u["main.batched"])
}
half.Revision = 15
if _, err = v.PlaceUnfinished("agent.dev", seat.PlaceUnfinishedInput{Key: "main.batched", Why: "older fingerprint"}); err == nil || !strings.Contains(err.Error(), "src2:o9") || !strings.Contains(err.Error(), "src2:bb") || !strings.Contains(err.Error(), "revision 9") || !strings.Contains(err.Error(), "revision 15") {
t.Errorf("place-unfinished of a key at an older fingerprint = %v, want it refused naming both fingerprints and the revisions", err)
}
if _, ok := u["main.batched"]; ok {
@@ -455,7 +455,9 @@ func (u *Unfinished) heldBack(branch, module string, e UnfinishedEntry, head Hal
// own fingerprint is carried by the revision already. A key whose carrier waits or runs is skipped (H-A-594 (4)); one tied to
// a failed mover the revision does not move is kept, tied, until that mover passes or leaves the registrations (H-A-594 (2),
// H-A-610); a failed mover whose entry in entries holds another fingerprint than its pipeline's, which a newer revision moved,
// ties nothing, said (design 47 H2 H-A-594 (2), H-A-761). It answers movers with the added ones after them.
// ties nothing, said (design 47 H2 H-A-594 (2), H-A-761). While revision is not newer than the revision of the pipeline a key
// names, a key whose entry holds another fingerprint is kept, said, not dropped (H-A-770 (5), (6)). It answers movers with the
// added ones after them.
func (u *Unfinished) Carry(branch string, revision int64, entries map[string]catalog.CatalogEntry, movers []seat.Mover) []seat.Mover {
if u == nil {
return movers
@@ -490,6 +492,13 @@ func (u *Unfinished) Carry(branch string, revision int64, entries map[string]cat
continue
}
entry, why, ok := u.entryOf(branch, revision, entries, module, e)
if !ok && revision <= e.Revision {
// A head not newer than the key's pipeline is a lagging view: the key is kept and judged again when the view moves
// (design 47 H2 H-A-770 (5), (6)).
u.logf("revision %d of %s does not carry %s and keeps its key: %s, but revision %d is not newer than the revision %d of its pipeline %s, so it is judged again when the view moves (H-A-770 (5), (6))",
revision, branch, module, why, revision, e.Revision, e.Pipeline)
continue
}
if !ok {
u.dropMoved(key, module, e.Fingerprint, why)
continue