H-A-480 c: test the rank wait and the clear's guard; say a mark lost to every race

Review round 1: the line that never marks a module waiting for its rank and the
clear's "only while the have still says the mark" had no failing test; each now
has one. A mark whose every write lost its race is now said, not dropped silently
(P-failure-loud).

Builds: design 47 H2 H-A-480 (review round 1 finding)
This commit is contained in:
2026-11-22 16:19:14 +01:00
parent a22769bbc6
commit 43839ae66a
2 changed files with 71 additions and 7 deletions
+9 -1
View File
@@ -762,7 +762,7 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
// The hold says what it waits on, as every hold but a failed backup does (design 47 G A-453, section 541).
wait = a.composeWait(strings.TrimSuffix(heldReason(why), ":"), why)
}
written := false
written, lost := false, 0
for try := 0; try < markTries && !written; try++ {
if ctx.Err() != nil {
return
@@ -789,6 +789,7 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
break
}
// The have moved since it was read: read it again, and judge the mark against what it says now.
lost++
h, rev, found, unread := a.readHaveAt(ctx, module)
if unread {
break
@@ -799,6 +800,13 @@ func (a *Agent) NotComposedEach(ctx context.Context, why string, held map[string
}
}
if !written {
if lost == markTries {
// Every write lost its race to another: not marked, and said (P-failure-loud); the next refusal marks it.
a.mu.Lock()
a.sayOnce("unmarked-moved:"+module, fmt.Sprintf("%s is not marked: its have moved under each of %d writes, and the node cannot compose it: %s",
module, markTries, why))
a.mu.Unlock()
}
continue
}
mark.why = why
+62 -6
View File
@@ -2347,15 +2347,22 @@ func testAComposersMarkKeepsWhatWasWrittenSinceItsRead(t *testing.T) {
failed := Have{Module: "second", Phase: string(nodeengineclient.PhaseFailed), Detail: "the apply failed: no space left"}
for _, row := range []struct {
name string
// between writes the module's have between the composer's read and its write.
between func(ctx context.Context, b *bed)
check func(h Have) bool
// before writes the module's have before the composer reads it; between writes it between its read and its write.
before, between func(ctx context.Context, b *bed)
check func(h Have) bool
}{
{"a wait for its rank", func(ctx context.Context, b *bed) { b.ag.placingHave(ctx, "second", []string{"first"}) },
{"a module that runs and waits for its rank", func(ctx context.Context, b *bed) {
b.ag.running["second"] = nodeengine.HaveByNodeModuleValue{Fp: fpOf("a"), Composed: "sha256:" + strings.Repeat("1", 64), Phase: nodeengineclient.PhaseRunning}
b.ag.placingHave(ctx, "second", []string{"first"})
}, nil,
func(h Have) bool {
return h.Phase == string(nodeengineclient.PhaseHeld) && h.Wait != nil && h.Wait.Step == nodeengine.WaitStepPlacing && h.Wait.On == "first"
}},
{"another cause", func(ctx context.Context, b *bed) { b.haves.Write(ctx, failed) },
{"a wait for its rank", nil, func(ctx context.Context, b *bed) { b.ag.placingHave(ctx, "second", []string{"first"}) },
func(h Have) bool {
return h.Phase == string(nodeengineclient.PhaseHeld) && h.Wait != nil && h.Wait.Step == nodeengine.WaitStepPlacing && h.Wait.On == "first"
}},
{"another cause", nil, func(ctx context.Context, b *bed) { b.haves.Write(ctx, failed) },
func(h Have) bool { return h.Phase == failed.Phase && h.Detail == failed.Detail }},
} {
t.Run(row.name, func(t *testing.T) {
@@ -2363,7 +2370,12 @@ func testAComposersMarkKeepsWhatWasWrittenSinceItsRead(t *testing.T) {
b.ag = New(b.env)
ctx := context.Background()
b.ag.wants["second"] = wantNow{Want: meshwants.WantsByWantNodeModuleValue{Fp: fpOf("b"), Pipeline: "main.7", Rank: 2}, Present: true}
b.haves.afterRead = map[string]func(){"second": func() { row.between(ctx, b) }}
if row.before != nil {
row.before(ctx, b)
}
if row.between != nil {
b.haves.afterRead = map[string]func(){"second": func() { row.between(ctx, b) }}
}
b.ag.NotComposedEach(ctx, "", map[string]string{"second": why})
if h := b.haves.last("second"); !row.check(h) {
t.Fatalf("what was written between the composer's read and its write was overwritten: %+v", h)
@@ -2385,4 +2397,48 @@ func testAComposersMarkKeepsWhatWasWrittenSinceItsRead(t *testing.T) {
t.Fatalf("the mark of a module that never ran stays once it composes: %+v", h)
}
})
t.Run("a cause written between the mark and its clear is kept", func(t *testing.T) {
b := newBed(t)
b.ag = New(b.env)
ctx := context.Background()
b.ag.wants["third"] = wantNow{Want: meshwants.WantsByWantNodeModuleValue{Fp: fpOf("c")}, Present: true}
b.haves.Write(ctx, Have{Module: "third", FP: fpOf("c"), Phase: string(nodeengineclient.PhaseRunning)})
b.ag.NotComposedEach(ctx, "", map[string]string{"third": why})
cause := Have{Module: "third", FP: fpOf("c"), Phase: string(nodeengineclient.PhaseFailed), Detail: "the apply failed: no space left"}
b.haves.Write(ctx, cause)
b.ag.NotComposedEach(ctx, "", nil)
if h := b.haves.last("third"); h.Phase != cause.Phase || h.Detail != cause.Detail {
t.Fatalf("the clear of a mark wrote over a cause written since: %+v", h)
}
})
t.Run("a mark that loses every race is said", func(t *testing.T) {
b := newBed(t)
b.ag = New(b.env)
ctx := context.Background()
b.ag.wants["fourth"] = wantNow{Want: meshwants.WantsByWantNodeModuleValue{Fp: fpOf("d")}, Present: true}
running := Have{Module: "fourth", FP: fpOf("d"), Phase: string(nodeengineclient.PhaseRunning)}
b.haves.Write(ctx, running)
// Every read is followed by a write of what runs: the key moves under each mark.
var again func()
again = func() {
b.haves.Write(ctx, running)
b.haves.mu.Lock()
b.haves.afterRead["fourth"] = again
b.haves.mu.Unlock()
}
b.haves.afterRead = map[string]func(){"fourth": again}
b.ag.NotComposedEach(ctx, "", map[string]string{"fourth": why})
b.haves.mu.Lock()
b.haves.afterRead = nil
b.haves.mu.Unlock()
said := false
b.mu.Lock()
for _, l := range b.said {
said = said || strings.Contains(l, "fourth is not marked") && strings.Contains(l, "moved")
}
b.mu.Unlock()
if !said {
t.Fatalf("a mark dropped after every write lost its race was not said: %v", b.said)
}
})
}